pynfs: add a set of tests for delegated timestamps
Subsystems (2)
Jeff Layton
maintainercover pynfs: add a set of tests for delegated timestamps
We've had a running set of issues with the delegated timestamp support in knfsd that is usually surfaced by a gitr test run. That's not always deterministic though since it involves the client. This adds a set of new tests that test various corner-cases of the delegated timestamp handling in the server.
If the server doesn't support delegated timestamps, then these tests return UNSUPPORTED.
---
Jeff Layton (6):
server41tests: factor out sampling the server's clock
server41tests: check that delegated times survive DELEGRETURN
server41tests: check delegated times that predate the server's WRITE
server41tests: check that times seen via CB_GETATTR survive return
server41tests: check CB_GETATTR times that predate the server's WRITE
server41tests: check delegated times after a truncate survive return
nfs4.1/server41tests/st_delegation.py | 229 +++++++++++++++++++++++++++++++--- 1 file changed, 215 insertions(+), 14 deletions(-)
---
base-commit: f03d0914f4fdae7735b207f1c8424274e12afa9a
change-id: 20261118-delegts-fdac2daff6f0
Best regards,
Signature · 1 line
Jeff Layton <[email protected]>
Jeff Layton
maintainerPATCH 1/6 server41tests: factor out sampling the server's clock
DELEG27 creates and removes a scratch directory to read the server's clock. Move that into _server_now() so new delegated-timestamp tests can share it.
--- nfs4.1/server41tests/st_delegation.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-)
nfs4.1/server41tests/st_delegation.py +18 -14
@@ -327,6 +327,23 @@ def testServerSelfConflict3(t, env): res = close_file(sess2, fh2, stateid=stateid2) check(res) +def _server_now(sess, env, name): + """Sample the server's clock + + The server may ignore a proxied time that is before the file's + time_modify and clamp one that is past its own clock (RFC 9754, + section 5), so use the server's clock rather than this host's: + create a scratch directory, take its time_modify, and remove it. + """ + res = sess.compound(env.home + [op.savefh(), + op.create(createtype4(NF4DIR), name, + {FATTR4_MODE: 0o755}), + op.getattr(1<<FATTR4_TIME_MODIFY), + op.restorefh(), + op.remove(name)]) + check(res) + return res.resarray[-3].obj_attributes[FATTR4_TIME_MODIFY] + def _testCbGetattr(t, env, change=0, size=0): cb = threading.Event() cbattrs = {}
@@ -559,20 +576,7 @@ def testCbGetattrAfterSyncWrite(t, env): check(res) if delegtype == OPEN_DELEGATE_WRITE_ATTRS_DELEG: - # The server may ignore a proxied time that is before the - # file's time_modify and clamp one that is past its own clock - # (RFC 9754, section 5), so sample the server's clock rather - # than this host's: create a scratch directory, take its - # time_modify, and remove it. - name = env.testname(t) + b"_clock" - res = sess1.compound(env.home + [op.savefh(), - op.create(createtype4(NF4DIR), name, - {FATTR4_MODE: 0o755}), - op.getattr(1<<FATTR4_TIME_MODIFY), - op.restorefh(), - op.remove(name)]) - check(res) - now = res.resarray[-3].obj_attributes[FATTR4_TIME_MODIFY] + now = _server_now(sess1, env, env.testname(t) + b"_clock") attrs2 = dict(attrs1) attrs2[FATTR4_TIME_ACCESS] = now attrs2[FATTR4_TIME_MODIFY] = now
Signature · 1 line
2.56.1
Jeff Layton
maintainerPATCH 2/6 server41tests: check that delegated times survive DELEGRETURN
In reply to Jeff LaytonGit's index records each file's c/mtime and size and treats any later difference as a modification. Over NFSv4.2 with delegated timestamps, git t1092 has found files whose times changed after DELEGRETURN, e.g. when nfsd stamped "now" over the holder's mtime at return.
Add DELEG28: get an OPEN_DELEGATE_WRITE_ATTRS_DELEG delegation, WRITE, then return it the way the Linux client does (SETATTR(delegated times)|GETATTR|DELEGRETURN), with an mtime after the server's WRITE stamp. Require that the server applies the mtime, and that change, size, time_modify and time_metadata don't move across DELEGRETURN.
The test is skipped if the server doesn't offer or grant delegated timestamps.
--- nfs4.1/server41tests/st_delegation.py | 87 +++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)
nfs4.1/server41tests/st_delegation.py +87 -0
@@ -661,3 +661,90 @@ def testCbGetattrAfterSyncWrite(t, env): if compareTimes(attrs2[FATTR4_TIME_MODIFY], attrs4[FATTR4_TIME_MODIFY]) != 0: fail(f"mtime after write ({attrs2[FATTR4_TIME_MODIFY]}) != " f"mtime from delegreturn ({attrs4[FATTR4_TIME_MODIFY]})") + +# Attributes that a stat-based cache (e.g. git's index) records +_STAT_ATTRS = [FATTR4_CHANGE, FATTR4_SIZE, FATTR4_TIME_MODIFY, FATTR4_TIME_METADATA] + +def _check_stat_same(before, after, when): + for attr, name in ((FATTR4_CHANGE, "change"), (FATTR4_SIZE, "size")): + if before[attr] != after[attr]: + fail(f"{name} moved {when}: {before[attr]} -> {after[attr]}") + for attr, name in ((FATTR4_TIME_MODIFY, "time_modify"), + (FATTR4_TIME_METADATA, "time_metadata")): + if compareTimes(before[attr], after[attr]) != 0: + fail(f"{name} moved {when}: {before[attr]} -> {after[attr]}") + +def _deleg_times_open(t, env): + """Create a file and get an OPEN_DELEGATE_WRITE_ATTRS_DELEG delegation""" + sess = env.c1.new_client_session(b"%s_1" % env.testname(t)) + + res = sess.compound([op.putrootfh(), + op.getattr(nfs4lib.list2bitmap([FATTR4_SUPPORTED_ATTRS, + FATTR4_OPEN_ARGUMENTS]))]) + check(res) + caps = res.resarray[-1].obj_attributes + if (not caps[FATTR4_SUPPORTED_ATTRS] & (1 << FATTR4_OPEN_ARGUMENTS) or + not caps[FATTR4_OPEN_ARGUMENTS].oa_share_access_want & + (1 << OPEN_ARGS_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS)): + t.fail_support("Server doesn't offer delegated timestamps") + + openmask = (OPEN4_SHARE_ACCESS_READ | + OPEN4_SHARE_ACCESS_WRITE | + OPEN4_SHARE_ACCESS_WANT_WRITE_DELEG | + OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS) + fh, stateid, deleg = __create_file_with_deleg(sess, env.testname(t), openmask) + if deleg.delegation_type != OPEN_DELEGATE_WRITE_ATTRS_DELEG: + t.fail_support("Didn't get a write delegation with delegated timestamps") + return sess, fh, stateid, deleg.write.stateid + +def _deleg_times_return(sess, env, fh, delegstateid, ts): + """Return the delegation the way the Linux client does + + PUTFH|SETATTR(delegated times)|GETATTR|DELEGRETURN. Returns the GETATTR + result: the last attributes seen while the delegation was held. + """ + ops = [op.putfh(fh), + op.setattr(delegstateid, {FATTR4_TIME_DELEG_ACCESS: ts, + FATTR4_TIME_DELEG_MODIFY: ts}), + op.getattr(nfs4lib.list2bitmap(_STAT_ATTRS)), + op.delegreturn(delegstateid)] + # The server may reject the proxied times with NFS4ERR_DELAY + for i in range(5): + res = sess.compound(ops) + if res.status != NFS4ERR_DELAY: + break + env.sleep(1) + check(res) + return res.resarray[-2].obj_attributes + +def _testDelegTimesStable(t, env): + size = 5 + + sess1, fh, stateid, delegstateid = _deleg_times_open(t, env) + + res = write_file(sess1, fh, b'z' * size, 0, delegstateid) + check(res) + env.sleep(.1) + ts = _server_now(sess1, env, env.testname(t) + b"_clock") + + held = _deleg_times_return(sess1, env, fh, delegstateid, ts) + after = do_getattrdict(sess1, fh, _STAT_ATTRS) + res = close_file(sess1, fh, stateid=stateid) + check(res) + + if compareTimes(held[FATTR4_TIME_MODIFY], ts) != 0: + fail(f"delegated time_modify not applied: {held[FATTR4_TIME_MODIFY]} != {ts}") + _check_stat_same(held, after, "after DELEGRETURN") + +def testDelegTimesReturn(t, env): + """Attributes seen under a timestamp delegation survive DELEGRETURN + + Get a write delegation with delegated timestamps, WRITE, then set a + delegated time_modify later than the server's WRITE stamp, GETATTR and + DELEGRETURN. A GETATTR after DELEGRETURN must report the same change, + size, time_modify and time_metadata. + + FLAGS: deleg all + CODE: DELEG28 + """ + _testDelegTimesStable(t, env)
Signature · 1 line
2.56.1
Jeff Layton
maintainerPATCH 3/6 server41tests: check delegated times that predate the server's WRITE
In reply to Jeff LaytonA client stamps mtime on write(2) and flushes later, so the delegated mtime it returns is usually older than the server's WRITE stamp. The server can't move ctime backward to match. Over NFSv4.2, git t1092 has seen stat-dirty files from this.
Add DELEG29: as DELEG28, but sample the delegated time before the WRITE. RFC 9754 lets the server ignore a time older than the file's time_modify, so don't require it to be applied; still require that nothing moves across DELEGRETURN.
--- nfs4.1/server41tests/st_delegation.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
nfs4.1/server41tests/st_delegation.py +22 -4
@@ -717,22 +717,29 @@ def _deleg_times_return(sess, env, fh, delegstateid, ts): check(res) return res.resarray[-2].obj_attributes -def _testDelegTimesStable(t, env): +def _testDelegTimesStable(t, env, early_stamp=False): size = 5 sess1, fh, stateid, delegstateid = _deleg_times_open(t, env) + # A client stamps mtime when the application writes, which is before + # the WRITE reaches the server + if early_stamp: + ts = _server_now(sess1, env, env.testname(t) + b"_clock") + env.sleep(.1) res = write_file(sess1, fh, b'z' * size, 0, delegstateid) check(res) - env.sleep(.1) - ts = _server_now(sess1, env, env.testname(t) + b"_clock") + if not early_stamp: + env.sleep(.1) + ts = _server_now(sess1, env, env.testname(t) + b"_clock") held = _deleg_times_return(sess1, env, fh, delegstateid, ts) after = do_getattrdict(sess1, fh, _STAT_ATTRS) res = close_file(sess1, fh, stateid=stateid) check(res) - if compareTimes(held[FATTR4_TIME_MODIFY], ts) != 0: + # A server may ignore a proxied time_modify that is before the file's + if not early_stamp and compareTimes(held[FATTR4_TIME_MODIFY], ts) != 0: fail(f"delegated time_modify not applied: {held[FATTR4_TIME_MODIFY]} != {ts}") _check_stat_same(held, after, "after DELEGRETURN")
@@ -748,3 +755,14 @@ def testDelegTimesReturn(t, env): CODE: DELEG28 """ _testDelegTimesStable(t, env) + +def testDelegTimesReturnEarlyStamp(t, env): + """Attributes seen under a timestamp delegation survive DELEGRETURN + + As DELEG28, but the delegated time_modify predates the server's WRITE + stamp, as when a client stamps on write(2) and flushes later. + + FLAGS: deleg all + CODE: DELEG29 + """ + _testDelegTimesStable(t, env, early_stamp=True)
Signature · 1 line
2.56.1
Jeff Layton
maintainerPATCH 4/6 server41tests: check that times seen via CB_GETATTR survive return
In reply to Jeff LaytonWhile a timestamp delegation is out, another client's GETATTR reports the times the holder returned in CB_GETATTR. Those must not change when the holder later SETATTRs the same times and returns the delegation.
Add DELEG30: after the WRITE, have a second client GETATTR, answer CB_GETATTR with an mtime after the server's WRITE stamp, then return as in DELEG28. Require that size, time_modify and time_metadata match across the second client's view, the holder's last GETATTR and a GETATTR after DELEGRETURN. Don't compare change across the holder's SETATTR, which replaces the server's WRITE stamp and so may bump it; git's index doesn't record it.
--- nfs4.1/server41tests/st_delegation.py | 59 ++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 5 deletions(-)
nfs4.1/server41tests/st_delegation.py +54 -5
@@ -665,8 +665,10 @@ def testCbGetattrAfterSyncWrite(t, env): # Attributes that a stat-based cache (e.g. git's index) records _STAT_ATTRS = [FATTR4_CHANGE, FATTR4_SIZE, FATTR4_TIME_MODIFY, FATTR4_TIME_METADATA] -def _check_stat_same(before, after, when): +def _check_stat_same(before, after, when, change=True): for attr, name in ((FATTR4_CHANGE, "change"), (FATTR4_SIZE, "size")): + if attr == FATTR4_CHANGE and not change: + continue if before[attr] != after[attr]: fail(f"{name} moved {when}: {before[attr]} -> {after[attr]}") for attr, name in ((FATTR4_TIME_MODIFY, "time_modify"),
@@ -674,9 +676,18 @@ def _check_stat_same(before, after, when): if compareTimes(before[attr], after[attr]) != 0: fail(f"{name} moved {when}: {before[attr]} -> {after[attr]}") -def _deleg_times_open(t, env): - """Create a file and get an OPEN_DELEGATE_WRITE_ATTRS_DELEG delegation""" +def _deleg_times_open(t, env, cbattrs=None, cb=None): + """Create a file and get an OPEN_DELEGATE_WRITE_ATTRS_DELEG delegation + + If cb is given, CB_GETATTR is answered with cbattrs, and sets cb. + """ sess = env.c1.new_client_session(b"%s_1" % env.testname(t)) + if cb is not None: + def getattr_post_hook(arg, env, res): + res.obj_attributes = cbattrs + env.notify = cb.set + return res + sess.client.cb_post_hook(OP_CB_GETATTR, getattr_post_hook) res = sess.compound([op.putrootfh(), op.getattr(nfs4lib.list2bitmap([FATTR4_SUPPORTED_ATTRS,
@@ -717,10 +728,13 @@ def _deleg_times_return(sess, env, fh, delegstateid, ts): check(res) return res.resarray[-2].obj_attributes -def _testDelegTimesStable(t, env, early_stamp=False): +def _testDelegTimesStable(t, env, early_stamp=False, observe=False): + cb = threading.Event() + cbattrs = {} size = 5 - sess1, fh, stateid, delegstateid = _deleg_times_open(t, env) + sess1, fh, stateid, delegstateid = _deleg_times_open(t, env, cbattrs, cb) + attrs1 = do_getattrdict(sess1, fh, [FATTR4_CHANGE]) # A client stamps mtime when the application writes, which is before # the WRITE reaches the server
@@ -733,6 +747,23 @@ def _testDelegTimesStable(t, env, early_stamp=False): env.sleep(.1) ts = _server_now(sess1, env, env.testname(t) + b"_clock") + if observe: + # No need to bump FATTR4_CHANGE because we've already flushed our data + cbattrs[FATTR4_CHANGE] = attrs1[FATTR4_CHANGE] + cbattrs[FATTR4_SIZE] = size + cbattrs[FATTR4_TIME_DELEG_ACCESS] = ts + cbattrs[FATTR4_TIME_DELEG_MODIFY] = ts + + sess2 = env.c1.new_client_session(b"%s_2" % env.testname(t)) + slot = sess2.compound_async([op.putfh(fh), + op.getattr(nfs4lib.list2bitmap(_STAT_ATTRS))]) + completed = cb.wait(2) + res = sess2.listen(slot) + if not completed: + fail("CB_GETATTR not received") + check(res) + seen = res.resarray[-1].obj_attributes + held = _deleg_times_return(sess1, env, fh, delegstateid, ts) after = do_getattrdict(sess1, fh, _STAT_ATTRS) res = close_file(sess1, fh, stateid=stateid)
@@ -741,6 +772,10 @@ def _testDelegTimesStable(t, env, early_stamp=False): # A server may ignore a proxied time_modify that is before the file's if not early_stamp and compareTimes(held[FATTR4_TIME_MODIFY], ts) != 0: fail(f"delegated time_modify not applied: {held[FATTR4_TIME_MODIFY]} != {ts}") + if observe: + # The SETATTR replaces the server's WRITE stamp, so change may move + _check_stat_same(seen, held, "when the holder set the times it " + "reported in CB_GETATTR", change=False) _check_stat_same(held, after, "after DELEGRETURN") def testDelegTimesReturn(t, env):
@@ -766,3 +801,17 @@ def testDelegTimesReturnEarlyStamp(t, env): CODE: DELEG29 """ _testDelegTimesStable(t, env, early_stamp=True) + +def testDelegTimesCbGetattr(t, env): + """Attributes seen through CB_GETATTR survive the holder's return + + Get a write delegation with delegated timestamps and WRITE. A second + client's GETATTR triggers CB_GETATTR, which reports a time_modify later + than the server's WRITE stamp. The holder then sets that same time and + returns the delegation. The second client's view, the holder's last + view and a GETATTR after DELEGRETURN must all match. + + FLAGS: deleg all + CODE: DELEG30 + """ + _testDelegTimesStable(t, env, observe=True)
Signature · 1 line
2.56.1
Jeff Layton
maintainerPATCH 5/6 server41tests: check CB_GETATTR times that predate the server's WRITE
In reply to Jeff LaytonCombine DELEG29 and DELEG30: the mtime the holder reports in CB_GETATTR and later SETATTRs is older than the server's WRITE stamp. A server that sets ctime to "now" when it applies an mtime older than ctime moves the ctime the second client already saw.
Add DELEG31.
--- nfs4.1/server41tests/st_delegation.py | 12 ++++++++++++ 1 file changed, 12 insertions(+)
nfs4.1/server41tests/st_delegation.py +12 -0
@@ -815,3 +815,15 @@ def testDelegTimesCbGetattr(t, env): CODE: DELEG30 """ _testDelegTimesStable(t, env, observe=True) + +def testDelegTimesCbGetattrEarlyStamp(t, env): + """Attributes seen through CB_GETATTR survive the holder's return + + As DELEG30, but the time_modify the holder reports predates the + server's WRITE stamp, as when a client stamps on write(2) and flushes + later. + + FLAGS: deleg all + CODE: DELEG31 + """ + _testDelegTimesStable(t, env, early_stamp=True, observe=True)
Signature · 1 line
2.56.1
Jeff Layton
maintainerPATCH 6/6 server41tests: check delegated times after a truncate survive return
In reply to Jeff LaytonA size-changing SETATTR always has the server stamp c/mtime (RFC 8881 section 18.30.4), even under a timestamp delegation. The Linux client had a bug where its delegated stamp could land before that, and ctime then changed after DELEGRETURN.
Add DELEG32: WRITE, truncate to 0 with the delegation stateid, then return with a delegated mtime after the truncate stamp. Require that the server applies the mtime and that nothing moves across DELEGRETURN.
--- nfs4.1/server41tests/st_delegation.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
nfs4.1/server41tests/st_delegation.py +31 -0
@@ -827,3 +827,34 @@ def testDelegTimesCbGetattrEarlyStamp(t, env): CODE: DELEG31 """ _testDelegTimesStable(t, env, early_stamp=True, observe=True) + +def testDelegTimesTruncate(t, env): + """Attributes seen under a timestamp delegation survive DELEGRETURN + + Get a write delegation with delegated timestamps, WRITE, then truncate + with a size-changing SETATTR, which has the server stamp c/mtime. Set a + delegated time_modify later than that stamp, GETATTR and DELEGRETURN. + A GETATTR after DELEGRETURN must report the same attributes. + + FLAGS: deleg all + CODE: DELEG32 + """ + sess1, fh, stateid, delegstateid = _deleg_times_open(t, env) + + res = write_file(sess1, fh, b'z' * 5, 0, delegstateid) + check(res) + res = sess1.compound([op.putfh(fh), op.setattr(delegstateid, {FATTR4_SIZE: 0})]) + check(res) + env.sleep(.1) + ts = _server_now(sess1, env, env.testname(t) + b"_clock") + + held = _deleg_times_return(sess1, env, fh, delegstateid, ts) + after = do_getattrdict(sess1, fh, _STAT_ATTRS) + res = close_file(sess1, fh, stateid=stateid) + check(res) + + if held[FATTR4_SIZE] != 0: + fail(f"Bad size: {held[FATTR4_SIZE]} != 0") + if compareTimes(held[FATTR4_TIME_MODIFY], ts) != 0: + fail(f"delegated time_modify not applied: {held[FATTR4_TIME_MODIFY]} != {ts}") + _check_stat_same(held, after, "after DELEGRETURN")
Signature · 1 line
2.56.1