[PATCH v2] smb: client: allow nolease option to be reconfigured on remount

rajasimandalos
2026-04-22T05:06:33Z

tcon->no_lease controls whether the client requests leases from the
server. Changing nolease via remount is silently accepted but has
no effect because the value is never propagated to the live tcon.

Add no_lease to smb3_sync_tcon_opts() so the flag is propagated to
every tcon on remount.

When switching to nolease, close all deferred file handles via
cifs_close_all_deferred_files_sb() outside the tlink_tree_lock,
since closing deferred handles can sleep. Deferred handles retain
active leases from before the switch; without closing them, those
files continue using lease-based caching despite nolease being set.

Both transitions are safe:
- lease -> nolease: deferred handles are closed, future opens
get OPLOCK_LEVEL_NONE.
- nolease -> lease: future opens request leases normally.

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

diff --git a/fs/smb/client/fs_context.c b/fs/smb/client/fs_context.c
index 45173f287f00..fb59b45c7f66 100644
--- a/fs/smb/client/fs_context.c
+++ b/fs/smb/client/fs_context.c
@@ -1317,6 +1317,7 @@ 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;
/*
* Note: this updates the limit for new cached dir opens
* but does not resize or evict existing cached dirents.
@@ -1325,6 +1326,14 @@ static void smb3_sync_tcon_opts(struct cifs_sb_info *cifs_sb,
spin_unlock(&tcon->tc_lock);
}
spin_unlock(&cifs_sb->tlink_tree_lock);
+
+ /*
+ * When switching to nolease, close all deferred file handles.
+ * cifs_close_all_deferred_files_sb() handles its own locking
+ * and must be called outside tlink_tree_lock since it can sleep.
+ */
+ if (ctx->no_lease)
+ cifs_close_all_deferred_files_sb(cifs_sb);
}

/*
--
2.43.0