Skip to content

Commit c2f8fde

Browse files
committed
fs: add helper to use mount option as path or fd
Allow filesystems to use a mount option either as a file or path. Link: https://lore.kernel.org/r/20241014-work-overlayfs-v3-1-32b3fed1286e@kernel.org Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 8cf0b93 commit c2f8fde

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

fs/fs_parser.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,26 @@ int fs_param_is_fd(struct p_log *log, const struct fs_parameter_spec *p,
308308
}
309309
EXPORT_SYMBOL(fs_param_is_fd);
310310

311+
int fs_param_is_file_or_string(struct p_log *log,
312+
const struct fs_parameter_spec *p,
313+
struct fs_parameter *param,
314+
struct fs_parse_result *result)
315+
{
316+
switch (param->type) {
317+
case fs_value_is_string:
318+
return fs_param_is_string(log, p, param, result);
319+
case fs_value_is_file:
320+
result->uint_32 = param->dirfd;
321+
if (result->uint_32 <= INT_MAX)
322+
return 0;
323+
break;
324+
default:
325+
break;
326+
}
327+
return fs_param_bad_value(log, param);
328+
}
329+
EXPORT_SYMBOL(fs_param_is_file_or_string);
330+
311331
int fs_param_is_uid(struct p_log *log, const struct fs_parameter_spec *p,
312332
struct fs_parameter *param, struct fs_parse_result *result)
313333
{

include/linux/fs_parser.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ typedef int fs_param_type(struct p_log *,
2828
*/
2929
fs_param_type fs_param_is_bool, fs_param_is_u32, fs_param_is_s32, fs_param_is_u64,
3030
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, fs_param_is_uid, fs_param_is_gid;
31+
fs_param_is_path, fs_param_is_fd, fs_param_is_uid, fs_param_is_gid,
32+
fs_param_is_file_or_string;
3233

3334
/*
3435
* Specification of the type of value a parameter wants.
@@ -133,6 +134,8 @@ static inline bool fs_validate_description(const char *name,
133134
#define fsparam_bdev(NAME, OPT) __fsparam(fs_param_is_blockdev, NAME, OPT, 0, NULL)
134135
#define fsparam_path(NAME, OPT) __fsparam(fs_param_is_path, NAME, OPT, 0, NULL)
135136
#define fsparam_fd(NAME, OPT) __fsparam(fs_param_is_fd, NAME, OPT, 0, NULL)
137+
#define fsparam_file_or_string(NAME, OPT) \
138+
__fsparam(fs_param_is_file_or_string, NAME, OPT, 0, NULL)
136139
#define fsparam_uid(NAME, OPT) __fsparam(fs_param_is_uid, NAME, OPT, 0, NULL)
137140
#define fsparam_gid(NAME, OPT) __fsparam(fs_param_is_gid, NAME, OPT, 0, NULL)
138141

0 commit comments

Comments
 (0)