]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/nfsd/vfs.c
Use f_lock to protect f_flags
[linux-2.6-omap-h63xx.git] / fs / nfsd / vfs.c
index 44aa92aba891c96fa7061ee5dda5bc6aaf6f0fec..c165a6403df03e52219925b875ef420adcbd331a 100644 (file)
@@ -744,16 +744,44 @@ nfsd_close(struct file *filp)
        fput(filp);
 }
 
+/*
+ * Sync a file
+ * As this calls fsync (not fdatasync) there is no need for a write_inode
+ * after it.
+ */
+static inline int nfsd_dosync(struct file *filp, struct dentry *dp,
+                             const struct file_operations *fop)
+{
+       struct inode *inode = dp->d_inode;
+       int (*fsync) (struct file *, struct dentry *, int);
+       int err;
+
+       err = filemap_fdatawrite(inode->i_mapping);
+       if (err == 0 && fop && (fsync = fop->fsync))
+               err = fsync(filp, dp, 0);
+       if (err == 0)
+               err = filemap_fdatawait(inode->i_mapping);
+
+       return err;
+}
+
 static int
 nfsd_sync(struct file *filp)
 {
-       return vfs_fsync(filp, filp->f_path.dentry, 0);
+        int err;
+       struct inode *inode = filp->f_path.dentry->d_inode;
+       dprintk("nfsd: sync file %s\n", filp->f_path.dentry->d_name.name);
+       mutex_lock(&inode->i_mutex);
+       err=nfsd_dosync(filp, filp->f_path.dentry, filp->f_op);
+       mutex_unlock(&inode->i_mutex);
+
+       return err;
 }
 
 int
-nfsd_sync_dir(struct dentry *dentry)
+nfsd_sync_dir(struct dentry *dp)
 {
-       return vfs_fsync(NULL, dentry, 0);
+       return nfsd_dosync(NULL, dp, dp->d_inode->i_fop);
 }
 
 /*
@@ -970,8 +998,11 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
 
        if (!EX_ISSYNC(exp))
                stable = 0;
-       if (stable && !EX_WGATHER(exp))
+       if (stable && !EX_WGATHER(exp)) {
+               spin_lock(&file->f_lock);
                file->f_flags |= O_SYNC;
+               spin_unlock(&file->f_lock);
+       }
 
        /* Write the data. */
        oldfs = get_fs(); set_fs(KERNEL_DS);