Can O_SYNC be implemented by using fsync?

From: Ulrich Kunitz (gefm21@uumail.de)
Date: Sat May 13 2000 - 06:36:59 EST


Hi,

this discusses item 5.1 in Alan's list of outstanding fixes before 2.4.

I'm using fsync to write out all dirty pages/blocks of a file in
generic_file_write to get O_SYNC behaviour. Patch is included below. It
is the wrong way to do O_SYNC? I've checked this and it seems to do what
would be expected and it caused no harm to me.

Another idea would be to use sync_page() in generic_file_write() that
calls block_sync_page() for ext2. block_sync_page() calls only
run_rask_queue(tq_disk). IMHO adding of sync_page_buffers() to
block_sync_page() would be required and there is still the inode and
superblock infos, that need to be written to disk before
generic_file_write() returns.

Which kernel version did support O_SYNC for ext2? AFAIK 2.2 kernels
don't support O_SYNC.

This is my patch:

--- linux-2.3.99-pre8/mm/filemap.c Sat May 13 10:13:32 2000
+++ linux-2.3.99-pre8-uk1/mm/filemap.c Sat May 13 10:43:21 2000
@@ -39,6 +39,8 @@
  * page-cache, 21.05.1999, Ingo Molnar <mingo@redhat.com>
  *
  * SMP-threaded pagemap-LRU 1999, Andrea Arcangeli <andrea@suse.de>
+ *
+ * O_SYNC support, 29. 4. 2000, Ulrich Kunitz <gefm21@uumail,de>
  */
 
 atomic_t page_cache_size = ATOMIC_INIT(0);
@@ -2521,7 +2523,14 @@
         if (cached_page)
                 page_cache_free(cached_page);
 
+ if ((file->f_flags & O_SYNC) && file->f_op && file->f_op->fsync) {
+ err = file->f_op->fsync(file, file->f_dentry);
+ if (err < 0)
+ status = err;
+ }
+
         err = written ? written : status;
+
 out:
         up(&inode->i_sem);
         return err;

Ciao,

Uli Kunitz

-- 
Ulrich Kunitz (gefm21@uumail.de)

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon May 15 2000 - 21:00:22 EST