From: Trond Myklebust <trond.myklebust@fys.uio.no>
To: "Dr. J. Bruce Fields" <bfields@fieldses.org>
Cc: linux-nfs@vger.kernel.org
Subject: Re: nfsd: Replace nfsd_sync() with vfs_fsync() and vfs_fsync_range()
Date: Fri, 29 Jan 2010 15:35:17 -0500 [thread overview]
Message-ID: <1264797317.3644.10.camel@localhost> (raw)
In-Reply-To: <1264796353.3644.4.camel@localhost>
On Fri, 2010-01-29 at 15:19 -0500, Trond Myklebust wrote:
> From: Trond Myklebust <Trond.Myklebust@netapp.com>
>
> Currently, the nfs server holds the inode->i_mutex across both the
> filemap_write_and_wait() call and the fsync() call itself. However we know
> that filemap_write_and_wait() is already safe against livelocks, so we only
> need to hold the mutex across the fsync() call.
>
> Fix this by reusing vfs_fsync(), which already does the right thing.
> Also make sure that we use vfs_fsync_range() in the COMMIT operation, to
> improve the efficiency for clients that do specify a range.
>
> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
> ---
>
> fs/nfsd/vfs.c | 58 +++++++++++++++++++++------------------------------------
> 1 files changed, 21 insertions(+), 37 deletions(-)
>
>
> diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
> index c194793..e4568d6 100644
> --- a/fs/nfsd/vfs.c
> +++ b/fs/nfsd/vfs.c
> @@ -769,40 +769,17 @@ nfsd_close(struct file *filp)
> }
>
> /*
> - * Sync a file
> - * As this calls fsync (not fdatasync) there is no need for a write_inode
> - * after it.
> + * Sync a directory
> + * returns 0 if the directory had no fsync method
> */
> -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_write_and_wait(inode->i_mapping);
> - if (err == 0 && fop && (fsync = fop->fsync))
> - err = fsync(filp, dp, 0);
> - return err;
> -}
> -
> -static int
> -nfsd_sync(struct file *filp)
> -{
> - 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 *dp)
> {
> - return nfsd_dosync(NULL, dp, dp->d_inode->i_fop);
> + int err;
> +
> + dprintk("nfsd: sync directory %s\n", dp->d_name.name);
> + err = vfs_fsync(NULL, dp, 0);
> + return (err != -EINVAL) ? err : 0;
> }
>
> /*
> @@ -1008,7 +985,9 @@ static int wait_for_concurrent_writes(struct file *file)
>
> if (inode->i_state & I_DIRTY) {
> dprintk("nfsd: write sync %d\n", task_pid_nr(current));
> - err = nfsd_sync(file);
> + err = vfs_fsync(file, file->f_path.dentry, 0);
> + if (err == -EINVAL)
> + err = 0;
> }
> last_ino = inode->i_ino;
> last_dev = inode->i_sb->s_dev;
> @@ -1156,8 +1135,6 @@ out:
> #ifdef CONFIG_NFSD_V3
> /*
> * Commit all pending writes to stable storage.
> - * Strictly speaking, we could sync just the indicated file region here,
> - * but there's currently no way we can ask the VFS to do so.
> *
> * Unfortunately we cannot lock the file to make sure we return full WCC
> * data to the client, as locking happens lower down in the filesystem.
> @@ -1176,11 +1153,18 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp,
> if (err)
> return err;
> if (EX_ISSYNC(fhp->fh_export)) {
> - if (file->f_op && file->f_op->fsync) {
> - err = nfserrno(nfsd_sync(file));
> - } else {
> + loff_t end = LLONG_MAX;
> + int err2;
> +
> + if (count != 0)
> + end = offset + count;
> + err2 = vfs_fsync_range(file, file->f_path.dentry,
> + offset, end, 0);
> +
Actually, we should probably check for offset < 0 || end < offset. I'll
add that...
Cheers
Trond
next prev parent reply other threads:[~2010-01-29 20:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-29 20:19 nfsd: Replace nfsd_sync() with vfs_fsync() and vfs_fsync_range() Trond Myklebust
2010-01-29 20:35 ` Trond Myklebust [this message]
2010-01-29 20:44 ` [PATCH v2] " Trond Myklebust
2010-01-29 20:50 ` Christoph Hellwig
2010-01-29 20:57 ` Trond Myklebust
2010-01-29 21:18 ` nfsd: Use vfs_fsync_range() in nfsd_commit Trond Myklebust
2010-01-29 21:27 ` Christoph Hellwig
2010-01-29 21:39 ` Trond Myklebust
2010-01-29 23:58 ` Dr. J. Bruce Fields
2010-03-17 19:08 ` Jeff Layton
[not found] ` <20100317150813.43815b5a-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2010-03-17 19:35 ` Trond Myklebust
2010-01-29 21:44 ` [PATCH v4] " Trond Myklebust
2010-01-29 23:53 ` Dr. J. Bruce Fields
2010-01-29 23:54 ` Dr. J. Bruce Fields
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1264797317.3644.10.camel@localhost \
--to=trond.myklebust@fys.uio.no \
--cc=bfields@fieldses.org \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.