Skip to contentSkip to conversation

nfs4.1: add some basic directory delegation tests

PATCH Superseded Jeff Layton 2 participants 10 messages Sep 30, 2025

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jeff Layton

author maintainer
#0 lore raw

cover nfs4.1: add some basic directory delegation tests

Add basic support for testing both GET_DIR_DELEGATION operations and CB_NOTIFY.

---
Jeff Layton (7):
nfs4.1: add proposed NOTIFY4_GFLAG_EXTEND flag
pynfs: add a getfh() to the end of create_obj() compound
server41tests: add a basic GET_DIR_DELEGATION test
server41tests: add a test for duplicate GET_DIR_DELEGATION requests
server41tests: add a test for removal from dir with dir delegation
server41tests: add a test for diretory add notifications
server41tests: add test for rename event notifications

 nfs4.1/nfs4client.py                 |   6 +
 nfs4.1/server41tests/__init__.py     |   1 +
 nfs4.1/server41tests/environment.py  |   2 +-
 nfs4.1/server41tests/st_dir_deleg.py | 221 +++++++++++++++++++++++++++++++++++
 nfs4.1/xdrdef/nfs4.x                 |   3 +-
 5 files changed, 231 insertions(+), 2 deletions(-)

---
base-commit: 3c14d9e3ad12272ab2f6092c85bb28ab03951484
change-id: 20250930-dir-deleg-4ae7364fb398

Best regards,

Signature · 1 line
Jeff Layton <[email protected]>
author maintainer
#1 lore raw

PATCH 1/7 nfs4.1: add proposed NOTIFY4_GFLAG_EXTEND flag

---
 nfs4.1/xdrdef/nfs4.x | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
nfs4.1/xdrdef/nfs4.x +2 -1
index ee3da8aa7a342e4d3829f4b1b1f82543275199c5..f03eb538a2980156a8149f0b00cc9bf19c0a91b9 100644
@@ -3611,7 +3611,8 @@ enum notify_type4 {
         NOTIFY4_REMOVE_ENTRY = 2,
         NOTIFY4_ADD_ENTRY = 3,
         NOTIFY4_RENAME_ENTRY = 4,
-        NOTIFY4_CHANGE_COOKIE_VERIFIER = 5
+        NOTIFY4_CHANGE_COOKIE_VERIFIER = 5,
+        NOTIFY4_GFLAG_EXTEND = 6 /* proposed in rfc8881bis */
 };
 
 /* Changed entry information.  */
Signature · 1 line
2.51.0
author maintainer
#2 lore raw

PATCH 2/7 pynfs: add a getfh() to the end of create_obj() compound

In reply to Jeff Layton
---
 nfs4.1/server41tests/environment.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
nfs4.1/server41tests/environment.py +1 -1
index 48284e029634fff60b7690e058cd4131bfea9b08..add13d8565e6529406c3b0db53f4e1396dae846a 100644
@@ -474,7 +474,7 @@ def create_obj(sess, path, kind=NF4DIR, attrs={FATTR4_MODE:0o755}):
     # Ensure using createtype4
     if not hasattr(kind, "type"):
         kind = createtype4(kind)
-    ops = use_obj(path[:-1]) + [op.create(kind, path[-1], attrs)]
+    ops = use_obj(path[:-1]) + [op.create(kind, path[-1], attrs), op.getfh()]
     return sess.compound(ops)
 
 def open_create_file(sess, owner, path=None, attrs={FATTR4_MODE: 0o644},
Signature · 1 line
2.51.0
author maintainer
#3 lore raw

PATCH 3/7 server41tests: add a basic GET_DIR_DELEGATION test

In reply to Jeff Layton
---
 nfs4.1/nfs4client.py                 |  6 +++
 nfs4.1/server41tests/__init__.py     |  1 +
 nfs4.1/server41tests/st_dir_deleg.py | 77 ++++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+)
nfs4.1/nfs4client.py +6 -0
index f4fabcc11be1328f47d6d738f78586b3e8541296..4650c052c118f1ceab30b6961aef885a910b96d5 100644
@@ -283,6 +283,12 @@ class NFS4Client(rpc.Client, rpc.Server):
         res = self.posthook(arg, env, res=NFS4_OK)
         return encode_status(res)
 
+    def op_cb_notify(self, arg, env):
+        log_cb.info("In CB_NOTIFY")
+        self.prehook(arg, env)
+        res = self.posthook(arg, env, res=NFS4_OK)
+        return encode_status(res)
+
     def op_cb_layoutrecall(self, arg, env):
         log_cb.info("In CB_LAYOUTRECALL")
         self.prehook(arg, env)
