From: dai.ngo@oracle.com
To: Jeff Layton <jlayton@kernel.org>, chuck.lever@oracle.com
Cc: linux-nfs@vger.kernel.org, linux-nfs@stwm.de
Subject: Re: [PATCH 2/3] NFSD: restore delegation's sc_count if nfsd4_run_cb fails
Date: Fri, 15 Dec 2023 12:00:37 -0800 [thread overview]
Message-ID: <dc7a582f-3898-4f92-9fcf-bf76373f657d@oracle.com> (raw)
In-Reply-To: <5b07e47d33925128400559f6c5eef694a9984279.camel@kernel.org>
On 12/15/23 11:42 AM, Jeff Layton wrote:
> On Fri, 2023-12-15 at 11:15 -0800, Dai Ngo wrote:
>> Under some load conditions the callback work request can not be queued
>> and nfsd4_run_cb returns 0 to caller. When this happens, the sc_count
>> of the delegation state was left with an extra reference count preventing
>> the state to be freed later.
>>
>> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
>> ---
>> fs/nfsd/nfs4state.c | 17 +++++++++++++----
>> 1 file changed, 13 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>> index 40415929e2ae..175f3e9f5822 100644
>> --- a/fs/nfsd/nfs4state.c
>> +++ b/fs/nfsd/nfs4state.c
>> @@ -2947,8 +2947,14 @@ void nfs4_cb_getattr(struct nfs4_cb_fattr *ncf)
>>
>> if (test_and_set_bit(CB_GETATTR_BUSY, &ncf->ncf_cb_flags))
>> return;
>> +
>> refcount_inc(&dp->dl_stid.sc_count);
>> - nfsd4_run_cb(&ncf->ncf_getattr);
>> + if (!nfsd4_run_cb(&ncf->ncf_getattr)) {
>> + refcount_dec(&dp->dl_stid.sc_count);
>> + clear_bit(CB_GETATTR_BUSY, &ncf->ncf_cb_flags);
>> + wake_up_bit(&ncf->ncf_cb_flags, CB_GETATTR_BUSY);
>> + WARN_ON_ONCE(1);
>> + }
>> }
>>
>> static struct nfs4_client *create_client(struct xdr_netobj name,
>> @@ -4967,7 +4973,10 @@ static void nfsd_break_one_deleg(struct nfs4_delegation *dp)
>> * we know it's safe to take a reference.
>> */
>> refcount_inc(&dp->dl_stid.sc_count);
>> - WARN_ON_ONCE(!nfsd4_run_cb(&dp->dl_recall));
>> + if (!nfsd4_run_cb(&dp->dl_recall)) {
>> + refcount_dec(&dp->dl_stid.sc_count);
>> + WARN_ON_ONCE(1);
>> + }
>> }
>>
>> /* Called from break_lease() with flc_lock held. */
>> @@ -8543,12 +8552,12 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct inode *inode,
>> return 0;
>> }
>> break_lease:
>> - spin_unlock(&ctx->flc_lock);
>> nfsd_stats_wdeleg_getattr_inc();
>> -
>> dp = fl->fl_owner;
>> ncf = &dp->dl_cb_fattr;
>> nfs4_cb_getattr(&dp->dl_cb_fattr);
>> + spin_unlock(&ctx->flc_lock);
>> +
> The other hunks in this patch make sense, but what's going on here with
> moving the lock down? Do we really need to hold the spinlock there? If
> so, I would have expected to see an explanation in the changelog.
We need to hold the flc_lock to prevent the lease to be removed which
allows the delegation state to be released. We need to do this since
we just do the refcount_dec if nfsd4_run_cb fails, instead of doing
nfs4_put_stid to free the state if this is the last refcount.
This is done to match the logic in nfsd_break_deleg_cb which has an useful
comment in nfsd_break_one_deleg.
-Dai
>
>> wait_on_bit(&ncf->ncf_cb_flags, CB_GETATTR_BUSY, TASK_INTERRUPTIBLE);
>> if (ncf->ncf_cb_status) {
>> status = nfserrno(nfsd_open_break_lease(inode, NFSD_MAY_READ));
next prev parent reply other threads:[~2023-12-15 20:02 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-15 19:15 [PATCH 0/3] Bug fixes for NFSD callback Dai Ngo
2023-12-15 19:15 ` [PATCH 1/3] SUNRPC: remove printk when back channel request not found Dai Ngo
2023-12-15 19:37 ` Jeff Layton
2023-12-15 19:15 ` [PATCH 2/3] NFSD: restore delegation's sc_count if nfsd4_run_cb fails Dai Ngo
2023-12-15 19:42 ` Jeff Layton
2023-12-15 20:00 ` dai.ngo [this message]
2023-12-15 20:15 ` Jeff Layton
2023-12-15 20:22 ` dai.ngo
2023-12-15 19:15 ` [PATCH 3/3] NFSD: Fix server reboot hang problem when callback workqueue is stuck Dai Ngo
2023-12-15 19:54 ` Chuck Lever
2023-12-15 20:40 ` dai.ngo
2023-12-15 21:41 ` Chuck Lever
2023-12-15 21:55 ` dai.ngo
2023-12-16 1:21 ` Chuck Lever
2023-12-16 3:18 ` dai.ngo
2023-12-16 3:57 ` Chuck Lever
2023-12-16 22:44 ` dai.ngo
2023-12-18 16:02 ` Chuck Lever
2023-12-18 18:17 ` dai.ngo
2023-12-18 19:10 ` Chuck Lever
2023-12-18 20:27 ` dai.ngo
2023-12-15 19:54 ` Jeff Layton
2023-12-15 20:18 ` dai.ngo
2023-12-15 20:25 ` Jeff Layton
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=dc7a582f-3898-4f92-9fcf-bf76373f657d@oracle.com \
--to=dai.ngo@oracle.com \
--cc=chuck.lever@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-nfs@stwm.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox