Repository navigation
Linux 6.17: fuse: add a quota admission lease for writeback-cache writes - #300
Conversation
|
I have no idea how relevant this is, but the mmap fault retry loop has no guaranteed exit. |
yongzech
left a comment
There was a problem hiding this comment.
Reviewed together with the redfsd part (red/red#30168 on GHE) and the libfuse part (DDNStorage/red-libfuse#139). The wire format matches redfsd and libfuse (fuse_quota_lease 32 bytes, lock lease reply 56 bytes, opcode 103, INIT bits 55/56).
The lease state machine looks correct: locking and lock order, RCU lifetime and reference counting, single-flight renewal, unmount teardown, owner-change detection, and the page_mkwrite/fault path. I found no bug in this PR on its own. One issue spans both sides; it's inline below.
Two related redfsd findings, raised on red#30168, touch this code:
- On redfsd's TSD-only fallback, a renewal's
genfalls below the installedl->gen, sofuse_qlease_apply_renewal()ignores renewals of a valid lease, andfuse_qlease_reject_applies()ignores rejections until the lease expires. The fix belongs in redfsd. - redfsd hands an owner with no quota limit
ttl_ms = INT32_MAX(about 24.8 days), and this PR doesn't cap it. A kernel-side cap would also be a reasonable guard.
This PR adds no tests.
With the writeback cache, a write returns once it has dirtied the page cache, and the data reaches the server later through writeback. By then the server cannot refuse it for quota without losing data that the application believes written, so quota has to be decided before the page is dirtied. Add a quota admission lease. The server grants a lease, with a TTL, while the owner of the file is under quota: per uid and gid when the server enforces user and group quota, per dataset otherwise. A buffered write or a store to a shared writable mapping dirties the page cache only while the inode's lease is valid, and the server takes the writeback of those pages without a quota check. The server offers FUSE_QUOTA_LEASE at INIT, and sets FUSE_QUOTA_ENABLED with it when quota is on for the mount. The quota state is fixed for the session; with quota off the kernel does no lease work. The lease is checked together with the DLM write grant. When the grant is missing, the write lock request is sent and its reply carries the lease (struct fuse_dlm_lock_lease_out). When the grant is held but the inode has no lease, FUSE_QUOTA_ADMIT asks for one. An expired lease is renewed with FUSE_QADMIT_RENEW after writeback of its inodes has started, and a background work renews a valid lease at half its TTL. Leases are kept per connection, hashed by lease id, with the inodes that use a lease linked to it. A REJECTED lease fails writes with EDQUOT for qlease_reject_hold_ms. Each lease part carries the mint sequence of the TSD voucher and of the UG voucher it was decided from, or FUSE_QLEASE_NO_UG when it read no UG voucher. The kernel keeps the highest of each and applies a reply only when no sequence it used is older and at least one is newer, so a reply decided from an older voucher neither moves a deadline back nor rejects a lease a newer reply renewed. The TTL a lease is installed with is capped at qlease_max_ttl_ms, 120 s by default. The server retries a transient failure itself and never answers a lease request with -EAGAIN, which the kernel treats as a protocol error, -EIO. A request the server ends with -EINTR, because the writer was interrupted while it retried, restarts the write when a signal is pending. page_mkwrite without a valid lease unmaps the page so that the store refaults through ->fault, which can admit with mmap_lock dropped; qlease_mmap_retry_ms bounds the retry of an admit error there, and each successful admission lets one store through even if its lease lapsed before the refault. A write lock request that admits nothing, grant-ahead or a load fault, sets FUSE_DLM_LOCK_NO_ADMIT in the former reserved field of struct fuse_dlm_lock_in, so the server fetches no voucher for it. A write reads the lease state without locks, under RCU and a seqcount; a per-lease spinlock serializes updates, and the connection lock covers only the hash and the inode links. The inode grows by the lease pointer, its link, the owner the lease was granted for and a pointer to the shared-mmap state, which is allocated only for shared writable mappings. Tracepoints cover installs, replies, renewals, expiry and rechecks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Hai Zhong Zhou <hazhou@ddn.com>
910990d to
c48b61a
Compare
|
@hbirth You're right: errors already ended the loop through the SIGBUS mark, but success did not. A successful admission returned @yongzech Thanks for the review. The two findings from the redfsd side:
The kernel changes are synced into red's |
hbirth
left a comment
There was a problem hiding this comment.
LGTM
We just have to solve the conflict ... and then we can merge it
|
After solving the conflict I will push this directly to DDNStorage |
|
This is already merged |
With the writeback cache, a write returns once it has dirtied the page cache, and the data reaches the server later through writeback. By then the server cannot refuse it for quota without losing data that the application believes written, so quota has to be decided before the page is dirtied.
Add a quota admission lease. The server grants a lease, with a TTL, while the owner of the file is under quota: per uid and gid when the server enforces user and group quota, per dataset otherwise. A buffered write or a store to a shared writable mapping dirties the page cache only while the inode's lease is valid, and the server takes the writeback of those pages without a quota check.
The server offers FUSE_QUOTA_LEASE at INIT, and sets FUSE_QUOTA_ENABLED with it when quota is on for the mount. The quota state is fixed for the session; with quota off the kernel does no lease work.
The lease is checked together with the DLM write grant. When the grant is missing, the write lock request is sent and its reply carries the lease (struct fuse_dlm_lock_lease_out). When the grant is held but the inode has no lease, FUSE_QUOTA_ADMIT asks for one. An expired lease is renewed with FUSE_QADMIT_RENEW after writeback of its inodes has started, and a background work renews a valid lease at half its TTL.
Leases are kept per connection, hashed by lease id, with the inodes that use a lease linked to it. A REJECTED lease fails writes with EDQUOT for qlease_reject_hold_ms. Each lease part carries a generation, so a reply decided from an older voucher neither moves a deadline back nor rejects a lease a newer reply renewed. The server retries a transient failure itself and never answers a lease request with -EAGAIN, which the kernel treats as a protocol error, -EIO. A request the server ends with -EINTR, because the writer was interrupted while it retried, restarts the write when a signal is pending. page_mkwrite without a valid lease unmaps the page so that the store refaults through ->fault, which can admit with mmap_lock dropped; qlease_mmap_retry_ms bounds the retry of an admit error there.
A write reads the lease state without locks, under RCU and a seqcount; a per-lease spinlock serializes updates, and the connection lock covers only the hash and the inode links. The inode grows by the lease pointer, its link, the owner the lease was granted for and a pointer to the shared-mmap state, which is allocated only for shared writable mappings. Tracepoints
cover installs, replies, renewals, expiry and rechecks.