Linux NFS development
 help / color / mirror / Atom feed
From: Chuck Lever <cel@kernel.org>
To: Calum Mackay <calum.mackay@oracle.com>
Cc: <linux-nfs@vger.kernel.org>
Subject: [PATCH v1 7/8] pynfs: add tests for delegation upgrade and downgrade wants
Date: Thu,  8 Oct 2026 11:47:28 -0400	[thread overview]
Message-ID: <20261008154729.77787-8-cel@kernel.org> (raw)
In-Reply-To: <20261008154729.77787-1-cel@kernel.org>

RFC 8881 Section 18.16.3 treats a want for the other delegation
type, from a client that already holds a delegation on the file, as
a request to upgrade or downgrade it. A server that supports neither
has to say so with WND4_NOT_SUPP_UPGRADE or WND4_NOT_SUPP_DOWNGRADE.
No test sends a want while a delegation is held, so a server that
gives another reason goes unnoticed.

Add DELEG34 and DELEG35. Each takes a delegation, then sends
OPEN(CLAIM_FH) from a second open-owner with a want for the other
type. The reply has to carry either a delegation of the wanted type
or the matching reason. DELEG35 reports UNSUPPORTED when the server
grants no write delegation to start from.

Signed-off-by: Chuck Lever <cel@kernel.org>
---
 nfs4.1/server41tests/st_delegation.py | 57 +++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/nfs4.1/server41tests/st_delegation.py b/nfs4.1/server41tests/st_delegation.py
index 3b6ca1d3b005..29d8341762d8 100644
--- a/nfs4.1/server41tests/st_delegation.py
+++ b/nfs4.1/server41tests/st_delegation.py
@@ -949,3 +949,60 @@ def testClaimFHDelegAfterClose(t, env):
     check(res)
     res = close_file(sess1, fh, stateid=stateid)
     check(res)
+
+def _testDelegXgrade(t, env, access, held_type, want_access, want_type, why):
+    name = env.testname(t)
+    sess1 = env.c1.new_client_session(b"%s_1" % name)
+    fh, stateid, deleg = __create_file_with_deleg(sess1, name, access)
+    if deleg.delegation_type != held_type:
+        _delegreturn(sess1, fh, deleg)
+        t.fail_support("Wanted %s, got %s" %
+                       (open_delegation_type4[held_type], _deleg_desc(deleg)))
+
+    res = _open_claim_fh(sess1, fh, b"%s_2" % name, want_access)
+    check(res)
+    stateid2 = res.resarray[-1].stateid
+    xgrade = res.resarray[-1].delegation
+    if xgrade.delegation_type == want_type:
+        deleg = xgrade
+
+    # Return the delegation first, so that a failure does not leave it
+    # behind to block the removal of the test file
+    _delegreturn(sess1, fh, deleg)
+    res = close_file(sess1, fh, stateid=stateid2)
+    check(res)
+    res = close_file(sess1, fh, stateid=stateid)
+    check(res)
+
+    if (xgrade.delegation_type != want_type and
+        (xgrade.delegation_type != OPEN_DELEGATE_NONE_EXT or
+         xgrade.ond_why != why)):
+        fail("Expected %s or %s, got %s" %
+             (open_delegation_type4[want_type], why_no_delegation4[why],
+              _deleg_desc(xgrade)))
+
+def testReadDelegUpgrade(t, env):
+    """WANT_WRITE_DELEG from the holder of a read delegation gets a
+       write delegation or WND4_NOT_SUPP_UPGRADE
+
+    FLAGS: open deleg all
+    CODE: DELEG35
+    """
+    _testDelegXgrade(t, env, OPEN4_SHARE_ACCESS_READ |
+                     OPEN4_SHARE_ACCESS_WANT_READ_DELEG, OPEN_DELEGATE_READ,
+                     OPEN4_SHARE_ACCESS_BOTH |
+                     OPEN4_SHARE_ACCESS_WANT_WRITE_DELEG, OPEN_DELEGATE_WRITE,
+                     WND4_NOT_SUPP_UPGRADE)
+
+def testWriteDelegDowngrade(t, env):
+    """WANT_READ_DELEG from the holder of a write delegation gets a
+       read delegation or WND4_NOT_SUPP_DOWNGRADE
+
+    FLAGS: writedelegations deleg all
+    CODE: DELEG36
+    """
+    _testDelegXgrade(t, env, OPEN4_SHARE_ACCESS_BOTH |
+                     OPEN4_SHARE_ACCESS_WANT_WRITE_DELEG, OPEN_DELEGATE_WRITE,
+                     OPEN4_SHARE_ACCESS_READ |
+                     OPEN4_SHARE_ACCESS_WANT_READ_DELEG, OPEN_DELEGATE_READ,
+                     WND4_NOT_SUPP_DOWNGRADE)
-- 
2.55.0


  parent reply	other threads:[~2026-10-08 15:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-08 15:47 [PATCH v1 0/8] Test the WANT_*_DELEG OPEN flags Chuck Lever
2026-10-08 15:47 ` [PATCH v1 1/8] pynfs: add test for OPEN(CLAIM_FH) with WANT_READ_DELEG Chuck Lever
2026-10-09  7:58   ` Substituting WANT_DELEGATION with OPEN(CLAIM_FH)? " Lionel Cons
2026-10-08 15:47 ` [PATCH v1 2/8] pynfs: add test for OPEN(CLAIM_FH) delegation request on an open file Chuck Lever
2026-10-08 15:47 ` [PATCH v1 3/8] pynfs: add test for a delegation request after a recall Chuck Lever
2026-10-08 15:47 ` [PATCH v1 4/8] pynfs: add tests for SETATTR by a delegation holder Chuck Lever
2026-10-08 15:47 ` [PATCH v1 5/8] pynfs: add test for WANT_OPEN_XOR_DELEGATION through CLAIM_FH Chuck Lever
2026-10-08 15:47 ` [PATCH v1 6/8] pynfs: add test for a CLAIM_FH delegation that outlives its open Chuck Lever
2026-10-08 15:47 ` Chuck Lever [this message]
2026-10-08 15:47 ` [PATCH v1 8/8] pynfs: add test for OPEN with WANT_CANCEL 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=20261008154729.77787-8-cel@kernel.org \
    --to=cel@kernel.org \
    --cc=calum.mackay@oracle.com \
    --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