diff options
author | Christoph Hellwig <hch@lst.de> | 2010-10-06 10:48:20 +0200 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2010-10-25 21:18:19 -0400 |
commit | c37650161a53c01ddd88587675f9a4adc909a73e (patch) | |
tree | 85821998de9a6723dedc42488b9491db9692d1e3 | |
parent | 81fca444001e5a41ab80ce8cf9a5734c00ec6546 (diff) |
fs: add sync_inode_metadata
Add a new helper to write out the inode using the writeback code,
that is including the correct dirty bit and list manipulation. A few
of filesystems already opencode this, and a lot of others should be
using it instead of using write_inode_now which also writes out the
data.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | drivers/staging/pohmelfs/inode.c | 6 | ||||
-rw-r--r-- | fs/exofs/file.c | 6 | ||||
-rw-r--r-- | fs/ext2/dir.c | 2 | ||||
-rw-r--r-- | fs/ext2/ext2.h | 1 | ||||
-rw-r--r-- | fs/ext2/inode.c | 11 | ||||
-rw-r--r-- | fs/ext2/xattr.c | 2 | ||||
-rw-r--r-- | fs/fs-writeback.c | 20 | ||||
-rw-r--r-- | fs/libfs.c | 6 | ||||
-rw-r--r-- | fs/nfsd/vfs.c | 16 | ||||
-rw-r--r-- | include/linux/fs.h | 1 |
10 files changed, 30 insertions, 41 deletions
diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c index 97dae297ca3..c62d30017c0 100644 --- a/drivers/staging/pohmelfs/inode.c +++ b/drivers/staging/pohmelfs/inode.c @@ -882,12 +882,8 @@ static struct inode *pohmelfs_alloc_inode(struct super_block *sb) static int pohmelfs_fsync(struct file *file, int datasync) { struct inode *inode = file->f_mapping->host; - struct writeback_control wbc = { - .sync_mode = WB_SYNC_ALL, - .nr_to_write = 0, /* sys_fsync did this */ - }; - return sync_inode(inode, &wbc); + return sync_inode_metadata(inode, 1); } ssize_t pohmelfs_write(struct file *file, const char __user *buf, diff --git a/fs/exofs/file.c b/fs/exofs/file.c index 68cb23e3bb9..b905c79b4f0 100644 --- a/fs/exofs/file.c +++ b/fs/exofs/file.c @@ -46,10 +46,6 @@ static int exofs_file_fsync(struct file *filp, int datasync) { int ret; struct inode *inode = filp->f_mapping->host; - struct writeback_control wbc = { - .sync_mode = WB_SYNC_ALL, - .nr_to_write = 0, /* metadata-only; caller takes care of data */ - }; struct super_block *sb; if (!(inode->i_state & I_DIRTY)) @@ -57,7 +53,7 @@ static int exofs_file_fsync(struct file *filp, int datasync) if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) return 0; - ret = sync_inode(inode, &wbc); + ret = sync_inode_metadata(inode, 1); /* This is a good place to write the sb */ /* TODO: Sechedule an sb-sync on create */ diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c index 764109886ec..2709b34206a 100644 --- a/fs/ext2/dir.c +++ b/fs/ext2/dir.c @@ -98,7 +98,7 @@ static int ext2_commit_chunk(struct page *page, loff_t pos, unsigned len) if (IS_DIRSYNC(dir)) { err = write_one_page(page, 1); if (!err) - err = ext2_sync_inode(dir); + err = sync_inode_metadata(dir, 1); } else { unlock_page(page); } diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h index 416daa62242..6346a2acf32 100644 --- a/fs/ext2/ext2.h +++ b/fs/ext2/ext2.h @@ -120,7 +120,6 @@ extern unsigned long ext2_count_free (struct buffer_head *, unsigned); extern struct inode *ext2_iget (struct super_block *, unsigned long); extern int ext2_write_inode (struct inode *, struct writeback_control *); extern void ext2_evict_inode(struct inode *); -extern int ext2_sync_inode (struct inode *); extern int ext2_get_block(struct inode *, sector_t, struct buffer_head *, int); extern int ext2_setattr (struct dentry *, struct iattr *); extern void ext2_set_inode_flags(struct inode *inode); diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index 533699c1604..40ad210a504 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -1203,7 +1203,7 @@ static int ext2_setsize(struct inode *inode, loff_t newsize) inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC; if (inode_needs_sync(inode)) { sync_mapping_buffers(inode->i_mapping); - ext2_sync_inode (inode); + sync_inode_metadata(inode, 1); } else { mark_inode_dirty(inode); } @@ -1523,15 +1523,6 @@ int ext2_write_inode(struct inode *inode, struct writeback_control *wbc) return __ext2_write_inode(inode, wbc->sync_mode == WB_SYNC_ALL); } -int ext2_sync_inode(struct inode *inode) -{ - struct writeback_control wbc = { - .sync_mode = WB_SYNC_ALL, - .nr_to_write = 0, /* sys_fsync did this */ - }; - return sync_inode(inode, &wbc); -} - int ext2_setattr(struct dentry *dentry, struct iattr *iattr) { struct inode *inode = dentry->d_inode; diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c index 8c29ae15129..f84700be327 100644 --- a/fs/ext2/xattr.c +++ b/fs/ext2/xattr.c @@ -699,7 +699,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh, EXT2_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0; inode->i_ctime = CURRENT_TIME_SEC; if (IS_SYNC(inode)) { - error = ext2_sync_inode (inode); + error = sync_inode_metadata(inode, 1); /* In case sync failed due to ENOSPC the inode was actually * written (only some dirty data were not) so we just proceed * as if nothing happened and cleanup the unused block */ diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index ab38fef1c9a..29e3f409bbd 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -1198,3 +1198,23 @@ int sync_inode(struct inode *inode, struct writeback_control *wbc) return ret; } EXPORT_SYMBOL(sync_inode); + +/** + * sync_inode - write an inode to disk + * @inode: the inode to sync + * @wait: wait for I/O to complete. + * + * Write an inode to disk and adjust it's dirty state after completion. + * + * Note: only writes the actual inode, no associated data or other metadata. + */ +int sync_inode_metadata(struct inode *inode, int wait) +{ + struct writeback_control wbc = { + .sync_mode = wait ? WB_SYNC_ALL : WB_SYNC_NONE, + .nr_to_write = 0, /* metadata-only */ + }; + + return sync_inode(inode, &wbc); +} +EXPORT_SYMBOL(sync_inode_metadata); diff --git a/fs/libfs.c b/fs/libfs.c index 62baa0387d6..2dbf4877d7e 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -892,10 +892,6 @@ EXPORT_SYMBOL_GPL(generic_fh_to_parent); */ int generic_file_fsync(struct file *file, int datasync) { - struct writeback_control wbc = { - .sync_mode = WB_SYNC_ALL, - .nr_to_write = 0, /* metadata-only; caller takes care of data */ - }; struct inode *inode = file->f_mapping->host; int err; int ret; @@ -906,7 +902,7 @@ int generic_file_fsync(struct file *file, int datasync) if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) return ret; - err = sync_inode(inode, &wbc); + err = sync_inode_metadata(inode, 1); if (ret == 0) ret = err; return ret; diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 661a6cf8e82..184938fcff0 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -281,23 +281,13 @@ commit_metadata(struct svc_fh *fhp) { struct inode *inode = fhp->fh_dentry->d_inode; const struct export_operations *export_ops = inode->i_sb->s_export_op; - int error = 0; if (!EX_ISSYNC(fhp->fh_export)) return 0; - if (export_ops->commit_metadata) { - error = export_ops->commit_metadata(inode); - } else { - struct writeback_control wbc = { - .sync_mode = WB_SYNC_ALL, - .nr_to_write = 0, /* metadata only */ - }; - - error = sync_inode(inode, &wbc); - } - - return error; + if (export_ops->commit_metadata) + return export_ops->commit_metadata(inode); + return sync_inode_metadata(inode, 1); } /* diff --git a/include/linux/fs.h b/include/linux/fs.h index 4f34ff6e555..0b03f490572 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1734,6 +1734,7 @@ static inline void file_accessed(struct file *file) } int sync_inode(struct inode *inode, struct writeback_control *wbc); +int sync_inode_metadata(struct inode *inode, int wait); struct file_system_type { const char *name; |