nfs4.1/server41tests/__init__.py +1 -0
index 5f223788147816079de4e2b0e9638ae90aa6d908..1422b131b1b4778f1d0bba1a44a5ec51a6ebadcd 100644
@@ -11,6 +11,7 @@ __all__ = ["st_exchange_id.py", # draft 21
            "st_trunking.py",
            "st_open.py",
            "st_delegation.py",
+           "st_dir_deleg.py",
            "st_verify.py",
            "st_getdevicelist.py",
            "st_lookupp.py",
nfs4.1/server41tests/st_dir_deleg.py new file +77 -0

77 lines not on this page · raw message

Signature · 1 line
2.51.0
author maintainer
#4 lore raw

PATCH 4/7 server41tests: add a test for duplicate GET_DIR_DELEGATION requests

In reply to Jeff Layton
---
 nfs4.1/server41tests/st_dir_deleg.py | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
nfs4.1/server41tests/st_dir_deleg.py +26 -0
index d63a16e06edd4515033ad81986cf1e84871ee7ad..ccf7eca8bcbe3401aaa8561e10db02d0836ca493 100644
@@ -75,3 +75,29 @@ def testDirDelegSimple(t, env):
     ops = [ op.putfh(fh), op.delegreturn(deleg) ]
     res = sess1.compound(ops)
     check(res)
+
+def testDirDelegDuplicate(t, env):
+    """Test that server returns GDD4_UNAVAIL on duplicate GDD4 request
+
+    FLAGS: dirdeleg all
+    CODE: DIRDELEG2
+    """
+    c = env.c1
+    recall = threading.Event()
+    sess1, fh, deleg = _getDirDeleg(t, env, [], recall)
+
+    # get a dir deleg with no notifications
+    ops = [ op.putfh(fh), op.get_dir_delegation(False,
+                                                nfs4lib.list2bitmap([]),
+                                                zerotime, zerotime,
+                                                nfs4lib.list2bitmap([]),
+                                                nfs4lib.list2bitmap([]))]
+    res = sess1.compound(ops)
+    check(res)
+    nfstatus = res.resarray[-1].gddr_res_non_fatal4.gddrnf_status
+    if (nfstatus != GDD4_UNAVAIL):
+        fail("Server replied to duplicate request with %d" % nfstatus)
+
+    ops = [ op.putfh(fh), op.delegreturn(deleg) ]
+    res = sess1.compound(ops)
+    check(res)
Signature · 1 line
2.51.0
author maintainer
#5 lore raw

PATCH 5/7 server41tests: add a test for removal from dir with dir delegation

In reply to Jeff Layton

...and actually request attributes in the GET_DIR_DELEGATION request.

---
 nfs4.1/server41tests/st_dir_deleg.py | 53 ++++++++++++++++++++++++++++++++++--
 1 file changed, 51 insertions(+), 2 deletions(-)
nfs4.1/server41tests/st_dir_deleg.py +51 -2
index ccf7eca8bcbe3401aaa8561e10db02d0836ca493..f44a8f10738b1e6d5868f4496ba4bda1c5be810d 100644
@@ -43,8 +43,26 @@ def _getDirDeleg(t, env, notify_mask, cb):
     ops = [ op.putfh(fh), op.get_dir_delegation(False,
                                                 nfs4lib.list2bitmap(notify_mask),
                                                 zerotime, zerotime,
-                                                nfs4lib.list2bitmap([]),
-                                                nfs4lib.list2bitmap([]))]
+                                                nfs4lib.list2bitmap([FATTR4_TYPE,
+                                                                     FATTR4_CHANGE,
+                                                                     FATTR4_SIZE,
+                                                                     FATTR4_FILEID,
+                                                                     FATTR4_FILEHANDLE,
+                                                                     FATTR4_MODE,
+                                                                     FATTR4_NUMLINKS,
+                                                                     FATTR4_RAWDEV,
+                                                                     FATTR4_SPACE_USED,
+                                                                     FATTR4_TIME_ACCESS,
+                                                                     FATTR4_TIME_METADATA,
+                                                                     FATTR4_TIME_MODIFY,
+                                                                     FATTR4_TIME_CREATE]),
+                                                nfs4lib.list2bitmap([FATTR4_CHANGE,
+                                                                     FATTR4_SIZE,
+                                                                     FATTR4_NUMLINKS,
+                                                                     FATTR4_SPACE_USED,
+                                                                     FATTR4_TIME_ACCESS,
+                                                                     FATTR4_TIME_METADATA,
+                                                                     FATTR4_TIME_MODIFY]))]
     res = sess1.compound(ops)
     check(res)
     deleg = res.resarray[-1].gddrnf_resok4.gddr_stateid
@@ -101,3 +119,34 @@ def testDirDelegDuplicate(t, env):
     ops = [ op.putfh(fh), op.delegreturn(deleg) ]
     res = sess1.compound(ops)
     check(res)
