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

Steve French
2026-04-22T15:29:24Z

On Wed, Apr 22, 2026 at 3:37 AM Bharath SM <bharathsm.hsk@gmail.com> wrote:
>
> On Tue, Apr 21, 2026 at 10:06 PM <rajasimandalos@gmail.com> wrote:
> >
> > From: Rajasi Mandal <rajasimandal@microsoft.com>
> >
> > 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);
> > }
> Similar to deferred files, I think we probably need to invalidate the
> cached directory
> entries when we remount with 'nolease' considering 'nolease' is a
> superset mount option
> and should affect all types of leases.
>
> One additional case to consider: if an application already has a file
> open with an RWH
> lease acquired before the remount, that handle may continue to hold
> its lease and benefit
> from caching until the server sends a lease break or the application
> closes the handle.
> Is that correct.?
> I think nolease remount only affects new opens; it cannot
> retroactively revoke leases on
> existing active file handles. It may be worth documenting and/or
> comment this behavior,
> so it's clear that lease->nolease takes effect gradually as old
> handles are closed rather than
> instantaneously across all files & handles.
>
> Other than these comments, change looks good to me.

Should those changes be in followon patch rather than adding to this
easier to understand patch?

--
Thanks,

Steve