Commit 0d63d8b2 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'vfs-6.7.autofs' of gitolite.kernel.org:pub/scm/linux/kernel/git/vfs/vfs

Pull autofs mount api updates from Christian Brauner:
 "This ports autofs to the new mount api. The patchset has existed for
  quite a while but never made it upstream. Ian picked it back up.

  This also fixes a bug where fs_param_is_fd() was passed a garbage
  param->dirfd but it expected it to be set to the fd that was used to
  set param->file otherwise result->uint_32 contains nonsense. So make
  sure it's set.

  One less filesystem using the old mount api. We're getting there,
  albeit rather slow. The last remaining major filesystem that hasn't
  converted is btrfs. Patches exist - I even wrote them - but so far
  they haven't made it upstream"

* tag 'vfs-6.7.autofs' of gitolite.kernel.org:pub/scm/linux/kernel/git/vfs/vfs:
  autofs: fix add autofs_parse_fd()
  fsconfig: ensure that dirfd is set to aux
  autofs: fix protocol sub version setting
  autofs: convert autofs to use the new mount api
  autofs: validate protocol version
  autofs: refactor parse_options()
  autofs: reformat 0pt enum declaration
  autofs: refactor super block info init
  autofs: add autofs_parse_fd()
  autofs: refactor autofs_prepare_pipe()