+
+def testDirDelegRemove(t, env):
+    """Create a dir_deleg that accepts notification of REMOVE events
+
+    FLAGS: dirdeleg all
+    CODE: DIRDELEG3
+    """
+    c = env.c1
+    cb = threading.Event()
+    sess1, fh, deleg = _getDirDeleg(t, env, [NOTIFY4_CHANGE_DIR_ATTRS, NOTIFY4_REMOVE_ENTRY], cb)
+
+    claim = open_claim4(CLAIM_NULL, env.testname(t))
+    owner = open_owner4(0, b"owner")
+    how = openflag4(OPEN4_CREATE, createhow4(GUARDED4, {FATTR4_SIZE:0}))
+    open_op = [ op.putfh(fh), op.open(0,
+                                      OPEN4_SHARE_ACCESS_WRITE | OPEN4_SHARE_ACCESS_WANT_NO_DELEG,
+                                      OPEN4_SHARE_DENY_NONE, owner, how, claim) ]
+    res = sess1.compound(open_op)
+    check(res)
+
+    sess2 = c.new_client_session(b"%s_2" % env.testname(t))
+    remove_op = [ op.putfh(fh), op.remove(env.testname(t)) ]
+    res = sess2.compound(remove_op)
+    check(res)
+
+    completed = cb.wait(5)
+    ops = [ op.putfh(fh), op.delegreturn(deleg) ]
+    res = sess1.compound(ops)
+
+    if (not completed or not cb.got_notify):
+        fail("Didn't receive a CB_NOTIFY from the server!")
Signature · 1 line
2.51.0
author maintainer
#6 lore raw

PATCH 6/7 server41tests: add a test for diretory add notifications

In reply to Jeff Layton
---
 nfs4.1/server41tests/st_dir_deleg.py | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
nfs4.1/server41tests/st_dir_deleg.py +33 -0
index f44a8f10738b1e6d5868f4496ba4bda1c5be810d..7073c590cb537f83552d7d8afa0ab02da1fe07c9 100644
@@ -150,3 +150,36 @@ def testDirDelegRemove(t, env):
 
     if (not completed or not cb.got_notify):
         fail("Didn't receive a CB_NOTIFY from the server!")
+
+def testDirDelegAdd(t, env):
+    """Create a dir_deleg that accepts notification of ADD events
+
+    FLAGS: dirdeleg all
+    CODE: DIRDELEG4
+    """
+    c = env.c1
+    cb = threading.Event()
+    sess1, fh, deleg = _getDirDeleg(t, env, [NOTIFY4_ADD_ENTRY], cb)
+
+    sess2 = c.new_client_session(b"%s_2" % env.testname(t))
+    claim = open_claim4(CLAIM_NULL, env.testname(t))
+    owner = open_owner4(0, b"owner")
+    how = openflag4(OPEN4_CREATE, createhow4(GUARDED4, {FATTR4_SIZE:0}))
+    open_op = [ op.putfh(fh), op.open(0,
+                                      OPEN4_SHARE_ACCESS_WRITE | OPEN4_SHARE_ACCESS_WANT_NO_DELEG,
+                                      OPEN4_SHARE_DENY_NONE, owner, how, claim), op.getfh() ]
+    res = sess2.compound(open_op)
+    check(res)
+
+    completed = cb.wait(2)
+
+    delegreturn_op = [ op.putfh(fh), op.delegreturn(deleg) ]
+    res = sess1.compound(delegreturn_op)
+    check(res)
+
+    remove_op = [ op.putfh(fh), op.remove(env.testname(t)) ]
+    res = sess2.compound(remove_op)
+    check(res)
+
+    if (not completed or not cb.got_notify):
+        fail("Didn't receive a CB_NOTIFY from the server!")
Signature · 1 line
2.51.0
author maintainer
#7 lore raw

PATCH 7/7 server41tests: add test for rename event notifications

In reply to Jeff Layton

Add a test of notifications for renames within the same dir.

---
 nfs4.1/server41tests/st_dir_deleg.py | 38 +++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)
nfs4.1/server41tests/st_dir_deleg.py +37 -1
index 7073c590cb537f83552d7d8afa0ab02da1fe07c9..bd1cd1c2ad5342b3026e245f5eb0823c01b1f9ea 100644
@@ -2,7 +2,7 @@ from .st_create_session import create_session
 from .st_open import open_claim4
 from xdrdef.nfs4_const import *
 
-from .environment import check, fail, create_obj, use_obj
+from .environment import check, fail, create_obj, use_obj, rename_obj
 from xdrdef.nfs4_type import *
 import nfs_ops
 op = nfs_ops.NFS4ops()
@@ -183,3 +183,39 @@ def testDirDelegAdd(t, env):
 
     if (not completed or not cb.got_notify):
         fail("Didn't receive a CB_NOTIFY from the server!")
