From: Chuck Lever <cel@kernel.org>
To: Chuck Lever <cel@kernel.org>, Jeff Layton <jlayton@kernel.org>,
NeilBrown <neil@brown.name>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 4/5] NFSD: Report unsupported delegation upgrade and downgrade
Date: Thu, 08 Oct 2026 14:18:30 -0400 [thread overview]
Message-ID: <20261008-want-read-v1-4-e372262857c8@kernel.org> (raw)
In-Reply-To: <20261008-want-read-v1-0-e372262857c8@kernel.org>
RFC 8881 Section 18.16.3 defines an OPEN that sets
OPEN4_SHARE_ACCESS_WANT_WRITE_DELEG, from a client holding an
OPEN_DELEGATE_READ delegation on the file, as a request to upgrade
the OPEN_DELEGATE_READ delegation. Likewise, an OPEN that sets
OPEN4_SHARE_ACCESS_WANT_READ_DELEG from a client holding an
OPEN_DELEGATE_WRITE delegation is a request to downgrade. A server
that supports neither upgrade nor downgrade replies with ond_why
set to WND4_NOT_SUPP_UPGRADE or WND4_NOT_SUPP_DOWNGRADE.
NFSD supports neither, but replies with WND4_RESOURCE to both
requests, inviting the client to ask again, futilely.
nfsd4_deleg_xgrade_none_ext() exists to supply the correct reasons,
but nfsd4_process_open2() calls it only when the delegation type in
the reply is still OPEN_DELEGATE_NONE, and nfs4_open_delegation()
has already replaced OPEN_DELEGATE_NONE with OPEN_DELEGATE_NONE_EXT
before nfsd4_process_open2() makes the check.
Have nfs4_set_delegation() report the type of the delegation the
client already holds, and have nfsd4_open_deleg_none_ext() choose
the upgrade or downgrade reason from the held type. Remove the
unreachable helper.
Fixes: d24433cdc91c ("nfsd41: implement NFS4_SHARE_WANT_NO_DELEG, NFS4_OPEN_DELEGATE_NONE_EXT, why_no_deleg")
Signed-off-by: Chuck Lever <cel@kernel.org>
---
fs/nfsd/nfs4state.c | 65 +++++++++++++++++++++++++----------------------------
1 file changed, 30 insertions(+), 35 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 6ed53864c9be..6bb70d50e9d9 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -1481,10 +1481,12 @@ static void destroy_unhashed_deleg(struct nfs4_delegation *dp)
* @fp: a pointer to the nfs4_file we're granting a delegation on
*
* Return:
- * On success: true iff an existing delegation is found
+ * The delegation @clp already holds on @fp, or NULL if it holds
+ * none. No reference is taken: the pointer is valid only while
+ * the caller holds fi_lock.
*/
-static bool
+static struct nfs4_delegation *
nfs4_delegation_exists(struct nfs4_client *clp, struct nfs4_file *fp)
{
struct nfs4_delegation *searchdp = NULL;
@@ -1497,10 +1499,10 @@ nfs4_delegation_exists(struct nfs4_client *clp, struct nfs4_file *fp)
list_for_each_entry(searchdp, &fp->fi_delegations, dl_perfile) {
searchclp = searchdp->dl_stid.sc_client;
if (clp == searchclp) {
- return true;
+ return searchdp;
}
}
- return false;
+ return NULL;
}
/**
@@ -7000,14 +7002,15 @@ nfs4_delegation_record_grant_slot(struct nfs4_delegation *dp,
static struct nfs4_delegation *
nfs4_set_delegation(struct nfsd4_open *open,
const struct nfsd4_compound_state *cstate,
- struct nfs4_ol_stateid *stp, struct svc_fh *parent)
+ struct nfs4_ol_stateid *stp, struct svc_fh *parent,
+ u32 *held_type)
{
bool deleg_ts = nfsd4_want_deleg_timestamps(open);
struct nfs4_client *clp = stp->st_stid.sc_client;
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
struct nfs4_file *fp = stp->st_stid.sc_file;
struct nfs4_clnt_odstate *odstate = stp->st_clnt_odstate;
- struct nfs4_delegation *dp;
+ struct nfs4_delegation *dp, *held;
struct nfsd_file *nf = NULL;
struct file_lease *fl;
int status = 0;
@@ -7066,9 +7069,11 @@ nfs4_set_delegation(struct nfsd4_open *open,
spin_lock(&nn->deleg_lock);
spin_lock(&fp->fi_lock);
- if (nfs4_delegation_exists(clp, fp))
+ held = nfs4_delegation_exists(clp, fp);
+ if (held) {
+ *held_type = held->dl_type;
status = -EEXIST;
- else if (nfsd4_verify_setuid_write(open, nf))
+ } else if (nfsd4_verify_setuid_write(open, nf))
status = -EPERM;
else if (!rcu_dereference_protected(fp->fi_deleg_file,
lockdep_is_held(&fp->fi_lock))) {
@@ -7140,6 +7145,10 @@ nfs4_set_delegation(struct nfsd4_open *open,
spin_lock(&clp->cl_lock);
spin_lock(&fp->fi_lock);
status = hash_delegation_locked(dp, fp);
+ if (status == -EEXIST) {
+ held = nfs4_delegation_exists(clp, fp);
+ *held_type = held->dl_type;
+ }
spin_unlock(&fp->fi_lock);
spin_unlock(&clp->cl_lock);
spin_unlock(&nn->deleg_lock);
@@ -7159,16 +7168,23 @@ nfs4_set_delegation(struct nfsd4_open *open,
return ERR_PTR(status);
}
-static void nfsd4_open_deleg_none_ext(struct nfsd4_open *open, int status)
+static void nfsd4_open_deleg_none_ext(struct nfsd4_open *open, int status,
+ u32 held_type)
{
open->op_delegate_type = OPEN_DELEGATE_NONE_EXT;
if (status == -EAGAIN)
open->op_why_no_deleg = WND4_CONTENTION;
else {
open->op_why_no_deleg = WND4_RESOURCE;
- switch (open->op_deleg_want) {
+ switch (open->op_deleg_want & NFS4_SHARE_WANT_TYPE_MASK) {
case OPEN4_SHARE_ACCESS_WANT_READ_DELEG:
+ if (deleg_is_write(held_type))
+ open->op_why_no_deleg = WND4_NOT_SUPP_DOWNGRADE;
+ break;
case OPEN4_SHARE_ACCESS_WANT_WRITE_DELEG:
+ if (deleg_is_read(held_type))
+ open->op_why_no_deleg = WND4_NOT_SUPP_UPGRADE;
+ break;
case OPEN4_SHARE_ACCESS_WANT_ANY_DELEG:
break;
case OPEN4_SHARE_ACCESS_WANT_CANCEL:
@@ -7268,6 +7284,7 @@ nfs4_open_delegation(struct svc_rqst *rqstp, struct nfsd4_open *open,
struct nfs4_client *clp = stp->st_stid.sc_client;
struct svc_fh *parent = NULL;
struct nfs4_delegation *dp;
+ u32 held_type = OPEN_DELEGATE_NONE;
struct kstat stat;
int status = 0;
int cb_up;
@@ -7299,7 +7316,8 @@ nfs4_open_delegation(struct svc_rqst *rqstp, struct nfsd4_open *open,
default:
goto out_no_deleg;
}
- dp = nfs4_set_delegation(open, &resp->cstate, stp, parent);
+ dp = nfs4_set_delegation(open, &resp->cstate, stp, parent,
+ &held_type);
if (IS_ERR(dp)) {
status = PTR_ERR(dp);
goto out_no_deleg;
@@ -7341,28 +7359,10 @@ nfs4_open_delegation(struct svc_rqst *rqstp, struct nfsd4_open *open,
/* 4.1 client asking for a delegation? */
if (open->op_deleg_want)
- nfsd4_open_deleg_none_ext(open, status);
+ nfsd4_open_deleg_none_ext(open, status, held_type);
return;
}
-static void nfsd4_deleg_xgrade_none_ext(struct nfsd4_open *open,
- struct nfs4_delegation *dp)
-{
- if (deleg_is_write(dp->dl_type)) {
- if (open->op_deleg_want & OPEN4_SHARE_ACCESS_WANT_READ_DELEG) {
- open->op_delegate_type = OPEN_DELEGATE_NONE_EXT;
- open->op_why_no_deleg = WND4_NOT_SUPP_DOWNGRADE;
- } else if (open->op_deleg_want & OPEN4_SHARE_ACCESS_WANT_WRITE_DELEG) {
- open->op_delegate_type = OPEN_DELEGATE_NONE_EXT;
- open->op_why_no_deleg = WND4_NOT_SUPP_UPGRADE;
- }
- }
- /* Otherwise the client must be confused wanting a delegation
- * it already has, therefore we don't return
- * OPEN_DELEGATE_NONE_EXT and reason.
- */
-}
-
/* Are we returning only a delegation stateid? */
static bool open_xor_delegation(struct nfsd4_open *open)
{
@@ -7509,11 +7509,6 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
status = nfs_ok;
trace_nfsd_open(&stp->st_stid.sc_stateid);
out:
- /* 4.1 client trying to upgrade/downgrade delegation? */
- if (open->op_delegate_type == OPEN_DELEGATE_NONE && dp &&
- open->op_deleg_want)
- nfsd4_deleg_xgrade_none_ext(open, dp);
-
if (fp)
put_nfs4_file(fp);
if (status == 0 && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
--
2.55.0
next prev parent reply other threads:[~2026-10-08 18:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 18:18 [PATCH 0/5] NFSD: Fixes for OPEN4_SHARE_ACCESS_WANT handling Chuck Lever
2026-10-08 18:18 ` [PATCH 1/5] NFSD: Report WND4_CANCELLED for an OPEN with WANT_CANCEL Chuck Lever
2026-10-08 18:18 ` [PATCH 2/5] NFSD: Report the correct value in an OPEN response's ond_why field Chuck Lever
2026-10-08 18:18 ` [PATCH 3/5] NFSD: Report WND4_CONTENTION for a recently recalled file Chuck Lever
2026-10-08 18:18 ` Chuck Lever [this message]
2026-10-08 18:18 ` [PATCH 5/5] NFSD: Honor OPEN4_SHARE_ACCESS_WANT_READ_DELEG on a read-write OPEN Chuck Lever
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=20261008-want-read-v1-4-e372262857c8@kernel.org \
--to=cel@kernel.org \
--cc=Dai.Ngo@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=okorniev@redhat.com \
--cc=tom@talpey.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