Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nilfs2: add missing blkdev_issue_flush() to nilfs_sync_fs()

Under normal circumstances nilfs_sync_fs() writes out the super block,
which causes a flush of the underlying block device. But this depends
on the THE_NILFS_SB_DIRTY flag, which is only set if the pointer to the
last segment crosses a segment boundary. So if only a small amount of
data is written before the call to nilfs_sync_fs(), no flush of the
block device occurs.

In the above case an additional call to blkdev_issue_flush() is needed.
To prevent unnecessary overhead, the new flag nilfs->ns_flushed_device
is introduced, which is cleared whenever new logs are written and set
whenever the block device is flushed. For convenience the function
nilfs_flush_device() is added, which contains the above logic.

Signed-off-by: Andreas Rohner <andreas.rohner@gmx.net>
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Andreas Rohner and committed by
Linus Torvalds
e2c7617a 0f2a84f4

+37 -10
+3 -5
fs/nilfs2/file.c
··· 56 56 mutex_unlock(&inode->i_mutex); 57 57 58 58 nilfs = inode->i_sb->s_fs_info; 59 - if (!err && nilfs_test_opt(nilfs, BARRIER)) { 60 - err = blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL); 61 - if (err != -EIO) 62 - err = 0; 63 - } 59 + if (!err) 60 + err = nilfs_flush_device(nilfs); 61 + 64 62 return err; 65 63 } 66 64
+3 -5
fs/nilfs2/ioctl.c
··· 1022 1022 return ret; 1023 1023 1024 1024 nilfs = inode->i_sb->s_fs_info; 1025 - if (nilfs_test_opt(nilfs, BARRIER)) { 1026 - ret = blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL); 1027 - if (ret == -EIO) 1028 - return ret; 1029 - } 1025 + ret = nilfs_flush_device(nilfs); 1026 + if (ret < 0) 1027 + return ret; 1030 1028 1031 1029 if (argp != NULL) { 1032 1030 down_read(&nilfs->ns_segctor_sem);
+3
fs/nilfs2/segment.c
··· 1833 1833 nilfs_set_next_segment(nilfs, segbuf); 1834 1834 1835 1835 if (update_sr) { 1836 + nilfs->ns_flushed_device = 0; 1836 1837 nilfs_set_last_segment(nilfs, segbuf->sb_pseg_start, 1837 1838 segbuf->sb_sum.seg_seq, nilfs->ns_cno++); 1838 1839 ··· 2217 2216 sci->sc_dsync_end = end; 2218 2217 2219 2218 err = nilfs_segctor_do_construct(sci, SC_LSEG_DSYNC); 2219 + if (!err) 2220 + nilfs->ns_flushed_device = 0; 2220 2221 2221 2222 nilfs_transaction_unlock(sb); 2222 2223 return err;
+6
fs/nilfs2/super.c
··· 310 310 nilfs->ns_sbsize)); 311 311 } 312 312 clear_nilfs_sb_dirty(nilfs); 313 + nilfs->ns_flushed_device = 1; 314 + /* make sure store to ns_flushed_device cannot be reordered */ 315 + smp_wmb(); 313 316 return nilfs_sync_super(sb, flag); 314 317 } 315 318 ··· 516 513 } 517 514 } 518 515 up_write(&nilfs->ns_sem); 516 + 517 + if (!err) 518 + err = nilfs_flush_device(nilfs); 519 519 520 520 return err; 521 521 }
+22
fs/nilfs2/the_nilfs.h
··· 46 46 /** 47 47 * struct the_nilfs - struct to supervise multiple nilfs mount points 48 48 * @ns_flags: flags 49 + * @ns_flushed_device: flag indicating if all volatile data was flushed 49 50 * @ns_bdev: block device 50 51 * @ns_sem: semaphore for shared states 51 52 * @ns_snapshot_mount_mutex: mutex to protect snapshot mounts ··· 104 103 */ 105 104 struct the_nilfs { 106 105 unsigned long ns_flags; 106 + int ns_flushed_device; 107 107 108 108 struct block_device *ns_bdev; 109 109 struct rw_semaphore ns_sem; ··· 371 369 static inline int nilfs_segment_is_active(struct the_nilfs *nilfs, __u64 n) 372 370 { 373 371 return n == nilfs->ns_segnum || n == nilfs->ns_nextnum; 372 + } 373 + 374 + static inline int nilfs_flush_device(struct the_nilfs *nilfs) 375 + { 376 + int err; 377 + 378 + if (!nilfs_test_opt(nilfs, BARRIER) || nilfs->ns_flushed_device) 379 + return 0; 380 + 381 + nilfs->ns_flushed_device = 1; 382 + /* 383 + * the store to ns_flushed_device must not be reordered after 384 + * blkdev_issue_flush(). 385 + */ 386 + smp_wmb(); 387 + 388 + err = blkdev_issue_flush(nilfs->ns_bdev, GFP_KERNEL, NULL); 389 + if (err != -EIO) 390 + err = 0; 391 + return err; 374 392 } 375 393 376 394 #endif /* _THE_NILFS_H */