cifs: client: allow changing multichannel mount options on remount
Subsystems (2)
PATCH 1/1 cifs: client: allow changing multichannel mount options on remount
From: Rajasi Mandal <[email protected]>
Previously, the client did not update a session's channel state when multichannel or max_channels mount options were changed via remount. This led to inconsistent behavior and prevented enabling or disabling multichannel support without a full unmount/remount cycle.
Enable dynamic reconfiguration of multichannel and max_channels during remount by:
- Introducing smb3_sync_ses_chan_max(), a centralized function for channel updates which synchronizes the session's channels with the updated configuration.
- Replacing cifs_disable_secondary_channels() with cifs_decrease_secondary_channels(), which accepts a from_reconfigure flag to support targeted cleanup during reconfiguration.
- Updating remount logic to detect changes in multichannel or max_channels and trigger appropriate session/channel updates.
Current limitation:
- The query_interfaces worker runs even when max_channels=1 so that multichannel can be enabled later via remount without requiring an unmount. This is a temporary approach and may be refined in the future.
Users can safely modify multichannel and max_channels on an existing mount. The client will correctly adjust the session's channel state to match the new configuration, preserving durability where possible and avoiding unnecessary disconnects.
--- fs/smb/client/cifsproto.h | 4 ++- fs/smb/client/connect.c | 4 ++- fs/smb/client/fs_context.c | 50 +++++++++++++++++++++++++++++++++- fs/smb/client/sess.c | 32 +++++++++++++++------- fs/smb/client/smb2pdu.c | 55 ++++++++++++++++++++++++++++---------- 5 files changed, 119 insertions(+), 26 deletions(-)
fs/smb/client/cifsproto.h +3 -1
@@ -649,6 +649,8 @@ int cifs_alloc_hash(const char *name, struct shash_desc **sdesc);void cifs_free_hash (struct shash_desc **sdesc);int cifs_try_adding_channels (struct cifs_ses *ses); +int smb3_update_ses_channels (struct cifs_ses *ses,struct TCP_Server_Info *server, +bool from_reconnect,bool from_reconfigure);bool is_ses_using_iface (struct cifs_ses *ses,struct cifs_server_iface *iface);void cifs_ses_mark_for_reconnect (struct cifs_ses *ses);
@@ -674,7 +676,7 @@ bool cifs_chan_is_iface_active(struct cifs_ses *ses, struct TCP_Server_Info *server);void -cifs_disable_secondary_channels (struct cifs_ses *ses); +cifs_decrease_secondary_channels (struct cifs_ses *ses,bool from_reconfigure);void cifs_chan_update_iface (struct cifs_ses *ses,struct TCP_Server_Info *server);int
fs/smb/client/connect.c +3 -1
@@ -3927,7 +3927,9 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx) ctx->prepath =NULL ; out: -cifs_try_adding_channels (mnt_ctx.ses); +smb3_update_ses_channels (mnt_ctx.ses, mnt_ctx.server, + false/* from_reconnect */ , + false/* from_reconfigure */ ); rc =mount_setup_tlink (cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);if (rc) goto error;
fs/smb/client/fs_context.c +49 -1
68 lines not on this page · raw message
fs/smb/client/sess.c +23 -9
@@ -265,12 +265,16 @@ int cifs_try_adding_channels(struct cifs_ses *ses) }/* -* called when multichannel is disabled by the server. -* this always gets called from smb2_reconnect -* and cannot get called in parallel threads. +* cifs_decrease_secondary_channels - Reduce the number of active secondary channels +* @ses: pointer to the CIFS session structure +* @from_reconfigure: if true, only reduce to chan_max; if false, reduce to a single channel +* +* This function disables and cleans up extra secondary channels for a CIFS session. +* If called during reconfiguration, it reduces the channel count to the new maximum (chan_max). +* Otherwise, it disables all but the primary channel. */ void -cifs_disable_secondary_channels (struct cifs_ses *ses) +cifs_decrease_secondary_channels (struct cifs_ses *ses,bool from_reconfigure) {int i, chan_count;struct TCP_Server_Info *server;
@@ -281,12 +285,13 @@ cifs_disable_secondary_channels(struct cifs_ses *ses)if (chan_count ==1 ) goto done; - ses->chan_count =1 ; - -/* for all secondary channels reset the need reconnect bit */ - ses->chans_need_reconnect &=1 ; +/* Update the chan_count to the new maximum */ +if (from_reconfigure) + ses->chan_count = ses->chan_max; +else + ses->chan_count =1 ; -for (i =1 ; i < chan_count; i++) { +for (i = ses->chan_max ; i < chan_count; i++) { iface = ses->chans[i].iface; server = ses->chans[i].server;
@@ -318,6 +323,15 @@ cifs_disable_secondary_channels(struct cifs_ses *ses)spin_lock (&ses->chan_lock); } +/* For extra secondary channels, reset the need reconnect bit */ +if (ses->chan_count ==1 ) { +cifs_dbg (VFS ,"server does not support multichannel anymore. Disable all other channels\n" ); + ses->chans_need_reconnect &=1 ; + }else { +cifs_dbg (VFS ,"Disable extra secondary channels\n" ); + ses->chans_need_reconnect &= ((1UL << ses->chan_max) -1 ); + } + done:spin_unlock (&ses->chan_lock); }
fs/smb/client/smb2pdu.c +41 -14
101 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 1/1 cifs: client: enforce consistent handling of multichannel and max_channels
From: Rajasi Mandal <[email protected]>
Previously, the behavior of the multichannel and max_channels mount options was inconsistent and order-dependent. For example, specifying "multichannel,max_channels=1" would result in 2 channels, while "max_channels=1,multichannel" would result in 1 channel. Additionally, conflicting combinations such as "nomultichannel,max_channels=3" or "multichannel,max_channels=1" did not produce errors and could lead to unexpected channel counts.
This commit introduces two new fields in smb3_fs_context to explicitly track whether multichannel and max_channels were specified during mount. The option parsing and validation logic is updated to ensure:
- The outcome is no longer dependent on the order of options.
- Conflicting combinations (e.g., "nomultichannel,max_channels=3" or "multichannel,max_channels=1") are detected and result in an error.
- The number of channels created is consistent with the specified options.
This improves the reliability and predictability of mount option handling for SMB3 multichannel support.
--- fs/smb/client/cifsfs.c | 1 - fs/smb/client/fs_context.c | 65 ++++++++++++++++++++++++++++---------- fs/smb/client/fs_context.h | 2 ++ 3 files changed, 50 insertions(+), 18 deletions(-)
fs/smb/client/cifsfs.c +0 -1
@@ -1016,7 +1016,6 @@ cifs_smb3_do_mount(struct file_system_type *fs_type, }else {cifs_info ("Attempting to mount %s\n" , old_ctx->source); } - cifs_sb =kzalloc (sizeof (*cifs_sb),GFP_KERNEL );if (!cifs_sb)return ERR_PTR (-ENOMEM );
fs/smb/client/fs_context.c +48 -17
109 lines not on this page · raw message
fs/smb/client/fs_context.h +2 -0
@@ -294,6 +294,8 @@ struct smb3_fs_context { bool domainauto:1; bool rdma:1; bool multichannel:1; + bool multichannel_specified:1; /* true if user specified multichannel or nomultichannel */ + bool max_channels_specified:1; /* true if user specified max_channels */ bool use_client_guid:1;/* reuse existing guid for multichannel */ u8 client_guid[SMB2_CLIENT_GUID_SIZE ];
Signature · 1 line
2.43.0
Re: [PATCH] cifs: client: enforce consistent handling of multichannel and max_channels
Quoted 19 lines · Rajasi Mandal
From: Rajasi Mandal <[email protected]>
Previously, the behavior of the multichannel and
max_channelsmount options was inconsistent and order-dependent. For example, specifying "multichannel,max_channels=1" would result in 2 channels, while "max_channels=1,multichannel" would result in 1 channel. Additionally, conflicting combinations such as "nomultichannel,max_channels=3" or "multichannel,max_channels=1" did not produce errors and could lead to unexpected channel counts.This commit introduces two new fields in
smb3_fs_contextto explicitly track whether multichannel andmax_channelswere specified during mount. The option parsing and validation logic is updated to ensure:
- The outcome is no longer dependent on the order of options.
- Conflicting combinations (e.g., "nomultichannel,max_channels=3" or "multichannel,max_channels=1") are detected and result in an error.
- The number of channels created is consistent with the specified options.
Quoted 5 lines
This improves the reliability and predictability of mount option handling for SMB3 multichannel support.
Reviewed-by Shyam Prasad N <[email protected]>Signed-off-by Rajasi Mandal <[email protected]>
It's conflicting because it's already too complex for something that should've been simple. This patch introduces a new field + unnecessary logic on top if it all.
cf. a PoC patch I sent a while ago, we can (ab)use fsparam with same key name, but different key types, so we could only deal with:
'nomultichannel', 'multichannel={0,1,off,no}' as multichannel disabled 'multichannel' as ctx->max_channels=2 (multichannel enabled, obviously) 'multichannel=X' as ctx->max_channels=X (ditto)
Makes 0 sense to have both multichannel and max_channels mount options.
Quoted 51 lines
---
fs/smb/client/cifsfs.c | 1 - fs/smb/client/fs_context.c | 65 ++++++++++++++++++++++++++++---------- fs/smb/client/fs_context.h | 2 ++ 3 files changed, 50 insertions(+), 18 deletions(-)fs/smb/client/cifsfs.c +0
-1@@ -1016,7 +1016,6 @@ cifs_smb3_do_mount(struct file_system_type *fs_type, }else {cifs_info ("Attempting to mount %s\n" , old_ctx->source); } - cifs_sb =kzalloc (sizeof (*cifs_sb),GFP_KERNEL );if (!cifs_sb)return ERR_PTR (-ENOMEM );fs/smb/client/fs_context.c +25
-0@@ -711,6 +711,47 @@ smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)return 0 ; } +static int smb3_handle_conflicting_options (struct fs_context *fc) +{ +struct smb3_fs_context *ctx =smb3_fc2context (fc); + +if (ctx->multichannel_specified) { +if (ctx->multichannel) { +if (!ctx->max_channels_specified) { + ctx->max_channels =2 ; + }else if (ctx->max_channels ==1 ) { +cifs_errorf (fc, +"max_channels must be greater than 1 when multichannel is enabled\n" ); +return -EINVAL ; + } + }else { +if (!ctx->max_channels_specified) { + ctx->max_channels =1 ; + }else if (ctx->max_channels >1 ) { +cifs_errorf (fc, +"max_channels must be equal to 1 when multichannel is disabled\n" ); +return -EINVAL ; + } + } + }else { +if (ctx->max_channels_specified) { +if (ctx->max_channels >1 )
fs/smb/client/fs_context.c smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx) · line 748
Quoted 10 lines
fs/smb/client/fs_context.c +10
-0+ ctx->multichannel = true; + else + ctx->multichannel = false; + }else { + ctx->multichannel = false; + ctx->max_channels =1 ; + } + } + +//resetting default values as remount doesn't initialize fs_context again
Please stick to /* ... */ comments style.
Quoted 91 lines
fs/smb/client/fs_context.c +13
-17+ ctx->multichannel_specified = false; + ctx->max_channels_specified = false; + +return 0 ; +} +static void smb3_fs_context_free (struct fs_context *fc);static int smb3_fs_context_parse_param (struct fs_context *fc,struct fs_parameter *param);@@ -785,6 +826,7 @@ static int smb3_fs_context_parse_monolithic(struct fs_context *fc,if (ret <0 )break ; } + ret =smb3_handle_conflicting_options (fc);return ret; }@@ -1296,15 +1338,11 @@ static int smb3_fs_context_parse_param(struct fs_context *fc, ctx->nodelete =1 ;break ;case Opt_multichannel: -if (result.negated) { + ctx->multichannel_specified = true; +if (result.negated) ctx->multichannel = false; - ctx->max_channels =1 ; - }else { +else ctx->multichannel = true; -/* if number of channels not specified, default to 2 */ -if (ctx->max_channels <2 ) - ctx->max_channels =2 ; - }break ;case Opt_uid: ctx->linux_uid = result.uid;@@ -1440,15 +1478,13 @@ static int smb3_fs_context_parse_param(struct fs_context *fc, ctx->max_credits = result.uint_32;break ;case Opt_max_channels: + ctx->max_channels_specified = true;if (result.uint_32 <1 || result.uint_32 >CIFS_MAX_CHANNELS ) {cifs_errorf (fc,"%s: Invalid max_channels value, needs to be 1-%d\n" , __func__,CIFS_MAX_CHANNELS ); goto cifs_parse_mount_err; } ctx->max_channels = result.uint_32; -/* If more than one channel requested ... they want multichan */ -if (result.uint_32 >1 ) - ctx->multichannel = true;break ;case Opt_max_cached_dirs:if (result.uint_32 <1 ) {@@ -1866,13 +1902,6 @@ static int smb3_fs_context_parse_param(struct fs_context *fc, goto cifs_parse_mount_err; } -/* -* Multichannel is not meaningful if max_channels is 1. -* Force multichannel to false to ensure consistent configuration. -*/ -if (ctx->multichannel && ctx->max_channels ==1 ) - ctx->multichannel = false; -return 0 ; cifs_parse_mount_err:@@ -1955,6 +1984,8 @@ int smb3_init_fs_context(struct fs_context *fc)/* default to no multichannel (single server connection) */ ctx->multichannel = false; + ctx->multichannel_specified = false; + ctx->max_channels_specified = false; ctx->max_channels =1 ; ctx->backupuid_specified = false;/* no backup intent for a user */ fs/smb/client/fs_context.h +2
-0@@ -294,6 +294,8 @@ struct smb3_fs_context { bool domainauto:1; bool rdma:1; bool multichannel:1; + bool multichannel_specified:1; /* true if user specified multichannel or nomultichannel */ + bool max_channels_specified:1; /* true if user specified max_channels */ bool use_client_guid:1;/* reuse existing guid for multichannel */ u8 client_guid[SMB2_CLIENT_GUID_SIZE ];Signature · 1 line
2.43.0
Cheers,
Enzo
Re: [PATCH] cifs: client: enforce consistent handling of multichannel and max_channels
Quoted 31 lines · Enzo Matsumiya via samba-technical
Quoted 19 lines · Rajasi Mandal
From: Rajasi Mandal <[email protected]>
Previously, the behavior of the multichannel and
max_channelsmount options was inconsistent and order-dependent. For example, specifying "multichannel,max_channels=1" would result in 2 channels, while "max_channels=1,multichannel" would result in 1 channel. Additionally, conflicting combinations such as "nomultichannel,max_channels=3" or "multichannel,max_channels=1" did not produce errors and could lead to unexpected channel counts.This commit introduces two new fields in
smb3_fs_contextto explicitly track whether multichannel andmax_channelswere specified during mount. The option parsing and validation logic is updated to ensure:
- The outcome is no longer dependent on the order of options.
- Conflicting combinations (e.g., "nomultichannel,max_channels=3" or "multichannel,max_channels=1") are detected and result in an error.
- The number of channels created is consistent with the specified options.Quoted 5 lines
This improves the reliability and predictability of mount option handling for SMB3 multichannel support.
Reviewed-by Shyam Prasad N <[email protected]>Signed-off-by Rajasi Mandal <[email protected]>It's conflicting because it's already too complex for something that should've been simple. This patch introduces a new field + unnecessary logic on top if it all.
Quoted 8 lines
cf. a PoC patch I sent a while ago, we can (ab)use fsparam with same key name, but different key types, so we could only deal with:
'nomultichannel', 'multichannel={0,1,off,no}' as multichannel disabled 'multichannel' as ctx->max_channels=2 (multichannel enabled, obviously) 'multichannel=X' as ctx->max_channels=X (ditto)
Makes 0 sense to have both multichannel and
max_channelsmount options.
We can't regress customers who use common mount options without warning them for multiple releases that parm is going to be removed.
I don't object to changing Opt_max_channels parsing so ctx->max_channels in fs_context fgoes rom a # to a combination of number and something which can be mapped to on/off (for on client picks default on the fly while for off sets channels to 1) and removing ctx->multichannel - so if you specify "multichannel" it sets ctx->max_channels to something like -1 (or whatever max # is) and if you set nomultichannel it sets ctx->max_channels to 1
Signature · 3 lines
Thanks, Steve
Hi Rajasi,
Quoted 67 lines · Rajasi Mandal
From: Rajasi Mandal <[email protected]>
Previously, the client did not update a session's channel state when multichannel or
max_channelsmount options were changed via remount. This led to inconsistent behavior and prevented enabling or disabling multichannel support without a full unmount/remount cycle.Enable dynamic reconfiguration of multichannel and
max_channelsduring remount by:
- Introducingsmb3_sync_ses_chan_max(), a centralized function for channel updates which synchronizes the session's channels with the updated configuration.
- Replacingcifs_disable_secondary_channels()withcifs_decrease_secondary_channels(), which accepts afrom_reconfigureflag to support targeted cleanup during reconfiguration.
- Updating remount logic to detect changes in multichannel ormax_channelsand trigger appropriate session/channel updates.Current limitation:
- Thequery_interfacesworker runs even when max_channels=1 so that multichannel can be enabled later via remount without requiring an unmount. This is a temporary approach and may be refined in the future.Users can safely modify multichannel and
max_channelson an existing mount. The client will correctly adjust the session's channel state to match the new configuration, preserving durability where possible and avoiding unnecessary disconnects.Reviewed-by Shyam Prasad N <[email protected]>Signed-off-by Rajasi Mandal <[email protected]>--- fs/smb/client/cifsproto.h | 4 ++- fs/smb/client/connect.c | 4 ++- fs/smb/client/fs_context.c | 50 +++++++++++++++++++++++++++++++++- fs/smb/client/sess.c | 32 +++++++++++++++------- fs/smb/client/smb2pdu.c | 55 ++++++++++++++++++++++++++++---------- 5 files changed, 119 insertions(+), 26 deletions(-)fs/smb/client/cifsproto.h +3
-1@@ -649,6 +649,8 @@ int cifs_alloc_hash(const char *name, struct shash_desc **sdesc);void cifs_free_hash (struct shash_desc **sdesc);int cifs_try_adding_channels (struct cifs_ses *ses); +int smb3_update_ses_channels (struct cifs_ses *ses,struct TCP_Server_Info *server, +bool from_reconnect,bool from_reconfigure);bool is_ses_using_iface (struct cifs_ses *ses,struct cifs_server_iface *iface);void cifs_ses_mark_for_reconnect (struct cifs_ses *ses);@@ -674,7 +676,7 @@ bool cifs_chan_is_iface_active(struct cifs_ses *ses, struct TCP_Server_Info *server);void -cifs_disable_secondary_channels (struct cifs_ses *ses); +cifs_decrease_secondary_channels (struct cifs_ses *ses,bool from_reconfigure);void cifs_chan_update_iface (struct cifs_ses *ses,struct TCP_Server_Info *server);int fs/smb/client/connect.c +0
-0
fs/smb/client/connect.c int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx) · line 3932
Quoted 7 lines
fs/smb/client/connect.c +3
-1@@ -3927,7 +3927,9 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx) ctx->prepath =NULL ; out: -cifs_try_adding_channels (mnt_ctx.ses); +smb3_update_ses_channels (mnt_ctx.ses, mnt_ctx.server, + false/* from_reconnect */ , + false/* from_reconfigure */ );
Shouldn't this be added to the non-dfs cifs_mount() too? I see that even cifs_try_adding_channels() is not present in this function, @Shyam Prasad is this expected?
Quoted 166 lines
fs/smb/client/connect.c +0
-0rc =mount_setup_tlink (cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);if (rc) goto error;fs/smb/client/fs_context.c +49
-1@@ -717,6 +717,7 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,static int smb3_fs_context_parse_monolithic (struct fs_context *fc,void *data);static int smb3_get_tree (struct fs_context *fc); +static void smb3_sync_ses_chan_max (struct cifs_ses *ses,unsigned int max_channels);static int smb3_reconfigure (struct fs_context *fc);static const struct fs_context_operations smb3_fs_context_ops = {@@ -1013,6 +1014,22 @@ int smb3_sync_session_ctx_passwords(struct cifs_sb_info *cifs_sb, struct cifs_sereturn 0 ; } +/* +* smb3_sync_ses_chan_max - Synchronize the session's maximum channel count +* @ses: pointer to the old CIFS session structure +* @max_channels: new maximum number of channels to allow +* +* Updates the session's chan_max field to the new value, protecting the update +* with the session's channel lock. This should be called whenever the maximum +* allowed channels for a session changes (e.g., after a remount or reconfigure). +*/ +static void smb3_sync_ses_chan_max (struct cifs_ses *ses,unsigned int max_channels) +{ +spin_lock (&ses->chan_lock); + ses->chan_max = max_channels; +spin_unlock (&ses->chan_lock); +} +static int smb3_reconfigure (struct fs_context *fc) {struct smb3_fs_context *ctx =smb3_fc2context (fc);@@ -1095,7 +1112,38 @@ static int smb3_reconfigure(struct fs_context *fc) ses->password2 = new_password2; } -mutex_unlock (&ses->session_mutex); +/* +* If multichannel or max_channels has changed, update the session's channels accordingly. +* This may add or remove channels to match the new configuration. +*/ +if ((ctx->multichannel != cifs_sb->ctx->multichannel) || + (ctx->max_channels != cifs_sb->ctx->max_channels)) { + +/* Synchronize ses->chan_max with the new mount context */ +smb3_sync_ses_chan_max (ses, ctx->max_channels); +/* Now update the session's channels to match the new configuration */ +/* Prevent concurrent scaling operations */ +spin_lock (&ses->ses_lock); +if (ses->flags &CIFS_SES_FLAG_SCALE_CHANNELS ) { +spin_unlock (&ses->ses_lock); +return -EINVAL ; + } + ses->flags |=CIFS_SES_FLAG_SCALE_CHANNELS ; +spin_unlock (&ses->ses_lock); + +mutex_unlock (&ses->session_mutex); + + rc =smb3_update_ses_channels (ses, ses->server, + false/* from_reconnect */ , + true/* from_reconfigure */ ); + +/* Clear scaling flag after operation */ +spin_lock (&ses->ses_lock); + ses->flags &= ~CIFS_SES_FLAG_SCALE_CHANNELS ; +spin_unlock (&ses->ses_lock); + }else { +mutex_unlock (&ses->session_mutex); + }STEAL_STRING (cifs_sb, ctx, domainname);STEAL_STRING (cifs_sb, ctx, nodename);fs/smb/client/sess.c +23
-9@@ -265,12 +265,16 @@ int cifs_try_adding_channels(struct cifs_ses *ses) }/* -* called when multichannel is disabled by the server. -* this always gets called from smb2_reconnect -* and cannot get called in parallel threads. +* cifs_decrease_secondary_channels - Reduce the number of active secondary channels +* @ses: pointer to the CIFS session structure +* @from_reconfigure: if true, only reduce to chan_max; if false, reduce to a single channel +* +* This function disables and cleans up extra secondary channels for a CIFS session. +* If called during reconfiguration, it reduces the channel count to the new maximum (chan_max). +* Otherwise, it disables all but the primary channel. */ void -cifs_disable_secondary_channels (struct cifs_ses *ses) +cifs_decrease_secondary_channels (struct cifs_ses *ses,bool from_reconfigure) {int i, chan_count;struct TCP_Server_Info *server;@@ -281,12 +285,13 @@ cifs_disable_secondary_channels(struct cifs_ses *ses)if (chan_count ==1 ) goto done; - ses->chan_count =1 ; - -/* for all secondary channels reset the need reconnect bit */ - ses->chans_need_reconnect &=1 ; +/* Update the chan_count to the new maximum */ +if (from_reconfigure) + ses->chan_count = ses->chan_max; +else + ses->chan_count =1 ; -for (i =1 ; i < chan_count; i++) { +for (i = ses->chan_max ; i < chan_count; i++) { iface = ses->chans[i].iface; server = ses->chans[i].server;@@ -318,6 +323,15 @@ cifs_disable_secondary_channels(struct cifs_ses *ses)spin_lock (&ses->chan_lock); } +/* For extra secondary channels, reset the need reconnect bit */ +if (ses->chan_count ==1 ) { +cifs_dbg (VFS ,"server does not support multichannel anymore. Disable all other channels\n" ); + ses->chans_need_reconnect &=1 ; + }else { +cifs_dbg (VFS ,"Disable extra secondary channels\n" ); + ses->chans_need_reconnect &= ((1UL << ses->chan_max) -1 ); + } + done:spin_unlock (&ses->chan_lock); }fs/smb/client/smb2pdu.c +4
-5@@ -168,7 +168,7 @@ smb2_hdr_assemble(struct smb2_hdr *shdr, __le16 smb2_cmd,static int cifs_chan_skip_or_disable (struct cifs_ses *ses,struct TCP_Server_Info *server, -bool from_reconnect) +bool from_reconnect,bool from_reconfigure) {struct TCP_Server_Info *pserver;unsigned int chan_index;@@ -206,14 +206,41 @@ cifs_chan_skip_or_disable(struct cifs_ses *ses,return -EHOSTDOWN ; } -cifs_server_dbg (VFS , -"server does not support multichannel anymore. Disable all other channels\n" ); -cifs_disable_secondary_channels (ses); - +cifs_decrease_secondary_channels (ses, from_reconfigure);return 0 ; } +/* +* smb3_update_ses_channels - Synchronize session channels with new configuration
fs/smb/client/smb2pdu.c cifs_chan_skip_or_disable(struct cifs_ses *ses, · line 225
Quoted 10 lines
fs/smb/client/smb2pdu.c +10
-0+* @ses: pointer to the CIFS session structure +* @server: pointer to the TCP server info structure +* @from_reconnect: indicates if called from reconnect context +* @from_reconfigure: indicates if called from reconfigure context +* +* Returns 0 on success or error code on failure. +* +* Note: Outside of reconfigure, this function is only called from reconnect scenarios +* when the server stops advertising multichannel (MC) capability. +*/
I see that function is being called during mount too. Did you mean cifs_decrease_secondary_channels()?
Quoted 75 lines
fs/smb/client/smb2pdu.c +27
-10+int smb3_update_ses_channels (struct cifs_ses *ses,struct TCP_Server_Info *server, +bool from_reconnect,bool from_reconfigure) +{ +int rc =0 ; +/* +* If the current channel count is less than the new chan_max, +* try to add channels to reach the new maximum. +* Otherwise, disable or skip extra channels to match the new configuration. +*/ +if (ses->chan_count < ses->chan_max) + rc =cifs_try_adding_channels (ses); +else + rc =cifs_chan_skip_or_disable (ses, server, from_reconnect, + from_reconfigure); + +return rc; +} +static int smb2_reconnect (__le16 smb2_command,struct cifs_tcon *tcon,struct TCP_Server_Info *server,bool from_reconnect)@@ -355,8 +382,8 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,*/ if (ses->chan_count >1 && !(server->capabilities &SMB2_GLOBAL_CAP_MULTI_CHANNEL )) { - rc =cifs_chan_skip_or_disable (ses, server, - from_reconnect); + rc =smb3_update_ses_channels (ses, server, + from_reconnect, false/* from_reconfigure */ );if (rc) {mutex_unlock (&ses->session_mutex); goto out;@@ -438,8 +465,9 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,* treat this as server not supporting multichannel */ - rc =cifs_chan_skip_or_disable (ses, server, - from_reconnect); + rc =smb3_update_ses_channels (ses, server, + from_reconnect, + false/* from_reconfigure */ ); goto skip_add_channels; }else if (rc) cifs_tcon_dbg(FYI, "%s: failed to query server interfaces: %d\n",@@ -451,7 +479,8 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,if (ses->chan_count ==1 )cifs_server_dbg (VFS ,"supports multichannel now\n" ); -cifs_try_adding_channels (ses); +smb3_update_ses_channels (ses, server, from_reconnect, + false/* from_reconfigure */ ); } }else {mutex_unlock (&ses->session_mutex);@@ -1105,8 +1134,7 @@ SMB2_negotiate(const unsigned int xid, req->SecurityMode =0 ; req->Capabilities =cpu_to_le32 (server->vals->req_capabilities); -if (ses->chan_max >1 ) - req->Capabilities |=cpu_to_le32 (SMB2_GLOBAL_CAP_MULTI_CHANNEL ); + req->Capabilities |=cpu_to_le32 (SMB2_GLOBAL_CAP_MULTI_CHANNEL );/* ClientGUID must be zero for SMB2.02 dialect */ if (server->vals->protocol_id ==SMB20_PROT_ID )@@ -1312,8 +1340,7 @@ int smb3_validate_negotiate(const unsigned int xid, struct cifs_tcon *tcon) pneg_inbuf->Capabilities =cpu_to_le32 (server->vals->req_capabilities); -if (tcon->ses->chan_max >1 ) - pneg_inbuf->Capabilities |=cpu_to_le32 (SMB2_GLOBAL_CAP_MULTI_CHANNEL ); + pneg_inbuf->Capabilities |=cpu_to_le32 (SMB2_GLOBAL_CAP_MULTI_CHANNEL );memcpy (pneg_inbuf->Guid, server->client_guid,SMB2_CLIENT_GUID_SIZE ); --
Quoted 3 lines
2.43.0
Thanks
Meetakshi
Quoted 73 lines · Meetakshi Setiya
Hi Rajasi,
Quoted 69 lines · Rajasi Mandal
From: Rajasi Mandal <[email protected]>
Previously, the client did not update a session's channel state when multichannel or
max_channelsmount options were changed via remount. This led to inconsistent behavior and prevented enabling or disabling multichannel support without a full unmount/remount cycle.Enable dynamic reconfiguration of multichannel and
max_channelsduring remount by:
- Introducingsmb3_sync_ses_chan_max(), a centralized function for channel updates which synchronizes the session's channels with the updated configuration.
- Replacingcifs_disable_secondary_channels()withcifs_decrease_secondary_channels(), which accepts afrom_reconfigureflag to support targeted cleanup during reconfiguration.
- Updating remount logic to detect changes in multichannel ormax_channelsand trigger appropriate session/channel updates.Current limitation:
- Thequery_interfacesworker runs even when max_channels=1 so that multichannel can be enabled later via remount without requiring an unmount. This is a temporary approach and may be refined in the future.Users can safely modify multichannel and
max_channelson an existing mount. The client will correctly adjust the session's channel state to match the new configuration, preserving durability where possible and avoiding unnecessary disconnects.Reviewed-by Shyam Prasad N <[email protected]>Signed-off-by Rajasi Mandal <[email protected]>--- fs/smb/client/cifsproto.h | 4 ++- fs/smb/client/connect.c | 4 ++- fs/smb/client/fs_context.c | 50 +++++++++++++++++++++++++++++++++- fs/smb/client/sess.c | 32 +++++++++++++++------- fs/smb/client/smb2pdu.c | 55 ++++++++++++++++++++++++++++---------- 5 files changed, 119 insertions(+), 26 deletions(-)fs/smb/client/cifsproto.h +3
-1@@ -649,6 +649,8 @@ int cifs_alloc_hash(const char *name, struct shash_desc **sdesc);void cifs_free_hash (struct shash_desc **sdesc);int cifs_try_adding_channels (struct cifs_ses *ses); +int smb3_update_ses_channels (struct cifs_ses *ses,struct TCP_Server_Info *server, +bool from_reconnect,bool from_reconfigure);bool is_ses_using_iface (struct cifs_ses *ses,struct cifs_server_iface *iface);void cifs_ses_mark_for_reconnect (struct cifs_ses *ses);@@ -674,7 +676,7 @@ bool cifs_chan_is_iface_active(struct cifs_ses *ses, struct TCP_Server_Info *server);void -cifs_disable_secondary_channels (struct cifs_ses *ses); +cifs_decrease_secondary_channels (struct cifs_ses *ses,bool from_reconfigure);void cifs_chan_update_iface (struct cifs_ses *ses,struct TCP_Server_Info *server);int fs/smb/client/connect.c +0
-0@@ -3927,7 +3927,9 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx) ctx->prepath =NULL ;
Quoted 9 lines
fs/smb/client/connect.c int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx) · line 3932
Quoted 5 lines
fs/smb/client/connect.c +3
-1out: -cifs_try_adding_channels (mnt_ctx.ses); +smb3_update_ses_channels (mnt_ctx.ses, mnt_ctx.server, + false/* from_reconnect */ , + false/* from_reconfigure */ );Shouldn't this be added to the non-dfs
cifs_mount()too? I see that evencifs_try_adding_channels()is not present in this function, @Shyam Prasad is this expected?
That's a good catch.
I think this is a day-0 bug.
I can see that the original change by Aurelien has the change only in DFS cifs_mount:
commit d70e9fa55884760b6d6c293dbf20d8c52ce11fb7
Author: Aurelien Aptel <[email protected]> Date: Fri Sep 20 06:31:10 2019 +0200
cifs: try opening channels after mounting
We should have a follow-up patch to fix this.
Quoted 263 lines
Quoted 167 lines
fs/smb/client/connect.c +0
-0rc =mount_setup_tlink (cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);if (rc) goto error;fs/smb/client/fs_context.c +49
-1@@ -717,6 +717,7 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,static int smb3_fs_context_parse_monolithic (struct fs_context *fc,void *data);static int smb3_get_tree (struct fs_context *fc); +static void smb3_sync_ses_chan_max (struct cifs_ses *ses,unsigned int max_channels);static int smb3_reconfigure (struct fs_context *fc);static const struct fs_context_operations smb3_fs_context_ops = {@@ -1013,6 +1014,22 @@ int smb3_sync_session_ctx_passwords(struct cifs_sb_info *cifs_sb, struct cifs_sereturn 0 ; } +/* +* smb3_sync_ses_chan_max - Synchronize the session's maximum channel count +* @ses: pointer to the old CIFS session structure +* @max_channels: new maximum number of channels to allow +* +* Updates the session's chan_max field to the new value, protecting the update +* with the session's channel lock. This should be called whenever the maximum +* allowed channels for a session changes (e.g., after a remount or reconfigure). +*/ +static void smb3_sync_ses_chan_max (struct cifs_ses *ses,unsigned int max_channels) +{ +spin_lock (&ses->chan_lock); + ses->chan_max = max_channels; +spin_unlock (&ses->chan_lock); +} +static int smb3_reconfigure (struct fs_context *fc) {struct smb3_fs_context *ctx =smb3_fc2context (fc);@@ -1095,7 +1112,38 @@ static int smb3_reconfigure(struct fs_context *fc) ses->password2 = new_password2; } -mutex_unlock (&ses->session_mutex); +/* +* If multichannel or max_channels has changed, update the session's channels accordingly. +* This may add or remove channels to match the new configuration. +*/ +if ((ctx->multichannel != cifs_sb->ctx->multichannel) || + (ctx->max_channels != cifs_sb->ctx->max_channels)) { + +/* Synchronize ses->chan_max with the new mount context */ +smb3_sync_ses_chan_max (ses, ctx->max_channels); +/* Now update the session's channels to match the new configuration */ +/* Prevent concurrent scaling operations */ +spin_lock (&ses->ses_lock); +if (ses->flags &CIFS_SES_FLAG_SCALE_CHANNELS ) { +spin_unlock (&ses->ses_lock); +return -EINVAL ; + } + ses->flags |=CIFS_SES_FLAG_SCALE_CHANNELS ; +spin_unlock (&ses->ses_lock); + +mutex_unlock (&ses->session_mutex); + + rc =smb3_update_ses_channels (ses, ses->server, + false/* from_reconnect */ , + true/* from_reconfigure */ ); + +/* Clear scaling flag after operation */ +spin_lock (&ses->ses_lock); + ses->flags &= ~CIFS_SES_FLAG_SCALE_CHANNELS ; +spin_unlock (&ses->ses_lock); + }else { +mutex_unlock (&ses->session_mutex); + }STEAL_STRING (cifs_sb, ctx, domainname);STEAL_STRING (cifs_sb, ctx, nodename);fs/smb/client/sess.c +23
-9@@ -265,12 +265,16 @@ int cifs_try_adding_channels(struct cifs_ses *ses) }/* -* called when multichannel is disabled by the server. -* this always gets called from smb2_reconnect -* and cannot get called in parallel threads. +* cifs_decrease_secondary_channels - Reduce the number of active secondary channels +* @ses: pointer to the CIFS session structure +* @from_reconfigure: if true, only reduce to chan_max; if false, reduce to a single channel +* +* This function disables and cleans up extra secondary channels for a CIFS session. +* If called during reconfiguration, it reduces the channel count to the new maximum (chan_max). +* Otherwise, it disables all but the primary channel. */ void -cifs_disable_secondary_channels (struct cifs_ses *ses) +cifs_decrease_secondary_channels (struct cifs_ses *ses,bool from_reconfigure) {int i, chan_count;struct TCP_Server_Info *server;@@ -281,12 +285,13 @@ cifs_disable_secondary_channels(struct cifs_ses *ses)if (chan_count ==1 ) goto done; - ses->chan_count =1 ; - -/* for all secondary channels reset the need reconnect bit */ - ses->chans_need_reconnect &=1 ; +/* Update the chan_count to the new maximum */ +if (from_reconfigure) + ses->chan_count = ses->chan_max; +else + ses->chan_count =1 ; -for (i =1 ; i < chan_count; i++) { +for (i = ses->chan_max ; i < chan_count; i++) { iface = ses->chans[i].iface; server = ses->chans[i].server;@@ -318,6 +323,15 @@ cifs_disable_secondary_channels(struct cifs_ses *ses)spin_lock (&ses->chan_lock); } +/* For extra secondary channels, reset the need reconnect bit */ +if (ses->chan_count ==1 ) { +cifs_dbg (VFS ,"server does not support multichannel anymore. Disable all other channels\n" ); + ses->chans_need_reconnect &=1 ; + }else { +cifs_dbg (VFS ,"Disable extra secondary channels\n" ); + ses->chans_need_reconnect &= ((1UL << ses->chan_max) -1 ); + } + done:spin_unlock (&ses->chan_lock); }fs/smb/client/smb2pdu.c +4
-5@@ -168,7 +168,7 @@ smb2_hdr_assemble(struct smb2_hdr *shdr, __le16 smb2_cmd,static int cifs_chan_skip_or_disable (struct cifs_ses *ses,struct TCP_Server_Info *server, -bool from_reconnect) +bool from_reconnect,bool from_reconfigure) {struct TCP_Server_Info *pserver;unsigned int chan_index;@@ -206,14 +206,41 @@ cifs_chan_skip_or_disable(struct cifs_ses *ses,return -EHOSTDOWN ; } -cifs_server_dbg (VFS , -"server does not support multichannel anymore. Disable all other channels\n" ); -cifs_disable_secondary_channels (ses); - +cifs_decrease_secondary_channels (ses, from_reconfigure);return 0 ; } +/* +* smb3_update_ses_channels - Synchronize session channels with new configuration fs/smb/client/smb2pdu.c cifs_chan_skip_or_disable(struct cifs_ses *ses, · line 225
Quoted 10 lines
fs/smb/client/smb2pdu.c +10
-0+* @ses: pointer to the CIFS session structure +* @server: pointer to the TCP server info structure +* @from_reconnect: indicates if called from reconnect context +* @from_reconfigure: indicates if called from reconfigure context +* +* Returns 0 on success or error code on failure. +* +* Note: Outside of reconfigure, this function is only called from reconnect scenarios +* when the server stops advertising multichannel (MC) capability. +*/ I see that function is being called during mount too. Did you mean
cifs_decrease_secondary_channels()?Quoted 75 lines
fs/smb/client/smb2pdu.c +27
-10+int smb3_update_ses_channels (struct cifs_ses *ses,struct TCP_Server_Info *server, +bool from_reconnect,bool from_reconfigure) +{ +int rc =0 ; +/* +* If the current channel count is less than the new chan_max, +* try to add channels to reach the new maximum. +* Otherwise, disable or skip extra channels to match the new configuration. +*/ +if (ses->chan_count < ses->chan_max) + rc =cifs_try_adding_channels (ses); +else + rc =cifs_chan_skip_or_disable (ses, server, from_reconnect, + from_reconfigure); + +return rc; +} +static int smb2_reconnect (__le16 smb2_command,struct cifs_tcon *tcon,struct TCP_Server_Info *server,bool from_reconnect)@@ -355,8 +382,8 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,*/ if (ses->chan_count >1 && !(server->capabilities &SMB2_GLOBAL_CAP_MULTI_CHANNEL )) { - rc =cifs_chan_skip_or_disable (ses, server, - from_reconnect); + rc =smb3_update_ses_channels (ses, server, + from_reconnect, false/* from_reconfigure */ );if (rc) {mutex_unlock (&ses->session_mutex); goto out;@@ -438,8 +465,9 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,* treat this as server not supporting multichannel */ - rc =cifs_chan_skip_or_disable (ses, server, - from_reconnect); + rc =smb3_update_ses_channels (ses, server, + from_reconnect, + false/* from_reconfigure */ ); goto skip_add_channels; }else if (rc) cifs_tcon_dbg(FYI, "%s: failed to query server interfaces: %d\n",@@ -451,7 +479,8 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,if (ses->chan_count ==1 )cifs_server_dbg (VFS ,"supports multichannel now\n" ); -cifs_try_adding_channels (ses); +smb3_update_ses_channels (ses, server, from_reconnect, + false/* from_reconfigure */ ); } }else {mutex_unlock (&ses->session_mutex);@@ -1105,8 +1134,7 @@ SMB2_negotiate(const unsigned int xid, req->SecurityMode =0 ; req->Capabilities =cpu_to_le32 (server->vals->req_capabilities); -if (ses->chan_max >1 ) - req->Capabilities |=cpu_to_le32 (SMB2_GLOBAL_CAP_MULTI_CHANNEL ); + req->Capabilities |=cpu_to_le32 (SMB2_GLOBAL_CAP_MULTI_CHANNEL );/* ClientGUID must be zero for SMB2.02 dialect */ if (server->vals->protocol_id ==SMB20_PROT_ID )@@ -1312,8 +1340,7 @@ int smb3_validate_negotiate(const unsigned int xid, struct cifs_tcon *tcon) pneg_inbuf->Capabilities =cpu_to_le32 (server->vals->req_capabilities); -if (tcon->ses->chan_max >1 ) - pneg_inbuf->Capabilities |=cpu_to_le32 (SMB2_GLOBAL_CAP_MULTI_CHANNEL ); + pneg_inbuf->Capabilities |=cpu_to_le32 (SMB2_GLOBAL_CAP_MULTI_CHANNEL );memcpy (pneg_inbuf->Guid, server->client_guid,SMB2_CLIENT_GUID_SIZE ); --Quoted 3 lines
2.43.0
Thanks
Meetakshi
Signature · 2 lines
Regards, Shyam
RAJASI MANDAL
Reviewed-by Shyam Prasad NSending a follow-up patch with corrected comment as pointed out by Meetakshi. Attaching the new patch here for easy reference.
Regards,
Rajasi
Quoted 414 lines · Shyam Prasad N
Quoted 4 lines · Meetakshi Setiya
Hi Rajasi,
On Tue, Nov 18, 2025 at 7:59 AM Rajasi Mandal <[email protected]>
Quoted 40 lines · wrote:
Quoted 40 lines
From: Rajasi Mandal <[email protected]>
Previously, the client did not update a session's channel state when multichannel or
max_channelsmount options were changed via remount. This led to inconsistent behavior and prevented enabling or disabling multichannel support without a full unmount/remount cycle.Enable dynamic reconfiguration of multichannel and
max_channelsduring remount by:
- Introducingsmb3_sync_ses_chan_max(), a centralized function for channel updates which synchronizes the session's channels with the updated configuration.
- Replacingcifs_disable_secondary_channels()withcifs_decrease_secondary_channels(), which accepts afrom_reconfigureflag to support targeted cleanup during reconfiguration.
- Updating remount logic to detect changes in multichannel ormax_channelsand trigger appropriate session/channel updates.Current limitation:
- Thequery_interfacesworker runs even when max_channels=1 so that multichannel can be enabled later via remount without requiring an unmount. This is a temporary approach and may be refined in the future.Users can safely modify multichannel and
max_channelson an existing mount. The client will correctly adjust the session's channel state to match the new configuration, preserving durability where possible and avoiding unnecessary disconnects.Reviewed-by Shyam Prasad N <[email protected]>Signed-off-by Rajasi Mandal <[email protected]>--- fs/smb/client/cifsproto.h | 4 ++- fs/smb/client/connect.c | 4 ++- fs/smb/client/fs_context.c | 50 +++++++++++++++++++++++++++++++++- fs/smb/client/sess.c | 32 +++++++++++++++------- fs/smb/client/smb2pdu.c | 55 ++++++++++++++++++++++++++++---------- 5 files changed, 119 insertions(+), 26 deletions(-)Quoted 5 lines
fs/smb/client/cifsproto.h int cifs_alloc_hash(const char *name, struct
Quoted 5 lines
fs/smb/client/cifsproto.h +0
-0@@ -649,6 +649,8 @@ int cifs_alloc_hash(const char *name, struct
shash_desc**sdesc);Quoted 4 lines
fs/smb/client/cifsproto.h int cifs_alloc_hash(const char *name, struct · line 652
Quoted 4 lines
fs/smb/client/cifsproto.h +1
-0void cifs_free_hash (struct shash_desc **sdesc);int cifs_try_adding_channels (struct cifs_ses *ses); +int smb3_update_ses_channels(struct cifs_ses *ses, struct
TCP_Server_Info*server,Quoted 1 line
fs/smb/client/cifsproto.h int cifs_alloc_hash(const char *name, struct · line 653
Quoted 1 line
fs/smb/client/cifsproto.h +1
-0+bool from_reconnect, bool
from_reconfigure);Quoted 1 line
fs/smb/client/cifsproto.h int cifs_alloc_hash(const char *name, struct · line 654
Quoted 1 line
fs/smb/client/cifsproto.h +0
-0bool is_ses_using_iface(struct cifs_ses *ses, struct
cifs_server_iface*iface);Quoted 8 lines
fs/smb/client/cifsproto.h bool · line 679
Quoted 8 lines
fs/smb/client/cifsproto.h +1
-1void cifs_ses_mark_for_reconnect (struct cifs_ses *ses);@@ -674,7 +676,7 @@ bool cifs_chan_is_iface_active(struct cifs_ses *ses, struct TCP_Server_Info *server);void -cifs_disable_secondary_channels (struct cifs_ses *ses); +cifs_decrease_secondary_channels(struct cifs_ses *ses, bool
from_reconfigure);Quoted 2 lines
fs/smb/client/cifsproto.h bool · line 681
Quoted 2 lines
fs/smb/client/cifsproto.h +0
-0void cifs_chan_update_iface(struct cifs_ses *ses, struct TCP_Server_Info*server);
Quoted 6 lines
fs/smb/client/connect.c int cifs_mount(struct cifs_sb_info *cifs_sb,
Quoted 6 lines
fs/smb/client/cifsproto.h +0
-0int fs/smb/client/connect.c +0
-0@@ -3927,7 +3927,9 @@ int cifs_mount(struct cifs_sb_info *cifs_sb,struct
smb3_fs_context*ctx)Quoted 11 lines
fs/smb/client/connect.c int cifs_mount(struct cifs_sb_info *cifs_sb, · line 3932
Quoted 7 lines
fs/smb/client/connect.c +3
-1ctx->prepath =NULL ; out: -cifs_try_adding_channels (mnt_ctx.ses); +smb3_update_ses_channels (mnt_ctx.ses, mnt_ctx.server, + false/* from_reconnect */ , + false/* from_reconfigure */ );Shouldn't this be added to the non-dfs
cifs_mount()too? I see that evencifs_try_adding_channels()is not present in this function, @Shyam Prasad is this expected?That's a good catch.
I think this is a day-0 bug.
I can see that the original change by Aurelien has the change only in DFScifs_mount:
commitd70e9fa55884760b6d6c293dbf20d8c52ce11fb7Author: Aurelien Aptel <[email protected]> Date: Fri Sep 20 06:31:10 2019 +0200cifs: try opening channels after mounting
We should have a follow-up patch to fix this.
Quoted 9 lines
fs/smb/client/fs_context.c static int smb3_fs_context_parse_param(struct
Quoted 9 lines
fs/smb/client/connect.c +0
-0rc =mount_setup_tlink (cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);if (rc) goto error;fs/smb/client/fs_context.c +0
-0@@ -717,6 +717,7 @@ static int smb3_fs_context_parse_param(struct
fs_context*fc,Quoted 4 lines
fs/smb/client/fs_context.c static int smb3_fs_context_parse_param(struct · line 720
Quoted 4 lines
fs/smb/client/fs_context.c +1
-0static int smb3_fs_context_parse_monolithic (struct fs_context *fc,void *data);static int smb3_get_tree (struct fs_context *fc); +static void smb3_sync_ses_chan_max(struct cifs_ses *ses, unsigned int
max_channels);Quoted 4 lines
fs/smb/client/fs_context.c int smb3_sync_session_ctx_passwords(struct
Quoted 4 lines
fs/smb/client/fs_context.c +0
-0static int smb3_reconfigure (struct fs_context *fc);static const struct fs_context_operations smb3_fs_context_ops = {@@ -1013,6 +1014,22 @@ int smb3_sync_session_ctx_passwords(struct
cifs_sb_info*cifs_sb, structcifs_seQuoted 5 lines
fs/smb/client/fs_context.c int smb3_sync_session_ctx_passwords(struct · line 1018
Quoted 5 lines
fs/smb/client/fs_context.c +2
-0return 0 ; } +/* +* smb3_sync_ses_chan_max - Synchronize the session's maximum channel count
Quoted 4 lines
fs/smb/client/fs_context.c int smb3_sync_session_ctx_passwords(struct · line 1022
Quoted 4 lines
fs/smb/client/fs_context.c +4
-0+* @ses: pointer to the old CIFS session structure +* @max_channels: new maximum number of channels to allow +* +* Updates the session's chan_max field to the new value, protecting the update
Quoted 1 line
fs/smb/client/fs_context.c int smb3_sync_session_ctx_passwords(struct · line 1023
Quoted 1 line
fs/smb/client/fs_context.c +1
-0+* with the session's channel lock. This should be called whenever the maximum
Quoted 1 line
fs/smb/client/fs_context.c int smb3_sync_session_ctx_passwords(struct · line 1024
Quoted 1 line
fs/smb/client/fs_context.c +1
-0+* allowed channels for a session changes (e.g., after a remount or reconfigure).
Quoted 2 lines
fs/smb/client/fs_context.c int smb3_sync_session_ctx_passwords(struct · line 1026
Quoted 2 lines
fs/smb/client/fs_context.c +2
-0+*/ +static void smb3_sync_ses_chan_max(struct cifs_ses *ses, unsigned int
max_channels)Quoted 10 lines
fs/smb/client/fs_context.c static int smb3_reconfigure(struct fs_context
Quoted 10 lines
fs/smb/client/fs_context.c +6
-0+{ +spin_lock (&ses->chan_lock); + ses->chan_max = max_channels; +spin_unlock (&ses->chan_lock); +} +static int smb3_reconfigure (struct fs_context *fc) {struct smb3_fs_context *ctx =smb3_fc2context (fc);@@ -1095,7 +1112,38 @@ static int smb3_reconfigure(struct fs_context*fc)
Quoted 6 lines
fs/smb/client/fs_context.c static int smb3_reconfigure(struct fs_context · line 1116
Quoted 6 lines
fs/smb/client/fs_context.c +2
-1ses->password2 = new_password2; } -mutex_unlock (&ses->session_mutex); +/* +* If multichannel or max_channels has changed, update the session's channels accordingly.
Quoted 1 line
fs/smb/client/fs_context.c static int smb3_reconfigure(struct fs_context · line 1117
Quoted 1 line
fs/smb/client/fs_context.c +1
-0+* This may add or remove channels to match the new configuration.
Quoted 5 lines
fs/smb/client/fs_context.c static int smb3_reconfigure(struct fs_context · line 1122
Quoted 5 lines
fs/smb/client/fs_context.c +5
-0+*/ +if ((ctx->multichannel != cifs_sb->ctx->multichannel) || + (ctx->max_channels != cifs_sb->ctx->max_channels)) { + +/* Synchronize ses->chan_max with the new mount context */
Quoted 2 lines
fs/smb/client/fs_context.c static int smb3_reconfigure(struct fs_context · line 1124
Quoted 2 lines
fs/smb/client/fs_context.c +2
-0+smb3_sync_ses_chan_max (ses, ctx->max_channels); +/* Now update the session's channels to match the new configuration */
Quoted 5 lines
Quoted 5 lines
fs/smb/client/fs_context.c +5
-0+/* Prevent concurrent scaling operations */ +spin_lock (&ses->ses_lock); +if (ses->flags &CIFS_SES_FLAG_SCALE_CHANNELS ) { +spin_unlock (&ses->ses_lock); +return -EINVAL ;Quoted 8 lines
fs/smb/client/fs_context.c static int smb3_reconfigure(struct fs_context · line 1137
Quoted 8 lines
fs/smb/client/fs_context.c +8
-0+ } + ses->flags |=CIFS_SES_FLAG_SCALE_CHANNELS ; +spin_unlock (&ses->ses_lock); + +mutex_unlock (&ses->session_mutex); + + rc =smb3_update_ses_channels (ses, ses->server, + false/* from_reconnect */,
Quoted 1 line
fs/smb/client/fs_context.c static int smb3_reconfigure(struct fs_context · line 1138
Quoted 1 line
fs/smb/client/fs_context.c +1
-0+ true/*
from_reconfigure*/);Quoted 9 lines
Quoted 9 lines
fs/smb/client/fs_context.c +8
-0+ +/* Clear scaling flag after operation */ +spin_lock (&ses->ses_lock); + ses->flags &= ~CIFS_SES_FLAG_SCALE_CHANNELS ; +spin_unlock (&ses->ses_lock); + }else { +mutex_unlock (&ses->session_mutex); + }Quoted 7 lines
fs/smb/client/sess.c int cifs_try_adding_channels(struct cifs_ses
Quoted 7 lines
fs/smb/client/fs_context.c +0
-0STEAL_STRING (cifs_sb, ctx, domainname);STEAL_STRING (cifs_sb, ctx, nodename);fs/smb/client/sess.c +0
-0@@ -265,12 +265,16 @@ int cifs_try_adding_channels(struct cifs_ses*ses)
Quoted 7 lines
fs/smb/client/sess.c int cifs_try_adding_channels(struct cifs_ses · line 268
Quoted 7 lines
fs/smb/client/sess.c +1
-3}/* -* called when multichannel is disabled by the server. -* this always gets called from smb2_reconnect -* and cannot get called in parallel threads. +* cifs_decrease_secondary_channels - Reduce the number of active secondary channels
Quoted 2 lines
fs/smb/client/sess.c int cifs_try_adding_channels(struct cifs_ses · line 270
Quoted 2 lines
fs/smb/client/sess.c +2
-0+* @ses: pointer to the CIFS session structure +* @from_reconfigure: if true, only reduce to chan_max; if false, reduce to a single channel
Quoted 2 lines
fs/smb/client/sess.c int cifs_try_adding_channels(struct cifs_ses · line 272
Quoted 2 lines
fs/smb/client/sess.c +2
-0+* +* This function disables and cleans up extra secondary channels for a CIFS session.
Quoted 1 line
fs/smb/client/sess.c int cifs_try_adding_channels(struct cifs_ses · line 273
Quoted 1 line
fs/smb/client/sess.c +1
-0+* If called during reconfiguration, it reduces the channel count to the new maximum (
chan_max).Quoted 5 lines
fs/smb/client/sess.c int cifs_try_adding_channels(struct cifs_ses · line 277
Quoted 5 lines
fs/smb/client/sess.c +2
-1+* Otherwise, it disables all but the primary channel. */ void -cifs_disable_secondary_channels (struct cifs_ses *ses) +cifs_decrease_secondary_channels(struct cifs_ses *ses, bool
from_reconfigure)Quoted 4 lines
fs/smb/client/sess.c cifs_disable_secondary_channels(struct cifs_ses
Quoted 4 lines
fs/smb/client/sess.c +0
-0{int i, chan_count;struct TCP_Server_Info *server;@@ -281,12 +285,13 @@ cifs_disable_secondary_channels(struct cifs_ses*ses)
Quoted 13 lines
Quoted 13 lines
fs/smb/client/sess.c +5
-4if (chan_count ==1 ) goto done; - ses->chan_count =1 ; - -/* for all secondary channels reset the need reconnect bit */ - ses->chans_need_reconnect &=1 ; +/* Update the chan_count to the new maximum */ +if (from_reconfigure) + ses->chan_count = ses->chan_max; +else + ses->chan_count =1 ;Quoted 6 lines
fs/smb/client/sess.c cifs_disable_secondary_channels(struct cifs_ses
Quoted 6 lines
fs/smb/client/sess.c +1
-1-for (i =1 ; i < chan_count; i++) { +for (i = ses->chan_max ; i < chan_count; i++) { iface = ses->chans[i].iface; server = ses->chans[i].server;@@ -318,6 +323,15 @@ cifs_disable_secondary_channels(struct cifs_ses*ses)
Quoted 4 lines
fs/smb/client/sess.c cifs_disable_secondary_channels(struct cifs_ses · line 326
Quoted 4 lines
fs/smb/client/sess.c +1
-0spin_lock (&ses->chan_lock); } +/* For extra secondary channels, reset the need reconnect bit */
Quoted 2 lines
fs/smb/client/sess.c cifs_disable_secondary_channels(struct cifs_ses · line 328
Quoted 2 lines
fs/smb/client/sess.c +2
-0+if (ses->chan_count ==1 ) { + cifs_dbg(VFS, "server does not support multichannelanymore. Disable all other channels\n");
Quoted 4 lines
fs/smb/client/sess.c cifs_disable_secondary_channels(struct cifs_ses · line 332
Quoted 4 lines
fs/smb/client/sess.c +4
-0+ ses->chans_need_reconnect &=1 ; + }else { +cifs_dbg (VFS ,"Disable extra secondary channels\n" ); + ses->chans_need_reconnect &= ((1UL << ses->chan_max) -1);
Quoted 10 lines
fs/smb/client/smb2pdu.c smb2_hdr_assemble(struct smb2_hdr *shdr, __le16
Quoted 10 lines
fs/smb/client/sess.c +2
-0+ } + done:spin_unlock (&ses->chan_lock); }fs/smb/client/smb2pdu.c +0
-0@@ -168,7 +168,7 @@ smb2_hdr_assemble(struct smb2_hdr *shdr, __le16
smb2_cmd,Quoted 12 lines
Quoted 12 lines
fs/smb/client/smb2pdu.c +1
-1static int cifs_chan_skip_or_disable (struct cifs_ses *ses,struct TCP_Server_Info *server, -bool from_reconnect) +bool from_reconnect,bool from_reconfigure) {struct TCP_Server_Info *pserver;unsigned int chan_index;@@ -206,14 +206,41 @@ cifs_chan_skip_or_disable(struct cifs_ses *ses,return -EHOSTDOWN ; }Quoted 2 lines
fs/smb/client/smb2pdu.c cifs_chan_skip_or_disable(struct cifs_ses *ses, · line 210
Quoted 2 lines
fs/smb/client/smb2pdu.c +0
-2- cifs_server_dbg(VFS, - "server does not support multichannel anymore. Disableall other channels\n");
Quoted 9 lines
fs/smb/client/smb2pdu.c cifs_chan_skip_or_disable(struct cifs_ses *ses, · line 215
Quoted 9 lines
fs/smb/client/smb2pdu.c +3
-2-cifs_disable_secondary_channels (ses); - +cifs_decrease_secondary_channels (ses, from_reconfigure);return 0 ; } +/* +* smb3_update_ses_channels - Synchronize session channels with new configuration
Quoted 8 lines
fs/smb/client/smb2pdu.c cifs_chan_skip_or_disable(struct cifs_ses *ses, · line 223
Quoted 8 lines
fs/smb/client/smb2pdu.c +8
-0+* @ses: pointer to the CIFS session structure +* @server: pointer to the TCP server info structure +* @from_reconnect: indicates if called from reconnect context +* @from_reconfigure: indicates if called from reconfigure context +* +* Returns 0 on success or error code on failure. +* +* Note: Outside of reconfigure, this function is only called from reconnect scenarios
Quoted 7 lines
fs/smb/client/smb2pdu.c cifs_chan_skip_or_disable(struct cifs_ses *ses, · line 225
Quoted 2 lines
fs/smb/client/smb2pdu.c +2
-0+* when the server stops advertising multichannel (MC) capability. +*/ I see that function is being called during mount too. Did you mean
cifs_decrease_secondary_channels()?Quoted 1 line
fs/smb/client/smb2pdu.c +1
-0+int smb3_update_ses_channels(struct cifs_ses *ses, struct
TCP_Server_Info*server,Quoted 7 lines
fs/smb/client/smb2pdu.c cifs_chan_skip_or_disable(struct cifs_ses *ses, · line 233
Quoted 7 lines
fs/smb/client/smb2pdu.c +7
-0+ bool from_reconnect, bool from_reconfigure) +{ +int rc =0 ; +/* +* If the current channel count is less than the new chan_max, +* try to add channels to reach the new maximum. +* Otherwise, disable or skip extra channels to match the new configuration.
Quoted 5 lines
fs/smb/client/smb2pdu.c cifs_chan_skip_or_disable(struct cifs_ses *ses, · line 238
Quoted 5 lines
fs/smb/client/smb2pdu.c +5
-0+*/ +if (ses->chan_count < ses->chan_max) + rc =cifs_try_adding_channels (ses); +else + rc = cifs_chan_skip_or_disable(ses, server,
from_reconnect,Quoted 9 lines
fs/smb/client/smb2pdu.c smb2_reconnect(__le16 smb2_command, struct
Quoted 9 lines
fs/smb/client/smb2pdu.c +5
-0+ from_reconfigure); + +return rc; +} +static int smb2_reconnect (__le16 smb2_command,struct cifs_tcon *tcon,struct TCP_Server_Info *server,bool from_reconnect)@@ -355,8 +382,8 @@ smb2_reconnect(__le16 smb2_command, struct
cifs_tcon*tcon,Quoted 7 lines
fs/smb/client/smb2pdu.c smb2_reconnect(__le16 smb2_command, struct · line 386
Quoted 7 lines
fs/smb/client/smb2pdu.c +2
-2*/ if (ses->chan_count >1 && !(server->capabilities &SMB2_GLOBAL_CAP_MULTI_CHANNEL )) { - rc =cifs_chan_skip_or_disable (ses, server, - from_reconnect); + rc =smb3_update_ses_channels (ses, server, + from_reconnect, false/*
from_reconfigure*/);Quoted 4 lines
fs/smb/client/smb2pdu.c smb2_reconnect(__le16 smb2_command, struct
Quoted 4 lines
fs/smb/client/smb2pdu.c +0
-0if (rc) {mutex_unlock (&ses->session_mutex); goto out;@@ -438,8 +465,9 @@ smb2_reconnect(__le16 smb2_command, struct
cifs_tcon*tcon,Quoted 1 line
fs/smb/client/smb2pdu.c smb2_reconnect(__le16 smb2_command, struct · line 465
Quoted 1 line
fs/smb/client/smb2pdu.c +0
-0* treat this as server not supporting multichannel
Quoted 7 lines
fs/smb/client/smb2pdu.c smb2_reconnect(__le16 smb2_command, struct · line 470
Quoted 7 lines
fs/smb/client/smb2pdu.c +3
-2*/ - rc =cifs_chan_skip_or_disable (ses, server, - from_reconnect); + rc =smb3_update_ses_channels (ses, server, + from_reconnect, + false/*
from_reconfigure*/);Quoted 3 lines
fs/smb/client/smb2pdu.c smb2_reconnect(__le16 smb2_command, struct · line 473
Quoted 3 lines
fs/smb/client/smb2pdu.c +0
-0goto skip_add_channels; }else if (rc) cifs_tcon_dbg(FYI, "%s: failed to query serverinterfaces: %d\n",
Quoted 1 line
fs/smb/client/smb2pdu.c smb2_reconnect(__le16 smb2_command, struct
Quoted 1 line
fs/smb/client/smb2pdu.c +0
-0@@ -451,7 +479,8 @@ smb2_reconnect(__le16 smb2_command, struct
cifs_tcon*tcon,Quoted 2 lines
fs/smb/client/smb2pdu.c smb2_reconnect(__le16 smb2_command, struct · line 480
Quoted 2 lines
fs/smb/client/smb2pdu.c +0
-0if (ses->chan_count ==1 ) cifs_server_dbg(VFS, "supportsmultichannel now\n");
Quoted 3 lines
fs/smb/client/smb2pdu.c smb2_reconnect(__le16 smb2_command, struct · line 481
Quoted 3 lines
fs/smb/client/smb2pdu.c +1
-1-cifs_try_adding_channels (ses); + smb3_update_ses_channels(ses, server,
from_reconnect,Quoted 1 line
fs/smb/client/smb2pdu.c smb2_reconnect(__le16 smb2_command, struct · line 482
Quoted 1 line
fs/smb/client/smb2pdu.c +1
-0+ false/*
from_reconfigure*/);Quoted 7 lines
fs/smb/client/smb2pdu.c SMB2_negotiate(const unsigned int xid, · line 1136
Quoted 7 lines
fs/smb/client/smb2pdu.c +0
-0} }else {mutex_unlock (&ses->session_mutex);@@ -1105,8 +1134,7 @@ SMB2_negotiate(const unsigned int xid, req->SecurityMode =0 ; req->Capabilities =
cpu_to_le32(server->vals->req_capabilities);Quoted 2 lines
fs/smb/client/smb2pdu.c SMB2_negotiate(const unsigned int xid, · line 1109
Quoted 2 lines
fs/smb/client/smb2pdu.c +0
-2-if (ses->chan_max >1 ) - req->Capabilities |=
cpu_to_le32(SMB2_GLOBAL_CAP_MULTI_CHANNEL);Quoted 1 line
fs/smb/client/smb2pdu.c SMB2_negotiate(const unsigned int xid, · line 1137
Quoted 1 line
fs/smb/client/smb2pdu.c +1
-0+ req->Capabilities |=
cpu_to_le32(SMB2_GLOBAL_CAP_MULTI_CHANNEL);Quoted 4 lines
fs/smb/client/smb2pdu.c int smb3_validate_negotiate(const unsigned int
Quoted 4 lines
fs/smb/client/smb2pdu.c +0
-0/* ClientGUID must be zero for SMB2.02 dialect */ if (server->vals->protocol_id ==SMB20_PROT_ID )@@ -1312,8 +1340,7 @@ int smb3_validate_negotiate(const unsigned intxid, struct
cifs_tcon*tcon)Quoted 5 lines
fs/smb/client/smb2pdu.c int smb3_validate_negotiate(const unsigned int · line 1315
Quoted 5 lines
fs/smb/client/smb2pdu.c +0
-2pneg_inbuf->Capabilities =cpu_to_le32 (server->vals->req_capabilities); -if (tcon->ses->chan_max >1 ) - pneg_inbuf->Capabilities |=
cpu_to_le32(SMB2_GLOBAL_CAP_MULTI_CHANNEL);Quoted 1 line
fs/smb/client/smb2pdu.c int smb3_validate_negotiate(const unsigned int · line 1342
Quoted 1 line
fs/smb/client/smb2pdu.c +1
-0+ pneg_inbuf->Capabilities |=
cpu_to_le32(SMB2_GLOBAL_CAP_MULTI_CHANNEL);Quoted 8 lines
Quoted 7 lines
fs/smb/client/smb2pdu.c +0
-1memcpy (pneg_inbuf->Guid, server->client_guid,SMB2_CLIENT_GUID_SIZE ); --2.43.0
Quoted 9 lines
Quoted 3 lines
Thanks
Meetakshi--
Regards,
Shyam
From: Rajasi Mandal <[email protected]>
Previously, the client did not update a session's channel state when multichannel or max_channels mount options were changed via remount. This led to inconsistent behavior and prevented enabling or disabling multichannel support without a full unmount/remount cycle.
Enable dynamic reconfiguration of multichannel and max_channels during remount by:
- Introducing smb3_sync_ses_chan_max(), a centralized function for channel updates which synchronizes the session's channels with the updated configuration.
- Replacing cifs_disable_secondary_channels() with cifs_decrease_secondary_channels(), which accepts a from_reconfigure flag to support targeted cleanup during reconfiguration.
- Updating remount logic to detect changes in multichannel or max_channels and trigger appropriate session/channel updates.
Current limitation:
- The query_interfaces worker runs even when max_channels=1 so that multichannel can be enabled later via remount without requiring an unmount. This is a temporary approach and may be refined in the future.
Users can safely modify multichannel and max_channels on an existing mount. The client will correctly adjust the session's channel state to match the new configuration, preserving durability where possible and avoiding unnecessary disconnects.
--- fs/smb/client/cifsproto.h | 4 ++- fs/smb/client/connect.c | 4 ++- fs/smb/client/fs_context.c | 50 +++++++++++++++++++++++++++++++++- fs/smb/client/sess.c | 32 ++++++++++++++++------ fs/smb/client/smb2pdu.c | 56 ++++++++++++++++++++++++++++---------- 5 files changed, 120 insertions(+), 26 deletions(-)
fs/smb/client/cifsproto.h +3 -1
@@ -649,6 +649,8 @@ int cifs_alloc_hash(const char *name, struct shash_desc **sdesc);void cifs_free_hash (struct shash_desc **sdesc);int cifs_try_adding_channels (struct cifs_ses *ses); +int smb3_update_ses_channels (struct cifs_ses *ses,struct TCP_Server_Info *server, +bool from_reconnect,bool from_reconfigure);bool is_ses_using_iface (struct cifs_ses *ses,struct cifs_server_iface *iface);void cifs_ses_mark_for_reconnect (struct cifs_ses *ses);
@@ -674,7 +676,7 @@ bool cifs_chan_is_iface_active(struct cifs_ses *ses, struct TCP_Server_Info *server);void -cifs_disable_secondary_channels (struct cifs_ses *ses); +cifs_decrease_secondary_channels (struct cifs_ses *ses,bool from_reconfigure);void cifs_chan_update_iface (struct cifs_ses *ses,struct TCP_Server_Info *server);int
fs/smb/client/connect.c +3 -1
@@ -3927,7 +3927,9 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx) ctx->prepath =NULL ; out: -cifs_try_adding_channels (mnt_ctx.ses); +smb3_update_ses_channels (mnt_ctx.ses, mnt_ctx.server, + false/* from_reconnect */ , + false/* from_reconfigure */ ); rc =mount_setup_tlink (cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);if (rc) goto error;
fs/smb/client/fs_context.c +49 -1
68 lines not on this page · raw message
fs/smb/client/sess.c +23 -9
@@ -265,12 +265,16 @@ int cifs_try_adding_channels(struct cifs_ses *ses) }/* -* called when multichannel is disabled by the server. -* this always gets called from smb2_reconnect -* and cannot get called in parallel threads. +* cifs_decrease_secondary_channels - Reduce the number of active secondary channels +* @ses: pointer to the CIFS session structure +* @from_reconfigure: if true, only reduce to chan_max; if false, reduce to a single channel +* +* This function disables and cleans up extra secondary channels for a CIFS session. +* If called during reconfiguration, it reduces the channel count to the new maximum (chan_max). +* Otherwise, it disables all but the primary channel. */ void -cifs_disable_secondary_channels (struct cifs_ses *ses) +cifs_decrease_secondary_channels (struct cifs_ses *ses,bool from_reconfigure) {int i, chan_count;struct TCP_Server_Info *server;
@@ -281,12 +285,13 @@ cifs_disable_secondary_channels(struct cifs_ses *ses)if (chan_count ==1 ) goto done; - ses->chan_count =1 ; - -/* for all secondary channels reset the need reconnect bit */ - ses->chans_need_reconnect &=1 ; +/* Update the chan_count to the new maximum */ +if (from_reconfigure) + ses->chan_count = ses->chan_max; +else + ses->chan_count =1 ; -for (i =1 ; i < chan_count; i++) { +for (i = ses->chan_max ; i < chan_count; i++) { iface = ses->chans[i].iface; server = ses->chans[i].server;
@@ -318,6 +323,15 @@ cifs_disable_secondary_channels(struct cifs_ses *ses)spin_lock (&ses->chan_lock); } +/* For extra secondary channels, reset the need reconnect bit */ +if (ses->chan_count ==1 ) { +cifs_dbg (VFS ,"server does not support multichannel anymore. Disable all other channels\n" ); + ses->chans_need_reconnect &=1 ; + }else { +cifs_dbg (VFS ,"Disable extra secondary channels\n" ); + ses->chans_need_reconnect &= ((1UL << ses->chan_max) -1 ); + } + done:spin_unlock (&ses->chan_lock); }
fs/smb/client/smb2pdu.c +42 -14
102 lines not on this page · raw message
Signature · 1 line
2.43.0
merged the two patches into ksmbd-for-next (will move to cifs-2.6.git for-next once the next P/R is complete, but want to avoid merge conflicts for now) pending additional testing and review
Quoted 373 lines · RAJASI MANDAL
Sending a follow-up patch with corrected comment as pointed out by Meetakshi. Attaching the new patch here for easy reference.
Regards,
RajasiQuoted 366 lines · Shyam Prasad N
Quoted 73 lines · Meetakshi Setiya
Hi Rajasi,
Quoted 69 lines · Rajasi Mandal
From: Rajasi Mandal <[email protected]>
Previously, the client did not update a session's channel state when multichannel or
max_channelsmount options were changed via remount. This led to inconsistent behavior and prevented enabling or disabling multichannel support without a full unmount/remount cycle.Enable dynamic reconfiguration of multichannel and
max_channelsduring remount by:
- Introducingsmb3_sync_ses_chan_max(), a centralized function for channel updates which synchronizes the session's channels with the updated configuration.
- Replacingcifs_disable_secondary_channels()withcifs_decrease_secondary_channels(), which accepts afrom_reconfigureflag to support targeted cleanup during reconfiguration.
- Updating remount logic to detect changes in multichannel ormax_channelsand trigger appropriate session/channel updates.Current limitation:
- Thequery_interfacesworker runs even when max_channels=1 so that multichannel can be enabled later via remount without requiring an unmount. This is a temporary approach and may be refined in the future.Users can safely modify multichannel and
max_channelson an existing mount. The client will correctly adjust the session's channel state to match the new configuration, preserving durability where possible and avoiding unnecessary disconnects.Reviewed-by Shyam Prasad N <[email protected]>Signed-off-by Rajasi Mandal <[email protected]>--- fs/smb/client/cifsproto.h | 4 ++- fs/smb/client/connect.c | 4 ++- fs/smb/client/fs_context.c | 50 +++++++++++++++++++++++++++++++++- fs/smb/client/sess.c | 32 +++++++++++++++------- fs/smb/client/smb2pdu.c | 55 ++++++++++++++++++++++++++++---------- 5 files changed, 119 insertions(+), 26 deletions(-)fs/smb/client/cifsproto.h +3
-1@@ -649,6 +649,8 @@ int cifs_alloc_hash(const char *name, struct shash_desc **sdesc);void cifs_free_hash (struct shash_desc **sdesc);int cifs_try_adding_channels (struct cifs_ses *ses); +int smb3_update_ses_channels (struct cifs_ses *ses,struct TCP_Server_Info *server, +bool from_reconnect,bool from_reconfigure);bool is_ses_using_iface (struct cifs_ses *ses,struct cifs_server_iface *iface);void cifs_ses_mark_for_reconnect (struct cifs_ses *ses);@@ -674,7 +676,7 @@ bool cifs_chan_is_iface_active(struct cifs_ses *ses, struct TCP_Server_Info *server);void -cifs_disable_secondary_channels (struct cifs_ses *ses); +cifs_decrease_secondary_channels (struct cifs_ses *ses,bool from_reconfigure);void cifs_chan_update_iface (struct cifs_ses *ses,struct TCP_Server_Info *server);int fs/smb/client/connect.c +0
-0@@ -3927,7 +3927,9 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx) ctx->prepath =NULL ;Quoted 9 lines
fs/smb/client/connect.c int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx) · line 3932
Quoted 5 lines
fs/smb/client/connect.c +3
-1out: -cifs_try_adding_channels (mnt_ctx.ses); +smb3_update_ses_channels (mnt_ctx.ses, mnt_ctx.server, + false/* from_reconnect */ , + false/* from_reconfigure */ );Shouldn't this be added to the non-dfs
cifs_mount()too? I see that evencifs_try_adding_channels()is not present in this function, @Shyam Prasad is this expected?That's a good catch.
I think this is a day-0 bug.
I can see that the original change by Aurelien has the change only in DFScifs_mount:
commitd70e9fa55884760b6d6c293dbf20d8c52ce11fb7Author: Aurelien Aptel <[email protected]> Date: Fri Sep 20 06:31:10 2019 +0200cifs: try opening channels after mounting
We should have a follow-up patch to fix this.
Quoted 253 lines
Quoted 167 lines
fs/smb/client/connect.c +0
-0rc =mount_setup_tlink (cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);if (rc) goto error;fs/smb/client/fs_context.c +49
-1@@ -717,6 +717,7 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,static int smb3_fs_context_parse_monolithic (struct fs_context *fc,void *data);static int smb3_get_tree (struct fs_context *fc); +static void smb3_sync_ses_chan_max (struct cifs_ses *ses,unsigned int max_channels);static int smb3_reconfigure (struct fs_context *fc);static const struct fs_context_operations smb3_fs_context_ops = {@@ -1013,6 +1014,22 @@ int smb3_sync_session_ctx_passwords(struct cifs_sb_info *cifs_sb, struct cifs_sereturn 0 ; } +/* +* smb3_sync_ses_chan_max - Synchronize the session's maximum channel count +* @ses: pointer to the old CIFS session structure +* @max_channels: new maximum number of channels to allow +* +* Updates the session's chan_max field to the new value, protecting the update +* with the session's channel lock. This should be called whenever the maximum +* allowed channels for a session changes (e.g., after a remount or reconfigure). +*/ +static void smb3_sync_ses_chan_max (struct cifs_ses *ses,unsigned int max_channels) +{ +spin_lock (&ses->chan_lock); + ses->chan_max = max_channels; +spin_unlock (&ses->chan_lock); +} +static int smb3_reconfigure (struct fs_context *fc) {struct smb3_fs_context *ctx =smb3_fc2context (fc);@@ -1095,7 +1112,38 @@ static int smb3_reconfigure(struct fs_context *fc) ses->password2 = new_password2; } -mutex_unlock (&ses->session_mutex); +/* +* If multichannel or max_channels has changed, update the session's channels accordingly. +* This may add or remove channels to match the new configuration. +*/ +if ((ctx->multichannel != cifs_sb->ctx->multichannel) || + (ctx->max_channels != cifs_sb->ctx->max_channels)) { + +/* Synchronize ses->chan_max with the new mount context */ +smb3_sync_ses_chan_max (ses, ctx->max_channels); +/* Now update the session's channels to match the new configuration */ +/* Prevent concurrent scaling operations */ +spin_lock (&ses->ses_lock); +if (ses->flags &CIFS_SES_FLAG_SCALE_CHANNELS ) { +spin_unlock (&ses->ses_lock); +return -EINVAL ; + } + ses->flags |=CIFS_SES_FLAG_SCALE_CHANNELS ; +spin_unlock (&ses->ses_lock); + +mutex_unlock (&ses->session_mutex); + + rc =smb3_update_ses_channels (ses, ses->server, + false/* from_reconnect */ , + true/* from_reconfigure */ ); + +/* Clear scaling flag after operation */ +spin_lock (&ses->ses_lock); + ses->flags &= ~CIFS_SES_FLAG_SCALE_CHANNELS ; +spin_unlock (&ses->ses_lock); + }else { +mutex_unlock (&ses->session_mutex); + }STEAL_STRING (cifs_sb, ctx, domainname);STEAL_STRING (cifs_sb, ctx, nodename);fs/smb/client/sess.c +23
-9@@ -265,12 +265,16 @@ int cifs_try_adding_channels(struct cifs_ses *ses) }/* -* called when multichannel is disabled by the server. -* this always gets called from smb2_reconnect -* and cannot get called in parallel threads. +* cifs_decrease_secondary_channels - Reduce the number of active secondary channels +* @ses: pointer to the CIFS session structure +* @from_reconfigure: if true, only reduce to chan_max; if false, reduce to a single channel +* +* This function disables and cleans up extra secondary channels for a CIFS session. +* If called during reconfiguration, it reduces the channel count to the new maximum (chan_max). +* Otherwise, it disables all but the primary channel. */ void -cifs_disable_secondary_channels (struct cifs_ses *ses) +cifs_decrease_secondary_channels (struct cifs_ses *ses,bool from_reconfigure) {int i, chan_count;struct TCP_Server_Info *server;@@ -281,12 +285,13 @@ cifs_disable_secondary_channels(struct cifs_ses *ses)if (chan_count ==1 ) goto done; - ses->chan_count =1 ; - -/* for all secondary channels reset the need reconnect bit */ - ses->chans_need_reconnect &=1 ; +/* Update the chan_count to the new maximum */ +if (from_reconfigure) + ses->chan_count = ses->chan_max; +else + ses->chan_count =1 ; -for (i =1 ; i < chan_count; i++) { +for (i = ses->chan_max ; i < chan_count; i++) { iface = ses->chans[i].iface; server = ses->chans[i].server;@@ -318,6 +323,15 @@ cifs_disable_secondary_channels(struct cifs_ses *ses)spin_lock (&ses->chan_lock); } +/* For extra secondary channels, reset the need reconnect bit */ +if (ses->chan_count ==1 ) { +cifs_dbg (VFS ,"server does not support multichannel anymore. Disable all other channels\n" ); + ses->chans_need_reconnect &=1 ; + }else { +cifs_dbg (VFS ,"Disable extra secondary channels\n" ); + ses->chans_need_reconnect &= ((1UL << ses->chan_max) -1 ); + } + done:spin_unlock (&ses->chan_lock); }fs/smb/client/smb2pdu.c +4
-5@@ -168,7 +168,7 @@ smb2_hdr_assemble(struct smb2_hdr *shdr, __le16 smb2_cmd,static int cifs_chan_skip_or_disable (struct cifs_ses *ses,struct TCP_Server_Info *server, -bool from_reconnect) +bool from_reconnect,bool from_reconfigure) {struct TCP_Server_Info *pserver;unsigned int chan_index;@@ -206,14 +206,41 @@ cifs_chan_skip_or_disable(struct cifs_ses *ses,return -EHOSTDOWN ; } -cifs_server_dbg (VFS , -"server does not support multichannel anymore. Disable all other channels\n" ); -cifs_disable_secondary_channels (ses); - +cifs_decrease_secondary_channels (ses, from_reconfigure);return 0 ; } +/* +* smb3_update_ses_channels - Synchronize session channels with new configuration fs/smb/client/smb2pdu.c cifs_chan_skip_or_disable(struct cifs_ses *ses, · line 225
Quoted 10 lines
fs/smb/client/smb2pdu.c +10
-0+* @ses: pointer to the CIFS session structure +* @server: pointer to the TCP server info structure +* @from_reconnect: indicates if called from reconnect context +* @from_reconfigure: indicates if called from reconfigure context +* +* Returns 0 on success or error code on failure. +* +* Note: Outside of reconfigure, this function is only called from reconnect scenarios +* when the server stops advertising multichannel (MC) capability. +*/ I see that function is being called during mount too. Did you mean
cifs_decrease_secondary_channels()?Quoted 72 lines
fs/smb/client/smb2pdu.c +27
-9+int smb3_update_ses_channels (struct cifs_ses *ses,struct TCP_Server_Info *server, +bool from_reconnect,bool from_reconfigure) +{ +int rc =0 ; +/* +* If the current channel count is less than the new chan_max, +* try to add channels to reach the new maximum. +* Otherwise, disable or skip extra channels to match the new configuration. +*/ +if (ses->chan_count < ses->chan_max) + rc =cifs_try_adding_channels (ses); +else + rc =cifs_chan_skip_or_disable (ses, server, from_reconnect, + from_reconfigure); + +return rc; +} +static int smb2_reconnect (__le16 smb2_command,struct cifs_tcon *tcon,struct TCP_Server_Info *server,bool from_reconnect)@@ -355,8 +382,8 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,*/ if (ses->chan_count >1 && !(server->capabilities &SMB2_GLOBAL_CAP_MULTI_CHANNEL )) { - rc =cifs_chan_skip_or_disable (ses, server, - from_reconnect); + rc =smb3_update_ses_channels (ses, server, + from_reconnect, false/* from_reconfigure */ );if (rc) {mutex_unlock (&ses->session_mutex); goto out;@@ -438,8 +465,9 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,* treat this as server not supporting multichannel */ - rc =cifs_chan_skip_or_disable (ses, server, - from_reconnect); + rc =smb3_update_ses_channels (ses, server, + from_reconnect, + false/* from_reconfigure */ ); goto skip_add_channels; }else if (rc) cifs_tcon_dbg(FYI, "%s: failed to query server interfaces: %d\n",@@ -451,7 +479,8 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,if (ses->chan_count ==1 )cifs_server_dbg (VFS ,"supports multichannel now\n" ); -cifs_try_adding_channels (ses); +smb3_update_ses_channels (ses, server, from_reconnect, + false/* from_reconfigure */ ); } }else {mutex_unlock (&ses->session_mutex);@@ -1105,8 +1134,7 @@ SMB2_negotiate(const unsigned int xid, req->SecurityMode =0 ; req->Capabilities =cpu_to_le32 (server->vals->req_capabilities); -if (ses->chan_max >1 ) - req->Capabilities |=cpu_to_le32 (SMB2_GLOBAL_CAP_MULTI_CHANNEL ); + req->Capabilities |=cpu_to_le32 (SMB2_GLOBAL_CAP_MULTI_CHANNEL );/* ClientGUID must be zero for SMB2.02 dialect */ if (server->vals->protocol_id ==SMB20_PROT_ID )@@ -1312,8 +1340,7 @@ int smb3_validate_negotiate(const unsigned int xid, struct cifs_tcon *tcon) pneg_inbuf->Capabilities =cpu_to_le32 (server->vals->req_capabilities); -if (tcon->ses->chan_max >1 ) - pneg_inbuf->Capabilities |=cpu_to_le32 (SMB2_GLOBAL_CAP_MULTI_CHANNEL ); + pneg_inbuf->Capabilities |=cpu_to_le32 (SMB2_GLOBAL_CAP_MULTI_CHANNEL );Quoted 10 lines
Quoted 6 lines
fs/smb/client/smb2pdu.c +0
-1memcpy (pneg_inbuf->Guid, server->client_guid,SMB2_CLIENT_GUID_SIZE ); --2.43.0
Thanks
Meetakshi--
Regards,
Shyam
Signature · 3 lines
Thanks, Steve
PATCH v2 1/1 cifs: client: allow changing multichannel mount options on remount
In reply to Rajasi MandalFrom: Rajasi Mandal <[email protected]>
Previously, the client did not update a session's channel state when multichannel or max_channels mount options were changed via remount. This led to inconsistent behavior and prevented enabling or disabling multichannel support without a full unmount/remount cycle.
Enable dynamic reconfiguration of multichannel and max_channels during remount by:
- Introducing smb3_sync_ses_chan_max(), a centralized function for channel updates which synchronizes the session's channels with the updated configuration.
- Replacing cifs_disable_secondary_channels() with cifs_decrease_secondary_channels(), which accepts a disable_mchan flag to support multichannel disable when the server stops supporting multichannel.
- Updating remount logic to detect changes in multichannel or max_channels and trigger appropriate session/channel updates.
Current limitation:
- The query_interfaces worker runs even when max_channels=1 so that multichannel can be enabled later via remount without requiring an unmount. This is a temporary approach and may be refined in the future.
Users can safely modify multichannel and max_channels on an existing mount. The client will correctly adjust the session's channel state to match the new configuration, preserving durability where possible and avoiding unnecessary disconnects.
--- fs/smb/client/cifsproto.h | 4 ++- fs/smb/client/connect.c | 4 ++- fs/smb/client/fs_context.c | 51 +++++++++++++++++++++++++++++++- fs/smb/client/sess.c | 35 ++++++++++++++++------ fs/smb/client/smb2pdu.c | 60 +++++++++++++++++++++++++++++--------- 5 files changed, 128 insertions(+), 26 deletions(-)
fs/smb/client/cifsproto.h +3 -1
@@ -649,6 +649,8 @@ int cifs_alloc_hash(const char *name, struct shash_desc **sdesc);void cifs_free_hash (struct shash_desc **sdesc);int cifs_try_adding_channels (struct cifs_ses *ses); +int smb3_update_ses_channels (struct cifs_ses *ses,struct TCP_Server_Info *server, +bool from_reconnect,bool disable_mchan);bool is_ses_using_iface (struct cifs_ses *ses,struct cifs_server_iface *iface);void cifs_ses_mark_for_reconnect (struct cifs_ses *ses);
@@ -674,7 +676,7 @@ bool cifs_chan_is_iface_active(struct cifs_ses *ses, struct TCP_Server_Info *server);void -cifs_disable_secondary_channels (struct cifs_ses *ses); +cifs_decrease_secondary_channels (struct cifs_ses *ses,bool disable_mchan);void cifs_chan_update_iface (struct cifs_ses *ses,struct TCP_Server_Info *server);int
fs/smb/client/connect.c +3 -1
@@ -3927,7 +3927,9 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx) ctx->prepath =NULL ; out: -cifs_try_adding_channels (mnt_ctx.ses); +smb3_update_ses_channels (mnt_ctx.ses, mnt_ctx.server, + false/* from_reconnect */ , + false/* disable_mchan */ ); rc =mount_setup_tlink (cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);if (rc) goto error;
fs/smb/client/fs_context.c +50 -1
69 lines not on this page · raw message
fs/smb/client/sess.c +26 -9
@@ -265,12 +265,16 @@ int cifs_try_adding_channels(struct cifs_ses *ses) }/* -* called when multichannel is disabled by the server. -* this always gets called from smb2_reconnect -* and cannot get called in parallel threads. +* cifs_decrease_secondary_channels - Reduce the number of active secondary channels +* @ses: pointer to the CIFS session structure +* @disable_mchan: if true, reduce to a single channel; if false, reduce to chan_max +* +* This function disables and cleans up extra secondary channels for a CIFS session. +* If called during reconfiguration, it reduces the channel count to the new maximum (chan_max). +* Otherwise, it disables all but the primary channel. */ void -cifs_disable_secondary_channels (struct cifs_ses *ses) +cifs_decrease_secondary_channels (struct cifs_ses *ses,bool disable_mchan) {int i, chan_count;struct TCP_Server_Info *server;
@@ -281,12 +285,16 @@ cifs_disable_secondary_channels(struct cifs_ses *ses)if (chan_count ==1 ) goto done; - ses->chan_count =1 ; - -/* for all secondary channels reset the need reconnect bit */ - ses->chans_need_reconnect &=1 ; +/* Update the chan_count to the new maximum */ +if (disable_mchan) { +cifs_dbg (FYI ,"server does not support multichannel anymore.\n" ); + ses->chan_count =1 ; + }else { + ses->chan_count = ses->chan_max; + } -for (i =1 ; i < chan_count; i++) { +/* Disable all secondary channels beyond the new chan_count */ +for (i = ses->chan_count ; i < chan_count; i++) { iface = ses->chans[i].iface; server = ses->chans[i].server;
@@ -318,6 +326,15 @@ cifs_disable_secondary_channels(struct cifs_ses *ses)spin_lock (&ses->chan_lock); } +/* For extra secondary channels, reset the need reconnect bit */ +if (ses->chan_count ==1 ) { +cifs_dbg (VFS ,"Disable all secondary channels\n" ); + ses->chans_need_reconnect &=1 ; + }else { +cifs_dbg (VFS ,"Disable extra secondary channels\n" ); + ses->chans_need_reconnect &= ((1UL << ses->chan_max) -1 ); + } + done:spin_unlock (&ses->chan_lock); }
fs/smb/client/smb2pdu.c +46 -14
106 lines not on this page · raw message
Signature · 1 line
2.43.0