From: Jeff Layton <jlayton@kernel.org>
To: dai.ngo@oracle.com, chuck.lever@oracle.com
Cc: linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v4 3/4] NFSD: handle GETATTR conflict with write delegation
Date: Mon, 22 May 2023 09:49:00 -0400 [thread overview]
Message-ID: <09113712aa83d9010ec3963368bce840dfb762db.camel@kernel.org> (raw)
In-Reply-To: <2eed123d-66fb-44a6-ba1a-c365b8bbd0be@oracle.com>
On Sun, 2023-05-21 at 20:56 -0700, dai.ngo@oracle.com wrote:
> On 5/21/23 7:56 PM, dai.ngo@oracle.com wrote:
> >
> > On 5/21/23 4:08 PM, Jeff Layton wrote:
> > > On Sat, 2023-05-20 at 14:36 -0700, Dai Ngo wrote:
> > > > If the GETATTR request on a file that has write delegation in effect
> > > > and the request attributes include the change info and size attribute
> > > > then the write delegation is recalled and NFS4ERR_DELAY is returned
> > > > for the GETATTR.
> > > >
> > > > Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
> > > > ---
> > > > fs/nfsd/nfs4xdr.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
> > > > 1 file changed, 45 insertions(+)
> > > >
> > > > diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
> > > > index 76db2fe29624..e069b970f136 100644
> > > > --- a/fs/nfsd/nfs4xdr.c
> > > > +++ b/fs/nfsd/nfs4xdr.c
> > > > @@ -2920,6 +2920,46 @@ nfsd4_encode_bitmap(struct xdr_stream *xdr,
> > > > u32 bmval0, u32 bmval1, u32 bmval2)
> > > > return nfserr_resource;
> > > > }
> > > > +static struct file_lock *
> > > > +nfs4_wrdeleg_filelock(struct svc_rqst *rqstp, struct inode *inode)
> > > > +{
> > > > + struct file_lock_context *ctx;
> > > > + struct file_lock *fl;
> > > > +
> > > > + ctx = locks_inode_context(inode);
> > > > + if (!ctx)
> > > > + return NULL;
> > > > + spin_lock(&ctx->flc_lock);
> > > > + if (!list_empty(&ctx->flc_lease)) {
> > > > + fl = list_first_entry(&ctx->flc_lease,
> > > > + struct file_lock, fl_list);
> > > > + if (fl->fl_type == F_WRLCK) {
> > > > + spin_unlock(&ctx->flc_lock);
> > > > + return fl;
> > > > + }
One more issue here too. FL_LAYOUT file_locks live on this list too.
They shouldn't conflict with leases or delegations, so you probably just
want to skip them.
Longer term, I wonder if we ought to add a new list in the
file_lock_context for layouts? There's no reason to keep them all on the
same list.
> > > > + }
> > > > + spin_unlock(&ctx->flc_lock);
> > > > + return NULL;
> > > > +}
> > > > +
> > > > +static __be32
> > > > +nfs4_handle_wrdeleg_conflict(struct svc_rqst *rqstp, struct inode
> > > > *inode)
> > > > +{
> > > > + __be32 status;
> > > > + struct file_lock *fl;
> > > > + struct nfs4_delegation *dp;
> > > > +
> > > > + fl = nfs4_wrdeleg_filelock(rqstp, inode);
> > > > + if (!fl)
> > > > + return 0;
> > > > + dp = fl->fl_owner;
> > > > + if (dp->dl_recall.cb_clp == *(rqstp->rq_lease_breaker))
> > > > + return 0;
> > > > + refcount_inc(&dp->dl_stid.sc_count);
> > > Another question: Why are you taking a reference here at all?
> >
> > This is same as in nfsd_break_one_deleg and revoke_delegation.
> > I think it is to prevent the delegation to be freed while delegation
> > is being recalled.
> >
> > > AFAICT,
> > > you don't even look at the delegation again after that point, so it's
> > > not clear to me who's responsible for putting that reference.
> >
> > In v2, the sc_count is decrement by nfs4_put_stid. I forgot to do that
> > in V4. I'll add it back in v5.
>
> Actually the refcount is decremented after the CB_RECALL is done
> by nfs4_put_stid in nfsd4_cb_recall_release. So we don't have to
> decrement it here. This is to prevent the delegation to be free
> while the recall is being sent.
>
That's the put for the increment in nfsd_break_one_deleg.
You don't need to take an extra reference to a delegation to call
nfsd_open_break_lease. You might not even know which delegation is being
broken. There could even be more than one, after all.
I think that extra refcount_inc is likely to cause a leak.
--
Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2023-05-22 13:49 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-20 21:36 [PATCH v4 0/4] NFSD: add support for NFSv4 write delegation Dai Ngo
2023-05-20 21:36 ` [PATCH v4 1/4] locks: allow support for " Dai Ngo
2023-05-21 16:27 ` Jeff Layton
2023-05-20 21:36 ` [PATCH v4 2/4] NFSD: enable " Dai Ngo
2023-05-20 21:36 ` [PATCH v4 3/4] NFSD: handle GETATTR conflict with " Dai Ngo
2023-05-21 16:30 ` Chuck Lever III
2023-05-21 16:49 ` Jeff Layton
2023-05-21 18:48 ` dai.ngo
2023-05-21 23:08 ` Jeff Layton
2023-05-22 2:31 ` Chuck Lever
2023-05-22 2:56 ` dai.ngo
2023-05-22 3:56 ` dai.ngo
2023-05-22 13:16 ` Chuck Lever III
2023-05-22 13:49 ` Jeff Layton [this message]
2023-05-22 17:10 ` dai.ngo
2023-05-20 21:36 ` [PATCH v4 4/4] NFSD: add trace point to track when write delegation is granted Dai Ngo
2023-05-21 16:08 ` [PATCH v4 0/4] NFSD: add support for NFSv4 write delegation Chuck Lever III
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=09113712aa83d9010ec3963368bce840dfb762db.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=dai.ngo@oracle.com \
--cc=linux-fsdevel@vger.kernel.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 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).