Skip to content

Commit 3e28111

Browse files
Eric Sandeenmartinetd
authored andcommitted
9p: fix new mount API cache option handling
After commit 4eb3117, 9p needs to be able to accept numerical cache= mount options as well as the string "shortcuts" because the option is printed numerically in /proc/mounts rather than by string. This was missed in the mount API conversion, which used an enum for the shortcuts and therefore could not handle a numeric equivalent as an argument to the cache option. Fix this by removing the enum and reverting to the slightly more open-coded option handling for Opt_cache, with the reinstated get_cache_mode() helper. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Message-ID: <48cdeec9-5bb9-4c7a-a203-39bb8e0ef443@redhat.com> Tested-by: Remi Pommarel <repk@triplefau.lt> Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
1 parent f044561 commit 3e28111

1 file changed

Lines changed: 32 additions & 12 deletions

File tree

fs/9p/v9fs.c

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,6 @@ static const struct constant_table p9_versions[] = {
7272
{}
7373
};
7474

75-
static const struct constant_table p9_cache_mode[] = {
76-
{ "loose", CACHE_SC_LOOSE },
77-
{ "fscache", CACHE_SC_FSCACHE },
78-
{ "mmap", CACHE_SC_MMAP },
79-
{ "readahead", CACHE_SC_READAHEAD },
80-
{ "none", CACHE_SC_NONE },
81-
{}
82-
};
83-
8475
/*
8576
* This structure contains all parameters used for the core code,
8677
* the client, and all the transports.
@@ -97,7 +88,7 @@ const struct fs_parameter_spec v9fs_param_spec[] = {
9788
fsparam_flag ("noxattr", Opt_noxattr),
9889
fsparam_flag ("directio", Opt_directio),
9990
fsparam_flag ("ignoreqv", Opt_ignoreqv),
100-
fsparam_enum ("cache", Opt_cache, p9_cache_mode),
91+
fsparam_string ("cache", Opt_cache),
10192
fsparam_string ("cachetag", Opt_cachetag),
10293
fsparam_string ("access", Opt_access),
10394
fsparam_flag ("posixacl", Opt_posixacl),
@@ -124,6 +115,33 @@ const struct fs_parameter_spec v9fs_param_spec[] = {
124115
{}
125116
};
126117

118+
/* Interpret mount options for cache mode */
119+
static int get_cache_mode(char *s)
120+
{
121+
int version = -EINVAL;
122+
123+
if (!strcmp(s, "loose")) {
124+
version = CACHE_SC_LOOSE;
125+
p9_debug(P9_DEBUG_9P, "Cache mode: loose\n");
126+
} else if (!strcmp(s, "fscache")) {
127+
version = CACHE_SC_FSCACHE;
128+
p9_debug(P9_DEBUG_9P, "Cache mode: fscache\n");
129+
} else if (!strcmp(s, "mmap")) {
130+
version = CACHE_SC_MMAP;
131+
p9_debug(P9_DEBUG_9P, "Cache mode: mmap\n");
132+
} else if (!strcmp(s, "readahead")) {
133+
version = CACHE_SC_READAHEAD;
134+
p9_debug(P9_DEBUG_9P, "Cache mode: readahead\n");
135+
} else if (!strcmp(s, "none")) {
136+
version = CACHE_SC_NONE;
137+
p9_debug(P9_DEBUG_9P, "Cache mode: none\n");
138+
} else if (kstrtoint(s, 0, &version) != 0) {
139+
version = -EINVAL;
140+
pr_info("Unknown Cache mode or invalid value %s\n", s);
141+
}
142+
return version;
143+
}
144+
127145
/*
128146
* Display the mount options in /proc/mounts.
129147
*/
@@ -269,8 +287,10 @@ int v9fs_parse_param(struct fs_context *fc, struct fs_parameter *param)
269287
#endif
270288
break;
271289
case Opt_cache:
272-
session_opts->cache = result.uint_32;
273-
p9_debug(P9_DEBUG_9P, "Cache mode: %s\n", param->string);
290+
r = get_cache_mode(param->string);
291+
if (r < 0)
292+
return r;
293+
session_opts->cache = r;
274294
break;
275295
case Opt_access:
276296
s = param->string;

0 commit comments

Comments
 (0)