parents d4e175f2 d3c50061
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include <linux/completion.h> #include <linux/completion.h>
#include <linux/file.h> #include <linux/file.h>
#include <linux/magic.h> #include <linux/magic.h>
#include <linux/fs_context.h>
#include <linux/fs_parser.h>
/* This is the range of ioctl() numbers we claim as ours */ /* This is the range of ioctl() numbers we claim as ours */
#define AUTOFS_IOC_FIRST AUTOFS_IOC_READY #define AUTOFS_IOC_FIRST AUTOFS_IOC_READY
...@@ -205,20 +207,34 @@ static inline void managed_dentry_clear_managed(struct dentry *dentry) ...@@ -205,20 +207,34 @@ static inline void managed_dentry_clear_managed(struct dentry *dentry)
/* Initializing function */ /* Initializing function */
int autofs_fill_super(struct super_block *, void *, int); extern const struct fs_parameter_spec autofs_param_specs[];
int autofs_init_fs_context(struct fs_context *fc);
struct autofs_info *autofs_new_ino(struct autofs_sb_info *); struct autofs_info *autofs_new_ino(struct autofs_sb_info *);
void autofs_clean_ino(struct autofs_info *); void autofs_clean_ino(struct autofs_info *);
static inline int autofs_prepare_pipe(struct file *pipe) static inline int autofs_check_pipe(struct file *pipe)
{ {
if (!(pipe->f_mode & FMODE_CAN_WRITE)) if (!(pipe->f_mode & FMODE_CAN_WRITE))
return -EINVAL; return -EINVAL;
if (!S_ISFIFO(file_inode(pipe)->i_mode)) if (!S_ISFIFO(file_inode(pipe)->i_mode))
return -EINVAL; return -EINVAL;
return 0;
}
static inline void autofs_set_packet_pipe_flags(struct file *pipe)
{
/* We want a packet pipe */ /* We want a packet pipe */
pipe->f_flags |= O_DIRECT; pipe->f_flags |= O_DIRECT;
/* We don't expect -EAGAIN */ /* We don't expect -EAGAIN */
pipe->f_flags &= ~O_NONBLOCK; pipe->f_flags &= ~O_NONBLOCK;
}
static inline int autofs_prepare_pipe(struct file *pipe)
{
int ret = autofs_check_pipe(pipe);
if (ret < 0)
return ret;
autofs_set_packet_pipe_flags(pipe);
return 0; return 0;
} }
......
...@@ -7,16 +7,11 @@ ...@@ -7,16 +7,11 @@
#include <linux/init.h> #include <linux/init.h>
#include "autofs_i.h" #include "autofs_i.h"
static struct dentry *autofs_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
{
return mount_nodev(fs_type, flags, data, autofs_fill_super);
}
struct file_system_type autofs_fs_type = { struct file_system_type autofs_fs_type = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "autofs", .name = "autofs",
.mount = autofs_mount, .init_fs_context = autofs_init_fs_context,
.parameters = autofs_param_specs,
.kill_sb = autofs_kill_sb, .kill_sb = autofs_kill_sb,
}; };
MODULE_ALIAS_FS("autofs"); MODULE_ALIAS_FS("autofs");
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/pagemap.h> #include <linux/pagemap.h>
#include <linux/parser.h>
#include "autofs_i.h" #include "autofs_i.h"
...@@ -110,91 +109,122 @@ static const struct super_operations autofs_sops = { ...@@ -110,91 +109,122 @@ static const struct super_operations autofs_sops = {
.evict_inode = autofs_evict_inode, .evict_inode = autofs_evict_inode,
}; };
enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto, enum {
Opt_indirect, Opt_direct, Opt_offset, Opt_strictexpire, Opt_direct,
Opt_ignore}; Opt_fd,
Opt_gid,
static const match_table_t tokens = { Opt_ignore,
{Opt_fd, "fd=%u"}, Opt_indirect,
{Opt_uid, "uid=%u"}, Opt_maxproto,
{Opt_gid, "gid=%u"}, Opt_minproto,
{Opt_pgrp, "pgrp=%u"}, Opt_offset,
{Opt_minproto, "minproto=%u"}, Opt_pgrp,
{Opt_maxproto, "maxproto=%u"}, Opt_strictexpire,
{Opt_indirect, "indirect"}, Opt_uid,
{Opt_direct, "direct"},
{Opt_offset, "offset"},
{Opt_strictexpire, "strictexpire"},
{Opt_ignore, "ignore"},
{Opt_err, NULL}
}; };
static int parse_options(char *options, const struct fs_parameter_spec autofs_param_specs[] = {
struct inode *root, int *pgrp, bool *pgrp_set, fsparam_flag ("direct", Opt_direct),
struct autofs_sb_info *sbi) fsparam_fd ("fd", Opt_fd),
{ fsparam_u32 ("gid", Opt_gid),
char *p; fsparam_flag ("ignore", Opt_ignore),
substring_t args[MAX_OPT_ARGS]; fsparam_flag ("indirect", Opt_indirect),
int option; fsparam_u32 ("maxproto", Opt_maxproto),
int pipefd = -1; fsparam_u32 ("minproto", Opt_minproto),
fsparam_flag ("offset", Opt_offset),
fsparam_u32 ("pgrp", Opt_pgrp),
fsparam_flag ("strictexpire", Opt_strictexpire),
fsparam_u32 ("uid", Opt_uid),
{}
};
struct autofs_fs_context {
kuid_t uid; kuid_t uid;
kgid_t gid; kgid_t gid;
int pgrp;
bool pgrp_set;
};
root->i_uid = current_uid(); /*
root->i_gid = current_gid(); * Open the fd. We do it here rather than in get_tree so that it's done in the
* context of the system call that passed the data and not the one that
* triggered the superblock creation, lest the fd gets reassigned.
*/
static int autofs_parse_fd(struct fs_context *fc, struct autofs_sb_info *sbi,
struct fs_parameter *param,
struct fs_parse_result *result)
{
struct file *pipe;
int ret;
sbi->min_proto = AUTOFS_MIN_PROTO_VERSION; if (param->type == fs_value_is_file) {
sbi->max_proto = AUTOFS_MAX_PROTO_VERSION; /* came through the new api */
pipe = param->file;
param->file = NULL;
} else {
pipe = fget(result->uint_32);
}
if (!pipe) {
errorf(fc, "could not open pipe file descriptor");
return -EBADF;
}
sbi->pipefd = -1; ret = autofs_check_pipe(pipe);
if (ret < 0) {
errorf(fc, "Invalid/unusable pipe");
if (param->type != fs_value_is_file)
fput(pipe);
return -EBADF;
}
autofs_set_packet_pipe_flags(pipe);
if (!options) if (sbi->pipe)
return 1; fput(sbi->pipe);
sbi->pipefd = result->uint_32;
sbi->pipe = pipe;
while ((p = strsep(&options, ",")) != NULL) { return 0;
int token; }
static int autofs_parse_param(struct fs_context *fc, struct fs_parameter *param)
{
struct autofs_fs_context *ctx = fc->fs_private;
struct autofs_sb_info *sbi = fc->s_fs_info;
struct fs_parse_result result;
kuid_t uid;
kgid_t gid;
int opt;
if (!*p) opt = fs_parse(fc, autofs_param_specs, param, &result);
continue; if (opt < 0)
return opt;
token = match_token(p, tokens, args); switch (opt) {
switch (token) {
case Opt_fd: case Opt_fd:
if (match_int(args, &pipefd)) return autofs_parse_fd(fc, sbi, param, &result);
return 1;
sbi->pipefd = pipefd;
break;
case Opt_uid: case Opt_uid:
if (match_int(args, &option)) uid = make_kuid(current_user_ns(), result.uint_32);
return 1;
uid = make_kuid(current_user_ns(), option);
if (!uid_valid(uid)) if (!uid_valid(uid))
return 1; return invalfc(fc, "Invalid uid");
root->i_uid = uid; ctx->uid = uid;
break; break;
case Opt_gid: case Opt_gid:
if (match_int(args, &option)) gid = make_kgid(current_user_ns(), result.uint_32);
return 1;
gid = make_kgid(current_user_ns(), option);
if (!gid_valid(gid)) if (!gid_valid(gid))
return 1; return invalfc(fc, "Invalid gid");
root->i_gid = gid; ctx->gid = gid;
break; break;
case Opt_pgrp: case Opt_pgrp:
if (match_int(args, &option)) ctx->pgrp = result.uint_32;
return 1; ctx->pgrp_set = true;
*pgrp = option;
*pgrp_set = true;
break; break;
case Opt_minproto: case Opt_minproto:
if (match_int(args, &option)) sbi->min_proto = result.uint_32;
return 1;
sbi->min_proto = option;
break; break;
case Opt_maxproto: case Opt_maxproto:
if (match_int(args, &option)) sbi->max_proto = result.uint_32;
return 1;
sbi->max_proto = option;
break; break;
case Opt_indirect: case Opt_indirect:
set_autofs_type_indirect(&sbi->type); set_autofs_type_indirect(&sbi->type);
...@@ -210,89 +240,48 @@ static int parse_options(char *options, ...@@ -210,89 +240,48 @@ static int parse_options(char *options,
break; break;
case Opt_ignore: case Opt_ignore:
sbi->flags |= AUTOFS_SBI_IGNORE; sbi->flags |= AUTOFS_SBI_IGNORE;
break;
default:
return 1;
} }
}
return (sbi->pipefd < 0); return 0;
} }
int autofs_fill_super(struct super_block *s, void *data, int silent) static struct autofs_sb_info *autofs_alloc_sbi(void)
{ {
struct inode *root_inode;
struct dentry *root;
struct file *pipe;
struct autofs_sb_info *sbi; struct autofs_sb_info *sbi;
struct autofs_info *ino;
int pgrp = 0;
bool pgrp_set = false;
int ret = -EINVAL;
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
if (!sbi) if (!sbi)
return -ENOMEM; return NULL;
pr_debug("starting up, sbi = %p\n", sbi);
s->s_fs_info = sbi;
sbi->magic = AUTOFS_SBI_MAGIC; sbi->magic = AUTOFS_SBI_MAGIC;
sbi->pipefd = -1;
sbi->pipe = NULL;
sbi->exp_timeout = 0;
sbi->oz_pgrp = NULL;
sbi->sb = s;
sbi->version = 0;
sbi->sub_version = 0;
sbi->flags = AUTOFS_SBI_CATATONIC; sbi->flags = AUTOFS_SBI_CATATONIC;
sbi->min_proto = AUTOFS_MIN_PROTO_VERSION;
sbi->max_proto = AUTOFS_MAX_PROTO_VERSION;
sbi->pipefd = -1;
set_autofs_type_indirect(&sbi->type); set_autofs_type_indirect(&sbi->type);
sbi->min_proto = 0;
sbi->max_proto = 0;
mutex_init(&sbi->wq_mutex); mutex_init(&sbi->wq_mutex);
mutex_init(&sbi->pipe_mutex); mutex_init(&sbi->pipe_mutex);
spin_lock_init(&sbi->fs_lock); spin_lock_init(&sbi->fs_lock);
sbi->queues = NULL;
spin_lock_init(&sbi->lookup_lock); spin_lock_init(&sbi->lookup_lock);
INIT_LIST_HEAD(&sbi->active_list); INIT_LIST_HEAD(&sbi->active_list);
INIT_LIST_HEAD(&sbi->expiring_list); INIT_LIST_HEAD(&sbi->expiring_list);
s->s_blocksize = 1024;
s->s_blocksize_bits = 10;
s->s_magic = AUTOFS_SUPER_MAGIC;
s->s_op = &autofs_sops;
s->s_d_op = &autofs_dentry_operations;
s->s_time_gran = 1;
/*
* Get the root inode and dentry, but defer checking for errors.
*/
ino = autofs_new_ino(sbi);
if (!ino) {
ret = -ENOMEM;
goto fail_free;
}
root_inode = autofs_get_inode(s, S_IFDIR | 0755);
root = d_make_root(root_inode);
if (!root) {
ret = -ENOMEM;
goto fail_ino;
}
pipe = NULL;
root->d_fsdata = ino; return sbi;
}
/* Can this call block? */ static int autofs_validate_protocol(struct fs_context *fc)
if (parse_options(data, root_inode, &pgrp, &pgrp_set, sbi)) { {
pr_err("called with bogus options\n"); struct autofs_sb_info *sbi = fc->s_fs_info;
goto fail_dput;
}
/* Test versions first */ /* Test versions first */
if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION || if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION ||
sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) { sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) {
pr_err("kernel does not match daemon version " errorf(fc, "kernel does not match daemon version "
"daemon (%d, %d) kernel (%d, %d)\n", "daemon (%d, %d) kernel (%d, %d)\n",
sbi->min_proto, sbi->max_proto, sbi->min_proto, sbi->max_proto,
AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION); AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
goto fail_dput; return -EINVAL;
} }
/* Establish highest kernel protocol version */ /* Establish highest kernel protocol version */
...@@ -300,13 +289,62 @@ int autofs_fill_super(struct super_block *s, void *data, int silent) ...@@ -300,13 +289,62 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
sbi->version = AUTOFS_MAX_PROTO_VERSION; sbi->version = AUTOFS_MAX_PROTO_VERSION;
else else
sbi->version = sbi->max_proto; sbi->version = sbi->max_proto;
switch (sbi->version) {
case 4:
sbi->sub_version = 7;
break;
case 5:
sbi->sub_version = AUTOFS_PROTO_SUBVERSION; sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
break;
default:
sbi->sub_version = 0;
}
return 0;
}
static int autofs_fill_super(struct super_block *s, struct fs_context *fc)
{
struct autofs_fs_context *ctx = fc->fs_private;
struct autofs_sb_info *sbi = s->s_fs_info;
struct inode *root_inode;
struct dentry *root;
struct autofs_info *ino;
int ret = -ENOMEM;
pr_debug("starting up, sbi = %p\n", sbi);
sbi->sb = s;
s->s_blocksize = 1024;
s->s_blocksize_bits = 10;
s->s_magic = AUTOFS_SUPER_MAGIC;
s->s_op = &autofs_sops;
s->s_d_op = &autofs_dentry_operations;
s->s_time_gran = 1;
/*
* Get the root inode and dentry, but defer checking for errors.
*/
ino = autofs_new_ino(sbi);
if (!ino)
goto fail;
root_inode = autofs_get_inode(s, S_IFDIR | 0755);
root_inode->i_uid = ctx->uid;
root_inode->i_gid = ctx->gid;
if (pgrp_set) { root = d_make_root(root_inode);
sbi->oz_pgrp = find_get_pid(pgrp); if (!root)
goto fail_ino;
root->d_fsdata = ino;
if (ctx->pgrp_set) {
sbi->oz_pgrp = find_get_pid(ctx->pgrp);
if (!sbi->oz_pgrp) { if (!sbi->oz_pgrp) {
pr_err("could not find process group %d\n", ret = invalf(fc, "Could not find process group %d",
pgrp); ctx->pgrp);
goto fail_dput; goto fail_dput;
} }
} else { } else {
...@@ -321,16 +359,7 @@ int autofs_fill_super(struct super_block *s, void *data, int silent) ...@@ -321,16 +359,7 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
pr_debug("pipe fd = %d, pgrp = %u\n", pr_debug("pipe fd = %d, pgrp = %u\n",
sbi->pipefd, pid_nr(sbi->oz_pgrp)); sbi->pipefd, pid_nr(sbi->oz_pgrp));
pipe = fget(sbi->pipefd);
if (!pipe) {
pr_err("could not open pipe file descriptor\n");
goto fail_put_pid;
}
ret = autofs_prepare_pipe(pipe);
if (ret < 0)
goto fail_fput;
sbi->pipe = pipe;
sbi->flags &= ~AUTOFS_SBI_CATATONIC; sbi->flags &= ~AUTOFS_SBI_CATATONIC;
/* /*
...@@ -342,20 +371,80 @@ int autofs_fill_super(struct super_block *s, void *data, int silent) ...@@ -342,20 +371,80 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
/* /*
* Failure ... clean up. * Failure ... clean up.
*/ */
fail_fput:
pr_err("pipe file descriptor does not contain proper ops\n");
fput(pipe);
fail_put_pid:
put_pid(sbi->oz_pgrp);
fail_dput: fail_dput:
dput(root); dput(root);
goto fail_free; goto fail;
fail_ino: fail_ino:
autofs_free_ino(ino); autofs_free_ino(ino);
fail_free: fail:
kfree(sbi); return ret;
s->s_fs_info = NULL; }
/*
* Validate the parameters and then request a superblock.
*/
static int autofs_get_tree(struct fs_context *fc)
{
struct autofs_sb_info *sbi = fc->s_fs_info;
int ret;
ret = autofs_validate_protocol(fc);
if (ret)
return ret; return ret;
if (sbi->pipefd < 0)
return invalf(fc, "No control pipe specified");
return get_tree_nodev(fc, autofs_fill_super);
}
static void autofs_free_fc(struct fs_context *fc)
{
struct autofs_fs_context *ctx = fc->fs_private;
struct autofs_sb_info *sbi = fc->s_fs_info;
if (sbi) {
if (sbi->pipe)
fput(sbi->pipe);
kfree(sbi);
}
kfree(ctx);
}
static const struct fs_context_operations autofs_context_ops = {
.free = autofs_free_fc,
.parse_param = autofs_parse_param,
.get_tree = autofs_get_tree,
};
/*
* Set up the filesystem mount context.
*/
int autofs_init_fs_context(struct fs_context *fc)
{
struct autofs_fs_context *ctx;
struct autofs_sb_info *sbi;
ctx = kzalloc(sizeof(struct autofs_fs_context), GFP_KERNEL);
if (!ctx)
goto nomem;
ctx->uid = current_uid();
ctx->gid = current_gid();
sbi = autofs_alloc_sbi();
if (!sbi)
goto nomem_ctx;
fc->fs_private = ctx;
fc->s_fs_info = sbi;
fc->ops = &autofs_context_ops;
return 0;
nomem_ctx:
kfree(ctx);
nomem:
return -ENOMEM;
} }
struct inode *autofs_get_inode(struct super_block *sb, umode_t mode) struct inode *autofs_get_inode(struct super_block *sb, umode_t mode)
......
...@@ -465,6 +465,7 @@ SYSCALL_DEFINE5(fsconfig, ...@@ -465,6 +465,7 @@ SYSCALL_DEFINE5(fsconfig,
param.file = fget(aux); param.file = fget(aux);
if (!param.file) if (!param.file)
goto out_key; goto out_key;
param.dirfd = aux;
break; break;
default: default:
break; break;
......
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