Linux NFS development
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@poochiereds.net>
To: Trond Myklebust <trond.myklebust@primarydata.com>
Cc: Benjamin Coddington <bcodding@redhat.com>,
	Linux NFS Mailing List <linux-nfs@vger.kernel.org>,
	Anna Schumaker <anna.schumaker@netapp.com>
Subject: Re: [PATCH 08/10] NFS: Move do_vfs_lock to shared inline
Date: Wed, 21 Oct 2015 19:49:40 -0400	[thread overview]
Message-ID: <20151021194940.76d3d9f8@tlielax.poochiereds.net> (raw)
In-Reply-To: <CAHQdGtTYxUdJvvALn0o=KVAwyNxCO03JXhexFysbjq6p9wrjUQ@mail.gmail.com>

On Wed, 21 Oct 2015 14:48:45 -0700
Trond Myklebust <trond.myklebust@primarydata.com> wrote:

> On Wed, Oct 14, 2015 at 12:55 PM, Jeff Layton <jlayton@poochiereds.net> wrote:
> >
> > On Wed, 14 Oct 2015 14:23:35 -0400
> > Benjamin Coddington <bcodding@redhat.com> wrote:
> >
> > > Send the inode instead of the file_lock to do_vfs_lock() in
> > > fs/lockd/clintproc.c (because there may not be a fl_file the unlock path).
> > > Now that we have posix_lock_inode_wait() the three copies of do_vfs_lock()
> > > can be collapsed.
> > >
> > > Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
> > > ---
> > >  fs/lockd/clntproc.c |   25 +++++--------------------
> > >  fs/nfs/file.c       |   20 ++------------------
> > >  fs/nfs/nfs4proc.c   |   16 ----------------
> > >  include/linux/fs.h  |   16 ++++++++++++++++
> > >  4 files changed, 23 insertions(+), 54 deletions(-)
> > >
> > > diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
> > > index 4a35e7c..bd484f0 100644
> > > --- a/fs/lockd/clntproc.c
> > > +++ b/fs/lockd/clntproc.c
> > > @@ -475,22 +475,6 @@ static void nlmclnt_locks_init_private(struct file_lock *fl, struct nlm_host *ho
> > >       fl->fl_ops = &nlmclnt_lock_ops;
> > >  }
> > >
> > > -static int do_vfs_lock(struct file_lock *fl)
> > > -{
> > > -     int res = 0;
> > > -     switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
> > > -             case FL_POSIX:
> > > -                     res = posix_lock_file_wait(fl->fl_file, fl);
> > > -                     break;
> > > -             case FL_FLOCK:
> > > -                     res = flock_lock_file_wait(fl->fl_file, fl);
> > > -                     break;
> > > -             default:
> > > -                     BUG();
> > > -     }
> > > -     return res;
> > > -}
> > > -
> > >  /*
> > >   * LOCK: Try to create a lock
> > >   *
> > > @@ -518,6 +502,7 @@ nlmclnt_lock(struct nlm_rqst *req, struct file_lock *fl)
> > >       struct nlm_host *host = req->a_host;
> > >       struct nlm_res  *resp = &req->a_res;
> > >       struct nlm_wait *block = NULL;
> > > +     struct inode *inode = file_inode(fl->fl_file);
> > >       unsigned char fl_flags = fl->fl_flags;
> > >       unsigned char fl_type;
> > >       int status = -ENOLCK;
> > > @@ -527,7 +512,7 @@ nlmclnt_lock(struct nlm_rqst *req, struct file_lock *fl)
> > >       req->a_args.state = nsm_local_state;
> > >
> > >       fl->fl_flags |= FL_ACCESS;
> > > -     status = do_vfs_lock(fl);
> > > +     status = do_vfs_lock(inode, fl);
> > >       fl->fl_flags = fl_flags;
> > >       if (status < 0)
> > >               goto out;
> > > @@ -577,7 +562,7 @@ again:
> > >               }
> > >               /* Ensure the resulting lock will get added to granted list */
> > >               fl->fl_flags |= FL_SLEEP;
> > > -             if (do_vfs_lock(fl) < 0)
> > > +             if (do_vfs_lock(inode, fl) < 0)
> > >                       printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __func__);
> > >               up_read(&host->h_rwsem);
> > >               fl->fl_flags = fl_flags;
> > > @@ -607,7 +592,7 @@ out_unlock:
> > >       fl_type = fl->fl_type;
> > >       fl->fl_type = F_UNLCK;
> > >       down_read(&host->h_rwsem);
> > > -     do_vfs_lock(fl);
> > > +     do_vfs_lock(inode, fl);
> > >       up_read(&host->h_rwsem);
> > >       fl->fl_type = fl_type;
> > >       fl->fl_flags = fl_flags;
> > > @@ -674,7 +659,7 @@ nlmclnt_unlock(struct nfs_open_context *ctx, struct nlm_rqst *req, struct file_l
> > >        */
> > >       fl->fl_flags |= FL_EXISTS;
> > >       down_read(&host->h_rwsem);
> > > -     status = do_vfs_lock(fl);
> > > +     status = do_vfs_lock(d_inode(ctx->dentry), fl);
> > >       up_read(&host->h_rwsem);
> > >       fl->fl_flags = fl_flags;
> > >       if (status == -ENOENT) {
> > > diff --git a/fs/nfs/file.c b/fs/nfs/file.c
> > > index 319847c..d16c50f 100644
> > > --- a/fs/nfs/file.c
> > > +++ b/fs/nfs/file.c
> > > @@ -737,22 +737,6 @@ out_noconflict:
> > >       goto out;
> > >  }
> > >
> > > -static int do_vfs_lock(struct file *file, struct file_lock *fl)
> > > -{
> > > -     int res = 0;
> > > -     switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
> > > -             case FL_POSIX:
> > > -                     res = posix_lock_file_wait(file, fl);
> > > -                     break;
> > > -             case FL_FLOCK:
> > > -                     res = flock_lock_file_wait(file, fl);
> > > -                     break;
> > > -             default:
> > > -                     BUG();
> > > -     }
> > > -     return res;
> > > -}
> > > -
> > >  static int
> > >  do_unlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)
> > >  {
> > > @@ -786,7 +770,7 @@ do_unlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)
> > >       if (!is_local)
> > >               status = NFS_PROTO(inode)->lock(ctx, cmd, fl);
> > >       else
> > > -             status = do_vfs_lock(filp, fl);
> > > +             status = do_vfs_lock(inode, fl);
> > >       return status;
> > >  }
> > >
> > > @@ -817,7 +801,7 @@ do_setlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)
> > >       if (!is_local)
> > >               status = NFS_PROTO(inode)->lock(ctx, cmd, fl);
> > >       else
> > > -             status = do_vfs_lock(filp, fl);
> > > +             status = do_vfs_lock(inode, fl);
> > >       if (status < 0)
> > >               goto out;
> > >
> > > diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
> > > index c08f8ac..6b19307 100644
> > > --- a/fs/nfs/nfs4proc.c
> > > +++ b/fs/nfs/nfs4proc.c
> > > @@ -5511,22 +5511,6 @@ static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *
> > >       return err;
> > >  }
> > >
> > > -static int do_vfs_lock(struct inode *inode, struct file_lock *fl)
> > > -{
> > > -     int res = 0;
> > > -     switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
> > > -             case FL_POSIX:
> > > -                     res = posix_lock_inode_wait(inode, fl);
> > > -                     break;
> > > -             case FL_FLOCK:
> > > -                     res = flock_lock_inode_wait(inode, fl);
> > > -                     break;
> > > -             default:
> > > -                     BUG();
> > > -     }
> > > -     return res;
> > > -}
> > > -
> > >  struct nfs4_unlockdata {
> > >       struct nfs_locku_args arg;
> > >       struct nfs_locku_res res;
> > > diff --git a/include/linux/fs.h b/include/linux/fs.h
> > > index 72d8a84..165577a 100644
> > > --- a/include/linux/fs.h
> > > +++ b/include/linux/fs.h
> > > @@ -1225,6 +1225,22 @@ static inline int flock_lock_file_wait(struct file *filp, struct file_lock *fl)
> > >       return flock_lock_inode_wait(file_inode(filp), fl);
> > >  }
> > >
> > > +static inline int do_vfs_lock(struct inode *inode, struct file_lock *fl)
> > > +{
> > > +     int res = 0;
> > > +     switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
> > > +             case FL_POSIX:
> > > +                     res = posix_lock_inode_wait(inode, fl);
> > > +                     break;
> > > +             case FL_FLOCK:
> > > +                     res = flock_lock_inode_wait(inode, fl);
> > > +                     break;
> > > +             default:
> > > +                     BUG();
> > > +     }
> > > +     return res;
> > > +}
> > > +
> > >  struct fasync_struct {
> > >       spinlock_t              fa_lock;
> > >       int                     magic;
> >
> > Meh ok...a little large for an inline though. Maybe you should move
> > that into fs/nfs_common and have it as an exported symbol? I'm not too
> > religious about it though since we don't have many call sites.
> 
> Is this ready to merge, or should we hold off pending an update?

This one is really fine IMO, but I do have a bit of concern with the
last patch in the series. That one adds an allocation to the unlock
codepath. If that fails then a dangling lock could be left hanging
around on the server. I think it's possible to do this without
allocating anything there, so I'd like to see that changed.

Otherwise, the set looks good to me. Nice work!

-- 
Jeff Layton <jlayton@poochiereds.net>

  reply	other threads:[~2015-10-21 23:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-14 18:23 [PATCH 00/10] locking fixups for NFS Benjamin Coddington
2015-10-14 18:23 ` [PATCH 01/10] NFS: keep nfs4_state for nfs4_lock_state cleanup Benjamin Coddington
2015-10-14 18:23 ` [PATCH 02/10] NFS4: remove a redundant lock range checks Benjamin Coddington
2015-10-14 18:23 ` [PATCH 03/10] NFS: Move the flock open mode check into nfs_flock() Benjamin Coddington
2015-10-14 18:23 ` [PATCH 04/10] NFS: Pass nfs_open_context instead of file to the lock procs Benjamin Coddington
2015-10-14 18:23 ` [PATCH 05/10] NFSv4: Pass nfs_open_context instead of nfs4_state to nfs4_proc_unlck() Benjamin Coddington
2015-10-14 18:23 ` [PATCH 06/10] lockd: Plumb nfs_open_context into nlm client unlock Benjamin Coddington
2015-10-14 18:23 ` [PATCH 07/10] lockd: Send the inode to nlmclnt_setlockargs() Benjamin Coddington
2015-10-14 18:23 ` [PATCH 08/10] NFS: Move do_vfs_lock to shared inline Benjamin Coddington
2015-10-14 19:55   ` Jeff Layton
2015-10-21 21:48     ` Trond Myklebust
2015-10-21 23:49       ` Jeff Layton [this message]
2015-10-22  0:11       ` Benjamin Coddington
2015-10-22  8:34       ` Christoph Hellwig
2015-10-22 15:50         ` Benjamin Coddington
2015-10-14 18:23 ` [PATCH 09/10] locks: Use more file_inode and fix a comment Benjamin Coddington
2015-10-14 19:56   ` Jeff Layton
2015-10-14 18:23 ` [PATCH 10/10] NFS: Deferred unlocks - always unlock on FL_CLOSE Benjamin Coddington
2015-10-14 20:30   ` Jeff Layton
2015-12-07 16:05     ` Benjamin Coddington

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=20151021194940.76d3d9f8@tlielax.poochiereds.net \
    --to=jlayton@poochiereds.net \
    --cc=anna.schumaker@netapp.com \
    --cc=bcodding@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trond.myklebust@primarydata.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox