Skip to content

nfs4: project NFSv4 range locks to the backend claim layer - #1915

Open
akamit91 wants to merge 5 commits into
chimera-nas:mainfrom
akamit91:nfs4-lock-conflicts
Open

akamit91 wants to merge 5 commits into
chimera-nas:mainfrom
akamit91:nfs4-lock-conflicts

Conversation

@akamit91

@akamit91 akamit91 commented Dec 6, 2026

Copy link
Copy Markdown
Collaborator

NFSv4 byte-range locks are now confirmed with the backend before the LOCK reply is sent. A lock taken through NFSv4 is therefore also held at the backend, where other nodes can see it. The change is three commits on top of upstream main.

  • nfs4: project range locks to the backend claim layer lets NFSv4 owners through the backend range gate. The backend token is carried on the lock records, so merging, carving and unlocking release the backend record too. NLM locks stay node-local.
  • nfs4: carry lock regrants and LOCKT through the backend range gate projects the surviving pieces of a downgrade or split onto the same token, and releases the retired tokens only after the LOCK reply is ready, so the range is never unheld during a regrant. LOCKT asks the backend as well as the local claim table. LOCKU and LOCK on the same lock state exclude each other: LOCKU returns NFS4ERR_DELAY while a LOCK is pinned on that state, and a LOCK is refused its pin while a LOCKU walk runs.
  • nfs4: finish lock completions on the request's thread runs the LOCK reply and the regrant finish on the request's own thread. Backend answers can arrive on any thread, and the reply has to go out on the owning evpl. A backend range-confirm error now denies only the requested range; before, it was reported as a whole-file conflict. If the server cannot remember a carried range token, it aborts rather than releasing the backend record while the local lease still holds those bytes.

Known limits:

  • A partial LOCKU does not yet shrink the backend lock. The backend keeps the old range until the lock is released in full.
  • Two LOCKs that merge on the same owner at the same time are not fully serialised yet. Closing that needs a range-replace operation in the claim layer; it is a follow-up.
  • A connection that closes while a LOCK waits on the backend is not covered by this PR.

Testing:

  • In the devcontainer, make syntax, sdk-include-check, build_debug and build_clang pass.
  • Full ctest, run serially (291 of 291), passes on Release and on Debug for this branch.
  • Parallel ctest (the default -j) fails intermittently with "Subprocess aborted", on this branch and on the unmodified base, so it is not used as the gate here.
  • reuse-lint fails on the base as well, because ext/specs/REUSE.toml and .reuse/dep5 both exist. copyright-check cannot run in the devcontainer: etc/copyright-year.sh uses git diff --merge-base, which the container's git rejects, so no header is checked.

Let NFSv4 owners through the backend range gate, and carry the backend tokens on the NFS lock records so that merging, carving and unlocking release them. NLM locks stay node-local. A partial LOCKU does not yet shrink the backend lock.

Signed-off-by: Amit Kumar <akamit91@hotmail.com>
A LOCK that downgrades or splits a held range no longer releases the old
backend record before the new pieces are in place. The surviving pieces are
projected onto the same backend token, and the retired tokens are released
only after the LOCK reply is ready, so the range is not left unheld during
the regrant.

LOCKT asks the backend as well as the local claim table, so a conflict held
on another node is reported with its range. The owner stays empty in the
DENIED reply because the backend does not carry it.

LOCKU and LOCK on the same lock state exclude each other in both directions.
LOCKU returns NFS4ERR_DELAY while a LOCK is still pinned on that state, and a
LOCK is refused its pin while a LOCKU walk runs. On DELAY the seqid and the
ranges are left untouched, so the client retries.

Tests cover downgrade and re-lock projection and LOCK denial by another
owner in the relock probe, and the LOCKU gate in the state table test.

Signed-off-by: Amit Kumar <akamit91@hotmail.com>
A LOCK or regrant can be answered by the claim layer on any thread, but
the reply has to go out on the request's own evpl. Route the completion
through nfs4_cb_defer_to_thread, which reuses the callback doorbell
queue, so the reply is always built on the owning thread.

A backend range confirm that fails with an error now denies only the
requested range. Before, the conflict was reported as the whole file,
which misreported the file as locked.

If the server cannot remember a carried range token, it aborts instead
of releasing the backend record. Releasing it would hand the bytes to
other nodes while the local lease still holds them.

Signed-off-by: Amit Kumar <akamit91@hotmail.com>
Upstream added nfs4_thread_run, the same cross-thread completion
helper this series introduced as nfs4_cb_defer_to_thread. Take the
upstream version and point the regrant and lock completion call sites
at it. Keep both the LOCKU/LOCK pin gate test and the upstream layout
stateid test.

Signed-off-by: Amit Kumar <akamit91@hotmail.com>
@github-actions

github-actions Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Quick-tier test coverage

