Skip to content

Commit 555782a

Browse files
Ronnie Sahlbergsmfrench
authored andcommitted
cifs: move smb version mount options into fs_context.c
This and related patches which move mount related code to fs_context.c has the advantage of shriking the code in fs/cifs/connect.c (which had the second most lines of code of any of the files in cifs.ko and was getting harder to read due to its size) and will also make it easier to switch over to the new mount API in the future. Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com> Reviewed-by: Aurelien Aptel <aaptel@suse.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 2f20f07 commit 555782a

4 files changed

Lines changed: 99 additions & 97 deletions

File tree

fs/cifs/cifsglob.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,18 +195,6 @@ struct smb_rqst {
195195
unsigned int rq_tailsz; /* length of last page */
196196
};
197197

198-
enum smb_version {
199-
Smb_1 = 1,
200-
Smb_20,
201-
Smb_21,
202-
Smb_30,
203-
Smb_302,
204-
Smb_311,
205-
Smb_3any,
206-
Smb_default,
207-
Smb_version_err
208-
};
209-
210198
struct mid_q_entry;
211199
struct TCP_Server_Info;
212200
struct cifsFileInfo;

fs/cifs/connect.c

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -280,20 +280,6 @@ static const match_table_t cifs_mount_option_tokens = {
280280
{ Opt_err, NULL }
281281
};
282282

283-
static const match_table_t cifs_smb_version_tokens = {
284-
{ Smb_1, SMB1_VERSION_STRING },
285-
{ Smb_20, SMB20_VERSION_STRING},
286-
{ Smb_21, SMB21_VERSION_STRING },
287-
{ Smb_30, SMB30_VERSION_STRING },
288-
{ Smb_302, SMB302_VERSION_STRING },
289-
{ Smb_302, ALT_SMB302_VERSION_STRING },
290-
{ Smb_311, SMB311_VERSION_STRING },
291-
{ Smb_311, ALT_SMB311_VERSION_STRING },
292-
{ Smb_3any, SMB3ANY_VERSION_STRING },
293-
{ Smb_default, SMBDEFAULT_VERSION_STRING },
294-
{ Smb_version_err, NULL }
295-
};
296-
297283
static int ip_connect(struct TCP_Server_Info *server);
298284
static int generic_ip_connect(struct TCP_Server_Info *server);
299285
static void tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink);
@@ -1327,77 +1313,6 @@ static int get_option_gid(substring_t args[], kgid_t *result)
13271313
return 0;
13281314
}
13291315

