mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 21:21:41 +00:00
vfs: Convert tracefs to use the new mount API
Convert the tracefs 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: David Howells <dhowells@redhat.com> Co-developed-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Eric Sandeen <sandeen@redhat.com> [sandeen: forward port to modern kernel, fix remounting] Link: https://lore.kernel.org/r/536e99d3-345c-448b-adee-a21389d7ab4b@redhat.com cc: Steven Rostedt <rostedt@goodmis.org> cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
a20971c187
commit
78ff640819
@ -11,14 +11,14 @@
|
|||||||
|
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
#include <linux/mount.h>
|
#include <linux/fs_context.h>
|
||||||
|
#include <linux/fs_parser.h>
|
||||||
#include <linux/kobject.h>
|
#include <linux/kobject.h>
|
||||||
#include <linux/namei.h>
|
#include <linux/namei.h>
|
||||||
#include <linux/tracefs.h>
|
#include <linux/tracefs.h>
|
||||||
#include <linux/fsnotify.h>
|
#include <linux/fsnotify.h>
|
||||||
#include <linux/security.h>
|
#include <linux/security.h>
|
||||||
#include <linux/seq_file.h>
|
#include <linux/seq_file.h>
|
||||||
#include <linux/parser.h>
|
|
||||||
#include <linux/magic.h>
|
#include <linux/magic.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
@ -231,7 +231,7 @@ struct inode *tracefs_get_inode(struct super_block *sb)
|
|||||||
return inode;
|
return inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tracefs_mount_opts {
|
struct tracefs_fs_info {
|
||||||
kuid_t uid;
|
kuid_t uid;
|
||||||
kgid_t gid;
|
kgid_t gid;
|
||||||
umode_t mode;
|
umode_t mode;
|
||||||
@ -243,68 +243,51 @@ enum {
|
|||||||
Opt_uid,
|
Opt_uid,
|
||||||
Opt_gid,
|
Opt_gid,
|
||||||
Opt_mode,
|
Opt_mode,
|
||||||
Opt_err
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const match_table_t tokens = {
|
static const struct fs_parameter_spec tracefs_param_specs[] = {
|
||||||
{Opt_uid, "uid=%u"},
|
fsparam_u32 ("gid", Opt_gid),
|
||||||
{Opt_gid, "gid=%u"},
|
fsparam_u32oct ("mode", Opt_mode),
|
||||||
{Opt_mode, "mode=%o"},
|
fsparam_u32 ("uid", Opt_uid),
|
||||||
{Opt_err, NULL}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tracefs_fs_info {
|
static int tracefs_parse_param(struct fs_context *fc, struct fs_parameter *param)
|
||||||
struct tracefs_mount_opts mount_opts;
|
|
||||||
};
|
|
||||||
|
|
||||||
static int tracefs_parse_options(char *data, struct tracefs_mount_opts *opts)
|
|
||||||
{
|
{
|
||||||
substring_t args[MAX_OPT_ARGS];
|
struct tracefs_fs_info *opts = fc->s_fs_info;
|
||||||
int option;
|
struct fs_parse_result result;
|
||||||
int token;
|
|
||||||
kuid_t uid;
|
kuid_t uid;
|
||||||
kgid_t gid;
|
kgid_t gid;
|
||||||
char *p;
|
int opt;
|
||||||
|
|
||||||
opts->opts = 0;
|
opt = fs_parse(fc, tracefs_param_specs, param, &result);
|
||||||
opts->mode = TRACEFS_DEFAULT_MODE;
|
if (opt < 0)
|
||||||
|
return opt;
|
||||||
|
|
||||||
while ((p = strsep(&data, ",")) != NULL) {
|
switch (opt) {
|
||||||
if (!*p)
|
case Opt_uid:
|
||||||
continue;
|
uid = make_kuid(current_user_ns(), result.uint_32);
|
||||||
|
if (!uid_valid(uid))
|
||||||
token = match_token(p, tokens, args);
|
return invalf(fc, "Unknown uid");
|
||||||
switch (token) {
|
opts->uid = uid;
|
||||||
case Opt_uid:
|
break;
|
||||||
if (match_int(&args[0], &option))
|
case Opt_gid:
|
||||||
return -EINVAL;
|
gid = make_kgid(current_user_ns(), result.uint_32);
|
||||||
uid = make_kuid(current_user_ns(), option);
|
if (!gid_valid(gid))
|
||||||
if (!uid_valid(uid))
|
return invalf(fc, "Unknown gid");
|
||||||
return -EINVAL;
|
opts->gid = gid;
|
||||||
opts->uid = uid;
|
break;
|
||||||
break;
|
case Opt_mode:
|
||||||
case Opt_gid:
|
opts->mode = result.uint_32 & S_IALLUGO;
|
||||||
if (match_int(&args[0], &option))
|
break;
|
||||||
return -EINVAL;
|
/*
|
||||||
gid = make_kgid(current_user_ns(), option);
|
* We might like to report bad mount options here;
|
||||||
if (!gid_valid(gid))
|
* but traditionally tracefs has ignored all mount options
|
||||||
return -EINVAL;
|
*/
|
||||||
opts->gid = gid;
|
|
||||||
break;
|
|
||||||
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 traditionally tracefs has ignored all mount options
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
opts->opts |= BIT(token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opts->opts |= BIT(opt);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +295,6 @@ static int tracefs_apply_options(struct super_block *sb, bool remount)
|
|||||||
{
|
{
|
||||||
struct tracefs_fs_info *fsi = sb->s_fs_info;
|
struct tracefs_fs_info *fsi = sb->s_fs_info;
|
||||||
struct inode *inode = d_inode(sb->s_root);
|
struct inode *inode = d_inode(sb->s_root);
|
||||||
struct tracefs_mount_opts *opts = &fsi->mount_opts;
|
|
||||||
umode_t tmp_mode;
|
umode_t tmp_mode;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -320,50 +302,46 @@ static int tracefs_apply_options(struct super_block *sb, bool remount)
|
|||||||
* options.
|
* options.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!remount || opts->opts & BIT(Opt_mode)) {
|
if (!remount || fsi->opts & BIT(Opt_mode)) {
|
||||||
tmp_mode = READ_ONCE(inode->i_mode) & ~S_IALLUGO;
|
tmp_mode = READ_ONCE(inode->i_mode) & ~S_IALLUGO;
|
||||||
tmp_mode |= opts->mode;
|
tmp_mode |= fsi->mode;
|
||||||
WRITE_ONCE(inode->i_mode, tmp_mode);
|
WRITE_ONCE(inode->i_mode, tmp_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!remount || opts->opts & BIT(Opt_uid))
|
if (!remount || fsi->opts & BIT(Opt_uid))
|
||||||
inode->i_uid = opts->uid;
|
inode->i_uid = fsi->uid;
|
||||||
|
|
||||||
if (!remount || opts->opts & BIT(Opt_gid))
|
if (!remount || fsi->opts & BIT(Opt_gid))
|
||||||
inode->i_gid = opts->gid;
|
inode->i_gid = fsi->gid;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tracefs_remount(struct super_block *sb, int *flags, char *data)
|
static int tracefs_reconfigure(struct fs_context *fc)
|
||||||
{
|
{
|
||||||
int err;
|
struct super_block *sb = fc->root->d_sb;
|
||||||
struct tracefs_fs_info *fsi = sb->s_fs_info;
|
struct tracefs_fs_info *sb_opts = sb->s_fs_info;
|
||||||
|
struct tracefs_fs_info *new_opts = fc->s_fs_info;
|
||||||
|
|
||||||
sync_filesystem(sb);
|
sync_filesystem(sb);
|
||||||
err = tracefs_parse_options(data, &fsi->mount_opts);
|
/* structure copy of new mount options to sb */
|
||||||
if (err)
|
*sb_opts = *new_opts;
|
||||||
goto fail;
|
|
||||||
|
|
||||||
tracefs_apply_options(sb, true);
|
return tracefs_apply_options(sb, true);
|
||||||
|
|
||||||
fail:
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tracefs_show_options(struct seq_file *m, struct dentry *root)
|
static int tracefs_show_options(struct seq_file *m, struct dentry *root)
|
||||||
{
|
{
|
||||||
struct tracefs_fs_info *fsi = root->d_sb->s_fs_info;
|
struct tracefs_fs_info *fsi = root->d_sb->s_fs_info;
|
||||||
struct tracefs_mount_opts *opts = &fsi->mount_opts;
|
|
||||||
|
|
||||||
if (!uid_eq(opts->uid, GLOBAL_ROOT_UID))
|
if (!uid_eq(fsi->uid, GLOBAL_ROOT_UID))
|
||||||
seq_printf(m, ",uid=%u",
|
seq_printf(m, ",uid=%u",
|
||||||
from_kuid_munged(&init_user_ns, opts->uid));
|
from_kuid_munged(&init_user_ns, fsi->uid));
|
||||||
if (!gid_eq(opts->gid, GLOBAL_ROOT_GID))
|
if (!gid_eq(fsi->gid, GLOBAL_ROOT_GID))
|
||||||
seq_printf(m, ",gid=%u",
|
seq_printf(m, ",gid=%u",
|
||||||
from_kgid_munged(&init_user_ns, opts->gid));
|
from_kgid_munged(&init_user_ns, fsi->gid));
|
||||||
if (opts->mode != TRACEFS_DEFAULT_MODE)
|
if (fsi->mode != TRACEFS_DEFAULT_MODE)
|
||||||
seq_printf(m, ",mode=%o", opts->mode);
|
seq_printf(m, ",mode=%o", fsi->mode);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -373,7 +351,6 @@ static const struct super_operations tracefs_super_operations = {
|
|||||||
.free_inode = tracefs_free_inode,
|
.free_inode = tracefs_free_inode,
|
||||||
.drop_inode = generic_delete_inode,
|
.drop_inode = generic_delete_inode,
|
||||||
.statfs = simple_statfs,
|
.statfs = simple_statfs,
|
||||||
.remount_fs = tracefs_remount,
|
|
||||||
.show_options = tracefs_show_options,
|
.show_options = tracefs_show_options,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -403,26 +380,14 @@ static const struct dentry_operations tracefs_dentry_operations = {
|
|||||||
.d_release = tracefs_d_release,
|
.d_release = tracefs_d_release,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int trace_fill_super(struct super_block *sb, void *data, int silent)
|
static int tracefs_fill_super(struct super_block *sb, struct fs_context *fc)
|
||||||
{
|
{
|
||||||
static const struct tree_descr trace_files[] = {{""}};
|
static const struct tree_descr trace_files[] = {{""}};
|
||||||
struct tracefs_fs_info *fsi;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
fsi = kzalloc(sizeof(struct tracefs_fs_info), GFP_KERNEL);
|
err = simple_fill_super(sb, TRACEFS_MAGIC, trace_files);
|
||||||
sb->s_fs_info = fsi;
|
|
||||||
if (!fsi) {
|
|
||||||
err = -ENOMEM;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = tracefs_parse_options(data, &fsi->mount_opts);
|
|
||||||
if (err)
|
if (err)
|
||||||
goto fail;
|
return err;
|
||||||
|
|
||||||
err = simple_fill_super(sb, TRACEFS_MAGIC, trace_files);
|
|
||||||
if (err)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
sb->s_op = &tracefs_super_operations;
|
sb->s_op = &tracefs_super_operations;
|
||||||
sb->s_d_op = &tracefs_dentry_operations;
|
sb->s_d_op = &tracefs_dentry_operations;
|
||||||
@ -430,24 +395,45 @@ static int trace_fill_super(struct super_block *sb, void *data, int silent)
|
|||||||
tracefs_apply_options(sb, false);
|
tracefs_apply_options(sb, false);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
|
||||||
kfree(fsi);
|
|
||||||
sb->s_fs_info = NULL;
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct dentry *trace_mount(struct file_system_type *fs_type,
|
static int tracefs_get_tree(struct fs_context *fc)
|
||||||
int flags, const char *dev_name,
|
|
||||||
void *data)
|
|
||||||
{
|
{
|
||||||
return mount_single(fs_type, flags, data, trace_fill_super);
|
return get_tree_single(fc, tracefs_fill_super);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tracefs_free_fc(struct fs_context *fc)
|
||||||
|
{
|
||||||
|
kfree(fc->s_fs_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct fs_context_operations tracefs_context_ops = {
|
||||||
|
.free = tracefs_free_fc,
|
||||||
|
.parse_param = tracefs_parse_param,
|
||||||
|
.get_tree = tracefs_get_tree,
|
||||||
|
.reconfigure = tracefs_reconfigure,
|
||||||
|
};
|
||||||
|
|
||||||
|
static int tracefs_init_fs_context(struct fs_context *fc)
|
||||||
|
{
|
||||||
|
struct tracefs_fs_info *fsi;
|
||||||
|
|
||||||
|
fsi = kzalloc(sizeof(struct tracefs_fs_info), GFP_KERNEL);
|
||||||
|
if (!fsi)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
fsi->mode = TRACEFS_DEFAULT_MODE;
|
||||||
|
|
||||||
|
fc->s_fs_info = fsi;
|
||||||
|
fc->ops = &tracefs_context_ops;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct file_system_type trace_fs_type = {
|
static struct file_system_type trace_fs_type = {
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.name = "tracefs",
|
.name = "tracefs",
|
||||||
.mount = trace_mount,
|
.init_fs_context = tracefs_init_fs_context,
|
||||||
|
.parameters = tracefs_param_specs,
|
||||||
.kill_sb = kill_litter_super,
|
.kill_sb = kill_litter_super,
|
||||||
};
|
};
|
||||||
MODULE_ALIAS_FS("tracefs");
|
MODULE_ALIAS_FS("tracefs");
|
||||||
|
Loading…
Reference in New Issue
Block a user