+
+def testDirDelegRename(t, env):
+    """Create a dir_deleg that accepts notification of RENAME events
+
+    FLAGS: dirdeleg all
+    CODE: DIRDELEG5
+    """
+    c = env.c1
+    cb = threading.Event()
+
+    sess1, fh, deleg = _getDirDeleg(t, env, [NOTIFY4_RENAME_ENTRY], cb)
+
+    claim = open_claim4(CLAIM_NULL, env.testname(t))
+    owner = open_owner4(0, b"owner")
+    how = openflag4(OPEN4_CREATE, createhow4(GUARDED4, {FATTR4_SIZE:0}))
+    open_op = [ op.putfh(fh), op.open(0,
+                                      OPEN4_SHARE_ACCESS_WRITE | OPEN4_SHARE_ACCESS_WANT_NO_DELEG,
+                                      OPEN4_SHARE_DENY_NONE, owner, how, claim) ]
+    res = sess1.compound(open_op)
+    check(res)
+
+    sess2 = c.new_client_session(b"%s_2" % env.testname(t))
+    topdir = c.homedir + [t.code.encode('utf8')]
+    oldpath = topdir + [env.testname(t)]
+    newpath = topdir + [b"%s_2" % env.testname(t)]
+    res = rename_obj(sess2, oldpath, newpath)
+    check(res)
+
+    completed = cb.wait(2)
+
+    delegreturn_op = [ op.putfh(fh), op.delegreturn(deleg) ]
+    res = sess1.compound(delegreturn_op)
+    check(res)
+
+    if (not completed or not cb.got_notify):
+        fail("Didn't receive a CB_NOTIFY from the server!")
Signature · 1 line
2.51.0
Reviewed-by on the v1 series
#8 lore raw
In reply to Jeff Layton
Quoted 20 lines · Jeff Layton

Add basic support for testing both GET_DIR_DELEGATION operations and CB_NOTIFY.

---
Jeff Layton (7):
nfs4.1: add proposed NOTIFY4_GFLAG_EXTEND flag
pynfs: add a getfh() to the end of create_obj() compound
server41tests: add a basic GET_DIR_DELEGATION test
server41tests: add a test for duplicate GET_DIR_DELEGATION requests
server41tests: add a test for removal from dir with dir delegation
server41tests: add a test for diretory add notifications
server41tests: add test for rename event notifications

 nfs4.1/nfs4client.py                 |   6 +
 nfs4.1/server41tests/__init__.py     |   1 +
 nfs4.1/server41tests/environment.py  |   2 +-
 nfs4.1/server41tests/st_dir_deleg.py | 221 +++++++++++++++++++++++++++++++++++
 nfs4.1/xdrdef/nfs4.x                 |   3 +-
 5 files changed, 231 insertions(+), 2 deletions(-)
Quoted 5 lines

---
base-commit: 3c14d9e3ad12272ab2f6092c85bb28ab03951484
change-id: 20250930-dir-deleg-4ae7364fb398

Best regards,

But one question: should these new tests not be in the "all" group? Seems like most NFS server implementations won't support directory delegations.

Signature · 1 line
Chuck Lever
author maintainer
#9 lore raw
Quoted 25 lines · Chuck Lever
Quoted 24 lines · Jeff Layton

Add basic support for testing both GET_DIR_DELEGATION operations and CB_NOTIFY.

---
Jeff Layton (7):
nfs4.1: add proposed NOTIFY4_GFLAG_EXTEND flag
pynfs: add a getfh() to the end of create_obj() compound
server41tests: add a basic GET_DIR_DELEGATION test
server41tests: add a test for duplicate GET_DIR_DELEGATION requests
server41tests: add a test for removal from dir with dir delegation
server41tests: add a test for diretory add notifications
server41tests: add test for rename event notifications

 nfs4.1/nfs4client.py                 |   6 +
 nfs4.1/server41tests/__init__.py     |   1 +
 nfs4.1/server41tests/environment.py  |   2 +-
 nfs4.1/server41tests/st_dir_deleg.py | 221 +++++++++++++++++++++++++++++++++++
 nfs4.1/xdrdef/nfs4.x                 |   3 +-
 5 files changed, 231 insertions(+), 2 deletions(-)

---
base-commit: 3c14d9e3ad12272ab2f6092c85bb28ab03951484
change-id: 20250930-dir-deleg-4ae7364fb398

Quoted 8 lines
Quoted 1 line

Best regards,

But one question: should these new tests not be in the "all" group? Seems like most NFS server implementations won't support directory delegations.

I had meant to remove that group before posting and then forgot about it. That is a good point though...

Ideally what would best would be to try and run it, and just make it a non-fatal error if the initial GET_DIR_DELEGATION fails? Maybe just make it pass_warn() in that case?

I like that idea better than hiding this away where we forget to run it. I'll see what I can put together.

Thanks,

Signature · 1 line
Jeff Layton <[email protected]>