Commit 103fb219 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'vfs-6.10.mount' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs

Pull vfs mount API conversions from Christian Brauner:
 "This converts qnx6, minix, debugfs, tracefs, freevxfs, and openpromfs
  to the new mount api, further reducing the number of filesystems
  relying on the legacy mount api"

* tag 'vfs-6.10.mount' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs:
  minix: convert minix to use the new mount api
  vfs: Convert tracefs to use the new mount API
  vfs: Convert debugfs to use the new mount API
  openpromfs: finish conversion to the new mount API
  freevxfs: Convert freevxfs to the new mount API.
  qnx6: convert qnx6 to use the new mount api
parents 1b0aabcc 7cd7bfe5
......@@ -14,7 +14,8 @@
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/mount.h>
#include <linux/fs_context.h>
#include <linux/fs_parser.h>
#include <linux/pagemap.h>
#include <linux/init.h>
#include <linux/kobject.h>
......@@ -23,7 +24,6 @@
#include <linux/fsnotify.h>
#include <linux/string.h>
#include <linux/seq_file.h>
#include <linux/parser.h>
#include <linux/magic.h>
#include <linux/slab.h>
#include <linux/security.h>
......@@ -77,7 +77,7 @@ static struct inode *debugfs_get_inode(struct super_block *sb)
return inode;
}
struct debugfs_mount_opts {
struct debugfs_fs_info {
kuid_t uid;
kgid_t gid;
umode_t mode;
......@@ -89,58 +89,42 @@ enum {
Opt_uid,
Opt_gid,
Opt_mode,
Opt_err
};
static const match_table_t tokens = {
{Opt_uid, "uid=%u"},
{Opt_gid, "gid=%u"},
{Opt_mode, "mode=%o"},
{Opt_err, NULL}
static const struct fs_parameter_spec debugfs_param_specs[] = {
fsparam_u32 ("gid", Opt_gid),
fsparam_u32oct ("mode", Opt_mode),
fsparam_u32 ("uid", Opt_uid),
{}
};
struct debugfs_fs_info {
struct debugfs_mount_opts mount_opts;
};
static int debugfs_parse_options(char *data, struct debugfs_mount_opts *opts)
static int debugfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
{
substring_t args[MAX_OPT_ARGS];
int option;
int token;
struct debugfs_fs_info *opts = fc->s_fs_info;
struct fs_parse_result result;
kuid_t uid;
kgid_t gid;
char *p;
opts->opts = 0;
opts->mode = DEBUGFS_DEFAULT_MODE;
int opt;
while ((p = strsep(&data, ",")) != NULL) {
if (!*p)
continue;
opt = fs_parse(fc, debugfs_param_specs, param, &result);
if (opt < 0)
return opt;
token = match_token(p, tokens, args);
switch (token) {
switch (opt) {
case Opt_uid:
if (match_int(&args[0], &option))
return -EINVAL;
uid = make_kuid(current_user_ns(), option);
uid = make_kuid(current_user_ns(), result.uint_32);
if (!uid_valid(uid))
return -EINVAL;
return invalf(fc, "Unknown uid");
opts->uid = uid;
break;
case Opt_gid:
if (match_int(&args[0], &option))
return -EINVAL;
gid = make_kgid(current_user_ns(), option);
gid = make_kgid(current_user_ns(), result.uint_32);
if (!gid_valid(gid))
return -EINVAL;
return invalf(fc, "Unknown gid");
opts->gid = gid;
break;
case Opt_mode:
if (match_octal(&args[0], &option))
return -EINVAL;
opts->mode = option & S_IALLUGO;
opts->mode = result.uint_32 & S_IALLUGO;
break;
/*
* We might like to report bad mount options here;
......@@ -148,8 +132,7 @@ static int debugfs_parse_options(char *data, struct debugfs_mount_opts *opts)
*/
}
opts->opts |= BIT(token);
}
opts->opts |= BIT(opt);
return 0;
}
......@@ -158,23 +141,22 @@ static void _debugfs_apply_options(struct super_block *sb, bool remount)
{
struct debugfs_fs_info *fsi = sb->s_fs_info;
struct inode *inode = d_inode(sb->s_root);
struct debugfs_mount_opts *opts = &fsi->mount_opts;
/*
* On remount, only reset mode/uid/gid if they were provided as mount
* options.
*/
if (!remount || opts->opts & BIT(Opt_mode)) {
if (!remount || fsi->opts & BIT(Opt_mode)) {
inode->i_mode &= ~S_IALLUGO;
inode->i_mode |= opts->mode;
inode->i_mode |= fsi->mode;
}
if (!remount || opts->opts & BIT(Opt_uid))
inode->i_uid = opts->uid;
if (!remount || fsi->opts & BIT(Opt_uid))
inode->i_uid = fsi->uid;
if (!remount || opts->opts & BIT(Opt_gid))
inode->i_gid = opts->gid;
if (!remount || fsi->opts & BIT(Opt_gid))
inode->i_gid = fsi->gid;
}
static void debugfs_apply_options(struct super_block *sb)
......@@ -187,35 +169,33 @@ static void debugfs_apply_options_remount(struct super_block *sb)
_debugfs_apply_options(sb, true);
}
static int debugfs_remount(struct super_block *sb, int *flags, char *data)
static int debugfs_reconfigure(struct fs_context *fc)
{
int err;
struct debugfs_fs_info *fsi = sb->s_fs_info;
struct super_block *sb = fc->root->d_sb;
struct debugfs_fs_info *sb_opts = sb->s_fs_info;
struct debugfs_fs_info *new_opts = fc->s_fs_info;
sync_filesystem(sb);
err = debugfs_parse_options(data, &fsi->mount_opts);
if (err)
goto fail;
/* structure copy of new mount options to sb */
*sb_opts = *new_opts;
debugfs_apply_options_remount(sb);
fail:
return err;
return 0;
}
static int debugfs_show_options(struct seq_file *m, struct dentry *root)
{
struct debugfs_fs_info *fsi = root->d_sb->s_fs_info;
struct debugfs_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",
from_kuid_munged(&init_user_ns, opts->uid));
if (!gid_eq(opts->gid, GLOBAL_ROOT_GID))
from_kuid_munged(&init_user_ns, fsi->uid));
if (!gid_eq(fsi->gid, GLOBAL_ROOT_GID))
seq_printf(m, ",gid=%u",
from_kgid_munged(&init_user_ns, opts->gid));
if (opts->mode != DEBUGFS_DEFAULT_MODE)
seq_printf(m, ",mode=%o", opts->mode);
from_kgid_munged(&init_user_ns, fsi->gid));
if (fsi->mode != DEBUGFS_DEFAULT_MODE)
seq_printf(m, ",mode=%o", fsi->mode);
return 0;
}
......@@ -229,7 +209,6 @@ static void debugfs_free_inode(struct inode *inode)
static const struct super_operations debugfs_super_operations = {
.statfs = simple_statfs,
.remount_fs = debugfs_remount,
.show_options = debugfs_show_options,
.free_inode = debugfs_free_inode,
};
......@@ -263,26 +242,14 @@ static const struct dentry_operations debugfs_dops = {
.d_automount = debugfs_automount,
};
static int debug_fill_super(struct super_block *sb, void *data, int silent)
static int debugfs_fill_super(struct super_block *sb, struct fs_context *fc)
{
static const struct tree_descr debug_files[] = {{""}};
struct debugfs_fs_info *fsi;
int err;
fsi = kzalloc(sizeof(struct debugfs_fs_info), GFP_KERNEL);
sb->s_fs_info = fsi;
if (!fsi) {
err = -ENOMEM;
goto fail;
}
err = debugfs_parse_options(data, &fsi->mount_opts);
if (err)
goto fail;
err = simple_fill_super(sb, DEBUGFS_MAGIC, debug_files);
if (err)
goto fail;
return err;
sb->s_op = &debugfs_super_operations;
sb->s_d_op = &debugfs_dops;
......@@ -290,27 +257,48 @@ static int debug_fill_super(struct super_block *sb, void *data, int silent)
debugfs_apply_options(sb);
return 0;
fail:
kfree(fsi);
sb->s_fs_info = NULL;
return err;
}
static struct dentry *debug_mount(struct file_system_type *fs_type,
int flags, const char *dev_name,
void *data)
static int debugfs_get_tree(struct fs_context *fc)
{
if (!(debugfs_allow & DEBUGFS_ALLOW_API))
return ERR_PTR(-EPERM);
return -EPERM;
return get_tree_single(fc, debugfs_fill_super);
}
static void debugfs_free_fc(struct fs_context *fc)
{
kfree(fc->s_fs_info);
}
return mount_single(fs_type, flags, data, debug_fill_super);
static const struct fs_context_operations debugfs_context_ops = {
.free = debugfs_free_fc,
.parse_param = debugfs_parse_param,
.get_tree = debugfs_get_tree,
.reconfigure = debugfs_reconfigure,
};
static int debugfs_init_fs_context(struct fs_context *fc)
{
struct debugfs_fs_info *fsi;
fsi = kzalloc(sizeof(struct debugfs_fs_info), GFP_KERNEL);
if (!fsi)
return -ENOMEM;
fsi->mode = DEBUGFS_DEFAULT_MODE;
fc->s_fs_info = fsi;
fc->ops = &debugfs_context_ops;
return 0;
}
static struct file_system_type debug_fs_type = {
.owner = THIS_MODULE,
.name = "debugfs",
.mount = debug_mount,
.init_fs_context = debugfs_init_fs_context,
.parameters = debugfs_param_specs,
.kill_sb = kill_litter_super,
};
MODULE_ALIAS_FS("debugfs");
......
......@@ -17,7 +17,7 @@
#include <linux/slab.h>
#include <linux/stat.h>
#include <linux/vfs.h>
#include <linux/mount.h>
#include <linux/fs_context.h>
#include "vxfs.h"
#include "vxfs_extern.h"
......@@ -91,10 +91,10 @@ vxfs_statfs(struct dentry *dentry, struct kstatfs *bufp)
return 0;
}
static int vxfs_remount(struct super_block *sb, int *flags, char *data)
static int vxfs_reconfigure(struct fs_context *fc)
{
sync_filesystem(sb);
*flags |= SB_RDONLY;
sync_filesystem(fc->root->d_sb);
fc->sb_flags |= SB_RDONLY;
return 0;
}
......@@ -120,23 +120,23 @@ static const struct super_operations vxfs_super_ops = {
.evict_inode = vxfs_evict_inode,
.put_super = vxfs_put_super,
.statfs = vxfs_statfs,
.remount_fs = vxfs_remount,
};
static int vxfs_try_sb_magic(struct super_block *sbp, int silent,
static int vxfs_try_sb_magic(struct super_block *sbp, struct fs_context *fc,
unsigned blk, __fs32 magic)
{
struct buffer_head *bp;
struct vxfs_sb *rsbp;
struct vxfs_sb_info *infp = VXFS_SBI(sbp);
int silent = fc->sb_flags & SB_SILENT;
int rc = -ENOMEM;
bp = sb_bread(sbp, blk);
do {
if (!bp || !buffer_mapped(bp)) {
if (!silent) {
printk(KERN_WARNING
"vxfs: unable to read disk superblock at %u\n",
warnf(fc,
"vxfs: unable to read disk superblock at %u",
blk);
}
break;
......@@ -146,8 +146,8 @@ static int vxfs_try_sb_magic(struct super_block *sbp, int silent,
rsbp = (struct vxfs_sb *)bp->b_data;
if (rsbp->vs_magic != magic) {
if (!silent)
printk(KERN_NOTICE
"vxfs: WRONG superblock magic %08x at %u\n",
infof(fc,
"vxfs: WRONG superblock magic %08x at %u",
rsbp->vs_magic, blk);
break;
}
......@@ -169,8 +169,7 @@ static int vxfs_try_sb_magic(struct super_block *sbp, int silent,
/**
* vxfs_fill_super - read superblock into memory and initialize filesystem
* @sbp: VFS superblock (to fill)
* @dp: fs private mount data
* @silent: do not complain loudly when sth is wrong
* @fc: filesytem context
*
* Description:
* We are called on the first mount of a filesystem to read the
......@@ -182,26 +181,27 @@ static int vxfs_try_sb_magic(struct super_block *sbp, int silent,
* Locking:
* We are under @sbp->s_lock.
*/
static int vxfs_fill_super(struct super_block *sbp, void *dp, int silent)
static int vxfs_fill_super(struct super_block *sbp, struct fs_context *fc)
{
struct vxfs_sb_info *infp;
struct vxfs_sb *rsbp;
u_long bsize;
struct inode *root;
int ret = -EINVAL;
int silent = fc->sb_flags & SB_SILENT;
u32 j;
sbp->s_flags |= SB_RDONLY;
infp = kzalloc(sizeof(*infp), GFP_KERNEL);
if (!infp) {
printk(KERN_WARNING "vxfs: unable to allocate incore superblock\n");
warnf(fc, "vxfs: unable to allocate incore superblock");
return -ENOMEM;
}
bsize = sb_min_blocksize(sbp, BLOCK_SIZE);
if (!bsize) {
printk(KERN_WARNING "vxfs: unable to set blocksize\n");
warnf(fc, "vxfs: unable to set blocksize");
goto out;
}
......@@ -210,24 +210,24 @@ static int vxfs_fill_super(struct super_block *sbp, void *dp, int silent)
sbp->s_time_min = 0;
sbp->s_time_max = U32_MAX;
if (!vxfs_try_sb_magic(sbp, silent, 1,
if (!vxfs_try_sb_magic(sbp, fc, 1,
(__force __fs32)cpu_to_le32(VXFS_SUPER_MAGIC))) {
/* Unixware, x86 */
infp->byte_order = VXFS_BO_LE;
} else if (!vxfs_try_sb_magic(sbp, silent, 8,
} else if (!vxfs_try_sb_magic(sbp, fc, 8,
(__force __fs32)cpu_to_be32(VXFS_SUPER_MAGIC))) {
/* HP-UX, parisc */
infp->byte_order = VXFS_BO_BE;
} else {
if (!silent)
printk(KERN_NOTICE "vxfs: can't find superblock.\n");
infof(fc, "vxfs: can't find superblock.");
goto out;
}
rsbp = infp->vsi_raw;
j = fs32_to_cpu(infp, rsbp->vs_version);
if ((j < 2 || j > 4) && !silent) {
printk(KERN_NOTICE "vxfs: unsupported VxFS version (%d)\n", j);
infof(fc, "vxfs: unsupported VxFS version (%d)", j);
goto out;
}
......@@ -244,17 +244,17 @@ static int vxfs_fill_super(struct super_block *sbp, void *dp, int silent)
j = fs32_to_cpu(infp, rsbp->vs_bsize);
if (!sb_set_blocksize(sbp, j)) {
printk(KERN_WARNING "vxfs: unable to set final block size\n");
warnf(fc, "vxfs: unable to set final block size");
goto out;
}
if (vxfs_read_olt(sbp, bsize)) {
printk(KERN_WARNING "vxfs: unable to read olt\n");
warnf(fc, "vxfs: unable to read olt");
goto out;
}
if (vxfs_read_fshead(sbp)) {
printk(KERN_WARNING "vxfs: unable to read fshead\n");
warnf(fc, "vxfs: unable to read fshead");
goto out;
}
......@@ -265,7 +265,7 @@ static int vxfs_fill_super(struct super_block *sbp, void *dp, int silent)
}
sbp->s_root = d_make_root(root);
if (!sbp->s_root) {
printk(KERN_WARNING "vxfs: unable to get root dentry.\n");
warnf(fc, "vxfs: unable to get root dentry.");
goto out_free_ilist;
}
......@@ -284,18 +284,29 @@ static int vxfs_fill_super(struct super_block *sbp, void *dp, int silent)
/*
* The usual module blurb.
*/
static struct dentry *vxfs_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
static int vxfs_get_tree(struct fs_context *fc)
{
return mount_bdev(fs_type, flags, dev_name, data, vxfs_fill_super);
return get_tree_bdev(fc, vxfs_fill_super);
}
static const struct fs_context_operations vxfs_context_ops = {
.get_tree = vxfs_get_tree,
.reconfigure = vxfs_reconfigure,
};
static int vxfs_init_fs_context(struct fs_context *fc)
{
fc->ops = &vxfs_context_ops;
return 0;
}
static struct file_system_type vxfs_fs_type = {
.owner = THIS_MODULE,
.name = "vxfs",
.mount = vxfs_mount,
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
.init_fs_context = vxfs_init_fs_context,
};
MODULE_ALIAS_FS("vxfs"); /* makes mount -t vxfs autoload the module */
MODULE_ALIAS("vxfs");
......
......@@ -20,11 +20,11 @@
#include <linux/mpage.h>
#include <linux/vfs.h>
#include <linux/writeback.h>
#include <linux/fs_context.h>
static int minix_write_inode(struct inode *inode,
struct writeback_control *wbc);
static int minix_statfs(struct dentry *dentry, struct kstatfs *buf);
static int minix_remount (struct super_block * sb, int * flags, char * data);
static void minix_evict_inode(struct inode *inode)
{
......@@ -111,19 +111,19 @@ static const struct super_operations minix_sops = {
.evict_inode = minix_evict_inode,
.put_super = minix_put_super,
.statfs = minix_statfs,
.remount_fs = minix_remount,
};
static int minix_remount (struct super_block * sb, int * flags, char * data)
static int minix_reconfigure(struct fs_context *fc)
{
struct minix_sb_info * sbi = minix_sb(sb);
struct minix_super_block * ms;
struct super_block *sb = fc->root->d_sb;
struct minix_sb_info * sbi = sb->s_fs_info;
sync_filesystem(sb);
ms = sbi->s_ms;
if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb))
if ((bool)(fc->sb_flags & SB_RDONLY) == sb_rdonly(sb))
return 0;
if (*flags & SB_RDONLY) {
if (fc->sb_flags & SB_RDONLY) {
if (ms->s_state & MINIX_VALID_FS ||
!(sbi->s_mount_state & MINIX_VALID_FS))
return 0;
......@@ -170,7 +170,7 @@ static bool minix_check_superblock(struct super_block *sb)
return true;
}
static int minix_fill_super(struct super_block *s, void *data, int silent)
static int minix_fill_super(struct super_block *s, struct fs_context *fc)
{
struct buffer_head *bh;
struct buffer_head **map;
......@@ -180,6 +180,7 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
struct inode *root_inode;
struct minix_sb_info *sbi;
int ret = -EINVAL;
int silent = fc->sb_flags & SB_SILENT;
sbi = kzalloc(sizeof(struct minix_sb_info), GFP_KERNEL);
if (!sbi)
......@@ -371,6 +372,23 @@ static int minix_fill_super(struct super_block *s, void *data, int silent)
return ret;
}
static int minix_get_tree(struct fs_context *fc)
{
return get_tree_bdev(fc, minix_fill_super);
}
static const struct fs_context_operations minix_context_ops = {
.get_tree = minix_get_tree,
.reconfigure = minix_reconfigure,
};
static int minix_init_fs_context(struct fs_context *fc)
{
fc->ops = &minix_context_ops;
return 0;
}
static int minix_statfs(struct dentry *dentry, struct kstatfs *buf)
{
struct super_block *sb = dentry->d_sb;
......@@ -680,18 +698,12 @@ void minix_truncate(struct inode * inode)
V2_minix_truncate(inode);
}
static struct dentry *minix_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
{
return mount_bdev(fs_type, flags, dev_name, data, minix_fill_super);
}
static struct file_system_type minix_fs_type = {
.owner = THIS_MODULE,
.name = "minix",
.mount = minix_mount,
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
.init_fs_context = minix_init_fs_context,
};
MODULE_ALIAS_FS("minix");
......
......@@ -355,10 +355,10 @@ static struct inode *openprom_iget(struct super_block *sb, ino_t ino)
return inode;
}
static int openprom_remount(struct super_block *sb, int *flags, char *data)
static int openpromfs_reconfigure(struct fs_context *fc)
{
sync_filesystem(sb);
*flags |= SB_NOATIME;
sync_filesystem(fc->root->d_sb);
fc->sb_flags |= SB_NOATIME;
return 0;
}
......@@ -366,7 +366,6 @@ static const struct super_operations openprom_sops = {
.alloc_inode = openprom_alloc_inode,
.free_inode = openprom_free_inode,
.statfs = simple_statfs,
.remount_fs = openprom_remount,
};
static int openprom_fill_super(struct super_block *s, struct fs_context *fc)
......@@ -415,6 +414,7 @@ static int openpromfs_get_tree(struct fs_context *fc)
static const struct fs_context_operations openpromfs_context_ops = {
.get_tree = openpromfs_get_tree,
.reconfigure = openpromfs_reconfigure,
};
static int openpromfs_init_fs_context(struct fs_context *fc)
......
......@@ -19,11 +19,11 @@
#include <linux/buffer_head.h>
#include <linux/writeback.h>
#include <linux/statfs.h>
#include <linux/parser.h>
#include <linux/seq_file.h>
#include <linux/mount.h>
#include <linux/crc32.h>
#include <linux/mpage.h>
#include <linux/fs_parser.h>
#include <linux/fs_context.h>
#include "qnx6.h"
static const struct super_operations qnx6_sops;
......@@ -31,7 +31,7 @@ static const struct super_operations qnx6_sops;
static void qnx6_put_super(struct super_block *sb);
static struct inode *qnx6_alloc_inode(struct super_block *sb);
static void qnx6_free_inode(struct inode *inode);
static int qnx6_remount(struct super_block *sb, int *flags, char *data);
static int qnx6_reconfigure(struct fs_context *fc);
static int qnx6_statfs(struct dentry *dentry, struct kstatfs *buf);
static int qnx6_show_options(struct seq_file *seq, struct dentry *root);
......@@ -40,7 +40,6 @@ static const struct super_operations qnx6_sops = {
.free_inode = qnx6_free_inode,
.put_super = qnx6_put_super,
.statfs = qnx6_statfs,
.remount_fs = qnx6_remount,
.show_options = qnx6_show_options,
};
......@@ -54,10 +53,12 @@ static int qnx6_show_options(struct seq_file *seq, struct dentry *root)
return 0;
}
static int qnx6_remount(struct super_block *sb, int *flags, char *data)
static int qnx6_reconfigure(struct fs_context *fc)
{
struct super_block *sb = fc->root->d_sb;
sync_filesystem(sb);
*flags |= SB_RDONLY;
fc->sb_flags |= SB_RDONLY;
return 0;
}
......@@ -218,39 +219,36 @@ void qnx6_superblock_debug(struct qnx6_super_block *sb, struct super_block *s)
#endif
enum {
Opt_mmifs,
Opt_err
Opt_mmifs
};
static const match_table_t tokens = {
{Opt_mmifs, "mmi_fs"},
{Opt_err, NULL}
struct qnx6_context {
unsigned long s_mount_opts;
};
static int qnx6_parse_options(char *options, struct super_block *sb)
{
char *p;
struct qnx6_sb_info *sbi = QNX6_SB(sb);
substring_t args[MAX_OPT_ARGS];
static const struct fs_parameter_spec qnx6_param_spec[] = {
fsparam_flag ("mmi_fs", Opt_mmifs),
{}
};
if (!options)
return 1;
static int qnx6_parse_param(struct fs_context *fc, struct fs_parameter *param)
{
struct qnx6_context *ctx = fc->fs_private;
struct fs_parse_result result;
int opt;
while ((p = strsep(&options, ",")) != NULL) {
int token;
if (!*p)
continue;
opt = fs_parse(fc, qnx6_param_spec, param, &result);
if (opt < 0)
return opt;
token = match_token(p, tokens, args);
switch (token) {
switch (opt) {
case Opt_mmifs:
set_opt(sbi->s_mount_opt, MMI_FS);
ctx->s_mount_opts |= QNX6_MOUNT_MMI_FS;
break;
default:
return 0;
}
return -EINVAL;
}
return 1;
return 0;
}
static struct buffer_head *qnx6_check_first_superblock(struct super_block *s,
......@@ -293,22 +291,25 @@ static struct buffer_head *qnx6_check_first_superblock(struct super_block *s,
static struct inode *qnx6_private_inode(struct super_block *s,
struct qnx6_root_node *p);
static int qnx6_fill_super(struct super_block *s, void *data, int silent)
static int qnx6_fill_super(struct super_block *s, struct fs_context *fc)
{
struct buffer_head *bh1 = NULL, *bh2 = NULL;
struct qnx6_super_block *sb1 = NULL, *sb2 = NULL;
struct qnx6_sb_info *sbi;
struct qnx6_context *ctx = fc->fs_private;
struct inode *root;
const char *errmsg;
struct qnx6_sb_info *qs;
int ret = -EINVAL;
u64 offset;
int bootblock_offset = QNX6_BOOTBLOCK_SIZE;
int silent = fc->sb_flags & SB_SILENT;
qs = kzalloc(sizeof(struct qnx6_sb_info), GFP_KERNEL);
if (!qs)
return -ENOMEM;
s->s_fs_info = qs;
qs->s_mount_opt = ctx->s_mount_opts;
/* Superblock always is 512 Byte long */
if (!sb_set_blocksize(s, QNX6_SUPERBLOCK_SIZE)) {
......@@ -316,12 +317,7 @@ static int qnx6_fill_super(struct super_block *s, void *data, int silent)
goto outnobh;
}
/* parse the mount-options */
if (!qnx6_parse_options((char *) data, s)) {
pr_err("invalid mount options.\n");
goto outnobh;
}
if (test_opt(s, MMI_FS)) {
if (qs->s_mount_opt == QNX6_MOUNT_MMI_FS) {
sb1 = qnx6_mmi_fill_super(s, silent);
if (sb1)
goto mmi_success;
......@@ -632,18 +628,43 @@ static void destroy_inodecache(void)
kmem_cache_destroy(qnx6_inode_cachep);
}
static struct dentry *qnx6_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
static int qnx6_get_tree(struct fs_context *fc)
{
return mount_bdev(fs_type, flags, dev_name, data, qnx6_fill_super);
return get_tree_bdev(fc, qnx6_fill_super);
}
static void qnx6_free_fc(struct fs_context *fc)
{
kfree(fc->fs_private);
}
static const struct fs_context_operations qnx6_context_ops = {
.parse_param = qnx6_parse_param,
.get_tree = qnx6_get_tree,
.reconfigure = qnx6_reconfigure,
.free = qnx6_free_fc,
};
static int qnx6_init_fs_context(struct fs_context *fc)
{
struct qnx6_context *ctx;
ctx = kzalloc(sizeof(struct qnx6_context), GFP_KERNEL);
if (!ctx)
return -ENOMEM;
fc->ops = &qnx6_context_ops;
fc->fs_private = ctx;
return 0;
}
static struct file_system_type qnx6_fs_type = {
.owner = THIS_MODULE,
.name = "qnx6",
.mount = qnx6_mount,
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
.init_fs_context = qnx6_init_fs_context,
.parameters = qnx6_param_spec,
};
MODULE_ALIAS_FS("qnx6");
......
......@@ -11,14 +11,14 @@
#include <linux/module.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/namei.h>
#include <linux/tracefs.h>
#include <linux/fsnotify.h>
#include <linux/security.h>
#include <linux/seq_file.h>
#include <linux/parser.h>
#include <linux/magic.h>
#include <linux/slab.h>
#include "internal.h"
......@@ -281,7 +281,7 @@ struct inode *tracefs_get_inode(struct super_block *sb)
return inode;
}
struct tracefs_mount_opts {
struct tracefs_fs_info {
kuid_t uid;
kgid_t gid;
umode_t mode;
......@@ -293,58 +293,42 @@ enum {
Opt_uid,
Opt_gid,
Opt_mode,
Opt_err
};
static const match_table_t tokens = {
{Opt_uid, "uid=%u"},
{Opt_gid, "gid=%u"},
{Opt_mode, "mode=%o"},
{Opt_err, NULL}
static const struct fs_parameter_spec tracefs_param_specs[] = {
fsparam_u32 ("gid", Opt_gid),
fsparam_u32oct ("mode", Opt_mode),
fsparam_u32 ("uid", Opt_uid),
{}
};
struct tracefs_fs_info {
struct tracefs_mount_opts mount_opts;
};
static int tracefs_parse_options(char *data, struct tracefs_mount_opts *opts)
static int tracefs_parse_param(struct fs_context *fc, struct fs_parameter *param)
{
substring_t args[MAX_OPT_ARGS];
int option;
int token;
struct tracefs_fs_info *opts = fc->s_fs_info;
struct fs_parse_result result;
kuid_t uid;
kgid_t gid;
char *p;
opts->opts = 0;
opts->mode = TRACEFS_DEFAULT_MODE;
int opt;
while ((p = strsep(&data, ",")) != NULL) {
if (!*p)
continue;
opt = fs_parse(fc, tracefs_param_specs, param, &result);
if (opt < 0)
return opt;
token = match_token(p, tokens, args);
switch (token) {
switch (opt) {
case Opt_uid:
if (match_int(&args[0], &option))
return -EINVAL;
uid = make_kuid(current_user_ns(), option);
uid = make_kuid(current_user_ns(), result.uint_32);
if (!uid_valid(uid))
return -EINVAL;
return invalf(fc, "Unknown uid");
opts->uid = uid;
break;
case Opt_gid:
if (match_int(&args[0], &option))
return -EINVAL;
gid = make_kgid(current_user_ns(), option);
gid = make_kgid(current_user_ns(), result.uint_32);
if (!gid_valid(gid))
return -EINVAL;
return invalf(fc, "Unknown gid");
opts->gid = gid;
break;
case Opt_mode:
if (match_octal(&args[0], &option))
return -EINVAL;
opts->mode = option & S_IALLUGO;
opts->mode = result.uint_32 & S_IALLUGO;
break;
/*
* We might like to report bad mount options here;
......@@ -352,8 +336,7 @@ static int tracefs_parse_options(char *data, struct tracefs_mount_opts *opts)
*/
}
opts->opts |= BIT(token);
}
opts->opts |= BIT(opt);
return 0;
}
......@@ -362,7 +345,6 @@ static int tracefs_apply_options(struct super_block *sb, bool remount)
{
struct tracefs_fs_info *fsi = sb->s_fs_info;
struct inode *inode = d_inode(sb->s_root);
struct tracefs_mount_opts *opts = &fsi->mount_opts;
struct tracefs_inode *ti;
bool update_uid, update_gid;
umode_t tmp_mode;
......@@ -372,22 +354,22 @@ static int tracefs_apply_options(struct super_block *sb, bool remount)
* 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 |= opts->mode;
tmp_mode |= fsi->mode;
WRITE_ONCE(inode->i_mode, tmp_mode);
}
if (!remount || opts->opts & BIT(Opt_uid))
inode->i_uid = opts->uid;
if (!remount || fsi->opts & BIT(Opt_uid))
inode->i_uid = fsi->uid;
if (!remount || opts->opts & BIT(Opt_gid))
inode->i_gid = opts->gid;
if (!remount || fsi->opts & BIT(Opt_gid))
inode->i_gid = fsi->gid;
if (remount && (opts->opts & BIT(Opt_uid) || opts->opts & BIT(Opt_gid))) {
if (remount && (fsi->opts & BIT(Opt_uid) || fsi->opts & BIT(Opt_gid))) {
update_uid = opts->opts & BIT(Opt_uid);
update_gid = opts->opts & BIT(Opt_gid);
update_uid = fsi->opts & BIT(Opt_uid);
update_gid = fsi->opts & BIT(Opt_gid);
rcu_read_lock();
list_for_each_entry_rcu(ti, &tracefs_inodes, list) {
......@@ -406,35 +388,31 @@ static int tracefs_apply_options(struct super_block *sb, bool remount)
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 tracefs_fs_info *fsi = sb->s_fs_info;
struct super_block *sb = fc->root->d_sb;
struct tracefs_fs_info *sb_opts = sb->s_fs_info;
struct tracefs_fs_info *new_opts = fc->s_fs_info;
sync_filesystem(sb);
err = tracefs_parse_options(data, &fsi->mount_opts);
if (err)
goto fail;
tracefs_apply_options(sb, true);
/* structure copy of new mount options to sb */
*sb_opts = *new_opts;
fail:
return err;
return tracefs_apply_options(sb, true);
}
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_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",
from_kuid_munged(&init_user_ns, opts->uid));
if (!gid_eq(opts->gid, GLOBAL_ROOT_GID))
from_kuid_munged(&init_user_ns, fsi->uid));
if (!gid_eq(fsi->gid, GLOBAL_ROOT_GID))
seq_printf(m, ",gid=%u",
from_kgid_munged(&init_user_ns, opts->gid));
if (opts->mode != TRACEFS_DEFAULT_MODE)
seq_printf(m, ",mode=%o", opts->mode);
from_kgid_munged(&init_user_ns, fsi->gid));
if (fsi->mode != TRACEFS_DEFAULT_MODE)
seq_printf(m, ",mode=%o", fsi->mode);
return 0;
}
......@@ -444,7 +422,6 @@ static const struct super_operations tracefs_super_operations = {
.free_inode = tracefs_free_inode,
.drop_inode = generic_delete_inode,
.statfs = simple_statfs,
.remount_fs = tracefs_remount,
.show_options = tracefs_show_options,
};
......@@ -489,26 +466,14 @@ static const struct dentry_operations tracefs_dentry_operations = {
.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[] = {{""}};
struct tracefs_fs_info *fsi;
int err;
fsi = kzalloc(sizeof(struct tracefs_fs_info), GFP_KERNEL);
sb->s_fs_info = fsi;
if (!fsi) {
err = -ENOMEM;
goto fail;
}
err = tracefs_parse_options(data, &fsi->mount_opts);
if (err)
goto fail;
err = simple_fill_super(sb, TRACEFS_MAGIC, trace_files);
if (err)
goto fail;
return err;
sb->s_op = &tracefs_super_operations;
sb->s_d_op = &tracefs_dentry_operations;
......@@ -516,24 +481,45 @@ static int trace_fill_super(struct super_block *sb, void *data, int silent)
tracefs_apply_options(sb, false);
return 0;
}
fail:
kfree(fsi);
sb->s_fs_info = NULL;
return err;
static int tracefs_get_tree(struct fs_context *fc)
{
return get_tree_single(fc, tracefs_fill_super);
}
static struct dentry *trace_mount(struct file_system_type *fs_type,
int flags, const char *dev_name,
void *data)
static void tracefs_free_fc(struct fs_context *fc)
{
return mount_single(fs_type, flags, data, trace_fill_super);
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 = {
.owner = THIS_MODULE,
.name = "tracefs",
.mount = trace_mount,
.init_fs_context = tracefs_init_fs_context,
.parameters = tracefs_param_specs,
.kill_sb = kill_litter_super,
};
MODULE_ALIAS_FS("tracefs");
......
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