diff options
author | Christoph Hellwig <hch@lst.de> | 2009-12-25 11:45:13 -0500 |
---|---|---|
committer | J. Bruce Fields <bfields@citi.umich.edu> | 2010-01-13 09:42:26 -0500 |
commit | 6a68f89ee1f2d177af4a5410fa7a45734c975fd6 (patch) | |
tree | 1a462b27a4d783d1b6a368bf6cf9c7970f93b8ae /fs/nfsd/vfs.c | |
parent | de3cab793c6a5c8505d66bee111edcc7098380ba (diff) |
nfsd: use vfs_fsync for non-directories
Instead of opencoding the fsync calling sequence use vfs_fsync. This also
gets rid of the useless i_mutex over the data writeout.
Consolidate the remaining special code for syncing directories and document
it's quirks.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
Diffstat (limited to 'fs/nfsd/vfs.c')
-rw-r--r-- | fs/nfsd/vfs.c | 49 |
1 files changed, 17 insertions, 32 deletions
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index c194793b642b..79d216f276d9 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c | |||
@@ -769,40 +769,25 @@ nfsd_close(struct file *filp) | |||
769 | } | 769 | } |
770 | 770 | ||
771 | /* | 771 | /* |
772 | * Sync a file | 772 | * Sync a directory to disk. |
773 | * As this calls fsync (not fdatasync) there is no need for a write_inode | 773 | * |
774 | * after it. | 774 | * We can't just call vfs_fsync because our requirements are slightly odd: |
775 | * | ||
776 | * a) we do not have a file struct available | ||
777 | * b) we expect to have i_mutex already held by the caller | ||
775 | */ | 778 | */ |
776 | static inline int nfsd_dosync(struct file *filp, struct dentry *dp, | 779 | int |
777 | const struct file_operations *fop) | 780 | nfsd_sync_dir(struct dentry *dentry) |
778 | { | ||
779 | struct inode *inode = dp->d_inode; | ||
780 | int (*fsync) (struct file *, struct dentry *, int); | ||
781 | int err; | ||
782 | |||
783 | err = filemap_write_and_wait(inode->i_mapping); | ||
784 | if (err == 0 && fop && (fsync = fop->fsync)) | ||
785 | err = fsync(filp, dp, 0); | ||
786 | return err; | ||
787 | } | ||
788 | |||
789 | static int | ||
790 | nfsd_sync(struct file *filp) | ||
791 | { | 781 | { |
792 | int err; | 782 | struct inode *inode = dentry->d_inode; |
793 | struct inode *inode = filp->f_path.dentry->d_inode; | 783 | int error; |
794 | dprintk("nfsd: sync file %s\n", filp->f_path.dentry->d_name.name); | ||
795 | mutex_lock(&inode->i_mutex); | ||
796 | err=nfsd_dosync(filp, filp->f_path.dentry, filp->f_op); | ||
797 | mutex_unlock(&inode->i_mutex); | ||
798 | 784 | ||
799 | return err; | 785 | WARN_ON(!mutex_is_locked(&inode->i_mutex)); |
800 | } | ||
801 | 786 | ||
802 | int | 787 | error = filemap_write_and_wait(inode->i_mapping); |
803 | nfsd_sync_dir(struct dentry *dp) | 788 | if (!error && inode->i_fop->fsync) |
804 | { | 789 | error = inode->i_fop->fsync(NULL, dentry, 0); |
805 | return nfsd_dosync(NULL, dp, dp->d_inode->i_fop); | 790 | return error; |
806 | } | 791 | } |
807 | 792 | ||
808 | /* | 793 | /* |
@@ -1008,7 +993,7 @@ static int wait_for_concurrent_writes(struct file *file) | |||
1008 | 993 | ||
1009 | if (inode->i_state & I_DIRTY) { | 994 | if (inode->i_state & I_DIRTY) { |
1010 | dprintk("nfsd: write sync %d\n", task_pid_nr(current)); | 995 | dprintk("nfsd: write sync %d\n", task_pid_nr(current)); |
1011 | err = nfsd_sync(file); | 996 | err = vfs_fsync(file, file->f_path.dentry, 0); |
1012 | } | 997 | } |
1013 | last_ino = inode->i_ino; | 998 | last_ino = inode->i_ino; |
1014 | last_dev = inode->i_sb->s_dev; | 999 | last_dev = inode->i_sb->s_dev; |
@@ -1177,7 +1162,7 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp, | |||
1177 | return err; | 1162 | return err; |
1178 | if (EX_ISSYNC(fhp->fh_export)) { | 1163 | if (EX_ISSYNC(fhp->fh_export)) { |
1179 | if (file->f_op && file->f_op->fsync) { | 1164 | if (file->f_op && file->f_op->fsync) { |
1180 | err = nfserrno(nfsd_sync(file)); | 1165 | err = nfserrno(vfs_fsync(file, file->f_path.dentry, 0)); |
1181 | } else { | 1166 | } else { |
1182 | err = nfserr_notsupp; | 1167 | err = nfserr_notsupp; |
1183 | } | 1168 | } |