Commit d2935de7 authored by David Howells's avatar David Howells Committed by Al Viro

vfs: Convert bpf to use the new mount API

Convert the bpf filesystem to the new internal mount API as the old
one will be obsoleted and removed.  This allows greater flexibility in
communication of mount parameters between userspace, the VFS and the
filesystem.

See Documentation/filesystems/mount_api.txt for more information.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
cc: Alexei Starovoitov <ast@kernel.org>
cc: Daniel Borkmann <daniel@iogearbox.net>
cc: Martin KaFai Lau <kafai@fb.com>
cc: Song Liu <songliubraving@fb.com>
cc: Yonghong Song <yhs@fb.com>
cc: netdev@vger.kernel.org
cc: bpf@vger.kernel.org
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 74983ac2
...@@ -14,8 +14,9 @@ ...@@ -14,8 +14,9 @@
#include <linux/mount.h> #include <linux/mount.h>
#include <linux/namei.h> #include <linux/namei.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/fs_context.h>
#include <linux/fs_parser.h>
#include <linux/kdev_t.h> #include <linux/kdev_t.h>
#include <linux/parser.h>
#include <linux/filter.h> #include <linux/filter.h>
#include <linux/bpf.h> #include <linux/bpf.h>
#include <linux/bpf_trace.h> #include <linux/bpf_trace.h>
...@@ -583,58 +584,52 @@ static const struct super_operations bpf_super_ops = { ...@@ -583,58 +584,52 @@ static const struct super_operations bpf_super_ops = {
enum { enum {
OPT_MODE, OPT_MODE,
OPT_ERR,
}; };
static const match_table_t bpf_mount_tokens = { static const struct fs_parameter_spec bpf_param_specs[] = {
{ OPT_MODE, "mode=%o" }, fsparam_u32oct ("mode", OPT_MODE),
{ OPT_ERR, NULL }, {}
};
static const struct fs_parameter_description bpf_fs_parameters = {
.name = "bpf",
.specs = bpf_param_specs,
}; };
struct bpf_mount_opts { struct bpf_mount_opts {
umode_t mode; umode_t mode;
}; };
static int bpf_parse_options(char *data, struct bpf_mount_opts *opts) static int bpf_parse_param(struct fs_context *fc, struct fs_parameter *param)
{ {
substring_t args[MAX_OPT_ARGS]; struct bpf_mount_opts *opts = fc->fs_private;
int option, token; struct fs_parse_result result;
char *ptr; int opt;
opts->mode = S_IRWXUGO;
while ((ptr = strsep(&data, ",")) != NULL) {
if (!*ptr)
continue;
token = match_token(ptr, bpf_mount_tokens, args); opt = fs_parse(fc, &bpf_fs_parameters, param, &result);
switch (token) { if (opt < 0)
case OPT_MODE:
if (match_octal(&args[0], &option))
return -EINVAL;
opts->mode = option & S_IALLUGO;
break;
/* We might like to report bad mount options here, but /* We might like to report bad mount options here, but
* traditionally we've ignored all mount options, so we'd * traditionally we've ignored all mount options, so we'd
* better continue to ignore non-existing options for bpf. * better continue to ignore non-existing options for bpf.
*/ */
} return opt == -ENOPARAM ? 0 : opt;
switch (opt) {
case OPT_MODE:
opts->mode = result.uint_32 & S_IALLUGO;
break;
} }
return 0; return 0;
} }
static int bpf_fill_super(struct super_block *sb, void *data, int silent) static int bpf_fill_super(struct super_block *sb, struct fs_context *fc)
{ {
static const struct tree_descr bpf_rfiles[] = { { "" } }; static const struct tree_descr bpf_rfiles[] = { { "" } };
struct bpf_mount_opts opts; struct bpf_mount_opts *opts = fc->fs_private;
struct inode *inode; struct inode *inode;
int ret; int ret;
ret = bpf_parse_options(data, &opts);
if (ret)
return ret;
ret = simple_fill_super(sb, BPF_FS_MAGIC, bpf_rfiles); ret = simple_fill_super(sb, BPF_FS_MAGIC, bpf_rfiles);
if (ret) if (ret)
return ret; return ret;
...@@ -644,21 +639,50 @@ static int bpf_fill_super(struct super_block *sb, void *data, int silent) ...@@ -644,21 +639,50 @@ static int bpf_fill_super(struct super_block *sb, void *data, int silent)
inode = sb->s_root->d_inode; inode = sb->s_root->d_inode;
inode->i_op = &bpf_dir_iops; inode->i_op = &bpf_dir_iops;
inode->i_mode &= ~S_IALLUGO; inode->i_mode &= ~S_IALLUGO;
inode->i_mode |= S_ISVTX | opts.mode; inode->i_mode |= S_ISVTX | opts->mode;
return 0; return 0;
} }
static struct dentry *bpf_mount(struct file_system_type *type, int flags, static int bpf_get_tree(struct fs_context *fc)
const char *dev_name, void *data)
{ {
return mount_nodev(type, flags, data, bpf_fill_super); return get_tree_nodev(fc, bpf_fill_super);
}
static void bpf_free_fc(struct fs_context *fc)
{
kfree(fc->fs_private);
}
static const struct fs_context_operations bpf_context_ops = {
.free = bpf_free_fc,
.parse_param = bpf_parse_param,
.get_tree = bpf_get_tree,
};
/*
* Set up the filesystem mount context.
*/
static int bpf_init_fs_context(struct fs_context *fc)
{
struct bpf_mount_opts *opts;
opts = kzalloc(sizeof(struct bpf_mount_opts), GFP_KERNEL);
if (!opts)
return -ENOMEM;
opts->mode = S_IRWXUGO;
fc->fs_private = opts;
fc->ops = &bpf_context_ops;
return 0;
} }
static struct file_system_type bpf_fs_type = { static struct file_system_type bpf_fs_type = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "bpf", .name = "bpf",
.mount = bpf_mount, .init_fs_context = bpf_init_fs_context,
.parameters = &bpf_fs_parameters,
.kill_sb = kill_litter_super, .kill_sb = kill_litter_super,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment