Skip to content

Commit 1ef15fb

Browse files
rajasi3010smfrench
authored andcommitted
cifs: client: enforce consistent handling of multichannel and max_channels
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. Reviewed-by: Shyam Prasad N <sprasad@microsoft.com> Signed-off-by: Rajasi Mandal <rajasimandal@microsoft.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 8697375 commit 1ef15fb

3 files changed

Lines changed: 50 additions & 18 deletions

File tree

fs/smb/client/cifsfs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,6 @@ cifs_smb3_do_mount(struct file_system_type *fs_type,
10161016
} else {
10171017
cifs_info("Attempting to mount %s\n", old_ctx->source);
10181018
}
1019-
10201019
cifs_sb = kzalloc(sizeof(*cifs_sb), GFP_KERNEL);
10211020
if (!cifs_sb)
10221021
return ERR_PTR(-ENOMEM);

fs/smb/client/fs_context.c

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,47 @@ smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)
711711
return 0;
712712
}
713713

714+
static int smb3_handle_conflicting_options(struct fs_context *fc)
715+
{
716+
struct smb3_fs_context *ctx = smb3_fc2context(fc);
717+
718+
if (ctx->multichannel_specified) {
719+
if (ctx->multichannel) {
720+
if (!ctx->max_channels_specified) {
721+
ctx->max_channels = 2;
722+
} else if (ctx->max_channels == 1) {
723+
cifs_errorf(fc,
724+
"max_channels must be greater than 1 when multichannel is enabled\n");
725+
return -EINVAL;
726+
}
727+
} else {
728+
if (!ctx->max_channels_specified) {
729+
ctx->max_channels = 1;
730+
} else if (ctx->max_channels > 1) {
731+
cifs_errorf(fc,
732+
"max_channels must be equal to 1 when multichannel is disabled\n");
733+
return -EINVAL;
734+
}
735+
}
736+
} else {
737+
if (ctx->max_channels_specified) {
738+
if (ctx->max_channels > 1)
739+
ctx->multichannel = true;
740+
else
741+
ctx->multichannel = false;
742+
} else {
743+
ctx->multichannel = false;
744+
ctx->max_channels = 1;
745+
}
746+
}
747+
748+
//resetting default values as remount doesn't initialize fs_context again
749+
ctx->multichannel_specified = false;
750+
ctx->max_channels_specified = false;
751+
752+
return 0;
753+
}
754+
714755
static void smb3_fs_context_free(struct fs_context *fc);
715756
static int smb3_fs_context_parse_param(struct fs_context *fc,
716757
struct fs_parameter *param);
@@ -784,6 +825,7 @@ static int smb3_fs_context_parse_monolithic(struct fs_context *fc,
784825
if (ret < 0)
785826
break;
786827
}
828+
ret = smb3_handle_conflicting_options(fc);
787829

788830
return ret;
789831
}
@@ -1250,15 +1292,11 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
12501292
ctx->nodelete = 1;
12511293
break;
12521294
case Opt_multichannel:
1253-
if (result.negated) {
1295+
ctx->multichannel_specified = true;
1296+
if (result.negated)
12541297
ctx->multichannel = false;
1255-
ctx->max_channels = 1;
1256-
} else {
1298+
else
12571299
ctx->multichannel = true;
1258-
/* if number of channels not specified, default to 2 */
1259-
if (ctx->max_channels < 2)
1260-
ctx->max_channels = 2;
1261-
}
12621300
break;
12631301
case Opt_uid:
12641302
ctx->linux_uid = result.uid;
@@ -1394,15 +1432,13 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
13941432
ctx->max_credits = result.uint_32;
13951433
break;
13961434
case Opt_max_channels:
1435+
ctx->max_channels_specified = true;
13971436
if (result.uint_32 < 1 || result.uint_32 > CIFS_MAX_CHANNELS) {
13981437
cifs_errorf(fc, "%s: Invalid max_channels value, needs to be 1-%d\n",
13991438
__func__, CIFS_MAX_CHANNELS);
14001439
goto cifs_parse_mount_err;
14011440
}
14021441
ctx->max_channels = result.uint_32;
1403-
/* If more than one channel requested ... they want multichan */
1404-
if (result.uint_32 > 1)
1405-
ctx->multichannel = true;
14061442
break;
14071443
case Opt_max_cached_dirs:
14081444
if (result.uint_32 < 1) {
@@ -1820,13 +1856,6 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
18201856
goto cifs_parse_mount_err;
18211857
}
18221858

1823-
/*
1824-
* Multichannel is not meaningful if max_channels is 1.
1825-
* Force multichannel to false to ensure consistent configuration.
1826-
*/
1827-
if (ctx->multichannel && ctx->max_channels == 1)
1828-
ctx->multichannel = false;
1829-
18301859
return 0;
18311860

18321861
cifs_parse_mount_err:
@@ -1913,6 +1942,8 @@ int smb3_init_fs_context(struct fs_context *fc)
19131942

19141943
/* default to no multichannel (single server connection) */
19151944
ctx->multichannel = false;
1945+
ctx->multichannel_specified = false;
1946+
ctx->max_channels_specified = false;
19161947
ctx->max_channels = 1;
19171948

19181949
ctx->backupuid_specified = false; /* no backup intent for a user */

fs/smb/client/fs_context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ struct smb3_fs_context {
294294
bool domainauto:1;
295295
bool rdma:1;
296296
bool multichannel:1;
297+
bool multichannel_specified:1; /* true if user specified multichannel or nomultichannel */
298+
bool max_channels_specified:1; /* true if user specified max_channels */
297299
bool use_client_guid:1;
298300
/* reuse existing guid for multichannel */
299301
u8 client_guid[SMB2_CLIENT_GUID_SIZE];

0 commit comments

Comments
 (0)