Component Functions Lines Branches
src/server/nfs █████████░ 91%
1,164/1,276
████████░░ 77%
24,526/31,734
██████░░░░ 61%
11,991/19,535
src/server/smb █████████░ 89%
698/786
███████░░░ 70%
16,801/23,886
██████░░░░ 59%
6,958/11,844
src/vfs █████████░ 91%
894/986
████████░░ 77%
17,847/23,068
██████░░░░ 63%
6,281/9,905
src/vfs/diskfs ████████░░ 83%
665/800
███████░░░ 75%
12,269/16,425
██████░░░░ 60%
3,126/5,202
src/vfs/nfs ████████░░ 75%
220/293
██████░░░░ 61%
5,458/8,878
█████░░░░░ 48%
1,496/3,124
src/server/s3 █████████░ 92%
313/342
████████░░ 77%
6,493/8,449
██████░░░░ 60%
1,988/3,292
src/posix ███████░░░ 70%
218/312
██████░░░░ 60%
3,270/5,427
█████░░░░░ 51%
843/1,665
src/vfs/memfs ██████████ 96%
93/97
████████░░ 79%
3,881/4,899
███████░░░ 72%
1,513/2,096
src/vfs/cairn ████████░░ 84%
106/126
███████░░░ 73%
3,466/4,772
██████░░░░ 63%
952/1,506
src/vfs/smb ██████████ 99%
173/175
████████░░ 82%
3,521/4,271
██████░░░░ 61%
840/1,366
src/common ████████░░ 79%
148/187
█████░░░░░ 51%
1,892/3,721
███░░░░░░░ 28%
804/2,825
src/server/fuse ████████░░ 77%
150/196
██████░░░░ 62%
2,297/3,700
█████░░░░░ 53%
1,369/2,601
src/server/rest ██████░░░░ 62%
58/94
█████░░░░░ 47%
1,114/2,377
████░░░░░░ 36%
333/938
src/vfs/io_uring █████████░ 93%
51/55
████████░░ 77%
1,790/2,320
██████░░░░ 63%
610/971
src/vfs/linux █████████░ 91%
58/64
███████░░░ 72%
1,682/2,320
██████░░░░ 60%
669/1,111
src/server ███████░░░ 66%
188/284
██████░░░░ 56%
1,175/2,104
████░░░░░░ 36%
190/532
src/client ██████░░░░ 61%
80/132
█████░░░░░ 50%
1,008/2,003
██░░░░░░░░ 24%
83/347
src/smb_common ██████████ 100%
51/51
████████░░ 78%
1,239/1,582
███████░░░ 69%
513/746
src/vfs/sdk █████████░ 94%
32/34
███████░░░ 71%
350/495
████████░░ 79%
129/164
src/nfs_common ██████████ 100%
15/15
███████░░░ 65%
231/355
███████░░░ 75%
139/186
src/vfs/memkv ██████████ 100%
14/14
█████████░ 90%
257/286
███████░░░ 72%
114/158
src/metrics ██████████ 100%
10/10
████████░░ 81%
198/243
██████░░░░ 61%
56/92
Total █████████░ 85%
5,399/6,329
███████░░░ 72%
110,765/153,315
██████░░░░ 58%
40,997/70,206
make coverage CTEST_ARGS="--output-on-failure"

Coverage of this pull request's changes

█████████░ 89% (465/525 changed lines executed)

File Changed lines executed
src/server/nfs/nfs4_proc_lock.c █████████░ 88% (198/226)
src/server/nfs/nfs4_proc_lockt.c █████████░ 88% (56/64)
src/server/nfs/nfs4_proc_locku.c █████████░ 85% (40/47)
src/server/nfs/nfs4_state.c ██████████ 96% (67/70)
src/server/nfs/nfs4_state.h no executable lines changed
src/vfs/vfs_claim.c █████████░ 94% (30/32)
src/vfs/vfs_claim.h no executable lines changed
src/vfs/vfs_claim_backend.c █████████░ 86% (74/86)
src/vfs/vfs_claim_internal.h no executable lines changed
src/vfs/vfs_procs.h no executable lines changed

Changed lines the quick-tier tests never executed: src/server/nfs/nfs4_proc_lock.c 141–142, 256–257, 271–273, 296–297, 354–361, 491–495, 501–503, 507, 550–551; src/server/nfs/nfs4_proc_lockt.c 71, 77–83; src/server/nfs/nfs4_proc_locku.c 160–166 …and 8 more.

Executed by the quick-tier tests (ctest) — code reached solely by the other suites counts as unexecuted here. Lines with no coverage mapping (declarations, braces, comments) are excluded rather than counted as misses.

A LOCKU replied as soon as the local lease dropped its ranges, but the
backend release is queued on the claim layer and can finish later. A
client that saw the unlock succeed could then be refused a LOCK on the
same bytes from another node, because the backend record still existed.

The LOCKU now arms a release-wait counter. Each queued backend release
takes a reference on it, and the owner reference taken at arm time is
dropped once the walk finishes. The last reference to drop completes the
compound on the request's thread through nfs4_thread_run. The v4.0 seqid
replay record is still written synchronously, so a retry sent while the
release is pending gets the same answer.

Signed-off-by: Amit Kumar <akamit91@hotmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant