[PATCH 6/9] smb: client: allow nolease option to be reconfigured on remount

rajasimandalos
2026-04-09T10:00:14Z

The nolease mount option (tcon->no_lease) controls whether the client
requests oplocks/leases from the server during SMB2 opens. Previously,
changing this option via remount was silently accepted but had no effect
because the value was never synced from the updated ctx to the live tcon.

Add no_lease to smb3_sync_tcon_opts() so the flag is propagated to all
tcons on remount, matching the pattern used by retry, nodelete, and
max_cached_dirs.

When switching to nolease, also close all deferred file handles via
cifs_close_all_deferred_files(). Deferred handles retain their
original lease from the previous open; without closing them, a
subsequent open would reuse the cached handle and inherit the stale
lease, preventing nolease from taking effect.

Both transitions are safe:
- lease -> nolease: deferred handles are force-closed, and future
opens get OPLOCK_LEVEL_NONE.
- nolease -> lease: future opens will request leases; existing
uncached files remain uncached until reopened.

On reconnect, cifs_reopen_file() reads the current tcon->no_lease and
the server grants (or not) accordingly, so the per-inode cache state
is naturally updated.

Signed-off-by: Rajasi Mandal <rajasimandal@microsoft.com>
---
fs/smb/client/fs_context.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/fs/smb/client/fs_context.c b/fs/smb/client/fs_context.c
index 5f0637035172..ce4842e778c4 100644
--- a/fs/smb/client/fs_context.c
+++ b/fs/smb/client/fs_context.c
@@ -1330,8 +1330,12 @@ static void smb3_sync_tcon_opts(struct cifs_sb_info *cifs_sb,

spin_lock(&tcon->tc_lock);
tcon->retry = ctx->retry;
+ tcon->no_lease = ctx->no_lease;
tcon->max_cached_dirs = ctx->max_cached_dirs;
spin_unlock(&tcon->tc_lock);
+
+ if (ctx->no_lease)
+ cifs_close_all_deferred_files(tcon);
}
spin_unlock(&cifs_sb->tlink_tree_lock);
}
--
2.43.0