Skip to content

Commit 328de52

Browse files
author
Al Viro
committed
turn fs_param_is_... into functions
Signed-off-by: Al Viro <[email protected]>
1 parent 48ce73b commit 328de52

File tree

3 files changed

+139
-129
lines changed

3 files changed

+139
-129
lines changed

fs/fs_parser.c

Lines changed: 124 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ EXPORT_SYMBOL(lookup_constant);
4848

4949
static inline bool is_flag(const struct fs_parameter_spec *p)
5050
{
51-
return p->type == fs_param_is_flag;
51+
return p->type == NULL;
5252
}
5353

5454
static const struct fs_parameter_spec *fs_lookup_key(
@@ -106,8 +106,6 @@ int __fs_parse(struct p_log *log,
106106
struct fs_parse_result *result)
107107
{
108108
const struct fs_parameter_spec *p;
109-
const struct constant_table *e;
110-
int ret = -ENOPARAM, b;
111109

112110
result->uint_64 = 0;
113111

@@ -121,96 +119,17 @@ int __fs_parse(struct p_log *log,
121119
/* Try to turn the type we were given into the type desired by the
122120
* parameter and give an error if we can't.
123121
*/
124-
switch (p->type) {
125-
case __fs_param_wasnt_defined:
126-
return -EINVAL;
127-
case fs_param_is_flag:
122+
if (is_flag(p)) {
128123
if (param->type != fs_value_is_flag)
129124
return inval_plog(log, "Unexpected value for '%s'",
130125
param->key);
131126
result->boolean = !result->negated;
132-
goto okay;
133-
case fs_param_is_bool:
134-
if (param->type != fs_value_is_string)
135-
goto bad_value;
136-
b = lookup_constant(bool_names, param->string, -1);
137-
if (b == -1)
138-
goto bad_value;
139-
result->boolean = b;
140-
goto okay;
141-
case fs_param_is_u32:
142-
if (param->type != fs_value_is_string)
143-
goto bad_value;
144-
ret = kstrtouint(param->string, 0, &result->uint_32);
145-
goto maybe_okay;
146-
case fs_param_is_u32_octal:
147-
if (param->type != fs_value_is_string)
148-
goto bad_value;
149-
ret = kstrtouint(param->string, 8, &result->uint_32);
150-
goto maybe_okay;
151-
case fs_param_is_u32_hex:
152-
if (param->type != fs_value_is_string)
153-
goto bad_value;
154-
ret = kstrtouint(param->string, 16, &result->uint_32);
155-
goto maybe_okay;
156-
case fs_param_is_s32:
157-
if (param->type != fs_value_is_string)
158-
goto bad_value;
159-
ret = kstrtoint(param->string, 0, &result->int_32);
160-
goto maybe_okay;
161-
case fs_param_is_u64:
162-
if (param->type != fs_value_is_string)
163-
goto bad_value;
164-
ret = kstrtoull(param->string, 0, &result->uint_64);
165-
goto maybe_okay;
166-
case fs_param_is_enum:
167-
if (param->type != fs_value_is_string)
168-
goto bad_value;
169-
e = __lookup_constant(p->data, param->string);
170-
if (e) {
171-
result->uint_32 = e->value;
172-
goto okay;
173-
}
174-
goto bad_value;
175-
case fs_param_is_string:
176-
if (param->type != fs_value_is_string || !*param->string)
177-
goto bad_value;
178-
goto okay;
179-
case fs_param_is_blob:
180-
if (param->type != fs_value_is_blob)
181-
goto bad_value;
182-
goto okay;
183-
case fs_param_is_fd: {
184-
switch (param->type) {
185-
case fs_value_is_string:
186-
ret = kstrtouint(param->string, 0, &result->uint_32);
187-
break;
188-
case fs_value_is_file:
189-
result->uint_32 = param->dirfd;
190-
ret = 0;
191-
default:
192-
goto bad_value;
193-
}
194-
195-
if (result->uint_32 > INT_MAX)
196-
goto bad_value;
197-
goto maybe_okay;
127+
} else {
128+
int ret = p->type(log, p, param, result);
129+
if (ret)
130+
return ret;
198131
}
199-
case fs_param_is_blockdev:
200-
case fs_param_is_path:
201-
goto okay;
202-
default:
203-
BUG();
204-
}
205-
206-
maybe_okay:
207-
if (ret < 0)
208-
goto bad_value;
209-
okay:
210132
return p->opt;
211-
212-
bad_value:
213-
return inval_plog(log, "Bad value for '%s'", param->key);
214133
}
215134
EXPORT_SYMBOL(__fs_parse);
216135

@@ -270,6 +189,124 @@ int fs_lookup_param(struct fs_context *fc,
270189
}
271190
EXPORT_SYMBOL(fs_lookup_param);
272191

192+
int fs_param_bad_value(struct p_log *log, struct fs_parameter *param)
193+
{
194+
return inval_plog(log, "Bad value for '%s'", param->key);
195+
}
196+
197+
int fs_param_is_bool(struct p_log *log, const struct fs_parameter_spec *p,
198+
struct fs_parameter *param, struct fs_parse_result *result)
199+
{
200+
int b;
201+
if (param->type != fs_value_is_string)
202+
return fs_param_bad_value(log, param);
203+
b = lookup_constant(bool_names, param->string, -1);
204+
if (b == -1)
205+
return fs_param_bad_value(log, param);
206+
result->boolean = b;
207+
return 0;
208+
}
209+
EXPORT_SYMBOL(fs_param_is_bool);
210+
211+
int fs_param_is_u32(struct p_log *log, const struct fs_parameter_spec *p,
212+
struct fs_parameter *param, struct fs_parse_result *result)
213+
{
214+
int base = (unsigned long)p->data;
215+
if (param->type != fs_value_is_string ||
216+
kstrtouint(param->string, base, &result->uint_32) < 0)
217+
return fs_param_bad_value(log, param);
218+
return 0;
219+
}
220+
EXPORT_SYMBOL(fs_param_is_u32);
221+
222+
int fs_param_is_s32(struct p_log *log, const struct fs_parameter_spec *p,
223+
struct fs_parameter *param, struct fs_parse_result *result)
224+
{
225+
if (param->type != fs_value_is_string ||
226+
kstrtoint(param->string, 0, &result->int_32) < 0)
227+
return fs_param_bad_value(log, param);
228+
return 0;
229+
}
230+
EXPORT_SYMBOL(fs_param_is_s32);
231+
232+
int fs_param_is_u64(struct p_log *log, const struct fs_parameter_spec *p,
233+
struct fs_parameter *param, struct fs_parse_result *result)
234+
{
235+
if (param->type != fs_value_is_string ||
236+
kstrtoull(param->string, 0, &result->uint_64) < 0)
237+
return fs_param_bad_value(log, param);
238+
return 0;
239+
}
240+
EXPORT_SYMBOL(fs_param_is_u64);
241+
242+
int fs_param_is_enum(struct p_log *log, const struct fs_parameter_spec *p,
243+
struct fs_parameter *param, struct fs_parse_result *result)
244+
{
245+
const struct constant_table *c;
246+
if (param->type != fs_value_is_string)
247+
return fs_param_bad_value(log, param);
248+
c = __lookup_constant(p->data, param->string);
249+
if (!c)
250+
return fs_param_bad_value(log, param);
251+
result->uint_32 = c->value;
252+
return 0;
253+
}
254+
EXPORT_SYMBOL(fs_param_is_enum);
255+
256+
int fs_param_is_string(struct p_log *log, const struct fs_parameter_spec *p,
257+
struct fs_parameter *param, struct fs_parse_result *result)
258+
{
259+
if (param->type != fs_value_is_string || !*param->string)
260+
return fs_param_bad_value(log, param);
261+
return 0;
262+
}
263+
EXPORT_SYMBOL(fs_param_is_string);
264+
265+
int fs_param_is_blob(struct p_log *log, const struct fs_parameter_spec *p,
266+
struct fs_parameter *param, struct fs_parse_result *result)
267+
{
268+
if (param->type != fs_value_is_blob)
269+
return fs_param_bad_value(log, param);
270+
return 0;
271+
}
272+
EXPORT_SYMBOL(fs_param_is_blob);
273+
274+
int fs_param_is_fd(struct p_log *log, const struct fs_parameter_spec *p,
275+
struct fs_parameter *param, struct fs_parse_result *result)
276+
{
277+
switch (param->type) {
278+
case fs_value_is_string:
279+
if (kstrtouint(param->string, 0, &result->uint_32) < 0)
280+
break;
281+
if (result->uint_32 <= INT_MAX)
282+
return 0;
283+
break;
284+
case fs_value_is_file:
285+
result->uint_32 = param->dirfd;
286+
if (result->uint_32 <= INT_MAX)
287+
return 0;
288+
break;
289+
default:
290+
break;
291+
}
292+
return fs_param_bad_value(log, param);
293+
}
294+
EXPORT_SYMBOL(fs_param_is_fd);
295+
296+
int fs_param_is_blockdev(struct p_log *log, const struct fs_parameter_spec *p,
297+
struct fs_parameter *param, struct fs_parse_result *result)
298+
{
299+
return 0;
300+
}
301+
EXPORT_SYMBOL(fs_param_is_blockdev);
302+
303+
int fs_param_is_path(struct p_log *log, const struct fs_parameter_spec *p,
304+
struct fs_parameter *param, struct fs_parse_result *result)
305+
{
306+
return 0;
307+
}
308+
EXPORT_SYMBOL(fs_param_is_path);
309+
273310
#ifdef CONFIG_VALIDATE_FS_PARSER
274311
/**
275312
* validate_constant_table - Validate a constant table
@@ -334,23 +371,6 @@ bool fs_validate_description(const char *name,
334371
pr_notice("*** VALIDATE %s ***\n", name);
335372

336373
for (param = desc; param->name; param++) {
337-
enum fs_parameter_type t = param->type;
338-
339-
/* Check that the type is in range */
340-
if (t == __fs_param_wasnt_defined ||
341-
t >= nr__fs_parameter_type) {
342-
pr_err("VALIDATE %s: PARAM[%s] Bad type %u\n",
343-
name, param->name, t);
344-
good = false;
345-
} else if (t == fs_param_is_enum) {
346-
const struct constant_table *e = param->data;
347-
if (!e || !e->name) {
348-
pr_err("VALIDATE %s: PARAM[%s] enum with no values\n",
349-
name, param->name);
350-
good = false;
351-
}
352-
}
353-
354374
/* Check for duplicate parameter names */
355375
for (p2 = desc; p2 < param; p2++) {
356376
if (strcmp(param->name, p2->name) == 0) {

fs/nfs/fs_context.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static const struct fs_parameter_spec nfs_fs_parameters[] = {
129129
fsparam_flag_no("fsc", Opt_fscache_flag),
130130
fsparam_string("fsc", Opt_fscache),
131131
fsparam_flag ("hard", Opt_hard),
132-
__fsparam(fs_param_is_flag, "intr", Opt_intr,
132+
__fsparam(NULL, "intr", Opt_intr,
133133
fs_param_neg_with_no|fs_param_deprecated, NULL),
134134
fsparam_enum ("local_lock", Opt_local_lock, nfs_param_enums_local_lock),
135135
fsparam_flag_no("lock", Opt_lock),

include/linux/fs_parser.h

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,18 @@ struct constant_table {
1717
int value;
1818
};
1919

20+
struct fs_parameter_spec;
21+
struct fs_parse_result;
22+
typedef int fs_param_type(struct p_log *,
23+
const struct fs_parameter_spec *,
24+
struct fs_parameter *,
25+
struct fs_parse_result *);
2026
/*
2127
* The type of parameter expected.
2228
*/
23-
enum fs_parameter_type {
24-
__fs_param_wasnt_defined,
25-
fs_param_is_flag,
26-
fs_param_is_bool,
27-
fs_param_is_u32,
28-
fs_param_is_u32_octal,
29-
fs_param_is_u32_hex,
30-
fs_param_is_s32,
31-
fs_param_is_u64,
32-
fs_param_is_enum,
33-
fs_param_is_string,
34-
fs_param_is_blob,
35-
fs_param_is_blockdev,
36-
fs_param_is_path,
37-
fs_param_is_fd,
38-
nr__fs_parameter_type,
39-
};
29+
fs_param_type fs_param_is_bool, fs_param_is_u32, fs_param_is_s32, fs_param_is_u64,
30+
fs_param_is_enum, fs_param_is_string, fs_param_is_blob, fs_param_is_blockdev,
31+
fs_param_is_path, fs_param_is_fd;
4032

4133
/*
4234
* Specification of the type of value a parameter wants.
@@ -46,8 +38,8 @@ enum fs_parameter_type {
4638
*/
4739
struct fs_parameter_spec {
4840
const char *name;
41+
fs_param_type *type; /* The desired parameter type */
4942
u8 opt; /* Option number (returned by fs_parse()) */
50-
enum fs_parameter_type type:8; /* The desired parameter type */
5143
unsigned short flags;
5244
#define fs_param_neg_with_no 0x0002 /* "noxxx" is negative param */
5345
#define fs_param_neg_with_empty 0x0004 /* "xxx=" is negative param */
@@ -120,16 +112,15 @@ static inline bool fs_validate_description(const char *name,
120112
.data = DATA \
121113
}
122114

123-
#define fsparam_flag(NAME, OPT) __fsparam(fs_param_is_flag, NAME, OPT, 0, NULL)
115+
#define fsparam_flag(NAME, OPT) __fsparam(NULL, NAME, OPT, 0, NULL)
124116
#define fsparam_flag_no(NAME, OPT) \
125-
__fsparam(fs_param_is_flag, NAME, OPT, \
126-
fs_param_neg_with_no, NULL)
117+
__fsparam(NULL, NAME, OPT, fs_param_neg_with_no, NULL)
127118
#define fsparam_bool(NAME, OPT) __fsparam(fs_param_is_bool, NAME, OPT, 0, NULL)
128119
#define fsparam_u32(NAME, OPT) __fsparam(fs_param_is_u32, NAME, OPT, 0, NULL)
129120
#define fsparam_u32oct(NAME, OPT) \
130-
__fsparam(fs_param_is_u32_octal, NAME, OPT, 0, NULL)
121+
__fsparam(fs_param_is_u32, NAME, OPT, 0, (void *)8)
131122
#define fsparam_u32hex(NAME, OPT) \
132-
__fsparam(fs_param_is_u32_hex, NAME, OPT, 0, NULL)
123+
__fsparam(fs_param_is_u32_hex, NAME, OPT, 0, (void *16))
133124
#define fsparam_s32(NAME, OPT) __fsparam(fs_param_is_s32, NAME, OPT, 0, NULL)
134125
#define fsparam_u64(NAME, OPT) __fsparam(fs_param_is_u64, NAME, OPT, 0, NULL)
135126
#define fsparam_enum(NAME, OPT, array) __fsparam(fs_param_is_enum, NAME, OPT, 0, array)
@@ -140,5 +131,4 @@ static inline bool fs_validate_description(const char *name,
140131
#define fsparam_path(NAME, OPT) __fsparam(fs_param_is_path, NAME, OPT, 0, NULL)
141132
#define fsparam_fd(NAME, OPT) __fsparam(fs_param_is_fd, NAME, OPT, 0, NULL)
142133

143-
144134
#endif /* _LINUX_FS_PARSER_H */

0 commit comments

Comments
 (0)