1330-
static int
1331-
cifs_parse_smb_version(char *value, struct smb_vol *vol, bool is_smb3)
1332-
{
1333-
substring_t args[MAX_OPT_ARGS];
1334-
1335-
switch (match_token(value, cifs_smb_version_tokens, args)) {
1336-
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
1337-
case Smb_1:
1338-
if (disable_legacy_dialects) {
1339-
cifs_dbg(VFS, "mount with legacy dialect disabled\n");
1340-
return 1;
1341-
}
1342-
if (is_smb3) {
1343-
cifs_dbg(VFS, "vers=1.0 (cifs) not permitted when mounting with smb3\n");
1344-
return 1;
1345-
}
1346-
cifs_dbg(VFS, "Use of the less secure dialect vers=1.0 is not recommended unless required for access to very old servers\n");
1347-
vol->ops = &smb1_operations;
1348-
vol->vals = &smb1_values;
1349-
break;
1350-
case Smb_20:
1351-
if (disable_legacy_dialects) {
1352-
cifs_dbg(VFS, "mount with legacy dialect disabled\n");
1353-
return 1;
1354-
}
1355-
if (is_smb3) {
1356-
cifs_dbg(VFS, "vers=2.0 not permitted when mounting with smb3\n");
1357-
return 1;
1358-
}
1359-
vol->ops = &smb20_operations;
1360-
vol->vals = &smb20_values;
1361-
break;
1362-
#else
1363-
case Smb_1:
1364-
cifs_dbg(VFS, "vers=1.0 (cifs) mount not permitted when legacy dialects disabled\n");
1365-
return 1;
1366-
case Smb_20:
1367-
cifs_dbg(VFS, "vers=2.0 mount not permitted when legacy dialects disabled\n");
1368-
return 1;
1369-
#endif /* CIFS_ALLOW_INSECURE_LEGACY */
1370-
case Smb_21:
1371-
vol->ops = &smb21_operations;
1372-
vol->vals = &smb21_values;
1373-
break;
1374-
case Smb_30:
1375-
vol->ops = &smb30_operations;
1376-
vol->vals = &smb30_values;
1377-
break;
1378-
case Smb_302:
1379-
vol->ops = &smb30_operations; /* currently identical with 3.0 */
1380-
vol->vals = &smb302_values;
1381-
break;
1382-
case Smb_311:
1383-
vol->ops = &smb311_operations;
1384-
vol->vals = &smb311_values;
1385-
break;
1386-
case Smb_3any:
1387-
vol->ops = &smb30_operations; /* currently identical with 3.0 */
1388-
vol->vals = &smb3any_values;
1389-
break;
1390-
case Smb_default:
1391-
vol->ops = &smb30_operations; /* currently identical with 3.0 */
1392-
vol->vals = &smbdefault_values;
1393-
break;
1394-
default:
1395-
cifs_dbg(VFS, "Unknown vers= option specified: %s\n", value);
1396-
return 1;
1397-
}
1398-
return 0;
1399-
}
1400-
14011316
/*
14021317
* Parse a devname into substrings and populate the vol->UNC and vol->prepath
14031318
* fields with the result. Returns 0 on success and an error otherwise.

fs/cifs/fs_context.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,91 @@
1010
#include "cifs_debug.h"
1111
#include "fs_context.h"
1212

13+
static const match_table_t cifs_smb_version_tokens = {
14+
{ Smb_1, SMB1_VERSION_STRING },
15+
{ Smb_20, SMB20_VERSION_STRING},
16+
{ Smb_21, SMB21_VERSION_STRING },
17+
{ Smb_30, SMB30_VERSION_STRING },
18+
{ Smb_302, SMB302_VERSION_STRING },
19+
{ Smb_302, ALT_SMB302_VERSION_STRING },
20+
{ Smb_311, SMB311_VERSION_STRING },
21+
{ Smb_311, ALT_SMB311_VERSION_STRING },
22+
{ Smb_3any, SMB3ANY_VERSION_STRING },
23+
{ Smb_default, SMBDEFAULT_VERSION_STRING },
24+
{ Smb_version_err, NULL }
25+
};
26+
27+
int
28+
cifs_parse_smb_version(char *value, struct smb_vol *vol, bool is_smb3)
29+
{
30+
substring_t args[MAX_OPT_ARGS];
31+
32+
switch (match_token(value, cifs_smb_version_tokens, args)) {
33+
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
34+
case Smb_1:
35+
if (disable_legacy_dialects) {
36+
cifs_dbg(VFS, "mount with legacy dialect disabled\n");
37+
return 1;
38+
}
39+
if (is_smb3) {
40+
cifs_dbg(VFS, "vers=1.0 (cifs) not permitted when mounting with smb3\n");
41+
return 1;
42+
}
43+
cifs_dbg(VFS, "Use of the less secure dialect vers=1.0 is not recommended unless required for access to very old servers\n");
44+
vol->ops = &smb1_operations;
45+
vol->vals = &smb1_values;
46+
break;
47+
case Smb_20:
48+
if (disable_legacy_dialects) {
49+
cifs_dbg(VFS, "mount with legacy dialect disabled\n");
50+
return 1;
51+
}
52+
if (is_smb3) {
53+
cifs_dbg(VFS, "vers=2.0 not permitted when mounting with smb3\n");
54+
return 1;
55+
}
56+
vol->ops = &smb20_operations;
57+
vol->vals = &smb20_values;
58+
break;
59+
#else
60+
case Smb_1:
61+
cifs_dbg(VFS, "vers=1.0 (cifs) mount not permitted when legacy dialects disabled\n");
62+
return 1;
63+
case Smb_20:
64+
cifs_dbg(VFS, "vers=2.0 mount not permitted when legacy dialects disabled\n");
65+
return 1;
66+
#endif /* CIFS_ALLOW_INSECURE_LEGACY */
67+
case Smb_21:
68+
vol->ops = &smb21_operations;
69+
vol->vals = &smb21_values;
70+
break;
71+
case Smb_30:
72+
vol->ops = &smb30_operations;
73+
vol->vals = &smb30_values;
74+
break;
75+
case Smb_302:
76+
vol->ops = &smb30_operations; /* currently identical with 3.0 */
77+
vol->vals = &smb302_values;
78+
break;
79+
case Smb_311:
80+
vol->ops = &smb311_operations;
81+
vol->vals = &smb311_values;
82+
break;
83+
case Smb_3any:
84+
vol->ops = &smb30_operations; /* currently identical with 3.0 */
85+
vol->vals = &smb3any_values;
86+
break;
87+
case Smb_default:
88+
vol->ops = &smb30_operations; /* currently identical with 3.0 */
89+
vol->vals = &smbdefault_values;
90+
break;
91+
default:
92+
cifs_dbg(VFS, "Unknown vers= option specified: %s\n", value);
93+
return 1;
94+
}
95+
return 0;
96+
}
97+
1398
static const match_table_t cifs_secflavor_tokens = {
1499
{ Opt_sec_krb5, "krb5" },
15100
{ Opt_sec_krb5i, "krb5i" },

fs/cifs/fs_context.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@
1212
#include <linux/parser.h>
1313
#include "cifsglob.h"
1414

15+
enum smb_version {
16+
Smb_1 = 1,
17+
Smb_20,
18+
Smb_21,
19+
Smb_30,
20+
Smb_302,
21+
Smb_311,
22+
Smb_3any,
23+
Smb_default,
24+
Smb_version_err
25+
};
26+
27+
int cifs_parse_smb_version(char *value, struct smb_vol *vol, bool is_smb3);
28+
1529
enum {
1630
Opt_cache_loose,
1731
Opt_cache_strict,

0 commit comments

Comments
 (0)