* [PATCH v2 01/11] nfsd: don't hold inode_lock while waiting for a delegation in nfsd_setattr()
2026-11-23 12:59 [PATCH v2 00/11] nfsd: various delegated timestamp fixes Jeff Layton
@ 2026-11-23 12:59 ` Jeff Layton
2026-11-23 12:59 ` [PATCH v2 02/11] nfsd: take freeze protection before updating delegation timestamps Jeff Layton
` (9 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Jeff Layton @ 2026-11-23 12:59 UTC (permalink / raw)
To: Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
Christian Brauner
Cc: Aurélien Couderc, linux-nfs, linux-kernel, Jeff Layton
When notify_change() breaks a delegation, nfsd_setattr() waits up to
NFSD_DELEGRETURN_TIMEOUT for the holder to return the delegation and
then retries once. nfsd_setattr() waits with inode_lock still held, but
what the holder sends before DELEGRETURN can need that lock. WRITEs that
flush the holder's dirty data take i_rwsem exclusively on ext4 and xfs,
and a SETATTR with delegated timestamps in the DELEGRETURN compound goes
through nfsd_setattr() itself. The wait then always times out, and the
SETATTR fails with NFS4ERR_DELAY after stalling the DELEGRETURN that the
wait was for.
Drop inode_lock across the wait, as callers of break_deleg_wait() do.
The file can change while the lock is dropped, so start over after the
wait. Check again that the truncate is allowed, take fresh pre-op
attributes, check the guard again, and sanitize a fresh copy of the
attributes, since the setid bits that a chown must clear depend on the
current mode. Redoing these steps under the lock keeps them atomic with
the attempt that changes the inode. fh_fill_pre_attrs() does nothing
once pre-op attributes are saved, so restore fh_pre_saved to its value
on entry.
If the wait times out, still try once more rather than finishing with
the attributes from before the wait. A lease that is already being
broken isn't broken again, so the retry just gets -EAGAIN.
Don't start over once the size change is done, though, as when a
filesystem returns -EAGAIN for the other attributes after the truncate.
The retry would truncate again, over whatever was written while the lock
was dropped, and the retry's fresh pre-op attributes would hide the
first truncate. Return the error instead, as if the wait had failed.
Fixes: 34b91dda7124 ("NFSD: Make nfsd4_setattr() wait before returning NFS4ERR_DELAY")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfsd/vfs.c | 48 +++++++++++++++++++++++++++++++-----------------
1 file changed, 31 insertions(+), 17 deletions(-)
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index e033fbc225cf..4a5674e583cc 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -549,7 +549,9 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
int host_err = 0;
bool get_write_count;
bool size_change = (iap->ia_valid & ATTR_SIZE);
- int retries;
+ bool pre_saved = fhp->fh_pre_saved;
+ bool retried = false;
+ struct iattr attrs;
trace_nfsd_vfs_setattr(rqstp, fhp, iap, guardtime);
@@ -587,8 +589,6 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
dentry = fhp->fh_dentry;
inode = d_inode(dentry);
- nfsd_sanitize_attrs(inode, iap);
-
/*
* The size case is special, it changes the file in addition to the
* attributes, and file systems don't expect it to be mixed with
@@ -611,6 +611,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
}
}
+retry:
inode_lock(inode);
if (size_change) {
err = nfsd_may_truncate(rqstp, fhp, iap);
@@ -630,20 +631,33 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
}
}
- for (retries = 1;;) {
- struct iattr attrs;
-
- /*
- * notify_change() can alter its iattr argument, making
- * @iap unsuitable for submission multiple times. Make a
- * copy for every loop iteration.
- */
- attrs = *iap;
- host_err = __nfsd_setattr(dentry, &attrs);
- if (host_err != -EAGAIN || !retries--)
- break;
- if (!nfsd_wait_for_delegreturn(rqstp, inode))
- break;
+ /*
+ * notify_change() can alter its iattr argument, making @iap
+ * unsuitable for submission multiple times. Pass a copy,
+ * sanitized under inode_lock, because the setid bits that a
+ * chown must clear depend on the current mode.
+ */
+ attrs = *iap;
+ nfsd_sanitize_attrs(inode, &attrs);
+ host_err = __nfsd_setattr(dentry, &attrs);
+ /*
+ * A delegation was broken. Drop inode_lock while waiting for the
+ * holder to return the delegation, since what the holder sends
+ * first, such as WRITEs that flush the holder's dirty data, can
+ * need the lock. The file can change meanwhile, so start over,
+ * taking fresh pre-op attributes and checking the guard again.
+ * Starting over is safe only if this attempt changed nothing. A
+ * retry would repeat a size change that is already done
+ * (__nfsd_setattr() clears ATTR_SIZE) over whatever was written
+ * after the truncate, so return the error in that case.
+ */
+ if (host_err == -EAGAIN && !retried &&
+ !(size_change && !(attrs.ia_valid & ATTR_SIZE))) {
+ inode_unlock(inode);
+ retried = true;
+ nfsd_wait_for_delegreturn(rqstp, inode);
+ fhp->fh_pre_saved = pre_saved;
+ goto retry;
}
if (attr->na_seclabel && attr->na_seclabel->len)
attr->na_labelerr = security_inode_setsecctx(dentry,
--
2.56.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v2 02/11] nfsd: take freeze protection before updating delegation timestamps
2026-11-23 12:59 [PATCH v2 00/11] nfsd: various delegated timestamp fixes Jeff Layton
2026-11-23 12:59 ` [PATCH v2 01/11] nfsd: don't hold inode_lock while waiting for a delegation in nfsd_setattr() Jeff Layton
@ 2026-11-23 12:59 ` Jeff Layton
2026-11-23 17:46 ` Chuck Lever
2026-11-23 12:59 ` [PATCH v2 03/11] nfsd: count a delegation in cl_delegs_in_recall only once Jeff Layton
` (8 subsequent siblings)
10 siblings, 1 reply; 13+ messages in thread
From: Jeff Layton @ 2026-11-23 12:59 UTC (permalink / raw)
To: Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
Christian Brauner
Cc: Aurélien Couderc, linux-nfs, linux-kernel, Jeff Layton
cb_getattr_update_times(), nfsd_update_cmtime_attr() and
nfsd4_finalize_deleg_timestamps() call notify_change() under
inode_lock(), but nothing holds freeze protection for the export's
filesystem. They can therefore modify a frozen filesystem. On ext4, a
foreign GETATTR whose CB_GETATTR finds that the holder modified the file
trips the WARN_ON() in ext4_journal_check_start(), and the inode's mtime
and ctime change while the filesystem is frozen.
The delegation's file (but see CB_GETATTR below) and the COPY or CLONE
destination are open for write, so the mount's write access is held.
Only the superblock's freeze protection is missing. Freeze protection is
taken outside inode_lock.
- cb_getattr_update_times() runs in the nfsd thread that is processing
the GETATTR. Rather than hold the thread until the thaw,
cb_getattr_update_times() tries for freeze protection and returns
NFS4ERR_DELAY, so the client retries. The GETATTR's delegation
reference doesn't keep the file open, though. A racing DELEGRETURN or
revocation can put fi_deleg_file, so pin fi_deleg_file to keep the
write access. Skip the update once the delegation is unhashed, because
the delegation's return may already have finalized the times. The
times from CB_GETATTR are older and would roll the finalized times
back.
- nfsd_update_cmtime_attr(), from COPY and CLONE, waits for the thaw, as
the data change that made the update necessary did.
- nfsd4_finalize_deleg_timestamps() runs when a delegation's lease is
released, including from the laundromat and during NFSD shutdown.
Neither path may wait for a thaw, so nfsd4_finalize_deleg_timestamps()
only tries for freeze protection, and leaves the times alone with a
notice when the filesystem is frozen.
Reported-by: Christian Brauner <brauner@kernel.org>
Closes: https://lore.kernel.org/linux-nfs/20261114-abdrehen-mahnwache-farbpalette-9c31774145cc@brauner/
Fixes: 7e8ae8486e44 ("fs/nfsd: fix update of inode attrs in CB_GETATTR")
Fixes: e5e9b24ab8fa ("nfsd: freeze c/mtime updates with outstanding WRITE_ATTRS delegation")
Fixes: 2863bac7f49c ("nfsd: update mtime/ctime on CLONE in presense of delegated attributes")
Fixes: 4183cf383b6f ("nfsd: update mtime/ctime on COPY in presence of delegated attributes")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfsd/nfs4state.c | 94 ++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 75 insertions(+), 19 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 048b2616d783..c4c0f6cfa14d 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -1453,6 +1453,30 @@ static void put_deleg_file(struct nfs4_file *fp)
}
}
+static void nfsd_cmtime_notice(struct inode *inode, int err)
+{
+ pr_notice_ratelimited("nfsd: Unable to update timestamps on inode %02x:%02x:%llu: %d\n",
+ MAJOR(inode->i_sb->s_dev),
+ MINOR(inode->i_sb->s_dev),
+ inode->i_ino, err);
+}
+
+/* Caller holds freeze protection for @f's filesystem */
+static void __nfsd_update_cmtime_attr(struct file *f, unsigned int flags)
+{
+ struct inode *inode = file_inode(f);
+ struct iattr attr = {
+ .ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_DELEG | flags,
+ };
+ int ret;
+
+ inode_lock(inode);
+ ret = notify_change(&nop_mnt_idmap, f->f_path.dentry, &attr, NULL);
+ inode_unlock(inode);
+ if (ret)
+ nfsd_cmtime_notice(inode, ret);
+}
+
static void nfsd4_finalize_deleg_timestamps(struct nfs4_delegation *dp, struct file *f)
{
/* don't do anything if FMODE_NOCMTIME isn't set */
@@ -1471,8 +1495,18 @@ static void nfsd4_finalize_deleg_timestamps(struct nfs4_delegation *dp, struct f
if (dp->dl_setattr)
return;
+ /*
+ * This function also runs from the laundromat and from NFSD
+ * shutdown. Neither path may wait for a frozen filesystem to
+ * thaw, so leave the times alone while the filesystem is frozen.
+ */
+ if (!file_start_write_trylock(f)) {
+ nfsd_cmtime_notice(file_inode(f), -EBUSY);
+ return;
+ }
/* Stamp everything to "now" */
- nfsd_update_cmtime_attr(f, ATTR_ATIME);
+ __nfsd_update_cmtime_attr(f, ATTR_ATIME);
+ file_end_write(f);
}
static void nfs4_unlock_deleg_lease(struct nfs4_delegation *dp)
@@ -10755,8 +10789,11 @@ static int cb_getattr_update_times(struct dentry *dentry, struct nfs4_delegation
{
struct inode *inode = d_inode(dentry);
struct nfs4_cb_fattr *ncf = &dp->dl_cb_fattr;
+ struct nfs4_file *fp = dp->dl_stid.sc_file;
struct iattr attrs = { };
- int ret;
+ struct nfsd_file *nf;
+ bool hashed;
+ int ret = 0;
if (deleg_attrs_deleg(dp->dl_type)) {
struct timespec64 now = current_time(inode);
@@ -10780,10 +10817,40 @@ static int cb_getattr_update_times(struct dentry *dentry, struct nfs4_delegation
if (!attrs.ia_valid)
return 0;
+ /*
+ * The reference on @dp doesn't keep the delegation's file open.
+ * A racing DELEGRETURN or revocation can put fi_deleg_file, so
+ * pin fi_deleg_file to keep the mount's write access.
+ */
+ rcu_read_lock();
+ nf = nfsd_file_get(rcu_dereference(fp->fi_deleg_file));
+ rcu_read_unlock();
+ if (!nf)
+ return 0;
+
+ /*
+ * Don't hold an nfsd thread until a frozen filesystem thaws.
+ * NFS4ERR_DELAY makes the client retry.
+ */
+ if (!file_start_write_trylock(nf->nf_file)) {
+ nfsd_file_put(nf);
+ return -EAGAIN;
+ }
attrs.ia_valid |= ATTR_DELEG;
inode_lock(inode);
- ret = notify_change(&nop_mnt_idmap, dentry, &attrs, NULL);
+ /*
+ * Once @dp is unhashed, its return or revocation may already have
+ * finalized the times under inode_lock. The CB_GETATTR times are
+ * older and would roll the finalized times back.
+ */
+ spin_lock(&fp->fi_lock);
+ hashed = delegation_hashed(dp);
+ spin_unlock(&fp->fi_lock);
+ if (hashed)
+ ret = notify_change(&nop_mnt_idmap, dentry, &attrs, NULL);
inode_unlock(inode);
+ file_end_write(nf->nf_file);
+ nfsd_file_put(nf);
return ret;
}
@@ -11052,25 +11119,14 @@ nfsd_get_dir_deleg(struct nfsd4_compound_state *cstate,
* @flags: any additional flags that should be updated
*
* Given upon opening a file delegated attributes were issues, update
- * @f attributes to current times.
+ * @f attributes to current times. Waits for a frozen filesystem to thaw,
+ * like the data change that makes this necessary.
*/
void nfsd_update_cmtime_attr(struct file *f, unsigned int flags)
{
- int ret;
- struct inode *inode = file_inode(f);
- struct iattr attr = {
- .ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_DELEG | flags,
- };
-
- inode_lock(inode);
- ret = notify_change(&nop_mnt_idmap, f->f_path.dentry, &attr, NULL);
- inode_unlock(inode);
- if (ret)
- pr_notice_ratelimited("nfsd: Unable to update timestamps on "
- "inode %02x:%02x:%llu: %d\n",
- MAJOR(inode->i_sb->s_dev),
- MINOR(inode->i_sb->s_dev),
- inode->i_ino, ret);
+ file_start_write(f);
+ __nfsd_update_cmtime_attr(f, flags);
+ file_end_write(f);
}
static void
--
2.56.1
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v2 02/11] nfsd: take freeze protection before updating delegation timestamps
2026-11-23 12:59 ` [PATCH v2 02/11] nfsd: take freeze protection before updating delegation timestamps Jeff Layton
@ 2026-11-23 17:46 ` Chuck Lever
0 siblings, 0 replies; 13+ messages in thread
From: Chuck Lever @ 2026-11-23 17:46 UTC (permalink / raw)
To: Jeff Layton
Cc: NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
Christian Brauner, Aurélien Couderc, linux-nfs,
linux-kernel
On Mon, Nov 23, 2026, Jeff Layton wrote:
> + /*
> + * This function also runs from the laundromat and from NFSD
> + * shutdown. Neither path may wait for a frozen filesystem to
> + * thaw, so leave the times alone while the filesystem is frozen.
> + */
> + if (!file_start_write_trylock(f)) {
> + nfsd_cmtime_notice(file_inode(f), -EBUSY);
> + return;
> + }
DELEGRETURN reaches this trylock too, through destroy_delegation().
FMODE_NOCMTIME is already clear by then, so nothing sets mtime and
ctime afterward. A client that writes under a WRITE_ATTRS_DELEG and
returns it without a SETATTR of the delegated times, while the
filesystem is frozen, leaves the file with its pre-delegation times
after the thaw.
The laundromat and shutdown can't wait, but DELEGRETURN runs in an
nfsd thread, and the WRITEs that dirtied the file already block in
file_start_write(). Can DELEGRETURN wait for the thaw as well, or
might it be OK to return NFS4ERR_DELAY in this case?
--
Chuck Lever
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 03/11] nfsd: count a delegation in cl_delegs_in_recall only once
2026-11-23 12:59 [PATCH v2 00/11] nfsd: various delegated timestamp fixes Jeff Layton
2026-11-23 12:59 ` [PATCH v2 01/11] nfsd: don't hold inode_lock while waiting for a delegation in nfsd_setattr() Jeff Layton
2026-11-23 12:59 ` [PATCH v2 02/11] nfsd: take freeze protection before updating delegation timestamps Jeff Layton
@ 2026-11-23 12:59 ` Jeff Layton
2026-11-23 12:59 ` [PATCH v2 04/11] nfsd: don't grant write delegations to NFSv4.0 clients on CLAIM_PREVIOUS Jeff Layton
` (7 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Jeff Layton @ 2026-11-23 12:59 UTC (permalink / raw)
To: Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
Christian Brauner
Cc: Aurélien Couderc, linux-nfs, linux-kernel, Jeff Layton
nfsd_break_deleg_cb() can run more than once per lease:
- __break_lease() calls lm_break for a read breaker
(FL_DOWNGRADE_PENDING) and again for a later write breaker
(FL_UNLOCK_PENDING).
- nfsd_handle_dir_event() and nfsd_recall_all_dir_delegs() call
nfsd_break_deleg_cb() directly, possibly repeatedly.
Each call increments cl_delegs_in_recall, but nfsd_change_deleg_cb()
decrements it only once, at F_UNLCK. The leaked count keeps
nfs4_anylock_blockers() true, so the client can never again become a
courtesy client.
When dl_recalled is already set, skip the increment, the client expiry,
and the stores to dl_recalled and fi_had_conflict. All callers and the
F_UNLCK decrement run under flc_lock. Setting fl_break_time to 0, the
nfsd_break_one_deleg() call, and the false return stay unconditional.
Fixes: 66af25799940 ("NFSD: add courteous server support for thread with only delegation")
Fixes: cb7444b27c85 ("nfsd: add notification handlers for dir events")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfsd/nfs4state.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index c4c0f6cfa14d..5c2151b329c4 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -6645,11 +6645,20 @@ nfsd_break_deleg_cb(struct file_lease *fl)
trace_nfsd_cb_recall(&dp->dl_stid);
- dp->dl_recalled = true;
- atomic_inc(&clp->cl_delegs_in_recall);
- if (try_to_expire_client(clp)) {
- nn = net_generic(clp->net, nfsd_net_id);
- mod_delayed_work(laundry_wq, &nn->laundromat_work, 0);
+ /*
+ * lm_break runs again for a write breaker after a read breaker, and
+ * the dir notification paths call nfsd_break_deleg_cb() directly.
+ * Only the first call may count the recall, since
+ * nfsd_change_deleg_cb() decrements cl_delegs_in_recall only once.
+ */
+ if (!dp->dl_recalled) {
+ dp->dl_recalled = true;
+ atomic_inc(&clp->cl_delegs_in_recall);
+ if (try_to_expire_client(clp)) {
+ nn = net_generic(clp->net, nfsd_net_id);
+ mod_delayed_work(laundry_wq, &nn->laundromat_work, 0);
+ }
+ fp->fi_had_conflict = true;
}
/*
@@ -6659,7 +6668,6 @@ nfsd_break_deleg_cb(struct file_lease *fl)
*/
fl->fl_break_time = 0;
- fp->fi_had_conflict = true;
nfsd_break_one_deleg(dp);
return false;
}
--
2.56.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v2 04/11] nfsd: don't grant write delegations to NFSv4.0 clients on CLAIM_PREVIOUS
2026-11-23 12:59 [PATCH v2 00/11] nfsd: various delegated timestamp fixes Jeff Layton
` (2 preceding siblings ...)
2026-11-23 12:59 ` [PATCH v2 03/11] nfsd: count a delegation in cl_delegs_in_recall only once Jeff Layton
@ 2026-11-23 12:59 ` Jeff Layton
2026-11-23 12:59 ` [PATCH v2 05/11] nfsd: set ctime when a SETATTR with delegated times changes other attributes Jeff Layton
` (6 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Jeff Layton @ 2026-11-23 12:59 UTC (permalink / raw)
To: Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
Christian Brauner
Cc: Aurélien Couderc, linux-nfs, linux-kernel, Jeff Layton
nfs4_open_delegation() refuses delegations for NFSv4.0 write opens on
CLAIM_NULL and CLAIM_FH, as its comment explains, but CLAIM_PREVIOUS
skips the check. An NFSv4.0 client reclaiming a write open during grace
can therefore get a write delegation, and NFSD can never complete a
GETATTR that the client sends before DELEGRETURN in the same compound.
Apply the same check to CLAIM_PREVIOUS.
Fixes: 1d3dd1d56ce8 ("NFSD: Enable write delegation support")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfsd/nfs4state.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 5c2151b329c4..4b28553efc8d 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -7533,6 +7533,9 @@ nfs4_open_delegation(struct svc_rqst *rqstp, struct nfsd4_open *open,
open->op_recall = false;
switch (open->op_claim_type) {
case NFS4_OPEN_CLAIM_PREVIOUS:
+ if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE &&
+ clp->cl_minorversion == 0)
+ goto out_no_deleg;
if (!cb_up)
open->op_recall = true;
break;
--
2.56.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v2 05/11] nfsd: set ctime when a SETATTR with delegated times changes other attributes
2026-11-23 12:59 [PATCH v2 00/11] nfsd: various delegated timestamp fixes Jeff Layton
` (3 preceding siblings ...)
2026-11-23 12:59 ` [PATCH v2 04/11] nfsd: don't grant write delegations to NFSv4.0 clients on CLAIM_PREVIOUS Jeff Layton
@ 2026-11-23 12:59 ` Jeff Layton
2026-11-23 12:59 ` [PATCH v2 06/11] nfsd: pin the client while a GETATTR holds a conflicting delegation Jeff Layton
` (5 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Jeff Layton @ 2026-11-23 12:59 UTC (permalink / raw)
To: Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
Christian Brauner
Cc: Aurélien Couderc, linux-nfs, linux-kernel, Jeff Layton
__nfsd_setattr() adds ATTR_CTIME only when ATTR_DELEG is clear, to keep
a delegated atime-only update from moving ctime. But ATTR_DELEG is set
for the whole iattr, so a holder's chmod or chown sent along with a
delegated atime changes the mode or owner without updating ctime.
Add ATTR_CTIME unless the request is a delegated atime-only update. A
delegated mtime whose ctime fails vetting now moves ctime to the current
time instead of leaving ctime alone.
Fixes: f9a348e0de19 ("nfsd: don't set the ctime on delegated atime updates")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfsd/vfs.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 4a5674e583cc..7bc251d55c3c 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -513,10 +513,12 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)
/*
* If ATTR_DELEG is set, then this is an update from a client that
* holds a delegation. If this is an update for only the atime, the
- * ctime should not be changed. If the update contains the mtime
- * too, then ATTR_CTIME should already be set.
+ * ctime should not be changed. Any other attribute change, such as
+ * a mode or owner change sent along with a delegated atime, must
+ * update the ctime.
*/
- if (!(iap->ia_valid & ATTR_DELEG))
+ if (!(iap->ia_valid & ATTR_DELEG) ||
+ (iap->ia_valid & ~(ATTR_DELEG | ATTR_ATIME | ATTR_ATIME_SET)))
iap->ia_valid |= ATTR_CTIME;
return notify_change(&nop_mnt_idmap, dentry, iap, NULL);
--
2.56.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v2 06/11] nfsd: pin the client while a GETATTR holds a conflicting delegation
2026-11-23 12:59 [PATCH v2 00/11] nfsd: various delegated timestamp fixes Jeff Layton
` (4 preceding siblings ...)
2026-11-23 12:59 ` [PATCH v2 05/11] nfsd: set ctime when a SETATTR with delegated times changes other attributes Jeff Layton
@ 2026-11-23 12:59 ` Jeff Layton
2026-11-23 12:59 ` [PATCH v2 07/11] nfsd: recall when a CB_GETATTR reply omits the size Jeff Layton
` (4 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Jeff Layton @ 2026-11-23 12:59 UTC (permalink / raw)
To: Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
Christian Brauner
Cc: Aurélien Couderc, linux-nfs, linux-kernel, Jeff Layton
nfsd4_deleg_getattr_conflict() takes a reference on a write delegation
it finds through the inode's lease, sends CB_GETATTR, waits for the
reply, and drops the reference only after the wait.
nfsd4_encode_fattr4() can also hold the delegation until the GETATTR
reply is encoded.
A delegation reference doesn't keep its client alive. __destroy_client()
doesn't wait for stateid references, and the final nfs4_put_stid() uses
the client (cl_lock, the stateid idr and ->sc_free). If the client is
destroyed while the GETATTR waits, the GETATTR's put can touch a freed
nfs4_client. For example, a client that does not reply to the CB_GETATTR
can have its lease expire during the wait.
Under flc_lock, while the lease is still on the inode, take a client
reference along with the delegation reference. Client teardown removes
the lease before free_client() drops the client's initial reference, so
the client is still live while the lease is on the inode.
nfsd4_put_leased_deleg() drops both references.
Fixes: c5967721e106 ("NFSD: handle GETATTR conflict with write delegation")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfsd/nfs4state.c | 41 ++++++++++++++++++++++++++++++++++++++---
fs/nfsd/nfs4xdr.c | 2 +-
fs/nfsd/state.h | 1 +
3 files changed, 40 insertions(+), 4 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 4b28553efc8d..4e7bbaf65050 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -2912,6 +2912,38 @@ void nfsd4_put_client(struct nfs4_client *clp)
kref_put(&clp->cl_nfsdfs.cl_ref, __free_client);
}
+/*
+ * Reference a delegation found through its lease, for use after flc_lock
+ * is dropped. A delegation reference alone doesn't keep the client.
+ * __destroy_client() doesn't wait for stateid references, yet
+ * nfs4_put_stid() uses the client, so pin the client as well. Caller
+ * holds flc_lock with @dp's lease on the inode. Client teardown removes
+ * the lease before free_client() drops the client's initial reference,
+ * so the initial reference is still held here.
+ */
+static bool nfsd4_get_leased_deleg(struct nfs4_delegation *dp)
+{
+ if (!refcount_inc_not_zero(&dp->dl_stid.sc_count))
+ return false;
+ nfsd4_get_client(dp->dl_stid.sc_client);
+ return true;
+}
+
+/**
+ * nfsd4_put_leased_deleg - release a delegation found through its lease
+ * @dp: delegation to release
+ *
+ * Drops the delegation and client references that the lease walk took.
+ * May free the client, so the caller must be able to sleep.
+ */
+void nfsd4_put_leased_deleg(struct nfs4_delegation *dp)
+{
+ struct nfs4_client *clp = dp->dl_stid.sc_client;
+
+ nfs4_put_stid(&dp->dl_stid);
+ nfsd4_put_client(clp);
+}
+
static void
free_client(struct nfs4_client *clp)
{
@@ -10880,7 +10912,7 @@ static int cb_getattr_update_times(struct dentry *dentry, struct nfs4_delegation
*
* Returns 0 if there is no conflict; otherwise an nfs_stat
* code is returned. If @pdp is set to a non-NULL value, then the
- * caller must put the reference.
+ * caller must release it with nfsd4_put_leased_deleg().
*/
__be32
nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry,
@@ -10925,7 +10957,10 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry,
return 0;
}
- refcount_inc(&dp->dl_stid.sc_count);
+ if (!nfsd4_get_leased_deleg(dp)) {
+ spin_unlock(&ctx->flc_lock);
+ return nfserr_jukebox;
+ }
ncf = &dp->dl_cb_fattr;
nfs4_cb_getattr(&dp->dl_cb_fattr);
spin_unlock(&ctx->flc_lock);
@@ -10966,7 +11001,7 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry,
}
status = nfs_ok;
out_status:
- nfs4_put_stid(&dp->dl_stid);
+ nfsd4_put_leased_deleg(dp);
return status;
}
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 950c67362566..e6131095024f 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -4106,7 +4106,7 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,
if (!timespec64_is_epoch(&ncf->ncf_cb_atime))
args.stat.atime = ncf->ncf_cb_atime;
- nfs4_put_stid(&dp->dl_stid);
+ nfsd4_put_leased_deleg(dp);
} else {
args.change_attr = nfsd4_change_attribute(&args.stat);
}
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index e9816000c943..f80abcc278f6 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -977,6 +977,7 @@ extern void nfsd4_shutdown_callback(struct nfs4_client *);
extern void nfsd4_shutdown_copy(struct nfs4_client *clp);
void nfsd4_get_client(struct nfs4_client *clp);
void nfsd4_put_client(struct nfs4_client *clp);
+void nfsd4_put_leased_deleg(struct nfs4_delegation *dp);
void nfsd4_async_copy_reaper(struct nfsd_net *nn);
bool nfsd4_has_active_async_copies(struct nfs4_client *clp);
void nfsd_update_cmtime_attr(struct file *f, unsigned int flags);
--
2.56.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v2 07/11] nfsd: recall when a CB_GETATTR reply omits the size
2026-11-23 12:59 [PATCH v2 00/11] nfsd: various delegated timestamp fixes Jeff Layton
` (5 preceding siblings ...)
2026-11-23 12:59 ` [PATCH v2 06/11] nfsd: pin the client while a GETATTR holds a conflicting delegation Jeff Layton
@ 2026-11-23 12:59 ` Jeff Layton
2026-11-23 12:59 ` [PATCH v2 08/11] nfsd: apply delegated times in a separate times-only setattr Jeff Layton
` (3 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Jeff Layton @ 2026-11-23 12:59 UTC (permalink / raw)
To: Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
Christian Brauner
Cc: Aurélien Couderc, linux-nfs, linux-kernel, Jeff Layton
decode_cb_fattr4() zeroes ncf_cb_fsize and fills it in only if the
reply's bitmap includes SIZE. nfsd4_deleg_getattr_conflict() doesn't
look at that bitmap. For a reply without SIZE, a non-empty file's size
doesn't match zero, so the waiter marks the file modified and sets
ncf_cur_fsize to zero. GETATTR replies then report the file as empty to
every client but the delegation holder.
NFSD always requests SIZE in CB_GETATTR, and the holder may have changed
the size. Add ncf_cb_bitmap0 to hold word 0 of the reply's bitmap,
cleared when the callback is issued. In nfsd4_cb_getattr_done(), treat a
reply without SIZE as failed. The waiter then recalls the delegation, as
for any other CB_GETATTR failure.
A reply that omits CHANGE is left alone. The zero change attribute does
not match, so the waiter errs on the safe side and treats the file as
modified.
Fixes: c5967721e106 ("NFSD: handle GETATTR conflict with write delegation")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfsd/nfs4callback.c | 1 +
fs/nfsd/nfs4state.c | 8 ++++++++
fs/nfsd/state.h | 1 +
3 files changed, 10 insertions(+)
diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
index 70ab4fd32195..ac65ba4c4b7d 100644
--- a/fs/nfsd/nfs4callback.c
+++ b/fs/nfsd/nfs4callback.c
@@ -737,6 +737,7 @@ static int nfs4_xdr_dec_cb_getattr(struct rpc_rqst *rqstp,
return status;
if (xdr_stream_decode_uint32_array(xdr, bitmap, 3) < 0)
return -EIO;
+ ncf->ncf_cb_bitmap0 = bitmap[0];
if (xdr_stream_decode_u32(xdr, &attrlen) < 0)
return -EIO;
maxlen = sizeof(ncf->ncf_cb_change) + sizeof(ncf->ncf_cb_fsize);
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 4e7bbaf65050..645ad916d2ef 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -3876,6 +3876,13 @@ nfsd4_cb_getattr_done(struct nfsd4_callback *cb, struct rpc_task *task)
trace_nfsd_cb_getattr_done(&dp->dl_stid.sc_stateid, task);
ncf->ncf_cb_status = task->tk_status;
+ /*
+ * A reply without SIZE leaves ncf_cb_fsize at zero, which the
+ * waiter would report as the file's size. Fail the callback, so
+ * the waiter recalls the delegation instead.
+ */
+ if (!task->tk_status && !(ncf->ncf_cb_bitmap0 & FATTR4_WORD0_SIZE))
+ ncf->ncf_cb_status = NFS4ERR_IO;
switch (task->tk_status) {
case -NFS4ERR_DELAY:
rpc_delay(task, 2 * HZ);
@@ -4123,6 +4130,7 @@ static void nfs4_cb_getattr(struct nfs4_cb_fattr *ncf)
/* set to proper status when nfsd4_cb_getattr_done runs */
ncf->ncf_cb_status = NFS4ERR_IO;
+ ncf->ncf_cb_bitmap0 = 0;
/* ensure that wake_bit is done when RUNNING is cleared */
set_bit(NFSD4_CALLBACK_WAKE, &ncf->ncf_getattr.cb_flags);
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index f80abcc278f6..c5f607049aaf 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -205,6 +205,7 @@ struct nfs4_cb_fattr {
u32 ncf_cb_status;
/* from CB_GETATTR reply */
+ u32 ncf_cb_bitmap0; /* word 0 of the returned bitmap */
u64 ncf_cb_change;
u64 ncf_cb_fsize;
struct timespec64 ncf_cb_mtime;
--
2.56.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v2 08/11] nfsd: apply delegated times in a separate times-only setattr
2026-11-23 12:59 [PATCH v2 00/11] nfsd: various delegated timestamp fixes Jeff Layton
` (6 preceding siblings ...)
2026-11-23 12:59 ` [PATCH v2 07/11] nfsd: recall when a CB_GETATTR reply omits the size Jeff Layton
@ 2026-11-23 12:59 ` Jeff Layton
2026-11-23 12:59 ` [PATCH v2 09/11] nfsd: grant a plain read delegation when timestamps are wanted on a read open Jeff Layton
` (2 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Jeff Layton @ 2026-11-23 12:59 UTC (permalink / raw)
To: Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
Christian Brauner
Cc: Aurélien Couderc, linux-nfs, linux-kernel, Jeff Layton
Delegated times were decoded into sa_iattr with ATTR_DELEG and applied
in the same nfsd_setattr() call as every other attribute. Problems:
- A holder that doesn't own the file gets EPERM. notify_change() checks
ownership for explicit times, but under RFC 9754 the delegation
stateid grants the authority to set the times.
- ATTR_DELEG applies to the whole iattr, so __nfsd_setattr() needs
special ctime handling for the other attributes.
- If the times are rejected, attrsset can't report the attributes that
were set.
Decode time_deleg_access and time_deleg_modify into new sa_deleg_atime
and sa_deleg_mtime fields. After nfsd_setattr() handles the other
attributes, nfsd4_deleg_set_times() applies the vetted times with
notify_change(ATTR_FORCE) and an iattr that holds only times:
- A times-only request skips nfsd_setattr() and the export's read-only
and immutable checks that nfsd_setattr() makes, so call
fh_verify(NFSD_MAY_SATTR) first.
- Leave ATTR_DELEG clear. nfsd_breaker_owns_lease() keeps the holder's
own lease intact, and any other lease is broken.
- Keep vetting against dl_[amc]time. When the vetted mtime is applied
but the delegated ctime is rejected, ctime now moves to the current
time instead of staying put, because the inode's mtime did change.
- Set dl_setattr only after notify_change() succeeds, so a failed update
doesn't skip the restamp on delegation return.
nfsd4_setattr() skips nfsd_setattr() for a request with only delegated
times. A request that sets both the plain and the delegated form of a
time gets NFS4ERR_INVAL. nfsd4_setattr() checks for that conflict, and
checks the stateid, only after the minor version's supported attributes.
A minor version without delegated times therefore gets
NFS4ERR_ATTRNOTSUPP for them.
attrsset keeps the non-time bits when the times step fails. A failure
inside nfsd_setattr() still reports nothing as set, because
nfsd_setattr() can't report a partial update.
Delegated times in CREATE and OPEN createattrs get NFS4ERR_INVAL.
RFC 9754 permits delegated times only in a SETATTR from a delegation
holder, and EXCLUSIVE4_1 already rejects them through
suppattr_exclcreat. A minor version that doesn't support delegated
times still gets NFS4ERR_ATTRNOTSUPP.
ATTR_DELEG no longer reaches __nfsd_setattr(), so drop its ATTR_DELEG
branch and always add ATTR_CTIME. Make commit_metadata() visible to
nfs4proc.c.
Fixes: 7e13f4f8d27d ("nfsd: handle delegated timestamps in SETATTR")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfsd/nfs4proc.c | 171 ++++++++++++++++++++++++++++++++++++-----------------
fs/nfsd/nfs4xdr.c | 54 +++++++++--------
fs/nfsd/vfs.c | 16 +----
fs/nfsd/vfs.h | 1 +
fs/nfsd/xdr4.h | 3 +
5 files changed, 152 insertions(+), 93 deletions(-)
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index b76320c265e1..1fa68a046fa5 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -1361,33 +1361,62 @@ nfsd4_secinfo_no_name_release(union nfsd4_op_u *u)
exp_put(u->secinfo_no_name.sin_exp);
}
+#define NFSD4_DELEG_TIME_BITS (FATTR4_WORD2_TIME_DELEG_ACCESS | \
+ FATTR4_WORD2_TIME_DELEG_MODIFY)
+
/*
- * Validate that the requested timestamps are within the acceptable range. If
- * timestamp appears to be in the future, then it will be clamped to
- * current_time().
+ * Apply a delegation holder's times in a times-only setattr. The stateid,
+ * not file ownership, grants the authority to set them, hence ATTR_FORCE.
+ * ATTR_DELEG isn't needed: nfsd_breaker_owns_lease() keeps the holder's
+ * own lease intact, and any other lease is broken.
*/
-static void
-vet_deleg_attrs(struct nfsd4_setattr *setattr, struct nfs4_delegation *dp)
+static __be32
+nfsd4_deleg_set_times(struct svc_rqst *rqstp, struct svc_fh *fhp,
+ struct nfsd4_setattr *setattr, struct nfs4_delegation *dp)
{
- struct timespec64 now = current_time(dp->dl_stid.sc_file->fi_inode);
- struct iattr *iattr = &setattr->sa_iattr;
+ struct iattr iattr = { };
+ struct timespec64 now;
+ struct inode *inode;
+ bool deleg_ctime = false;
+ __be32 status;
+ int host_err;
- if ((setattr->sa_bmval[2] & FATTR4_WORD2_TIME_DELEG_ACCESS) &&
- !nfsd4_vet_deleg_time(&iattr->ia_atime, &dp->dl_atime, &now))
- iattr->ia_valid &= ~(ATTR_ATIME | ATTR_ATIME_SET);
+ /* nfsd4_setattr() skips nfsd_setattr() for a times-only request */
+ status = fh_verify(rqstp, fhp, 0, NFSD_MAY_SATTR);
+ if (status)
+ return status;
+ inode = d_inode(fhp->fh_dentry);
+ now = current_time(inode);
+ if (setattr->sa_bmval[2] & FATTR4_WORD2_TIME_DELEG_ACCESS) {
+ iattr.ia_atime = setattr->sa_deleg_atime;
+ if (nfsd4_vet_deleg_time(&iattr.ia_atime, &dp->dl_atime, &now))
+ iattr.ia_valid |= ATTR_ATIME | ATTR_ATIME_SET;
+ }
if (setattr->sa_bmval[2] & FATTR4_WORD2_TIME_DELEG_MODIFY) {
- if (nfsd4_vet_deleg_time(&iattr->ia_mtime, &dp->dl_mtime, &now)) {
- iattr->ia_ctime = iattr->ia_mtime;
- if (nfsd4_vet_deleg_time(&iattr->ia_ctime, &dp->dl_ctime, &now))
- dp->dl_setattr = true;
- else
- iattr->ia_valid &= ~(ATTR_CTIME | ATTR_CTIME_SET);
- } else {
- iattr->ia_valid &= ~(ATTR_CTIME | ATTR_CTIME_SET |
- ATTR_MTIME | ATTR_MTIME_SET);
+ iattr.ia_mtime = setattr->sa_deleg_mtime;
+ if (nfsd4_vet_deleg_time(&iattr.ia_mtime, &dp->dl_mtime, &now)) {
+ iattr.ia_valid |= ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME;
+ iattr.ia_ctime = iattr.ia_mtime;
+ if (nfsd4_vet_deleg_time(&iattr.ia_ctime, &dp->dl_ctime, &now)) {
+ iattr.ia_valid |= ATTR_CTIME_SET;
+ deleg_ctime = true;
+ }
}
}
+ if (!iattr.ia_valid)
+ return nfs_ok;
+
+ iattr.ia_valid |= ATTR_FORCE;
+ inode_lock(inode);
+ host_err = notify_change(&nop_mnt_idmap, fhp->fh_dentry, &iattr, NULL);
+ inode_unlock(inode);
+ if (host_err)
+ return nfserrno(host_err);
+ if (deleg_ctime)
+ dp->dl_setattr = true;
+ host_err = commit_metadata(fhp);
+ return nfserrno(host_err);
}
static __be32
@@ -1401,16 +1430,34 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
.na_pacl = posix_acl_dup(setattr->sa_pacl),
.na_dpacl = posix_acl_dup(setattr->sa_dpacl),
};
- bool save_no_wcc, deleg_attrs;
+ struct nfs4_delegation *dp = NULL;
+ u32 *bmval = setattr->sa_bmval;
struct nfs4_stid *st = NULL;
- struct inode *inode;
+ u32 deleg_bits, other_bits;
__be32 status = nfs_ok;
+ struct inode *inode;
+ bool save_no_wcc;
int err;
- deleg_attrs = setattr->sa_bmval[2] & (FATTR4_WORD2_TIME_DELEG_ACCESS |
- FATTR4_WORD2_TIME_DELEG_MODIFY);
+ deleg_bits = bmval[2] & NFSD4_DELEG_TIME_BITS;
+ other_bits = bmval[0] | bmval[1] | (bmval[2] & ~NFSD4_DELEG_TIME_BITS);
- if (deleg_attrs || (setattr->sa_iattr.ia_valid & ATTR_SIZE)) {
+ /* The checks below assume the minor version supports every attribute */
+ if (!nfsd_attrs_supported(cstate->minorversion, bmval)) {
+ status = nfserr_attrnotsupp;
+ goto out_err;
+ }
+
+ /* Setting both forms of the same time is ambiguous */
+ if (((deleg_bits & FATTR4_WORD2_TIME_DELEG_ACCESS) &&
+ (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET)) ||
+ ((deleg_bits & FATTR4_WORD2_TIME_DELEG_MODIFY) &&
+ (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET))) {
+ status = nfserr_inval;
+ goto out_err;
+ }
+
+ if (deleg_bits || (setattr->sa_iattr.ia_valid & ATTR_SIZE)) {
int flags = WR_STATE;
/*
@@ -1431,20 +1478,15 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
goto out_err;
}
- if (deleg_attrs) {
+ if (deleg_bits) {
status = nfserr_bad_stateid;
- if (st && (st->sc_type & SC_TYPE_DELEG)) {
- struct nfs4_delegation *dp = delegstateid(st);
-
- /* Only for *_ATTRS_DELEG flavors */
- if (deleg_attrs_deleg(dp->dl_type)) {
- vet_deleg_attrs(setattr, dp);
- status = nfs_ok;
- }
+ /* Only an *_ATTRS_DELEG delegation may set delegated times */
+ if (st && (st->sc_type & SC_TYPE_DELEG) &&
+ deleg_attrs_deleg(delegstateid(st)->dl_type)) {
+ dp = delegstateid(st);
+ status = nfs_ok;
}
}
- if (st)
- nfs4_put_stid(st);
if (status)
goto out_err;
@@ -1453,36 +1495,55 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
status = nfserrno(err);
goto out_err;
}
- status = nfs_ok;
status = check_attr_support(cstate, setattr->sa_bmval, nfsd_attrmask);
if (status)
goto out;
- if (setattr->sa_acl && (attrs.na_dpacl || attrs.na_pacl)) {
- status = nfserr_inval;
- goto out;
- }
+ if (!deleg_bits || other_bits) {
+ if (setattr->sa_acl && (attrs.na_dpacl || attrs.na_pacl)) {
+ status = nfserr_inval;
+ goto out;
+ }
- inode = cstate->current_fh.fh_dentry->d_inode;
- status = nfsd4_acl_to_attr(S_ISDIR(inode->i_mode) ? NF4DIR : NF4REG,
- setattr->sa_acl, &attrs);
+ inode = cstate->current_fh.fh_dentry->d_inode;
+ status = nfsd4_acl_to_attr(S_ISDIR(inode->i_mode) ? NF4DIR : NF4REG,
+ setattr->sa_acl, &attrs);
+ if (status)
+ goto out;
+ save_no_wcc = cstate->current_fh.fh_no_wcc;
+ cstate->current_fh.fh_no_wcc = true;
+ status = nfsd_setattr(rqstp, &cstate->current_fh, &attrs, NULL);
+ cstate->current_fh.fh_no_wcc = save_no_wcc;
+ if (!status)
+ status = nfserrno(attrs.na_labelerr);
+ if (!status)
+ status = nfserrno(attrs.na_dpaclerr);
+ if (!status)
+ status = nfserrno(attrs.na_paclerr);
+ if (status)
+ goto out;
+ /*
+ * A failure inside nfsd_setattr() may follow a partial
+ * update. nfsd_setattr() can't report which parts were
+ * applied, so attrsset is filled in only on success.
+ */
+ setattr->sa_attrsset[0] = bmval[0];
+ setattr->sa_attrsset[1] = bmval[1];
+ setattr->sa_attrsset[2] = bmval[2] & ~NFSD4_DELEG_TIME_BITS;
+ }
- if (status)
- goto out;
- save_no_wcc = cstate->current_fh.fh_no_wcc;
- cstate->current_fh.fh_no_wcc = true;
- status = nfsd_setattr(rqstp, &cstate->current_fh, &attrs, NULL);
- cstate->current_fh.fh_no_wcc = save_no_wcc;
- if (!status)
- status = nfserrno(attrs.na_labelerr);
- if (!status)
- status = nfserrno(attrs.na_dpaclerr);
- if (!status)
- status = nfserrno(attrs.na_paclerr);
+ if (deleg_bits) {
+ status = nfsd4_deleg_set_times(rqstp, &cstate->current_fh,
+ setattr, dp);
+ if (!status)
+ setattr->sa_attrsset[2] |= deleg_bits;
+ }
out:
fh_drop_write(&cstate->current_fh);
out_err:
+ if (st)
+ nfs4_put_stid(st);
nfsd_attrs_free(&attrs);
return status;
}
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index e6131095024f..80760fd407aa 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -510,7 +510,9 @@ static __be32
nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen,
struct iattr *iattr, struct nfs4_acl **acl,
struct xdr_netobj *label, int *umask,
- struct posix_acl **dpaclp, struct posix_acl **paclp)
+ struct posix_acl **dpaclp, struct posix_acl **paclp,
+ struct timespec64 *deleg_atime,
+ struct timespec64 *deleg_mtime)
{
unsigned int starting_pos;
u32 attrlist4_count;
@@ -529,6 +531,16 @@ nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen,
return nfserr_attrnotsupp;
}
+ /*
+ * RFC 9754 section 5 permits delegated times only in SETATTR. A
+ * minor version without delegated times gets NFS4ERR_ATTRNOTSUPP
+ * instead of NFS4ERR_INVAL.
+ */
+ if ((bmval[2] & FATTR4_WORD2_TIME_DELEG_ACCESS && !deleg_atime) ||
+ (bmval[2] & FATTR4_WORD2_TIME_DELEG_MODIFY && !deleg_mtime))
+ return nfsd_attrs_supported(argp->minorversion, bmval) ?
+ nfserr_inval : nfserr_attrnotsupp;
+
if (xdr_stream_decode_u32(argp->xdr, &attrlist4_count) < 0)
return nfserr_bad_xdr;
starting_pos = xdr_stream_pos(argp->xdr);
@@ -658,9 +670,8 @@ nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen,
return nfserr_bad_xdr;
if (access.nseconds >= NSEC_PER_SEC)
return nfserr_inval;
- iattr->ia_atime.tv_sec = access.seconds;
- iattr->ia_atime.tv_nsec = access.nseconds;
- iattr->ia_valid |= ATTR_ATIME | ATTR_ATIME_SET | ATTR_DELEG;
+ deleg_atime->tv_sec = access.seconds;
+ deleg_atime->tv_nsec = access.nseconds;
}
if (bmval[2] & FATTR4_WORD2_TIME_DELEG_MODIFY) {
fattr4_time_deleg_modify modify;
@@ -669,12 +680,8 @@ nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen,
return nfserr_bad_xdr;
if (modify.nseconds >= NSEC_PER_SEC)
return nfserr_inval;
- iattr->ia_mtime.tv_sec = modify.seconds;
- iattr->ia_mtime.tv_nsec = modify.nseconds;
- iattr->ia_ctime.tv_sec = modify.seconds;
- iattr->ia_ctime.tv_nsec = modify.nseconds;
- iattr->ia_valid |= ATTR_CTIME | ATTR_CTIME_SET |
- ATTR_MTIME | ATTR_MTIME_SET | ATTR_DELEG;
+ deleg_mtime->tv_sec = modify.seconds;
+ deleg_mtime->tv_nsec = modify.nseconds;
}
*dpaclp = NULL;
@@ -1014,7 +1021,8 @@ nfsd4_decode_create(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
ARRAY_SIZE(create->cr_bmval),
&create->cr_iattr, &create->cr_acl,
&create->cr_label, &create->cr_umask,
- &create->cr_dpacl, &create->cr_pacl);
+ &create->cr_dpacl, &create->cr_pacl,
+ NULL, NULL);
if (status)
return status;
@@ -1166,7 +1174,8 @@ nfsd4_decode_createhow4(struct nfsd4_compoundargs *argp, struct nfsd4_open *open
ARRAY_SIZE(open->op_bmval),
&open->op_iattr, &open->op_acl,
&open->op_label, &open->op_umask,
- &open->op_dpacl, &open->op_pacl);
+ &open->op_dpacl, &open->op_pacl,
+ NULL, NULL);
if (status)
return status;
break;
@@ -1185,7 +1194,8 @@ nfsd4_decode_createhow4(struct nfsd4_compoundargs *argp, struct nfsd4_open *open
ARRAY_SIZE(open->op_bmval),
&open->op_iattr, &open->op_acl,
&open->op_label, &open->op_umask,
- &open->op_dpacl, &open->op_pacl);
+ &open->op_dpacl, &open->op_pacl,
+ NULL, NULL);
if (status)
return status;
break;
@@ -1513,7 +1523,8 @@ nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
ARRAY_SIZE(setattr->sa_bmval),
&setattr->sa_iattr, &setattr->sa_acl,
&setattr->sa_label, NULL, &setattr->sa_dpacl,
- &setattr->sa_pacl);
+ &setattr->sa_pacl, &setattr->sa_deleg_atime,
+ &setattr->sa_deleg_mtime);
}
static __be32
@@ -5755,17 +5766,10 @@ nfsd4_encode_setattr(struct nfsd4_compoundres *resp, __be32 nfserr,
struct nfsd4_setattr *setattr = &u->setattr;
__be32 status;
- switch (nfserr) {
- case nfs_ok:
- /* attrsset */
- status = nfsd4_encode_bitmap4(resp->xdr, setattr->sa_bmval[0],
- setattr->sa_bmval[1],
- setattr->sa_bmval[2]);
- break;
- default:
- /* attrsset */
- status = nfsd4_encode_bitmap4(resp->xdr, 0, 0, 0);
- }
+ /* attrsset: also reported on failure (RFC 8881 section 18.30.3) */
+ status = nfsd4_encode_bitmap4(resp->xdr, setattr->sa_attrsset[0],
+ setattr->sa_attrsset[1],
+ setattr->sa_attrsset[2]);
return status != nfs_ok ? status : nfserr;
}
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 7bc251d55c3c..a990c76dce0f 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -409,7 +409,7 @@ commit_inode_metadata(struct inode *inode)
return sync_inode_metadata(inode, 1);
}
-static int
+int
commit_metadata(struct svc_fh *fhp)
{
struct inode *inode = d_inode(fhp->fh_dentry);
@@ -507,20 +507,10 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)
return 0;
}
- if ((iap->ia_valid & ~ATTR_DELEG) == 0)
+ if (iap->ia_valid == 0)
return 0;
- /*
- * If ATTR_DELEG is set, then this is an update from a client that
- * holds a delegation. If this is an update for only the atime, the
- * ctime should not be changed. Any other attribute change, such as
- * a mode or owner change sent along with a delegated atime, must
- * update the ctime.
- */
- if (!(iap->ia_valid & ATTR_DELEG) ||
- (iap->ia_valid & ~(ATTR_DELEG | ATTR_ATIME | ATTR_ATIME_SET)))
- iap->ia_valid |= ATTR_CTIME;
-
+ iap->ia_valid |= ATTR_CTIME;
return notify_change(&nop_mnt_idmap, dentry, iap, NULL);
}
diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h
index d974929398f8..9054f002df35 100644
--- a/fs/nfsd/vfs.h
+++ b/fs/nfsd/vfs.h
@@ -166,6 +166,7 @@ __be32 nfsd_lookup_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp,
const char *name, unsigned int len,
struct svc_export **exp_ret,
struct dentry **dentry_ret, int access);
+int commit_metadata(struct svc_fh *fhp);
__be32 nfsd_setattr(struct svc_rqst *, struct svc_fh *,
struct nfsd_attrs *, const struct timespec64 *);
int nfsd_mountpoint(struct dentry *, struct svc_export *);
diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
index 28481a2c8285..3031dace6d1b 100644
--- a/fs/nfsd/xdr4.h
+++ b/fs/nfsd/xdr4.h
@@ -377,6 +377,9 @@ struct nfsd4_setattr {
struct xdr_netobj sa_label;
struct posix_acl *sa_dpacl;
struct posix_acl *sa_pacl;
+ struct timespec64 sa_deleg_atime; /* request */
+ struct timespec64 sa_deleg_mtime; /* request */
+ u32 sa_attrsset[3]; /* response */
};
struct nfsd4_setclientid {
--
2.56.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v2 09/11] nfsd: grant a plain read delegation when timestamps are wanted on a read open
2026-11-23 12:59 [PATCH v2 00/11] nfsd: various delegated timestamp fixes Jeff Layton
` (7 preceding siblings ...)
2026-11-23 12:59 ` [PATCH v2 08/11] nfsd: apply delegated times in a separate times-only setattr Jeff Layton
@ 2026-11-23 12:59 ` Jeff Layton
2026-11-23 12:59 ` [PATCH v2 10/11] nfsd: check fi_had_conflict under deleg_lock before hashing a delegation Jeff Layton
2026-11-23 12:59 ` [PATCH v2 11/11] nfsd: take the write delegation grant stat before hashing Jeff Layton
10 siblings, 0 replies; 13+ messages in thread
From: Jeff Layton @ 2026-11-23 12:59 UTC (permalink / raw)
To: Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
Christian Brauner
Cc: Aurélien Couderc, linux-nfs, linux-kernel, Jeff Layton
A read open that wants delegated timestamps gets
OPEN_DELEGATE_READ_ATTRS_DELEG. Several clients can hold read
delegations at once, so delegating atime correctly would need exclusive
authority over atime or a merge of every read holder's times. NFSD
supports neither exclusive atime authority nor such a merge.
Grant OPEN_DELEGATE_READ instead. The want flag is a request, so
declining the attribute delegation complies with RFC 9754 section 5. The
XDR cases for OPEN_DELEGATE_READ_ATTRS_DELEG stay, since
open_delegation_type4 is on the wire.
Fixes: 6ae30d6eb26b ("nfsd: add support for delegated timestamps")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfsd/nfs4state.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 645ad916d2ef..466416708072 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -7329,10 +7329,14 @@ nfs4_set_delegation(struct nfsd4_open *open,
* A read delegation can go to a client that holds a write open
* of the file: nfsd_breaker_owns_lease() keeps the holder's own
* opens from breaking it.
+ *
+ * Never OPEN_DELEGATE_READ_ATTRS_DELEG: delegating atime correctly
+ * would need exclusive authority over it, or merging the times of
+ * several read holders. The want flag is only a request.
*/
if (!nf && (open->op_share_access & NFS4_SHARE_ACCESS_READ)) {
nf = find_readable_file(fp);
- dl_type = deleg_ts ? OPEN_DELEGATE_READ_ATTRS_DELEG : OPEN_DELEGATE_READ;
+ dl_type = OPEN_DELEGATE_READ;
}
if (!nf)
@@ -7630,9 +7634,7 @@ nfs4_open_delegation(struct svc_rqst *rqstp, struct nfsd4_open *open,
spin_unlock(&f->f_lock);
trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid);
} else {
- open->op_delegate_type = deleg_ts && nfs4_delegation_stat(dp, currentfh, &stat) ?
- OPEN_DELEGATE_READ_ATTRS_DELEG : OPEN_DELEGATE_READ;
- dp->dl_atime = stat.atime;
+ open->op_delegate_type = OPEN_DELEGATE_READ;
trace_nfsd_deleg_read(&dp->dl_stid.sc_stateid);
}
nfs4_put_stid(&dp->dl_stid);
--
2.56.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v2 10/11] nfsd: check fi_had_conflict under deleg_lock before hashing a delegation
2026-11-23 12:59 [PATCH v2 00/11] nfsd: various delegated timestamp fixes Jeff Layton
` (8 preceding siblings ...)
2026-11-23 12:59 ` [PATCH v2 09/11] nfsd: grant a plain read delegation when timestamps are wanted on a read open Jeff Layton
@ 2026-11-23 12:59 ` Jeff Layton
2026-11-23 12:59 ` [PATCH v2 11/11] nfsd: take the write delegation grant stat before hashing Jeff Layton
10 siblings, 0 replies; 13+ messages in thread
From: Jeff Layton @ 2026-11-23 12:59 UTC (permalink / raw)
To: Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
Christian Brauner
Cc: Aurélien Couderc, linux-nfs, linux-kernel, Jeff Layton
nfs4_set_delegation() checks fi_had_conflict without a lock, then takes
deleg_lock and hashes the delegation. A lease break in between sets
fi_had_conflict and queues the recall. The recall's prepare callback,
nfsd4_cb_recall_prepare(), takes deleg_lock and puts the delegation on
del_recall_lru only if the delegation is hashed. If the prepare runs
before the hash, NFSD grants a delegation that is already recalled but
not on del_recall_lru. The laundromat then never revokes the delegation
if the client does not return it.
Check fi_had_conflict again under deleg_lock. The break sets
fi_had_conflict before queueing the recall. A prepare that ran before
the hash therefore left fi_had_conflict set, and a prepare that runs
after the hash finds the delegation hashed.
Before 5ea9a7c5fe41, nfs4_set_delegation() made the final check under
fi_lock, which nfsd_break_deleg_cb() also took.
Fixes: 5ea9a7c5fe41 ("nfsd: don't take fi_lock in nfsd_break_deleg_cb()")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfsd/nfs4state.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 466416708072..9ea3b0e9b7ec 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -7428,7 +7428,17 @@ nfs4_set_delegation(struct nfsd4_open *open,
spin_lock(&nn->deleg_lock);
spin_lock(&clp->cl_lock);
spin_lock(&fp->fi_lock);
- status = hash_delegation_locked(dp, fp);
+ /*
+ * Check again under deleg_lock. A break after the unlocked check
+ * has queued a recall whose prepare takes deleg_lock. The prepare
+ * doesn't queue an unhashed delegation for revocation, so the
+ * laundromat would never revoke a delegation granted after the
+ * break.
+ */
+ if (fp->fi_had_conflict)
+ status = -EAGAIN;
+ else
+ status = hash_delegation_locked(dp, fp);
if (status == -EEXIST) {
held = nfs4_delegation_exists(clp, fp);
*held_type = held->dl_type;
--
2.56.1
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v2 11/11] nfsd: take the write delegation grant stat before hashing
2026-11-23 12:59 [PATCH v2 00/11] nfsd: various delegated timestamp fixes Jeff Layton
` (9 preceding siblings ...)
2026-11-23 12:59 ` [PATCH v2 10/11] nfsd: check fi_had_conflict under deleg_lock before hashing a delegation Jeff Layton
@ 2026-11-23 12:59 ` Jeff Layton
10 siblings, 0 replies; 13+ messages in thread
From: Jeff Layton @ 2026-11-23 12:59 UTC (permalink / raw)
To: Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
Christian Brauner
Cc: Aurélien Couderc, linux-nfs, linux-kernel, Jeff Layton
nfs4_open_delegation() sets ncf_initial_cinfo and dl_[amc]time from a
stat taken after nfs4_set_delegation() has hashed the delegation. The
window between hashing and the stat is not reachable today. A CB_GETATTR
sent in that window does not carry a referring call, so the client
replies with NFS4ERR_BADHANDLE and the waiter never compares the zero
ncf_initial_cinfo. But an upcoming per-delegation timestamp record must
be initialized before anything can reach the delegation.
- Pass the current filehandle into nfs4_set_delegation() for the stat's
export, and move nfs4_delegation_stat() above nfs4_set_delegation().
- Take the grant stat after kernel_setlease() and the conflict checks,
just before hashing. Don't grant the delegation if the stat fails.
- The stat can sleep and so widens the window between the unlocked
fi_had_conflict check and hashing. The check under deleg_lock that the
previous patch added still catches a break in that window.
- Stat again after hashing, and decline the delegation if the change
attribute moved. The holder's WRITE through an earlier open doesn't
break its own lease and can land between the stats, as can a foreign
write whose break raced past the fi_had_conflict check. A plain write
delegation synthesizes change as ncf_initial_cinfo + 1, so a stale
ncf_initial_cinfo could report a change attribute below a value that
clients already saw. Compare with the grant stat's change attribute,
which nfs4_set_delegation() returns, rather than with
ncf_initial_cinfo. Once the delegation is hashed, a GETATTR whose
CB_GETATTR reports a modified file can advance ncf_initial_cinfo.
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfsd/nfs4state.c | 93 ++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 63 insertions(+), 30 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 9ea3b0e9b7ec..87ec545ebc48 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -7277,11 +7277,35 @@ nfs4_delegation_record_grant_slot(struct nfs4_delegation *dp,
dp->dl_recall_grant.valid = true;
}
+static bool
+nfs4_delegation_stat(struct nfs4_delegation *dp, struct svc_fh *currentfh,
+ struct kstat *stat)
+{
+ struct nfsd_file *nf = find_writeable_file(dp->dl_stid.sc_file);
+ struct path path;
+ int rc;
+
+ if (!nf)
+ return false;
+
+ path.mnt = currentfh->fh_export->ex_path.mnt;
+ path.dentry = file_dentry(nf->nf_file);
+
+ rc = vfs_getattr(&path, stat,
+ STATX_MODE | STATX_SIZE | STATX_ATIME |
+ STATX_MTIME | STATX_CTIME | STATX_CHANGE_COOKIE,
+ AT_STATX_SYNC_AS_STAT);
+
+ nfsd_file_put(nf);
+ return rc == 0;
+}
+
static struct nfs4_delegation *
nfs4_set_delegation(struct nfsd4_open *open,
const struct nfsd4_compound_state *cstate,
struct nfs4_ol_stateid *stp, struct svc_fh *parent,
- u32 *held_type)
+ struct svc_fh *currentfh, u32 *held_type,
+ u64 *grant_change)
{
bool deleg_ts = nfsd4_want_deleg_timestamps(open);
struct nfs4_client *clp = stp->st_stid.sc_client;
@@ -7425,6 +7449,25 @@ nfs4_set_delegation(struct nfsd4_open *open,
if (fp->fi_had_conflict)
goto out_unlock;
+ /*
+ * Anything that can reach the delegation once the delegation is
+ * hashed may read ncf_initial_cinfo and dl_[amc]time, so set them
+ * before hashing. nfs4_open_delegation() stats again after hashing
+ * to catch a write that lands between the two stats.
+ */
+ if (deleg_is_write(dl_type)) {
+ struct kstat stat;
+
+ status = -EIO;
+ if (!nfs4_delegation_stat(dp, currentfh, &stat))
+ goto out_unlock;
+ *grant_change = nfsd4_change_attribute(&stat);
+ dp->dl_cb_fattr.ncf_initial_cinfo = *grant_change;
+ dp->dl_atime = stat.atime;
+ dp->dl_ctime = stat.ctime;
+ dp->dl_mtime = stat.mtime;
+ }
+
spin_lock(&nn->deleg_lock);
spin_lock(&clp->cl_lock);
spin_lock(&fp->fi_lock);
@@ -7488,29 +7531,6 @@ static void nfsd4_open_deleg_none_ext(struct nfsd4_open *open, int status,
}
}
-static bool
-nfs4_delegation_stat(struct nfs4_delegation *dp, struct svc_fh *currentfh,
- struct kstat *stat)
-{
- struct nfsd_file *nf = find_writeable_file(dp->dl_stid.sc_file);
- struct path path;
- int rc;
-
- if (!nf)
- return false;
-
- path.mnt = currentfh->fh_export->ex_path.mnt;
- path.dentry = file_dentry(nf->nf_file);
-
- rc = vfs_getattr(&path, stat,
- STATX_MODE | STATX_SIZE | STATX_ATIME |
- STATX_MTIME | STATX_CTIME | STATX_CHANGE_COOKIE,
- AT_STATX_SYNC_AS_STAT);
-
- nfsd_file_put(nf);
- return rc == 0;
-}
-
/*
* Add NFS4_SHARE_ACCESS_READ to the write delegation granted on OPEN
* with NFS4_SHARE_ACCESS_WRITE by allocating separate nfsd_file and
@@ -7579,6 +7599,7 @@ nfs4_open_delegation(struct svc_rqst *rqstp, struct nfsd4_open *open,
struct svc_fh *parent = NULL;
struct nfs4_delegation *dp;
u32 held_type = OPEN_DELEGATE_NONE;
+ u64 grant_change = 0;
struct kstat stat;
int status = 0;
int cb_up;
@@ -7613,8 +7634,8 @@ nfs4_open_delegation(struct svc_rqst *rqstp, struct nfsd4_open *open,
default:
goto out_no_deleg;
}
- dp = nfs4_set_delegation(open, &resp->cstate, stp, parent,
- &held_type);
+ dp = nfs4_set_delegation(open, &resp->cstate, stp, parent, currentfh,
+ &held_type, &grant_change);
if (IS_ERR(dp)) {
status = PTR_ERR(dp);
goto out_no_deleg;
@@ -7632,12 +7653,24 @@ nfs4_open_delegation(struct svc_rqst *rqstp, struct nfsd4_open *open,
nfs4_put_stid(&dp->dl_stid);
goto out_no_deleg;
}
+ /*
+ * The holder's own WRITE through an earlier open doesn't
+ * break the lease and can land after the grant stat, as can
+ * a foreign write whose break raced past the fi_had_conflict
+ * check. A plain write delegation synthesizes change from
+ * ncf_initial_cinfo, so ncf_initial_cinfo must not be stale.
+ * Compare with the grant stat's change attribute, not with
+ * ncf_initial_cinfo. A GETATTR can already have advanced
+ * ncf_initial_cinfo past the grant stat's value.
+ */
+ if (nfsd4_change_attribute(&stat) != grant_change) {
+ destroy_delegation(dp);
+ nfs4_put_stid(&dp->dl_stid);
+ status = -EAGAIN;
+ goto out_no_deleg;
+ }
open->op_delegate_type = deleg_ts ? OPEN_DELEGATE_WRITE_ATTRS_DELEG :
OPEN_DELEGATE_WRITE;
- dp->dl_cb_fattr.ncf_initial_cinfo = nfsd4_change_attribute(&stat);
- dp->dl_atime = stat.atime;
- dp->dl_ctime = stat.ctime;
- dp->dl_mtime = stat.mtime;
spin_lock(&f->f_lock);
if (deleg_ts)
f->f_mode |= FMODE_NOCMTIME;
--
2.56.1
^ permalink raw reply [flat|nested] 13+ messages in thread