Commit 11475975 authored by Ryusuke Konishi's avatar Ryusuke Konishi Committed by Linus Torvalds

nilfs2: flush disk caches in syncing

There are two cases that the cache flush is needed to avoid data loss
against unexpected hang or power failure.  One is sync file function (i.e.
 nilfs_sync_file) and another is checkpointing ioctl.

This issues a cache flush request to device for such cases if barrier
mount option is enabled, and makes sure data really is on persistent
storage on their completion.
Signed-off-by: default avatarRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent a1d49449
...@@ -37,6 +37,7 @@ int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -37,6 +37,7 @@ int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
* This function should be implemented when the writeback function * This function should be implemented when the writeback function
* will be implemented. * will be implemented.
*/ */
struct the_nilfs *nilfs;
struct inode *inode = file->f_mapping->host; struct inode *inode = file->f_mapping->host;
int err; int err;
...@@ -45,18 +46,21 @@ int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -45,18 +46,21 @@ int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
return err; return err;
mutex_lock(&inode->i_mutex); mutex_lock(&inode->i_mutex);
if (!nilfs_inode_dirty(inode)) { if (nilfs_inode_dirty(inode)) {
mutex_unlock(&inode->i_mutex); if (datasync)
return 0; err = nilfs_construct_dsync_segment(inode->i_sb, inode,
0, LLONG_MAX);
else
err = nilfs_construct_segment(inode->i_sb);
} }
if (datasync)
err = nilfs_construct_dsync_segment(inode->i_sb, inode, 0,
LLONG_MAX);
else
err = nilfs_construct_segment(inode->i_sb);
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
nilfs = inode->i_sb->s_fs_info;
if (!err && nilfs_test_opt(nilfs, BARRIER)) {
err = blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
if (err != -EIO)
err = 0;
}
return err; return err;
} }
......
...@@ -692,8 +692,14 @@ static int nilfs_ioctl_sync(struct inode *inode, struct file *filp, ...@@ -692,8 +692,14 @@ static int nilfs_ioctl_sync(struct inode *inode, struct file *filp,
if (ret < 0) if (ret < 0)
return ret; return ret;
nilfs = inode->i_sb->s_fs_info;
if (nilfs_test_opt(nilfs, BARRIER)) {
ret = blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
if (ret == -EIO)
return ret;
}
if (argp != NULL) { if (argp != NULL) {
nilfs = inode->i_sb->s_fs_info;
down_read(&nilfs->ns_segctor_sem); down_read(&nilfs->ns_segctor_sem);
cno = nilfs->ns_cno - 1; cno = nilfs->ns_cno - 1;
up_read(&nilfs->ns_segctor_sem); up_read(&nilfs->ns_segctor_sem);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment