Skip to content

Commit e2c7617

Browse files
zeitgeist87torvalds
authored andcommitted
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>
1 parent 0f2a84f commit e2c7617

5 files changed

Lines changed: 37 additions & 10 deletions

File tree

‎fs/nilfs2/file.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,9 @@ int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
5656
mutex_unlock(&inode->i_mutex);
5757

5858
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+
6462
return err;
6563
}
6664

‎fs/nilfs2/ioctl.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,11 +1022,9 @@ static int nilfs_ioctl_sync(struct inode *inode, struct file *filp,
10221022
return ret;
10231023

10241024
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;
10301028

10311029
if (argp != NULL) {
10321030
down_read(&nilfs->ns_segctor_sem);

‎fs/nilfs2/segment.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,7 @@ static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci)
18331833
nilfs_set_next_segment(nilfs, segbuf);
18341834

18351835
if (update_sr) {
1836+
nilfs->ns_flushed_device = 0;
18361837
nilfs_set_last_segment(nilfs, segbuf->sb_pseg_start,
18371838
segbuf->sb_sum.seg_seq, nilfs->ns_cno++);
18381839

@@ -2216,6 +2217,8 @@ int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode,
22162217
sci->sc_dsync_end = end;
22172218

22182219
err = nilfs_segctor_do_construct(sci, SC_LSEG_DSYNC);
2220+
if (!err)
2221+
nilfs->ns_flushed_device = 0;
22192222

22202223
nilfs_transaction_unlock(sb);
22212224
return err;

‎fs/nilfs2/super.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ int nilfs_commit_super(struct super_block *sb, int flag)
310310
nilfs->ns_sbsize));
311311
}
312312
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();
313316
return nilfs_sync_super(sb, flag);
314317
}
315318

@@ -514,6 +517,9 @@ static int nilfs_sync_fs(struct super_block *sb, int wait)
514517
}
515518
up_write(&nilfs->ns_sem);
516519

520+
if (!err)
521+
err = nilfs_flush_device(nilfs);
522+
517523
return err;
518524
}
519525

‎fs/nilfs2/the_nilfs.h‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ enum {
4646
/**
4747
* struct the_nilfs - struct to supervise multiple nilfs mount points
4848
* @ns_flags: flags
49+
* @ns_flushed_device: flag indicating if all volatile data was flushed
4950
* @ns_bdev: block device
5051
* @ns_sem: semaphore for shared states
5152
* @ns_snapshot_mount_mutex: mutex to protect snapshot mounts
@@ -103,6 +104,7 @@ enum {
103104
*/
104105
struct the_nilfs {
105106
unsigned long ns_flags;
107+
int ns_flushed_device;
106108

107109
struct block_device *ns_bdev;
108110
struct rw_semaphore ns_sem;
@@ -371,4 +373,24 @@ static inline int nilfs_segment_is_active(struct the_nilfs *nilfs, __u64 n)
371373
return n == nilfs->ns_segnum || n == nilfs->ns_nextnum;
372374
}
373375

376+
static inline int nilfs_flush_device(struct the_nilfs *nilfs)
377+
{
378+
int err;
379+
380+
if (!nilfs_test_opt(nilfs, BARRIER) || nilfs->ns_flushed_device)
381+
return 0;
382+
383+
nilfs->ns_flushed_device = 1;
384+
/*
385+
* the store to ns_flushed_device must not be reordered after
386+
* blkdev_issue_flush().
387+
*/
388+
smp_wmb();
389+
390+
err = blkdev_issue_flush(nilfs->ns_bdev, GFP_KERNEL, NULL);
391+
if (err != -EIO)
392+
err = 0;
393+
return err;
394+
}
395+
374396
#endif /* _THE_NILFS_H */

0 commit comments

Comments
 (0)