Skip to content

Commit

Permalink
nfsd: fix double-locks of directory mutex
Browse files Browse the repository at this point in the history
A number of nfsd operations depend on the i_mutex to cover more code
than just the fsync, so the approach of 4c728ef "add a vfs_fsync
helper" doesn't work for nfsd.  Revert the parts of those patches that
touch nfsd.

Note: we can't, however, remove the logic from vfs_fsync that was needed
only for the special case of nfsd, because a vfs_fsync(NULL,...) call
can still result indirectly from a stackable filesystem that was called
by nfsd.  (Thanks to Christoph Hellwig for pointing this out.)

Reported-by: Eric Sesterhenn <snakebyte@gmx.de>
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
  • Loading branch information
J. Bruce Fields committed Jan 7, 2009
1 parent 2779e3a commit 9a8d248
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions fs/nfsd/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/*
Expand Down

0 comments on commit 9a8d248

Please sign in to comment.