ext4: honor O_(D)SYNC semantic in ext4_fallocate()
authorZheng Liu <gnehzuil.liu@gmail.com>
Sat, 30 Jun 2012 23:12:57 +0000 (19:12 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 30 Jun 2012 23:12:57 +0000 (19:12 -0400)
Ext4 must make sure the transaction to be commited to the disk when
user opens a file with O_(D)SYNC flag and do a fallocate(2) call.

This problem had been reported by Christoph Hellwig in this thread:
http://www.spinics.net/lists/linux-btrfs/msg13621.html

Reported-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
fs/ext4/extents.c

index 91341ec6e06a94f2f400d10039a64585cd17ed2e..f1089cba913a88d573fea673c8a406f26fe7a79d 100644 (file)
@@ -4420,6 +4420,8 @@ retry:
                ext4_falloc_update_inode(inode, mode, new_size,
                                         (map.m_flags & EXT4_MAP_NEW));
                ext4_mark_inode_dirty(handle, inode);
+               if ((file->f_flags & O_SYNC) && ret >= max_blocks)
+                       ext4_handle_sync(handle);
                ret2 = ext4_journal_stop(handle);
                if (ret2)
                        break;