From: "J. Bruce Fields" <bfields@fieldses.org>
To: dai.ngo@oracle.com
Cc: chuck.lever@oracle.com, jlayton@redhat.com,
viro@zeniv.linux.org.uk, linux-nfs@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH RFC v23 5/7] fs/lock: add 2 callbacks to lock_manager_operations to resolve conflict
Date: Fri, 29 Apr 2022 21:18:26 -0400 [thread overview]
Message-ID: <20220430011826.GA14842@fieldses.org> (raw)
In-Reply-To: <20220429195819.GI7107@fieldses.org>
On Fri, Apr 29, 2022 at 03:58:19PM -0400, J. Bruce Fields wrote:
> On Fri, Apr 29, 2022 at 10:24:11AM -0700, dai.ngo@oracle.com wrote:
> >
> > On 4/29/22 8:16 AM, J. Bruce Fields wrote:
> > >On Thu, Apr 28, 2022 at 12:06:33AM -0700, Dai Ngo wrote:
> > >>Add 2 new callbacks, lm_lock_expirable and lm_expire_lock, to
> > >>lock_manager_operations to allow the lock manager to take appropriate
> > >>action to resolve the lock conflict if possible.
> > >>
> > >>A new field, lm_mod_owner, is also added to lock_manager_operations.
> > >>The lm_mod_owner is used by the fs/lock code to make sure the lock
> > >>manager module such as nfsd, is not freed while lock conflict is being
> > >>resolved.
> > >>
> > >>lm_lock_expirable checks and returns true to indicate that the lock
> > >>conflict can be resolved else return false. This callback must be
> > >>called with the flc_lock held so it can not block.
> > >>
> > >>lm_expire_lock is called to resolve the lock conflict if the returned
> > >>value from lm_lock_expirable is true. This callback is called without
> > >>the flc_lock held since it's allowed to block. Upon returning from
> > >>this callback, the lock conflict should be resolved and the caller is
> > >>expected to restart the conflict check from the beginnning of the list.
> > >>
> > >>Lock manager, such as NFSv4 courteous server, uses this callback to
> > >>resolve conflict by destroying lock owner, or the NFSv4 courtesy client
> > >>(client that has expired but allowed to maintains its states) that owns
> > >>the lock.
> > >>
> > >>Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
> > >>---
> > >> Documentation/filesystems/locking.rst | 4 ++++
> > >> fs/locks.c | 45 +++++++++++++++++++++++++++++++----
> > >> include/linux/fs.h | 3 +++
> > >> 3 files changed, 48 insertions(+), 4 deletions(-)
> > >>
> > >>diff --git a/Documentation/filesystems/locking.rst b/Documentation/filesystems/locking.rst
> > >>index c26d854275a0..0997a258361a 100644
> > >>--- a/Documentation/filesystems/locking.rst
> > >>+++ b/Documentation/filesystems/locking.rst
> > >>@@ -428,6 +428,8 @@ prototypes::
> > >> void (*lm_break)(struct file_lock *); /* break_lease callback */
> > >> int (*lm_change)(struct file_lock **, int);
> > >> bool (*lm_breaker_owns_lease)(struct file_lock *);
> > >>+ bool (*lm_lock_expirable)(struct file_lock *);
> > >>+ void (*lm_expire_lock)(void);
> > >> locking rules:
> > >>@@ -439,6 +441,8 @@ lm_grant: no no no
> > >> lm_break: yes no no
> > >> lm_change yes no no
> > >> lm_breaker_owns_lease: yes no no
> > >>+lm_lock_expirable yes no no
> > >>+lm_expire_lock no no yes
> > >> ====================== ============= ================= =========
> > >> buffer_head
> > >>diff --git a/fs/locks.c b/fs/locks.c
> > >>index c369841ef7d1..d48c3f455657 100644
> > >>--- a/fs/locks.c
> > >>+++ b/fs/locks.c
> > >>@@ -896,6 +896,37 @@ static bool flock_locks_conflict(struct file_lock *caller_fl,
> > >> return locks_conflict(caller_fl, sys_fl);
> > >> }
> > >>+static bool
> > >>+resolve_lock_conflict_locked(struct file_lock_context *ctx,
> > >>+ struct file_lock *cfl, bool rwsem)
> > >>+{
> > >>+ void *owner;
> > >>+ bool ret;
> > >>+ void (*func)(void);
> > >>+
> > >>+ if (cfl->fl_lmops && cfl->fl_lmops->lm_lock_expirable &&
> > >>+ cfl->fl_lmops->lm_expire_lock) {
> > >>+ ret = (*cfl->fl_lmops->lm_lock_expirable)(cfl);
> > >>+ if (!ret)
> > >>+ return false;
> > >>+ owner = cfl->fl_lmops->lm_mod_owner;
> > >>+ if (!owner)
> > >>+ return false;
> > >>+ func = cfl->fl_lmops->lm_expire_lock;
> > >>+ __module_get(owner);
> > >>+ if (rwsem)
> > >>+ percpu_up_read(&file_rwsem);
> > >>+ spin_unlock(&ctx->flc_lock);
> > >Dropping and reacquiring locks inside a function like this makes me
> > >nervous. It means it's not obvious in the caller that the lock isn't
> > >held throughout.
> > >
> > >I know it's more verbose, but let's just open-code this logic in the
> > >callers.
> >
> > fix in v24.
> >
> > >
> > >(And, thanks for catching the test_lock case, I'd forgotten it.)
> > >
> > >Also: do we *really* need to drop the file_rwsem? Were you seeing it
> > >that cause problems? The only possible conflict is with someone trying
> > >to read /proc/locks, and I'm surprised that it'd be a problem to let
> > >them wait here.
> >
> > Yes, apparently file_rwsem is used when the laundromat expires the
> > COURTESY client client and causes deadlock.
>
> It's taken, but only for read. I'm rather surprised that would cause a
> deadlock. Do you have any kind of trace showing what happened?
>
> Oh well, it's not a big deal to just open code this and set the "retry:"
> before both lock acquisitions, that's probably best in fact. I'm just
> curious.
I remember running across this:
https://lore.kernel.org/linux-nfs/20210927201433.GA1704@fieldses.org/
though that didn't involve the laundromat. Were you seeing an actual
deadlock with these new patches? Or a lockdep warning like that one?
--b.
next prev parent reply other threads:[~2022-04-30 1:18 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-28 7:06 [PATCH RFC v23 0/7] NFSD: Initial implementation of NFSv4 Courteous Server Dai Ngo
2022-04-28 7:06 ` [PATCH RFC v23 1/7] NFSD: add courteous server support for thread with only delegation Dai Ngo
2022-04-29 14:16 ` J. Bruce Fields
2022-04-29 17:26 ` dai.ngo
2022-04-29 14:55 ` J. Bruce Fields
2022-04-29 17:21 ` dai.ngo
2022-04-29 19:55 ` J. Bruce Fields
2022-04-29 19:59 ` J. Bruce Fields
2022-04-28 7:06 ` [PATCH RFC v23 2/7] NFSD: add support for share reservation conflict to courteous server Dai Ngo
2022-04-29 14:36 ` J. Bruce Fields
2022-04-29 17:20 ` dai.ngo
2022-04-28 7:06 ` [PATCH RFC v23 3/7] NFSD: move create/destroy of laundry_wq to init_nfsd and exit_nfsd Dai Ngo
2022-04-28 7:06 ` [PATCH RFC v23 4/7] fs/lock: add helper locks_owner_has_blockers to check for blockers Dai Ngo
2022-04-28 7:06 ` [PATCH RFC v23 5/7] fs/lock: add 2 callbacks to lock_manager_operations to resolve conflict Dai Ngo
2022-04-29 15:16 ` J. Bruce Fields
2022-04-29 17:24 ` dai.ngo
2022-04-29 19:58 ` J. Bruce Fields
2022-04-30 1:18 ` J. Bruce Fields [this message]
2022-04-30 22:54 ` dai.ngo
2022-04-28 7:06 ` [PATCH RFC v23 6/7] NFSD: add support for lock conflict to courteous server Dai Ngo
2022-04-28 7:06 ` [PATCH RFC v23 7/7] NFSD: Show state of courtesy client in client info Dai Ngo
2022-04-28 15:03 ` [PATCH RFC v23 0/7] NFSD: Initial implementation of NFSv4 Courteous Server Chuck Lever III
2022-04-29 15:25 ` J. Bruce Fields
2022-04-29 16:56 ` Chuck Lever III
2022-04-29 17:40 ` dai.ngo
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=20220430011826.GA14842@fieldses.org \
--to=bfields@fieldses.org \
--cc=chuck.lever@oracle.com \
--cc=dai.ngo@oracle.com \
--cc=jlayton@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).