Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796310958; b=rug+AQPEfFH+EYwqE0Xy3T7vvuVn0UPXLrkfHN4v8tIxkyxbC+W63idK2khESy91MOPd Co+ggXld3G19oisMhRJqVAE05i8vBGB63terSeU60gHvoQFJfCjShsiZ9OLICdYvmV2mu CCtmOtluM03JKTLsEXpBw7Oqbas8w5ufdTCOQf5pLvKKY9QDLjJ0GuPPHOcQ/pquiVbpq T6Aj0ZU5Vw6uSbyDYPNhv8yLmmopwNRz2UmTiXaCV+GmGsqEepkl/c0ZLOpicamctqvVP ZNbKXwQINhZ1d4wk2SaLbUjCVJ0k89yBsLeqk2S09IwzwfHTNyZx0Xn94B+DIUDsqdQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796310958; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=NdIw1z631bjOhuHlUjE6CJoZB7EZWpEg/PO5bgb0y1U=; b=UQkCaPj8sP72PctBdbmgYAQfxUPUgqMFqtC8qYHU1uWLTce6/YSV4/KeVRpYd+0ETQXP IKkblHahOwYSd3pqaCqisvos12fuIwkcf3cBMqb09Vw06FxVlxRYxPBFb3sXZwhP9gw44 eXUeT5jggjJjEaNshOfsizvAE11kaAXzZ6yf4j5uEmzy5rqjfU/XmMgxQPlq32h3fMFSq 5AnfrILn7K4n0TZ116piv4OJcicJhYE143FNKjir1gzScLZWSY00O/EpYi8XqUgusOA+L /CBlFdbyPATFhm8B8MDssJQScspHKEPCk3VdXZJmqjUFfT/oM1pg6enRWAji5WHpPwQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=l37vzHGP; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1759606A330 for ; Thu, 3 Dec 2026 15:15:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=l37vzHGP Received: by smtp.kernel.org (Postfix) with ESMTPSA id 501BD1F00924; Thu, 3 Dec 2026 15:15:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796310958; bh=NdIw1z631bjOhuHlUjE6CJoZB7EZWpEg/PO5bgb0y1U=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=l37vzHGP+zQmgUVfjKLhIyi+lhhuzYznzNVy0M3O2t8GCme1gGF/Eb0oqwsXf0FRD DvCHeDBh0BEQQDjB7vgjgIQy9I3LyUAOOrBQf4jQX3PMvskuqvWdmhlc3wmi/flQKI MHh3PRY49IgWgCdLSS2Nq9eY0lvhe38Rem+QOsuJbj89DfK+i4TgQT44P8/NK2I3WB k50XoV8pYt+YcCZf5s+/aLFZ9t2atVIbogGf2yzZdNLWj926I96pZzmbdXEwDxXagw ZfvHFVPQeF+r0zvVIRrgaD/hZMAa5/3lb5T4X77R+iK4HtmVfa6xOT/CyoJnTBL1KS tkSsWNBbfX96Q== From: Jeff Layton Date: Thu, 03 Dec 2026 10:15:45 -0500 Subject: [PATCH 2/2] server41tests: add standalone CB_NOTIFY_LOCK tests X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261203-cb_notify_lock-v1-2-9f18fbacc50f@kernel.org> References: <20261203-cb_notify_lock-v1-0-9f18fbacc50f@kernel.org> In-Reply-To: <20261203-cb_notify_lock-v1-0-9f18fbacc50f@kernel.org> To: Chuck Lever , Calum Mackay Cc: linux-nfs@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6044; i=jlayton@kernel.org; h=from:subject:message-id; bh=be1oC45+tN6sYxMPCgs+WeJAzh3Lm040YK0YxRNILLU=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBrEYesr/yMNKsKuDKMg9e18CPYDMMfdbvgZAZRt sWPK0DLebSJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCaxGHrAAKCRAADmhBGVaC Fe+lEAC4Wm5ksl+zMyvlhZdrcrSRK9wDs8V8eSwO7pNX0KEEFldvTlnfI0UrLCwtIPbyKxPoxQM TWvqrC901edoW1bn+a3XrJIVV6OF5sUUYV1fRW56ot2sU+hfnWO0pQ4Orc8PwShxwa7pXN+uGXN MoTC5Vp/ZATC49FF5ADR9x+QtBOggTJUulCUQZrgfXp82ln3tAfDPIXBeS+42tQreGvn/9Y9sv9 xglb5zdyxAX7LRICfbl3374jCn2qZg7dblu1C8f9r9klUhNJchS5sb2O9Sx8z5euXnPMJi3pK2N /Jd1ghfiXWNhzFA2fjUSbOJZEtYBNhHBq+4iDU14V8R6PsyHKIeC7UXyH1sZL6RIZ0oYnOWaoBJ tixMn2LX8gs51H9S3PZiM+/20y2ni+eBqlVNZ02ZO4V9IamlfrQ1VLDtXWcYUHPs1VuiqFdnmPk DoQjPXJZgdEs0/cQDaB77VjeX6N7fIbHJH0pjUFDBY3ODoQS/0XfS17XIQ8Daz1u1LZhWGr8tf0 ml+Ynh8qM4qCo1XqyPZpP4ziRQ3tb3gpNJOAza2Q3h1lHvP4Tr1Xf2HBPnI5+NRyoHYbfaDC8Ah QH3f876aN5f9advgobjEvNmM5ngNVwEUulwYcsHRqbMXiRdm8mzYfAEXiG2MduHaAuGOnEd4FFg vi4V+yu1+BNDV0w== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 CALLBACK1 is the only test that expects a CB_NOTIFY_LOCK, and it reaches that check only after idling for two lease periods and expiring a client through the serverhelper. Without a serverhelper, CALLBACK1 fails at the expiry check first, so an unattended run cannot catch a server that never sends the callback. NFSD in Linux v6.7 through v6.12 is such a server: on filesystems without their own ->lock, NFSD clears FL_SLEEP from every blocking LOCK. Add CALLBACK2, which checks that a WRITEW_LT denied by another client's lock gets a CB_NOTIFY_LOCK after the holder's LOCKU, and CALLBACK3, which checks that a denied WRITE_LT does not. CALLBACK3 catches the NFSD bug fixed by kernel commit 246a90a5109b ("nfsd: fix FL_SLEEP being set unconditionally for all LOCK types"). Both tests report UNSUPPORTED when OPEN does not set OPEN4_RESULT_MAY_NOTIFY_LOCK. Signed-off-by: Jeff Layton --- nfs4.1/server41tests/st_callback.py | 110 ++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/nfs4.1/server41tests/st_callback.py b/nfs4.1/server41tests/st_callback.py index cdfc74a5775b..32d496a5efd3 100644 --- a/nfs4.1/server41tests/st_callback.py +++ b/nfs4.1/server41tests/st_callback.py @@ -133,3 +133,113 @@ def testCbNotifyLockExpiredClient(t, env): res = close_file(sess2, fh2, stateid=stateid2) check(res) + +# How long to wait for a CB_NOTIFY_LOCK after the conflicting lock +# is released. +NOTIFY_LOCK_WAIT = 10 + +def _new_owner_lock_op(open_stateid, owner, locktype): + """LOCK of the whole file by a new lock owner""" + open_to_lock_owner = open_to_lock_owner4(0, open_stateid, 0, + lock_owner4(0, owner)) + locker = locker4(open_owner=open_to_lock_owner, new_lock_owner=True) + return op.lock(locktype, False, 0, NFS4_UINT64_MAX, locker) + +def _notify_lock_conflict(t, env, locktype): + """Set up a lock conflict between two clients + + The first client holds a WRITE_LT on the whole file. The second + client then requests a lock of type locktype on the whole file, + and gets NFS4ERR_DENIED. Any CB_NOTIFY_LOCK the second client + receives is recorded in the returned "notifies" list. + """ + notifies = [] + notified = threading.Event() + def pre_hook(arg, env): + notifies.append(arg) + notified.set() + + sess1 = env.c1.new_client_session(b"%s_1" % env.testname(t)) + res = create_file(sess1, env.testname(t)) + check(res) + fh1 = res.resarray[-1].object + open_stateid1 = res.resarray[-2].stateid + res = sess1.compound([op.putfh(fh1), + _new_owner_lock_op(open_stateid1, b"lock1", + WRITE_LT)]) + check(res, msg="WRITE_LT by the first client") + lock_stateid1 = res.resarray[-1].lock_stateid + + sess2 = env.c1.new_client_session(b"%s_2" % env.testname(t)) + sess2.client.cb_pre_hook(OP_CB_NOTIFY_LOCK, pre_hook) + res = open_file(sess2, env.testname(t), access=OPEN4_SHARE_ACCESS_BOTH) + check(res) + fh2 = res.resarray[-1].object + open_stateid2 = res.resarray[-2].stateid + if not res.resarray[-2].rflags & OPEN4_RESULT_MAY_NOTIFY_LOCK: + t.fail_support("Server did not set OPEN4_RESULT_MAY_NOTIFY_LOCK") + + lock_op2 = _new_owner_lock_op(open_stateid2, b"lock2", locktype) + res = sess2.compound([op.putfh(fh2), lock_op2]) + check(res, NFS4ERR_DENIED, + "%s while another client holds a WRITE_LT" % nfs_lock_type4[locktype]) + + return {"sess1": sess1, "fh1": fh1, "open_stateid1": open_stateid1, + "lock_stateid1": lock_stateid1, + "sess2": sess2, "fh2": fh2, "open_stateid2": open_stateid2, + "lock_op2": lock_op2, + "notifies": notifies, "notified": notified} + +def _notify_lock_release(s): + """Release the first client's lock and close its file""" + res = s["sess1"].compound([op.putfh(s["fh1"]), + op.locku(WRITE_LT, 0, s["lock_stateid1"], + 0, NFS4_UINT64_MAX)]) + check(res, msg="LOCKU by the first client") + res = close_file(s["sess1"], s["fh1"], stateid=s["open_stateid1"]) + check(res) + +def testCbNotifyLockBlocking(t, env): + """A blocking LOCK denied by another client's lock gets a + CB_NOTIFY_LOCK when that lock is released + + FLAGS: callback all + CODE: CALLBACK2 + """ + s = _notify_lock_conflict(t, env, WRITEW_LT) + _notify_lock_release(s) + + s["notified"].wait(NOTIFY_LOCK_WAIT) + if not s["notifies"]: + fail("Did not receive CB_NOTIFY_LOCK within %d seconds of LOCKU" + % NOTIFY_LOCK_WAIT) + arg = s["notifies"][0] + if arg.cnla_fh != s["fh2"]: + fail("CB_NOTIFY_LOCK has the wrong filehandle") + if arg.cnla_lock_owner.owner != b"lock2": + fail("CB_NOTIFY_LOCK has lock owner %r, expected %r" % + (arg.cnla_lock_owner.owner, b"lock2")) + + res = s["sess2"].compound([op.putfh(s["fh2"]), s["lock_op2"]]) + check(res, msg="WRITEW_LT retried after CB_NOTIFY_LOCK") + res = close_file(s["sess2"], s["fh2"], stateid=s["open_stateid2"]) + check(res) + +def testCbNotifyLockNonBlocking(t, env): + """A non-blocking LOCK denied by another client's lock does not get + a CB_NOTIFY_LOCK when that lock is released + + FLAGS: callback all + CODE: CALLBACK3 + """ + s = _notify_lock_conflict(t, env, WRITE_LT) + _notify_lock_release(s) + + s["notified"].wait(NOTIFY_LOCK_WAIT) + if s["notifies"]: + fail("Received CB_NOTIFY_LOCK for a non-blocking LOCK") + + res = s["sess2"].compound([op.putfh(s["fh2"]), s["lock_op2"]]) + check(res, msg="WRITE_LT retried after the conflicting lock was released") + res = close_file(s["sess2"], s["fh2"], stateid=s["open_stateid2"]) + check(res) -- 2.56.1