Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1665947 > unrolled thread
| Started by | David Howells <dhowells@redhat.com> |
|---|---|
| First post | 2017-06-14 17:20 +0200 |
| Last post | 2017-06-16 18:00 +0200 |
| Articles | 20 on this page of 42 — 8 participants |
Back to article view | Back to linux.kernel
[RFC][PATCH 00/27] VFS: Introduce filesystem context [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:20 +0200
[PATCH 11/27] VFS: Remove unused code after filesystem context changes [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:20 +0200
[PATCH 20/27] NFS: Split nfs_parse_mount_options() [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:20 +0200
[PATCH 03/27] VFS: Make get_mnt_ns() return the namespace [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:20 +0200
Re: [PATCH 03/27] VFS: Make get_mnt_ns() return the namespace [ver #5] Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-15 11:20 +0200
[PATCH 27/27] kernfs, sysfs, cgroup: Support fs_context [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:20 +0200
Re: [PATCH 27/27] kernfs, sysfs, cgroup: Support fs_context [ver #5] Tejun Heo <tj@kernel.org> - 2017-06-14 20:00 +0200
Re: [PATCH 27/27] ... and the intel_rdt driver David Howells <dhowells@redhat.com> - 2017-06-15 00:40 +0200
[PATCH 26/27] cpuset: Use fs_context [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:20 +0200
[PATCH 16/27] proc: Add fs_context support to procfs [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:20 +0200
Re: [PATCH 16/27] proc: Add fs_context support to procfs [ver #5] Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-15 12:20 +0200
[PATCH 01/27] Provide a function to create a NUL-terminated string from unterminated data [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:20 +0200
[PATCH 09/27] VFS: Add LSM hooks for filesystem context [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:20 +0200
[PATCH 25/27] ipc: Convert mqueue fs to fs_context [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:20 +0200
Re: [PATCH 25/27] ipc: Convert mqueue fs to fs_context [ver #5] Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-15 12:10 +0200
Re: [PATCH 25/27] ipc: Convert mqueue fs to fs_context [ver #5] David Howells <dhowells@redhat.com> - 2017-06-15 16:50 +0200
[PATCH 23/27] NFS: Do some tidying of the parsing code [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:20 +0200
[PATCH 22/27] NFS: Add a small buffer in nfs_fs_context to avoid string dup [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:20 +0200
[PATCH 14/27] VFS: Add a sample program for fsopen/fsmount [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:20 +0200
[PATCH 02/27] VFS: Clean up whitespace in fs/namespace.c and fs/super.c [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:20 +0200
[PATCH 04/27] VFS: Make get_filesystem() return the affected filesystem [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:20 +0200
[PATCH 18/27] NFS: Constify mount argument match tables [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:20 +0200
[PATCH 05/27] VFS: Provide empty name qstr [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:30 +0200
[PATCH 15/27] procfs: Move proc_fill_super() to fs/proc/root.c [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:30 +0200
[PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:30 +0200
Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] Randy Dunlap <rdunlap@infradead.org> - 2017-06-14 20:10 +0200
Updated docs David Howells <dhowells@redhat.com> - 2017-06-15 01:00 +0200
Re: Updated docs Randy Dunlap <rdunlap@infradead.org> - 2017-06-15 04:00 +0200
Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] Casey Schaufler <casey@schaufler-ca.com> - 2017-06-14 22:10 +0200
Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 22:50 +0200
Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] Casey Schaufler <casey@schaufler-ca.com> - 2017-06-14 23:00 +0200
Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] Theodore Ts'o <tytso@mit.edu> - 2017-06-17 12:00 +0200
Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] David Howells <dhowells@redhat.com> - 2017-06-17 16:20 +0200
Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] Jeff Layton <jlayton@redhat.com> - 2017-06-17 17:00 +0200
Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] Randy Dunlap <rdunlap@infradead.org> - 2017-06-17 17:20 +0200
Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] David Howells <dhowells@redhat.com> - 2017-06-19 09:50 +0200
[PATCH 21/27] NFS: Deindent nfs_fs_context_parse_option() [ver #5] David Howells <dhowells@redhat.com> - 2017-06-14 17:30 +0200
Re: [PATCH 07/27] VFS: Differentiate mount flags (MS_*) from internal superblock flags [ver #5] Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-15 11:50 +0200
Re: [PATCH 07/27] VFS: Differentiate mount flags (MS_*) from internal superblock flags [ver #5] Christoph Hellwig <hch@infradead.org> - 2017-06-16 11:10 +0200
Re: [PATCH 07/27] VFS: Differentiate mount flags (MS_*) from internal superblock flags [ver #5] David Howells <dhowells@redhat.com> - 2017-06-16 17:00 +0200
Re: [PATCH 07/27] VFS: Differentiate mount flags (MS_*) from internal superblock flags [ver #5] Christoph Hellwig <hch@infradead.org> - 2017-06-16 18:00 +0200
Re: [PATCH 07/27] VFS: Differentiate mount flags (MS_*) from internal superblock flags [ver #5] David Howells <dhowells@redhat.com> - 2017-06-16 18:00 +0200
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2017-06-14 17:20 +0200 |
| Subject | [PATCH 04/27] VFS: Make get_filesystem() return the affected filesystem [ver #5] |
| Message-ID | <tSifq-6QJ-67@gated-at.bofh.it> |
| In reply to | #1665947 |
Make get_filesystem() return a pointer to the filesystem on which it just
got a ref.
Suggested-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: David Howells <dhowells@redhat.com>
---
fs/filesystems.c | 3 ++-
include/linux/fs.h | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/filesystems.c b/fs/filesystems.c
index cac75547d35c..591e52d23ed4 100644
--- a/fs/filesystems.c
+++ b/fs/filesystems.c
@@ -33,9 +33,10 @@ static struct file_system_type *file_systems;
static DEFINE_RWLOCK(file_systems_lock);
/* WARNING: This can be used only if we _already_ own a reference */
-void get_filesystem(struct file_system_type *fs)
+struct file_system_type *get_filesystem(struct file_system_type *fs)
{
__module_get(fs->owner);
+ return fs;
}
void put_filesystem(struct file_system_type *fs)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 803e5a9b2654..bc0c054894b9 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2956,7 +2956,7 @@ extern int generic_block_fiemap(struct inode *inode,
struct fiemap_extent_info *fieinfo, u64 start,
u64 len, get_block_t *get_block);
-extern void get_filesystem(struct file_system_type *fs);
+extern struct file_system_type *get_filesystem(struct file_system_type *fs);
extern void put_filesystem(struct file_system_type *fs);
extern struct file_system_type *get_fs_type(const char *name);
extern struct super_block *get_super(struct block_device *);
[toc] | [prev] | [next] | [standalone]
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2017-06-14 17:20 +0200 |
| Subject | [PATCH 18/27] NFS: Constify mount argument match tables [ver #5] |
| Message-ID | <tSifq-6QJ-93@gated-at.bofh.it> |
| In reply to | #1665947 |
The mount argument match tables should never be altered so constify them.
Signed-off-by: David Howells <dhowells@redhat.com>
---
fs/nfs/fs_context.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/nfs/fs_context.c b/fs/nfs/fs_context.c
index 3e2fe57b9b07..a41f034aafb2 100644
--- a/fs/nfs/fs_context.c
+++ b/fs/nfs/fs_context.c
@@ -197,7 +197,7 @@ enum {
Opt_lookupcache_err
};
-static match_table_t nfs_lookupcache_tokens = {
+static const match_table_t nfs_lookupcache_tokens = {
{ Opt_lookupcache_all, "all" },
{ Opt_lookupcache_positive, "pos" },
{ Opt_lookupcache_positive, "positive" },
@@ -213,7 +213,7 @@ enum {
Opt_local_lock_err
};
-static match_table_t nfs_local_lock_tokens = {
+static const match_table_t nfs_local_lock_tokens = {
{ Opt_local_lock_all, "all" },
{ Opt_local_lock_flock, "flock" },
{ Opt_local_lock_posix, "posix" },
@@ -229,7 +229,7 @@ enum {
Opt_vers_err
};
-static match_table_t nfs_vers_tokens = {
+static const match_table_t nfs_vers_tokens = {
{ Opt_vers_2, "2" },
{ Opt_vers_3, "3" },
{ Opt_vers_4, "4" },
[toc] | [prev] | [next] | [standalone]
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2017-06-14 17:30 +0200 |
| Subject | [PATCH 05/27] VFS: Provide empty name qstr [ver #5] |
| Message-ID | <tSip3-6TQ-5@gated-at.bofh.it> |
| In reply to | #1665947 |
Provide an empty name (ie. "") qstr for general use.
Signed-off-by: David Howells <dhowells@redhat.com>
---
fs/dcache.c | 8 ++++++--
fs/gfs2/dir.c | 3 +--
fs/namei.c | 3 +--
fs/nsfs.c | 3 +--
fs/pipe.c | 3 +--
include/linux/dcache.h | 5 +++++
6 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/fs/dcache.c b/fs/dcache.c
index cddf39777835..d3da2a3ffd73 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -90,6 +90,11 @@ EXPORT_SYMBOL(rename_lock);
static struct kmem_cache *dentry_cache __read_mostly;
+const struct qstr empty_name = QSTR_INIT("", 0);
+EXPORT_SYMBOL(empty_name);
+const struct qstr slash_name = QSTR_INIT("/", 1);
+EXPORT_SYMBOL(slash_name);
+
/*
* This is the single most critical data structure when it comes
* to the dcache: the hashtable for lookups. Somebody should try
@@ -1580,8 +1585,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
*/
dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
if (unlikely(!name)) {
- static const struct qstr anon = QSTR_INIT("/", 1);
- name = &anon;
+ name = &slash_name;
dname = dentry->d_iname;
} else if (name->len > DNAME_INLINE_LEN-1) {
size_t size = offsetof(struct external_name, name[1]);
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
index 79113219be5f..a5dfff6a033e 100644
--- a/fs/gfs2/dir.c
+++ b/fs/gfs2/dir.c
@@ -872,7 +872,6 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh,
struct buffer_head *bh;
struct gfs2_leaf *leaf;
struct gfs2_dirent *dent;
- struct qstr name = { .name = "" };
struct timespec tv = current_time(inode);
error = gfs2_alloc_blocks(ip, &bn, &n, 0, NULL);
@@ -896,7 +895,7 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh,
leaf->lf_sec = cpu_to_be64(tv.tv_sec);
memset(leaf->lf_reserved2, 0, sizeof(leaf->lf_reserved2));
dent = (struct gfs2_dirent *)(leaf+1);
- gfs2_qstr2dirent(&name, bh->b_size - sizeof(struct gfs2_leaf), dent);
+ gfs2_qstr2dirent(&empty_name, bh->b_size - sizeof(struct gfs2_leaf), dent);
*pbh = bh;
return leaf;
}
diff --git a/fs/namei.c b/fs/namei.c
index 6571a5f5112e..0d35760fee00 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -3400,7 +3400,6 @@ static int do_last(struct nameidata *nd,
struct dentry *vfs_tmpfile(struct dentry *dentry, umode_t mode, int open_flag)
{
- static const struct qstr name = QSTR_INIT("/", 1);
struct dentry *child = NULL;
struct inode *dir = dentry->d_inode;
struct inode *inode;
@@ -3414,7 +3413,7 @@ struct dentry *vfs_tmpfile(struct dentry *dentry, umode_t mode, int open_flag)
if (!dir->i_op->tmpfile)
goto out_err;
error = -ENOMEM;
- child = d_alloc(dentry, &name);
+ child = d_alloc(dentry, &slash_name);
if (unlikely(!child))
goto out_err;
error = dir->i_op->tmpfile(dir, child, mode);
diff --git a/fs/nsfs.c b/fs/nsfs.c
index f3db56e83dd2..08127a2b8559 100644
--- a/fs/nsfs.c
+++ b/fs/nsfs.c
@@ -53,7 +53,6 @@ static void nsfs_evict(struct inode *inode)
static void *__ns_get_path(struct path *path, struct ns_common *ns)
{
struct vfsmount *mnt = nsfs_mnt;
- struct qstr qname = { .name = "", };
struct dentry *dentry;
struct inode *inode;
unsigned long d;
@@ -85,7 +84,7 @@ static void *__ns_get_path(struct path *path, struct ns_common *ns)
inode->i_fop = &ns_file_operations;
inode->i_private = ns;
- dentry = d_alloc_pseudo(mnt->mnt_sb, &qname);
+ dentry = d_alloc_pseudo(mnt->mnt_sb, &empty_name);
if (!dentry) {
iput(inode);
return ERR_PTR(-ENOMEM);
diff --git a/fs/pipe.c b/fs/pipe.c
index 73b84baf58f8..97e5be897753 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -739,13 +739,12 @@ int create_pipe_files(struct file **res, int flags)
struct inode *inode = get_pipe_inode();
struct file *f;
struct path path;
- static struct qstr name = { .name = "" };
if (!inode)
return -ENFILE;
err = -ENOMEM;
- path.dentry = d_alloc_pseudo(pipe_mnt->mnt_sb, &name);
+ path.dentry = d_alloc_pseudo(pipe_mnt->mnt_sb, &empty_name);
if (!path.dentry)
goto err_inode;
path.mnt = mntget(pipe_mnt);
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index d2e38dc6172c..3f65a4fa72ed 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -55,6 +55,11 @@ struct qstr {
#define QSTR_INIT(n,l) { { { .len = l } }, .name = n }
+extern const char empty_string[];
+extern const struct qstr empty_name;
+extern const char slash_string[];
+extern const struct qstr slash_name;
+
struct dentry_stat_t {
long nr_dentry;
long nr_unused;
[toc] | [prev] | [next] | [standalone]
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2017-06-14 17:30 +0200 |
| Subject | [PATCH 15/27] procfs: Move proc_fill_super() to fs/proc/root.c [ver #5] |
| Message-ID | <tSip4-6TQ-21@gated-at.bofh.it> |
| In reply to | #1665947 |
Move proc_fill_super() to fs/proc/root.c as that's where the other
superblock stuff is.
Signed-off-by: David Howells <dhowells@redhat.com>
---
fs/proc/inode.c | 48 +-----------------------------------------------
fs/proc/internal.h | 4 +---
fs/proc/root.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 49 insertions(+), 51 deletions(-)
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 0163d71d5887..a4bf66af0ba9 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -22,7 +22,6 @@
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/mount.h>
-#include <linux/magic.h>
#include <linux/uaccess.h>
@@ -113,7 +112,7 @@ static int proc_show_options(struct seq_file *seq, struct dentry *root)
return 0;
}
-static const struct super_operations proc_sops = {
+const struct super_operations proc_sops = {
.alloc_inode = proc_alloc_inode,
.destroy_inode = proc_destroy_inode,
.drop_inode = generic_delete_inode,
@@ -470,48 +469,3 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
pde_put(de);
return inode;
}
-
-int proc_fill_super(struct super_block *s, void *data, int silent)
-{
- struct pid_namespace *ns = get_pid_ns(s->s_fs_info);
- struct inode *root_inode;
- int ret;
-
- if (!proc_parse_options(data, ns))
- return -EINVAL;
-
- /* User space would break if executables or devices appear on proc */
- s->s_iflags |= SB_I_USERNS_VISIBLE | SB_I_NOEXEC | SB_I_NODEV;
- s->s_flags |= SB_NODIRATIME | SB_NOSUID | SB_NOEXEC;
- s->s_blocksize = 1024;
- s->s_blocksize_bits = 10;
- s->s_magic = PROC_SUPER_MAGIC;
- s->s_op = &proc_sops;
- s->s_time_gran = 1;
-
- /*
- * procfs isn't actually a stacking filesystem; however, there is
- * too much magic going on inside it to permit stacking things on
- * top of it
- */
- s->s_stack_depth = FILESYSTEM_MAX_STACK_DEPTH;
-
- pde_get(&proc_root);
- root_inode = proc_get_inode(s, &proc_root);
- if (!root_inode) {
- pr_err("proc_fill_super: get root inode failed\n");
- return -ENOMEM;
- }
-
- s->s_root = d_make_root(root_inode);
- if (!s->s_root) {
- pr_err("proc_fill_super: allocate dentry failed\n");
- return -ENOMEM;
- }
-
- ret = proc_setup_self(s);
- if (ret) {
- return ret;
- }
- return proc_setup_thread_self(s);
-}
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index c5ae09b6c726..b681533f59dd 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -197,13 +197,12 @@ struct pde_opener {
struct completion *c;
};
extern const struct inode_operations proc_link_inode_operations;
-
extern const struct inode_operations proc_pid_link_inode_operations;
+extern const struct super_operations proc_sops;
extern void proc_init_inodecache(void);
void set_proc_pid_nlink(void);
extern struct inode *proc_get_inode(struct super_block *, struct proc_dir_entry *);
-extern int proc_fill_super(struct super_block *, void *data, int flags);
extern void proc_entry_rundown(struct proc_dir_entry *);
/*
@@ -261,7 +260,6 @@ static inline void proc_tty_init(void) {}
* root.c
*/
extern struct proc_dir_entry proc_root;
-extern int proc_parse_options(char *options, struct pid_namespace *pid);
extern void proc_self_init(void);
extern int proc_remount(struct super_block *, int *, char *);
diff --git a/fs/proc/root.c b/fs/proc/root.c
index fd91901a299e..3dd3838d9e08 100644
--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -22,6 +22,7 @@
#include <linux/pid_namespace.h>
#include <linux/parser.h>
#include <linux/cred.h>
+#include <linux/magic.h>
#include "internal.h"
@@ -35,7 +36,7 @@ static const match_table_t tokens = {
{Opt_err, NULL},
};
-int proc_parse_options(char *options, struct pid_namespace *pid)
+static int proc_parse_options(char *options, struct pid_namespace *pid)
{
char *p;
substring_t args[MAX_OPT_ARGS];
@@ -77,6 +78,51 @@ int proc_parse_options(char *options, struct pid_namespace *pid)
return 1;
}
+static int proc_fill_super(struct super_block *s, void *data, int silent)
+{
+ struct pid_namespace *ns = get_pid_ns(s->s_fs_info);
+ struct inode *root_inode;
+ int ret;
+
+ if (!proc_parse_options(data, ns))
+ return -EINVAL;
+
+ /* User space would break if executables or devices appear on proc */
+ s->s_iflags |= SB_I_USERNS_VISIBLE | SB_I_NOEXEC | SB_I_NODEV;
+ s->s_flags |= SB_NODIRATIME | SB_NOSUID | SB_NOEXEC;
+ s->s_blocksize = 1024;
+ s->s_blocksize_bits = 10;
+ s->s_magic = PROC_SUPER_MAGIC;
+ s->s_op = &proc_sops;
+ s->s_time_gran = 1;
+
+ /*
+ * procfs isn't actually a stacking filesystem; however, there is
+ * too much magic going on inside it to permit stacking things on
+ * top of it
+ */
+ s->s_stack_depth = FILESYSTEM_MAX_STACK_DEPTH;
+
+ pde_get(&proc_root);
+ root_inode = proc_get_inode(s, &proc_root);
+ if (!root_inode) {
+ pr_err("proc_fill_super: get root inode failed\n");
+ return -ENOMEM;
+ }
+
+ s->s_root = d_make_root(root_inode);
+ if (!s->s_root) {
+ pr_err("proc_fill_super: allocate dentry failed\n");
+ return -ENOMEM;
+ }
+
+ ret = proc_setup_self(s);
+ if (ret) {
+ return ret;
+ }
+ return proc_setup_thread_self(s);
+}
+
int proc_remount(struct super_block *sb, int *flags, char *data)
{
struct pid_namespace *pid = sb->s_fs_info;
[toc] | [prev] | [next] | [standalone]
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2017-06-14 17:30 +0200 |
| Subject | [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] |
| Message-ID | <tSip4-6TQ-23@gated-at.bofh.it> |
| In reply to | #1665947 |
Introduce a filesystem context concept to be used during superblock
creation for mount and superblock reconfiguration for remount. This is
allocated at the beginning of the mount procedure and into it is placed:
(1) Filesystem type.
(2) Namespaces.
(3) Device name.
(4) Superblock flags (MS_*).
(5) Security details.
(6) Filesystem-specific data, as set by the mount options.
Signed-off-by: David Howells <dhowells@redhat.com>
---
Documentation/filesystems/mounting.txt | 436 ++++++++++++++++++++++++++++++++
include/linux/fs_context.h | 72 +++++
2 files changed, 508 insertions(+)
create mode 100644 Documentation/filesystems/mounting.txt
create mode 100644 include/linux/fs_context.h
diff --git a/Documentation/filesystems/mounting.txt b/Documentation/filesystems/mounting.txt
new file mode 100644
index 000000000000..315a5a4ff5cc
--- /dev/null
+++ b/Documentation/filesystems/mounting.txt
@@ -0,0 +1,436 @@
+ ===================
+ FILESYSTEM MOUNTING
+ ===================
+
+CONTENTS
+
+ (1) Overview.
+
+ (2) The filesystem context.
+
+ (3) The filesystem context operations.
+
+ (4) Filesystem context security.
+
+ (5) VFS filesystem context operations.
+
+
+========
+OVERVIEW
+========
+
+The creation of new mounts is now to be done in a multistep process:
+
+ (1) Create a filesystem context.
+
+ (2) Parse the options and attach them to the context. Options may be passed
+ individually from userspace.
+
+ (3) Validate and pre-process the context.
+
+ (4) Get or create a superblock and mountable root.
+
+ (5) Perform the mount.
+
+ (6) Return an error message attached to the context.
+
+ (7) Destroy the context.
+
+To support this, the file_system_type struct gains two new fields:
+
+ unsigned short fs_context_size;
+
+which indicates the total amount of space that should be allocated for context
+data (see the Filesystem Context section), and:
+
+ int (*init_fs_context)(struct fs_context *fc, struct super_block *src_sb);
+
+which is invoked to set up the filesystem-specific parts of a filesystem
+context, including the additional space. The src_sb parameter is used to
+convey the superblock from which the filesystem may draw extra information
+(such as namespaces), for submount (FS_CONTEXT_FOR_SUBMOUNT) or remount
+(FS_CONTEXT_FOR_REMOUNT) purposes or it will be NULL.
+
+Note that security initialisation is done *after* the filesystem is called so
+that the namespaces may be adjusted first.
+
+And the super_operations struct gains one:
+
+ int (*remount_fs_fc) (struct super_block *, struct fs_context *);
+
+This shadows the ->remount_fs() operation and takes a prepared filesystem
+context instead of the mount flags and data page. It may modify the ms_flags
+in the context for the caller to pick up.
+
+[NOTE] remount_fs_fc is intended as a replacement for remount_fs.
+
+
+======================
+THE FILESYSTEM CONTEXT
+======================
+
+The creation and reconfiguration of a superblock is governed by a filesystem
+context. This is represented by the fs_context structure:
+
+ struct fs_context {
+ const struct fs_context_operations *ops;
+ struct file_system_type *fs;
+ struct dentry *root;
+ struct user_namespace *user_ns;
+ struct net *net_ns;
+ const struct cred *cred;
+ char *device;
+ void *security;
+ unsigned int sb_flags;
+ bool sloppy;
+ bool silent;
+ bool degraded;
+ enum fs_context_purpose purpose : 8;
+ };
+
+When the VFS creates this, it allocates ->fs_context_size bytes (as specified
+by the file_system_type object) to hold both the fs_context struct and any
+extra data required by the filesystem. The fs_context struct is placed at the
+beginning of this space. Any extra space beyond that is for use by the
+filesystem. The filesystem should wrap the struct in its own, e.g.:
+
+ struct nfs_fs_context {
+ struct fs_context fc;
+ ...
+ };
+
+placing the fs_context struct first. container_of() can then be used. The
+file_system_type would be initialised thus:
+
+ struct file_system_type nfs = {
+ ...
+ .fs_context_size = sizeof(struct nfs_fs_context),
+ .init_fs_context = nfs_init_fs_context,
+ ...
+ };
+
+The fs_context fields are as follows:
+
+ (*) const struct fs_context_operations *ops
+
+ These are operations that can be done on a filesystem context (see
+ below). This must be set by the ->init_fs_context() file_system_type
+ operation.
+
+ (*) struct file_system_type *fs
+
+ A pointer to the file_system_type of the filesystem that is being
+ constructed or reconfigured. This retains a ref on the type owner.
+
+ (*) struct dentry *root
+
+ A pointer to the root of the mountable tree (and indirectly, the
+ superblock thereof). This is filled in by the ->get_tree() op.
+
+ (*) struct user_namespace *user_ns
+ (*) struct net *net_ns
+
+ This is a subset of the namespaces in use by the invoking process. This
+ retains a ref on each namespace. The subscribed namespaces may be
+ replaced by the filesystem to reflect other sources, such as the parent
+ mount superblock on an automount.
+
+ (*) struct cred *cred
+
+ The mounter's credentials. This retains a ref on the credentials.
+
+ (*) char *device
+
+ This is the device to be mounted. It may be a block device
+ (e.g. /dev/sda1) or something more exotic, such as the "host:/path" that
+ NFS desires.
+
+ (*) void *security
+
+ A place for the LSMs to hang their security data for the superblock. The
+ relevant security operations are described below.
+
+ (*) unsigned int sb_flags
+
+ This holds the MS_* flags mount flags.
+
+ (*) bool sloppy
+ (*) bool silent
+
+ These are set if the sloppy or silent mount options are given.
+
+ [NOTE] sloppy is probably unnecessary when userspace passes over one
+ option at a time since the error can just be ignored if userspace deems it
+ to be unimportant.
+
+ [NOTE] silent is probably redundant with ms_flags & MS_SILENT.
+
+ (*) bool degraded
+
+ This is set if any preallocated resources in the context have been used
+ up, thereby rendering it unreusable for the ->get_tree() op.
+
+ (*) enum fs_context_purpose
+
+ This indicates the purpose for which the context is intended. The
+ available values are:
+
+ FS_CONTEXT_FOR_NEW -- New mount
+ FS_CONTEXT_FOR_SUBMOUNT -- New automatic submount of extant mount
+ FS_CONTEXT_FOR_REMOUNT -- Change an existing mount
+
+The mount context is created by calling vfs_new_fs_context(), vfs_sb_reconfig()
+or vfs_dup_fs_context() and is destroyed with put_fs_context(). Note that the
+structure is not refcounted.
+
+VFS, security and filesystem mount options are set individually with
+vfs_parse_mount_option(). Options provided by the old mount(2) system call as
+a page of data can be parsed with generic_monolithic_mount_data().
+
+When mounting, the filesystem is allowed to take data from any of the pointers
+and attach it to the superblock (or whatever), provided it clears the pointer
+in the mount context.
+
+The filesystem is also allowed to allocate resources and pin them with the
+mount context. For instance, NFS might pin the appropriate protocol version
+module.
+
+
+=================================
+THE FILESYSTEM CONTEXT OPERATIONS
+=================================
+
+The filesystem context points to a table of operations:
+
+ struct fs_context_operations {
+ void (*free)(struct fs_context *fc);
+ int (*dup)(struct fs_context *fc, struct fs_context *src_fc);
+ int (*parse_option)(struct fs_context *fc, char *p);
+ int (*monolithic_mount_data)(struct fs_context *fc, void *data);
+ int (*validate)(struct fs_context *fc);
+ int (*get_tree)(struct fs_context *fc);
+ };
+
+These operations are invoked by the various stages of the mount procedure to
+manage the filesystem context. They are as follows:
+
+ (*) void (*free)(struct fs_context *fc);
+
+ Called to clean up the filesystem-specific part of the filesystem context
+ when the context is destroyed. It should be aware that parts of the
+ context may have been removed and NULL'd out by ->get_tree().
+
+ (*) int (*dup)(struct fs_context *fc, struct fs_context *src_fc);
+
+ Called when a filesystem context has been duplicated to get any refs or
+ copy any non-referenced resources held in the filesystem-specific part of
+ the filesystem context. An error may be returned to indicate failure to
+ do this.
+
+ [!] Note that even if this fails, put_fs_context() will be called
+ immediately thereafter, so ->dup() *must* make the
+ filesystem-specific part safe for ->free().
+
+ (*) int (*parse_option)(struct fs_context *fc, char *p);
+
+ Called when an option is to be added to the filesystem context. p points
+ to the option string, likely in "key[=val]" format. VFS-specific options
+ will have been weeded out and fc->sb_flags updated in the context.
+ Security options will also have been weeded out and fc->security updated.
+
+ If successful, 0 should be returned and a negative error code otherwise.
+ If an ambiguous error (such as -EINVAL) is returned, sb_cfg_error() or
+ sb_cfg_inval() should be used to provide a string that provides more
+ information.
+
+ (*) int (*monolithic_mount_data)(struct fs_context *fc, void *data);
+
+ Called when the mount(2) system call is invoked to pass the entire data
+ page in one go. If this is expected to be just a list of "key[=val]"
+ items separated by commas, then this may be set to NULL.
+
+ The return value is as for ->parse_option().
+
+ If the filesystem (eg. NFS) needs to examine the data first and then finds
+ it's the standard key-val list then it may pass it off to
+ generic_monolithic_mount_data().
+
+ (*) int (*validate)(struct fs_context *fc);
+
+ Called when all the options have been applied and the mount is about to
+ take place. It is should check for inconsistencies from mount options and
+ it is also allowed to do preliminary resource acquisition. For instance,
+ the core NFS module could load the NFS protocol module here.
+
+ Note that if fc->mount_type == FS_CONTEXT_FOR_REMOUNT, some of the options
+ necessary for a new mount may not be set.
+
+ The return value is as for ->parse_option().
+
+ (*) int (*get_tree)(struct fs_context *fc);
+
+ Called to get or create the mountable root and superblock, using the
+ information stored in the filesystem context (remounts go
+ via a different vector). It may detach any resources it desires from the
+ filesystem context and transfer them to the superblock it
+ creates.
+
+ On success it should set fc->root to the mountable root.
+
+ In the case of an error, it should return a negative error code and
+ consider invoking sb_cfg_inval() or sb_cfg_error().
+
+
+=========================================
+FILESYSTEM CONTEXT SECURITY
+========================================
+
+The filesystem context contains a security points that the LSMs
+can use for building up a security context for the superblock to be mounted.
+There are a number of operations used by the new mount code for this purpose:
+
+ (*) int security_fs_context_alloc(struct fs_context *fc,
+ struct super_block *src_sb);
+
+ Called to initialise fc->security (which is preset to NULL) and allocate
+ any resources needed. It should return 0 on success and a negative error
+ code on failure.
+
+ src_sb is non-NULL in the case of a remount (FS_CONTEXT_FOR_REMOUNT) in
+ which case it indicates the superblock to be remounted or in the case of a
+ submount (FS_CONTEXT_FOR_SUBMOUNT) in which case it indicates the parent
+ superblock.
+
+ (*) int security_fs_context_dup(struct fs_context *fc,
+ struct fs_context *src_mc);
+
+ Called to initialise fc->security (which is preset to NULL) and allocate
+ any resources needed. The original filesystem context is
+ pointed to by src_mc and may be used for reference. It should return 0 on
+ success and a negative error code on failure.
+
+ (*) void security_fs_context_free(struct fs_context *fc);
+
+ Called to clean up anything attached to fc->security. Note that the
+ contents may have been transferred to a superblock and the pointer NULL'd
+ out during mount.
+
+ (*) int security_fs_context_parse_option(struct fs_context *fc, char *opt);
+
+ Called for each mount option. The mount options are in "key[=val]" form.
+ An active LSM may reject one with an error, pass one over and return 0 or
+ consume one and return 1. If consumed, the option isn't passed on to the
+ filesystem.
+
+ If it returns an error, more information can be returned with
+ sb_cfg_inval() or sb_cfg_error().
+
+ (*) int security_sb_get_tree(struct fs_context *fc);
+
+ Called during the mount procedure to verify that the specified superblock
+ is allowed to be mounted and to transfer the security data there.
+
+ On success, it should return 0; otherwise it should return an error and
+ perhaps call invalf() or errorf() to indicate the problem. It should not
+ return -ENOMEM as this should be taken care of in advance.
+
+ [NOTE] Should I add a security_fs_context_validate() operation so that the
+ LSM has the opportunity to allocate stuff and check the options as a
+ whole?
+
+
+=================================
+VFS FILESYSTEM CONTEXT OPERATIONS
+=================================
+
+There are four operations for creating a filesystem context and
+one for destroying a context:
+
+ (*) struct fs_context *__vfs_new_fs_context(struct file_system_type *fs_type,
+ struct super_block *src_sb;
+ unsigned int ms_flags);
+
+ Create a filesystem context given a filesystem type pointer.
+ This allocates the filesystem context, sets the flags,
+ initialises the security and calls fs_type->init_fs_context() to initialise
+ the filesystem context.
+
+ src_sb can be NULL or it may indicate a superblock that is going to be
+ remounted (FS_CONTEXT_FOR_REMOUNT) or a superblock that is the parent of a
+ submount (FS_CONTEXT_FOR_SUBMOUNT). This superblock is provided as a
+ source of namespace information.
+
+ (*) struct fs_context *vfs_sb_reconfig(struct vfsmount *mnt,
+ unsigned int ms_flags);
+
+ Create a filesystem context from the same filesystem as an
+ extant mount and initialise the mount parameters from the superblock
+ underlying that mount. This is for use by remount.
+
+ (*) struct fs_context *vfs_new_fs_context(const char *fs_name);
+
+ Create a filesystem context given a filesystem name. It is assumed that
+ the mount flags will be passed in as text options or set directly later.
+ This is intended to be called from sys_mount() or sys_fsopen(). This
+ copies current's namespaces to the context.
+
+ (*) struct fs_context *vfs_dup_fs_context(struct fs_context *src_fc);
+
+ Duplicate a filesystem context, copying any options noted and duplicating
+ or additionally referencing any resources held therein. This is
+ available for use where a filesystem has to get a mount within a mount,
+ such as NFS4 does by internally mounting the root of the target server
+ and then doing a private pathwalk to the target directory.
+
+ (*) void put_fs_context(struct fs_context *fc);
+
+ Destroy a filesystem context, releasing any resources it holds. This
+ calls the ->free() operation. This is intended to be called by anyone
+ who created a filesystem context.
+
+ [!] filesystem contexts are not refcounted, so this causes unconditional
+ destruction.
+
+In all the above operations, apart from the put op, the return is a mount
+context pointer or a negative error code. No error string is saved as the
+error string is only guaranteed as long as the file_system_type is pinned (and
+thus the module).
+
+In the remaining operations, if an error occurs, a negative error code is
+returned and, if not obvious, fc->error_msg may have been set to point to a
+useful string. This string should not be freed.
+
+ (*) int vfs_get_tree(struct fs_context *fc);
+
+ Get or create the mountable root and superblock, using the parameters in
+ the filesystem context to select/configure the superblock. This invokes
+ the ->validate() op and then the ->get_tree() op.
+
+ [NOTE] ->validate() can probably be rolled into ->get_tree() and
+ ->remount_fs_fc().
+
+ (*) struct vfsmount *vfs_kern_mount_fc(struct fs_context *fc);
+
+ Create a mount given the parameters in the specified filesystem context.
+
+ (*) struct vfsmount *vfs_submount_fc(const struct dentry *mountpoint,
+ struct fs_context *fc);
+
+ Create a mount given a filesystem context and set MS_SUBMOUNT on it. A
+ wrapper around vfs_kern_mount_fc(). This is intended to be called from
+ filesystems that have automount points (NFS, AFS, ...).
+
+ (*) int vfs_parse_mount_option(struct fs_context *fc, char *data);
+
+ Supply a single mount option to the filesystem context. The mount option
+ should likely be in a "key[=val]" string form. The option is first
+ checked to see if it corresponds to a standard mount flag (in which case
+ it is used to mark an MS_xxx flag and consumed) or a security option (in
+ which case the LSM consumes it) before it is passed on to the filesystem.
+
+ (*) int generic_monolithic_mount_data(struct fs_context *fc, void *data);
+
+ Parse a sys_mount() data page, assuming the form to be a text list
+ consisting of key[=val] options separated by commas. Each item in the
+ list is passed to vfs_mount_option(). This is the default when the
+ ->monolithic_mount_data() operation is NULL.
diff --git a/include/linux/fs_context.h b/include/linux/fs_context.h
new file mode 100644
index 000000000000..429c40be2c9e
--- /dev/null
+++ b/include/linux/fs_context.h
@@ -0,0 +1,72 @@
+/* Filesystem superblock creation and reconfiguration context.
+ *
+ * Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _LINUX_FS_CONTEXT_H
+#define _LINUX_FS_CONTEXT_H
+
+#include <linux/kernel.h>
+#include <linux/errno.h>
+
+struct cred;
+struct dentry;
+struct file_operations;
+struct file_system_type;
+struct mnt_namespace;
+struct net;
+struct pid_namespace;
+struct super_block;
+struct user_namespace;
+struct vfsmount;
+
+enum fs_context_purpose {
+ FS_CONTEXT_FOR_NEW, /* New superblock for direct mount */
+ FS_CONTEXT_FOR_SUBMOUNT, /* New superblock for automatic submount */
+ FS_CONTEXT_FOR_REMOUNT, /* Superblock reconfiguration for remount */
+};
+
+/*
+ * Filesystem context as allocated and constructed by the ->init_fs_context()
+ * file_system_type operation. The size of the object allocated is specified
+ * in struct file_system_type::fs_context_size and this must include sufficient
+ * space for the fs_context struct.
+ *
+ * Superblock creation fills in ->root whereas reconfiguration begins with this
+ * already set.
+ *
+ * See Documentation/filesystems/mounting.txt
+ */
+struct fs_context {
+ const struct fs_context_operations *ops;
+ struct file_system_type *fs_type;
+ struct dentry *root; /* The root and superblock */
+ struct user_namespace *user_ns; /* The user namespace for this mount */
+ struct net *net_ns; /* The network namespace for this mount */
+ const struct cred *cred; /* The mounter's credentials */
+ char *device; /* The device name or mount target */
+ char *subtype; /* The subtype to set on the superblock */
+ void *security; /* The LSM context */
+ unsigned int sb_flags; /* The superblock flags (MS_*) */
+ bool sloppy; /* Unrecognised options are okay */
+ bool silent;
+ bool degraded; /* True if the context can't be reused */
+ enum fs_context_purpose purpose : 8;
+};
+
+struct fs_context_operations {
+ void (*free)(struct fs_context *fc);
+ int (*dup)(struct fs_context *fc, struct fs_context *src_fc);
+ int (*parse_option)(struct fs_context *fc, char *p);
+ int (*monolithic_mount_data)(struct fs_context *fc, void *data);
+ int (*validate)(struct fs_context *fc);
+ int (*get_tree)(struct fs_context *fc);
+};
+
+#endif /* _LINUX_FS_CONTEXT_H */
[toc] | [prev] | [next] | [standalone]
| From | Randy Dunlap <rdunlap@infradead.org> |
|---|---|
| Date | 2017-06-14 20:10 +0200 |
| Subject | Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] |
| Message-ID | <tSkTT-64-9@gated-at.bofh.it> |
| In reply to | #1665991 |
On 06/14/17 08:16, David Howells wrote:
> Introduce a filesystem context concept to be used during superblock
> creation for mount and superblock reconfiguration for remount. This is
> allocated at the beginning of the mount procedure and into it is placed:
>
> (1) Filesystem type.
>
> (2) Namespaces.
>
> (3) Device name.
>
> (4) Superblock flags (MS_*).
>
> (5) Security details.
>
> (6) Filesystem-specific data, as set by the mount options.
>
> Signed-off-by: David Howells <dhowells@redhat.com>
> ---
>
> Documentation/filesystems/mounting.txt | 436 ++++++++++++++++++++++++++++++++
> include/linux/fs_context.h | 72 +++++
> 2 files changed, 508 insertions(+)
> create mode 100644 Documentation/filesystems/mounting.txt
> create mode 100644 include/linux/fs_context.h
>
> diff --git a/Documentation/filesystems/mounting.txt b/Documentation/filesystems/mounting.txt
> new file mode 100644
> index 000000000000..315a5a4ff5cc
> --- /dev/null
> +++ b/Documentation/filesystems/mounting.txt
> @@ -0,0 +1,436 @@
> + ===================
> + FILESYSTEM MOUNTING
> + ===================
> +
> +CONTENTS
> +
> + (1) Overview.
> +
> + (2) The filesystem context.
> +
> + (3) The filesystem context operations.
> +
> + (4) Filesystem context security.
> +
> + (5) VFS filesystem context operations.
> +
> +
> +========
> +OVERVIEW
> +========
> +
> +The creation of new mounts is now to be done in a multistep process:
> +
> + (1) Create a filesystem context.
> +
> + (2) Parse the options and attach them to the context. Options may be passed
> + individually from userspace.
> +
> + (3) Validate and pre-process the context.
> +
> + (4) Get or create a superblock and mountable root.
> +
> + (5) Perform the mount.
> +
> + (6) Return an error message attached to the context.
> +
> + (7) Destroy the context.
> +
> +To support this, the file_system_type struct gains two new fields:
> +
> + unsigned short fs_context_size;
> +
> +which indicates the total amount of space that should be allocated for context
> +data (see the Filesystem Context section), and:
> +
> + int (*init_fs_context)(struct fs_context *fc, struct super_block *src_sb);
> +
> +which is invoked to set up the filesystem-specific parts of a filesystem
> +context, including the additional space. The src_sb parameter is used to
> +convey the superblock from which the filesystem may draw extra information
> +(such as namespaces), for submount (FS_CONTEXT_FOR_SUBMOUNT) or remount
;
> +(FS_CONTEXT_FOR_REMOUNT) purposes or it will be NULL.
> +
> +Note that security initialisation is done *after* the filesystem is called so
> +that the namespaces may be adjusted first.
> +
> +And the super_operations struct gains one:
one field:
> +
> + int (*remount_fs_fc) (struct super_block *, struct fs_context *);
> +
> +This shadows the ->remount_fs() operation and takes a prepared filesystem
> +context instead of the mount flags and data page. It may modify the ms_flags
> +in the context for the caller to pick up.
> +
> +[NOTE] remount_fs_fc is intended as a replacement for remount_fs.
> +
> +
> +======================
> +THE FILESYSTEM CONTEXT
> +======================
> +
> +The creation and reconfiguration of a superblock is governed by a filesystem
> +context. This is represented by the fs_context structure:
> +
> + struct fs_context {
> + const struct fs_context_operations *ops;
> + struct file_system_type *fs;
> + struct dentry *root;
> + struct user_namespace *user_ns;
> + struct net *net_ns;
> + const struct cred *cred;
> + char *device;
> + void *security;
> + unsigned int sb_flags;
> + bool sloppy;
> + bool silent;
> + bool degraded;
> + enum fs_context_purpose purpose : 8;
> + };
> +
> +When the VFS creates this, it allocates ->fs_context_size bytes (as specified
> +by the file_system_type object) to hold both the fs_context struct and any
> +extra data required by the filesystem. The fs_context struct is placed at the
> +beginning of this space. Any extra space beyond that is for use by the
> +filesystem. The filesystem should wrap the struct in its own, e.g.:
> +
> + struct nfs_fs_context {
> + struct fs_context fc;
> + ...
> + };
> +
> +placing the fs_context struct first. container_of() can then be used. The
> +file_system_type would be initialised thus:
> +
> + struct file_system_type nfs = {
> + ...
> + .fs_context_size = sizeof(struct nfs_fs_context),
> + .init_fs_context = nfs_init_fs_context,
> + ...
> + };
> +
> +The fs_context fields are as follows:
> +
> + (*) const struct fs_context_operations *ops
> +
> + These are operations that can be done on a filesystem context (see
> + below). This must be set by the ->init_fs_context() file_system_type
> + operation.
> +
> + (*) struct file_system_type *fs
> +
> + A pointer to the file_system_type of the filesystem that is being
> + constructed or reconfigured. This retains a ref on the type owner.
s/ref/reference/
> +
> + (*) struct dentry *root
> +
> + A pointer to the root of the mountable tree (and indirectly, the
> + superblock thereof). This is filled in by the ->get_tree() op.
> +
> + (*) struct user_namespace *user_ns
> + (*) struct net *net_ns
> +
> + This is a subset of the namespaces in use by the invoking process. This
These are They
> + retains a ref on each namespace. The subscribed namespaces may be
retain a reference
> + replaced by the filesystem to reflect other sources, such as the parent
> + mount superblock on an automount.
> +
> + (*) struct cred *cred
> +
> + The mounter's credentials. This retains a ref on the credentials.
s/ref/reference/
> +
> + (*) char *device
> +
> + This is the device to be mounted. It may be a block device
> + (e.g. /dev/sda1) or something more exotic, such as the "host:/path" that
> + NFS desires.
> +
> + (*) void *security
> +
> + A place for the LSMs to hang their security data for the superblock. The
> + relevant security operations are described below.
> +
> + (*) unsigned int sb_flags
> +
> + This holds the MS_* flags mount flags.
> +
> + (*) bool sloppy
> + (*) bool silent
> +
> + These are set if the sloppy or silent mount options are given.
> +
> + [NOTE] sloppy is probably unnecessary when userspace passes over one
> + option at a time since the error can just be ignored if userspace deems it
> + to be unimportant.
> +
> + [NOTE] silent is probably redundant with ms_flags & MS_SILENT.
> +
> + (*) bool degraded
> +
> + This is set if any preallocated resources in the context have been used
> + up, thereby rendering it unreusable for the ->get_tree() op.
> +
> + (*) enum fs_context_purpose
> +
> + This indicates the purpose for which the context is intended. The
> + available values are:
> +
> + FS_CONTEXT_FOR_NEW -- New mount
> + FS_CONTEXT_FOR_SUBMOUNT -- New automatic submount of extant mount
> + FS_CONTEXT_FOR_REMOUNT -- Change an existing mount
> +
> +The mount context is created by calling vfs_new_fs_context(), vfs_sb_reconfig()
> +or vfs_dup_fs_context() and is destroyed with put_fs_context(). Note that the
> +structure is not refcounted.
> +
> +VFS, security and filesystem mount options are set individually with
> +vfs_parse_mount_option(). Options provided by the old mount(2) system call as
> +a page of data can be parsed with generic_monolithic_mount_data().
> +
> +When mounting, the filesystem is allowed to take data from any of the pointers
> +and attach it to the superblock (or whatever), provided it clears the pointer
> +in the mount context.
> +
> +The filesystem is also allowed to allocate resources and pin them with the
> +mount context. For instance, NFS might pin the appropriate protocol version
> +module.
> +
> +
> +=================================
> +THE FILESYSTEM CONTEXT OPERATIONS
> +=================================
> +
> +The filesystem context points to a table of operations:
> +
> + struct fs_context_operations {
> + void (*free)(struct fs_context *fc);
> + int (*dup)(struct fs_context *fc, struct fs_context *src_fc);
> + int (*parse_option)(struct fs_context *fc, char *p);
> + int (*monolithic_mount_data)(struct fs_context *fc, void *data);
> + int (*validate)(struct fs_context *fc);
> + int (*get_tree)(struct fs_context *fc);
> + };
> +
> +These operations are invoked by the various stages of the mount procedure to
> +manage the filesystem context. They are as follows:
> +
> + (*) void (*free)(struct fs_context *fc);
> +
> + Called to clean up the filesystem-specific part of the filesystem context
> + when the context is destroyed. It should be aware that parts of the
> + context may have been removed and NULL'd out by ->get_tree().
> +
> + (*) int (*dup)(struct fs_context *fc, struct fs_context *src_fc);
> +
> + Called when a filesystem context has been duplicated to get any refs or
> + copy any non-referenced resources held in the filesystem-specific part of
> + the filesystem context. An error may be returned to indicate failure to
> + do this.
> +
> + [!] Note that even if this fails, put_fs_context() will be called
> + immediately thereafter, so ->dup() *must* make the
> + filesystem-specific part safe for ->free().
> +
> + (*) int (*parse_option)(struct fs_context *fc, char *p);
> +
> + Called when an option is to be added to the filesystem context. p points
> + to the option string, likely in "key[=val]" format. VFS-specific options
> + will have been weeded out and fc->sb_flags updated in the context.
> + Security options will also have been weeded out and fc->security updated.
> +
> + If successful, 0 should be returned and a negative error code otherwise.
> + If an ambiguous error (such as -EINVAL) is returned, sb_cfg_error() or
> + sb_cfg_inval() should be used to provide a string that provides more
> + information.
> +
> + (*) int (*monolithic_mount_data)(struct fs_context *fc, void *data);
> +
> + Called when the mount(2) system call is invoked to pass the entire data
> + page in one go. If this is expected to be just a list of "key[=val]"
> + items separated by commas, then this may be set to NULL.
> +
> + The return value is as for ->parse_option().
> +
> + If the filesystem (eg. NFS) needs to examine the data first and then finds
> + it's the standard key-val list then it may pass it off to
> + generic_monolithic_mount_data().
> +
> + (*) int (*validate)(struct fs_context *fc);
> +
> + Called when all the options have been applied and the mount is about to
> + take place. It is should check for inconsistencies from mount options and
> + it is also allowed to do preliminary resource acquisition. For instance,
> + the core NFS module could load the NFS protocol module here.
> +
> + Note that if fc->mount_type == FS_CONTEXT_FOR_REMOUNT, some of the options
> + necessary for a new mount may not be set.
> +
> + The return value is as for ->parse_option().
> +
> + (*) int (*get_tree)(struct fs_context *fc);
> +
> + Called to get or create the mountable root and superblock, using the
> + information stored in the filesystem context (remounts go
> + via a different vector). It may detach any resources it desires from the
> + filesystem context and transfer them to the superblock it
> + creates.
> +
> + On success it should set fc->root to the mountable root.
> +
> + In the case of an error, it should return a negative error code and
> + consider invoking sb_cfg_inval() or sb_cfg_error().
> +
> +
> +=========================================
> +FILESYSTEM CONTEXT SECURITY
> +========================================
> +
> +The filesystem context contains a security points that the LSMs
point or pointer ?
> +can use for building up a security context for the superblock to be mounted.
> +There are a number of operations used by the new mount code for this purpose:
--
~Randy
[toc] | [prev] | [next] | [standalone]
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2017-06-15 01:00 +0200 |
| Subject | Updated docs |
| Message-ID | <tSpqx-2Lv-3@gated-at.bofh.it> |
| In reply to | #1666123 |
Randy Dunlap <rdunlap@infradead.org> wrote:
> > +which is invoked to set up the filesystem-specific parts of a filesystem
> > +context, including the additional space. The src_sb parameter is used to
> > +convey the superblock from which the filesystem may draw extra information
> > +(such as namespaces), for submount (FS_CONTEXT_FOR_SUBMOUNT) or remount
>
> ;
Actually, this should rather be something like:
which is invoked to set up the filesystem-specific parts of a filesystem
context, including the additional space. The src_sb parameter is used to
convey the superblock from which the filesystem may draw extra information
(such as namespaces) for submount (FS_CONTEXT_FOR_SUBMOUNT) or remount
(FS_CONTEXT_FOR_REMOUNT) purposes - otherwise it will be NULL.
I forgot to thoroughly update the docs, so here they are.
David
---
===================
FILESYSTEM MOUNTING
===================
CONTENTS
(1) Overview.
(2) The filesystem context.
(3) The filesystem context operations.
(4) Filesystem context security.
(5) VFS filesystem context operations.
========
OVERVIEW
========
The creation of new mounts is now to be done in a multistep process:
(1) Create a filesystem context.
(2) Parse the options and attach them to the context. Options may be passed
individually from userspace.
(3) Validate and pre-process the context.
(4) Get or create a superblock and mountable root.
(5) Perform the mount.
(6) Return an error message attached to the context.
(7) Destroy the context.
To support this, the file_system_type struct gains two new fields:
unsigned short fs_context_size;
which indicates the total amount of space that should be allocated for context
data (see the Filesystem Context section), and:
int (*init_fs_context)(struct fs_context *fc, struct super_block *src_sb);
which is invoked to set up the filesystem-specific parts of a filesystem
context, including the additional space. The src_sb parameter is used to
convey the superblock from which the filesystem may draw extra information
(such as namespaces) for submount (FS_CONTEXT_FOR_SUBMOUNT) or remount
(FS_CONTEXT_FOR_REMOUNT) purposes - otherwise it will be NULL.
Note that security initialisation is done *after* the filesystem is called so
that the namespaces may be adjusted first.
And the super_operations struct gains one field:
int (*remount_fs_fc) (struct super_block *, struct fs_context *);
This shadows the ->remount_fs() operation and takes a prepared filesystem
context instead of the mount flags and data page. It may modify the sb_flags
in the context for the caller to pick up.
[NOTE] remount_fs_fc is intended as a replacement for remount_fs.
======================
THE FILESYSTEM CONTEXT
======================
The creation and reconfiguration of a superblock is governed by a filesystem
context. This is represented by the fs_context structure:
struct fs_context {
const struct fs_context_operations *ops;
struct file_system_type *fs;
struct dentry *root;
struct user_namespace *user_ns;
struct net *net_ns;
const struct cred *cred;
char *device;
char *subtype;
void *security;
unsigned int sb_flags;
bool sloppy;
bool silent;
bool degraded;
enum fs_context_purpose purpose : 8;
};
When the VFS creates this, it allocates ->fs_context_size bytes (as specified
by the file_system_type object) to hold both the fs_context struct and any
extra data required by the filesystem. The fs_context struct is placed at the
beginning of this space. Any extra space beyond that is for use by the
filesystem. The filesystem should wrap the struct in its own, e.g.:
struct nfs_fs_context {
struct fs_context fc;
...
};
placing the fs_context struct first. container_of() can then be used. The
file_system_type would be initialised thus:
struct file_system_type nfs = {
...
.fs_context_size = sizeof(struct nfs_fs_context),
.init_fs_context = nfs_init_fs_context,
...
};
The fs_context fields are as follows:
(*) const struct fs_context_operations *ops
These are operations that can be done on a filesystem context (see
below). This must be set by the ->init_fs_context() file_system_type
operation.
(*) struct file_system_type *fs
A pointer to the file_system_type of the filesystem that is being
constructed or reconfigured. This retains a reference on the type owner.
(*) struct dentry *root
A pointer to the root of the mountable tree (and indirectly, the
superblock thereof). This is filled in by the ->get_tree() op.
(*) struct user_namespace *user_ns
(*) struct net *net_ns
There are a subset of the namespaces in use by the invoking process. They
retain references on each namespace. The subscribed namespaces may be
replaced by the filesystem to reflect other sources, such as the parent
mount superblock on an automount.
(*) struct cred *cred
The mounter's credentials. This retains a reference on the credentials.
(*) char *device
This is the device to be mounted. It may be a block device
(e.g. /dev/sda1) or something more exotic, such as the "host:/path" that
NFS desires.
(*) char *subtype
This is a string to be added to the type displayed in /proc/mounts to
qualify it (used by FUSE). This is available for the filesystem to set if
desired.
(*) void *security
A place for the LSMs to hang their security data for the superblock. The
relevant security operations are described below.
(*) unsigned int sb_flags
This holds the SB_* flags to be set in super_block::s_flags.
(*) bool sloppy
(*) bool silent
These are set if the sloppy or silent mount options are given.
[NOTE] sloppy is probably unnecessary when userspace passes over one
option at a time since the error can just be ignored if userspace deems it
to be unimportant.
[NOTE] silent is probably redundant with sb_flags & SB_SILENT.
(*) bool degraded
This is set if any preallocated resources in the context have been used
up, thereby rendering it unreusable for the ->get_tree() op.
(*) enum fs_context_purpose
This indicates the purpose for which the context is intended. The
available values are:
FS_CONTEXT_FOR_NEW -- New mount
FS_CONTEXT_FOR_SUBMOUNT -- New automatic submount of extant mount
FS_CONTEXT_FOR_REMOUNT -- Change an existing mount
The mount context is created by calling vfs_new_fs_context(), vfs_sb_reconfig()
or vfs_dup_fs_context() and is destroyed with put_fs_context(). Note that the
structure is not refcounted.
VFS, security and filesystem mount options are set individually with
vfs_parse_mount_option(). Options provided by the old mount(2) system call as
a page of data can be parsed with generic_monolithic_mount_data().
When mounting, the filesystem is allowed to take data from any of the pointers
and attach it to the superblock (or whatever), provided it clears the pointer
in the mount context.
The filesystem is also allowed to allocate resources and pin them with the
mount context. For instance, NFS might pin the appropriate protocol version
module.
=================================
THE FILESYSTEM CONTEXT OPERATIONS
=================================
The filesystem context points to a table of operations:
struct fs_context_operations {
void (*free)(struct fs_context *fc);
int (*dup)(struct fs_context *fc, struct fs_context *src_fc);
int (*parse_option)(struct fs_context *fc, char *p);
int (*monolithic_mount_data)(struct fs_context *fc, void *data);
int (*validate)(struct fs_context *fc);
int (*get_tree)(struct fs_context *fc);
};
These operations are invoked by the various stages of the mount procedure to
manage the filesystem context. They are as follows:
(*) void (*free)(struct fs_context *fc);
Called to clean up the filesystem-specific part of the filesystem context
when the context is destroyed. It should be aware that parts of the
context may have been removed and NULL'd out by ->get_tree().
(*) int (*dup)(struct fs_context *fc, struct fs_context *src_fc);
Called when a filesystem context has been duplicated to get any refs or
copy any non-referenced resources held in the filesystem-specific part of
the filesystem context. An error may be returned to indicate failure to
do this.
[!] Note that even if this fails, put_fs_context() will be called
immediately thereafter, so ->dup() *must* make the
filesystem-specific part safe for ->free().
(*) int (*parse_option)(struct fs_context *fc, char *p);
Called when an option is to be added to the filesystem context. p points
to the option string, likely in "key[=val]" format. VFS-specific options
will have been weeded out and fc->sb_flags updated in the context.
Security options will also have been weeded out and fc->security updated.
If successful, 0 should be returned and a negative error code otherwise.
If an ambiguous error (such as -EINVAL) is returned, sb_cfg_error() or
sb_cfg_inval() should be used to provide a string that provides more
information.
(*) int (*monolithic_mount_data)(struct fs_context *fc, void *data);
Called when the mount(2) system call is invoked to pass the entire data
page in one go. If this is expected to be just a list of "key[=val]"
items separated by commas, then this may be set to NULL.
The return value is as for ->parse_option().
If the filesystem (eg. NFS) needs to examine the data first and then finds
it's the standard key-val list then it may pass it off to
generic_monolithic_mount_data().
(*) int (*validate)(struct fs_context *fc);
Called when all the options have been applied and the mount is about to
take place. It is should check for inconsistencies from mount options and
it is also allowed to do preliminary resource acquisition. For instance,
the core NFS module could load the NFS protocol module here.
Note that if fc->purpose == FS_CONTEXT_FOR_REMOUNT, some of the options
necessary for a new mount may not be set.
The return value is as for ->parse_option().
(*) int (*get_tree)(struct fs_context *fc);
Called to get or create the mountable root and superblock, using the
information stored in the filesystem context (remounts go
via a different vector). It may detach any resources it desires from the
filesystem context and transfer them to the superblock it
creates.
On success it should set fc->root to the mountable root.
In the case of an error, it should return a negative error code and
consider invoking sb_cfg_inval() or sb_cfg_error().
===========================
FILESYSTEM CONTEXT SECURITY
===========================
The filesystem context contains a security pointer that the LSMs can use for
building up a security context for the superblock to be mounted. There are a
number of operations used by the new mount code for this purpose:
(*) int security_fs_context_alloc(struct fs_context *fc,
struct super_block *src_sb);
Called to initialise fc->security (which is preset to NULL) and allocate
any resources needed. It should return 0 on success and a negative error
code on failure.
src_sb is non-NULL in the case of a remount (FS_CONTEXT_FOR_REMOUNT) in
which case it indicates the superblock to be remounted or in the case of a
submount (FS_CONTEXT_FOR_SUBMOUNT) in which case it indicates the parent
superblock.
(*) int security_fs_context_dup(struct fs_context *fc,
struct fs_context *src_fc);
Called to initialise fc->security (which is preset to NULL) and allocate
any resources needed. The original filesystem context is pointed to by
src_fc and may be used for reference. It should return 0 on success and a
negative error code on failure.
(*) void security_fs_context_free(struct fs_context *fc);
Called to clean up anything attached to fc->security. Note that the
contents may have been transferred to a superblock and the pointer NULL'd
out during mount.
(*) int security_fs_context_parse_option(struct fs_context *fc, char *opt);
Called for each mount option. The mount options are in "key[=val]" form.
An active LSM may reject one with an error, pass one over and return 0 or
consume one and return 1. If consumed, the option isn't passed on to the
filesystem.
If it returns an error, more information can be returned with
invalf() or errorf().
(*) int security_sb_get_tree(struct fs_context *fc);
Called during the mount procedure to verify that the specified superblock
is allowed to be mounted and to transfer the security data there.
On success, it should return 0; otherwise it should return an error and
perhaps call invalf() or errorf() to indicate the problem. It should not
return -ENOMEM as this should be taken care of in advance.
[NOTE] Should I add a security_fs_context_validate() operation so that the
LSM has the opportunity to allocate stuff and check the options as a
whole?
(*) int security_sb_mountpoint(struct fs_context *fc, struct path *mountpoint)
Called during the mount procedure to verify that the root dentry attached
to the context is permitted to be attached to the specified mountpoint.
It should return 0 on success and a negative error code on failure.
=================================
VFS FILESYSTEM CONTEXT OPERATIONS
=================================
There are four operations for creating a filesystem context and
one for destroying a context:
(*) struct fs_context *vfs_new_fs_context(struct file_system_type *fs_type,
struct super_block *src_sb;
unsigned int sb_flags);
Create a filesystem context for a given filesystem type. This allocates
the filesystem context, sets the flags, initialises the security and calls
fs_type->init_fs_context() to initialise the filesystem context.
src_sb can be NULL or it may indicate a superblock that is going to be
remounted (FS_CONTEXT_FOR_REMOUNT) or a superblock that is the parent of a
submount (FS_CONTEXT_FOR_SUBMOUNT). This superblock is provided as a
source of namespace information.
(*) struct fs_context *vfs_sb_reconfig(struct vfsmount *mnt,
unsigned int sb_flags);
Create a filesystem context from the same filesystem as an extant mount
and initialise the mount parameters from the superblock underlying that
mount. This is for use by remount.
(*) struct fs_context *vfs_dup_fs_context(struct fs_context *src_fc);
Duplicate a filesystem context, copying any options noted and duplicating
or additionally referencing any resources held therein. This is available
for use where a filesystem has to get a mount within a mount, such as NFS4
does by internally mounting the root of the target server and then doing a
private pathwalk to the target directory.
(*) void put_fs_context(struct fs_context *fc);
Destroy a filesystem context, releasing any resources it holds. This
calls the ->free() operation. This is intended to be called by anyone who
created a filesystem context.
[!] filesystem contexts are not refcounted, so this causes unconditional
destruction.
In all the above operations, apart from the put op, the return is a mount
context pointer or a negative error code.
In the remaining operations, if an error occurs, a negative error code is
returned and, if not obvious, invalf() or errorf() may have been invoked to set
a supplementary error message.
(*) int vfs_get_tree(struct fs_context *fc);
Get or create the mountable root and superblock, using the parameters in
the filesystem context to select/configure the superblock. This invokes
the ->validate() op and then the ->get_tree() op.
[NOTE] ->validate() could perhaps be rolled into ->get_tree() and
->remount_fs_fc().
(*) struct vfsmount *vfs_kern_mount_fc(struct fs_context *fc);
Create a mount given the parameters in the specified filesystem context.
(*) int vfs_parse_mount_option(struct fs_context *fc, char *data);
Supply a single mount option to the filesystem context. The mount option
should likely be in a "key[=val]" string form. The option is first
checked to see if it corresponds to a standard mount flag (in which case
it is used to set an MS_xxx flag and consumed) or a security option (in
which case the LSM consumes it) before it is passed on to the filesystem.
(*) int generic_monolithic_mount_data(struct fs_context *fc, void *data);
Parse a sys_mount() data page, assuming the form to be a text list
consisting of key[=val] options separated by commas. Each item in the
list is passed to vfs_mount_option(). This is the default when the
->monolithic_mount_data() operation is NULL.
[toc] | [prev] | [next] | [standalone]
| From | Randy Dunlap <rdunlap@infradead.org> |
|---|---|
| Date | 2017-06-15 04:00 +0200 |
| Subject | Re: Updated docs |
| Message-ID | <tSseJ-4tL-7@gated-at.bofh.it> |
| In reply to | #1666308 |
Thanks for the update. I have 2 more things for you to consider. a. In multiple places, there is something like "return 0 when no error and return a negative error code otherwise." I would say "or return a negative error code otherwise." b. (below) > =========================== > FILESYSTEM CONTEXT SECURITY > =========================== > > The filesystem context contains a security pointer that the LSMs can use for > building up a security context for the superblock to be mounted. There are a > number of operations used by the new mount code for this purpose: > > (*) int security_fs_context_alloc(struct fs_context *fc, > struct super_block *src_sb); > > Called to initialise fc->security (which is preset to NULL) and allocate > any resources needed. It should return 0 on success and a negative error > code on failure. > > src_sb is non-NULL in the case of a remount (FS_CONTEXT_FOR_REMOUNT) in > which case it indicates the superblock to be remounted or in the case of a > submount (FS_CONTEXT_FOR_SUBMOUNT) in which case it indicates the parent > superblock. > -ETOOMANYCASES Maybe: For a remount (FS_CONTEXT_FOR_REMOUNT), src_sb is non-NULL and indicates the superblock to be remounted. For a submount (FS_CONTEXT_FOR_SUBMOUNT), src_sb is also non-NULL and represents the parent superblock. cheers. -- ~Randy
[toc] | [prev] | [next] | [standalone]
| From | Casey Schaufler <casey@schaufler-ca.com> |
|---|---|
| Date | 2017-06-14 22:10 +0200 |
| Subject | Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] |
| Message-ID | <tSmM2-1fI-29@gated-at.bofh.it> |
| In reply to | #1665991 |
On 6/14/2017 8:16 AM, David Howells wrote:
> Introduce a filesystem context concept to be used during superblock
> creation for mount and superblock reconfiguration for remount. This is
> allocated at the beginning of the mount procedure and into it is placed:
>
> (1) Filesystem type.
>
> (2) Namespaces.
>
> (3) Device name.
>
> (4) Superblock flags (MS_*).
>
> (5) Security details.
>
> (6) Filesystem-specific data, as set by the mount options.
>
> Signed-off-by: David Howells <dhowells@redhat.com>
> ---
>
> Documentation/filesystems/mounting.txt | 436 ++++++++++++++++++++++++++++++++
> include/linux/fs_context.h | 72 +++++
> 2 files changed, 508 insertions(+)
> create mode 100644 Documentation/filesystems/mounting.txt
> create mode 100644 include/linux/fs_context.h
>
> diff --git a/Documentation/filesystems/mounting.txt b/Documentation/filesystems/mounting.txt
> new file mode 100644
> index 000000000000..315a5a4ff5cc
> --- /dev/null
> +++ b/Documentation/filesystems/mounting.txt
> @@ -0,0 +1,436 @@
> + ===================
> + FILESYSTEM MOUNTING
> + ===================
> +
> +CONTENTS
> +
> + (1) Overview.
> +
> + (2) The filesystem context.
> +
> + (3) The filesystem context operations.
> +
> + (4) Filesystem context security.
> +
> + (5) VFS filesystem context operations.
> +
> +
> +========
> +OVERVIEW
> +========
> +
> +The creation of new mounts is now to be done in a multistep process:
> +
> + (1) Create a filesystem context.
> +
> + (2) Parse the options and attach them to the context. Options may be passed
> + individually from userspace.
> +
> + (3) Validate and pre-process the context.
> +
> + (4) Get or create a superblock and mountable root.
> +
> + (5) Perform the mount.
> +
> + (6) Return an error message attached to the context.
> +
> + (7) Destroy the context.
> +
> +To support this, the file_system_type struct gains two new fields:
> +
> + unsigned short fs_context_size;
> +
> +which indicates the total amount of space that should be allocated for context
> +data (see the Filesystem Context section), and:
> +
> + int (*init_fs_context)(struct fs_context *fc, struct super_block *src_sb);
> +
> +which is invoked to set up the filesystem-specific parts of a filesystem
> +context, including the additional space. The src_sb parameter is used to
> +convey the superblock from which the filesystem may draw extra information
> +(such as namespaces), for submount (FS_CONTEXT_FOR_SUBMOUNT) or remount
> +(FS_CONTEXT_FOR_REMOUNT) purposes or it will be NULL.
> +
> +Note that security initialisation is done *after* the filesystem is called so
> +that the namespaces may be adjusted first.
> +
> +And the super_operations struct gains one:
> +
> + int (*remount_fs_fc) (struct super_block *, struct fs_context *);
> +
> +This shadows the ->remount_fs() operation and takes a prepared filesystem
> +context instead of the mount flags and data page. It may modify the ms_flags
> +in the context for the caller to pick up.
> +
> +[NOTE] remount_fs_fc is intended as a replacement for remount_fs.
> +
> +
> +======================
> +THE FILESYSTEM CONTEXT
> +======================
> +
> +The creation and reconfiguration of a superblock is governed by a filesystem
> +context. This is represented by the fs_context structure:
> +
> + struct fs_context {
> + const struct fs_context_operations *ops;
> + struct file_system_type *fs;
> + struct dentry *root;
> + struct user_namespace *user_ns;
> + struct net *net_ns;
> + const struct cred *cred;
> + char *device;
> + void *security;
> + unsigned int sb_flags;
> + bool sloppy;
> + bool silent;
> + bool degraded;
> + enum fs_context_purpose purpose : 8;
> + };
Could you namespace the fields of this structure?
e.g. fs_cred, fs_security
It makes it so much easier to determine which ->cred
you're looking at.
> +
> +When the VFS creates this, it allocates ->fs_context_size bytes (as specified
> +by the file_system_type object) to hold both the fs_context struct and any
> +extra data required by the filesystem. The fs_context struct is placed at the
> +beginning of this space. Any extra space beyond that is for use by the
> +filesystem. The filesystem should wrap the struct in its own, e.g.:
> +
> + struct nfs_fs_context {
> + struct fs_context fc;
> + ...
> + };
> +
> +placing the fs_context struct first. container_of() can then be used. The
> +file_system_type would be initialised thus:
> +
> + struct file_system_type nfs = {
> + ...
> + .fs_context_size = sizeof(struct nfs_fs_context),
> + .init_fs_context = nfs_init_fs_context,
> + ...
> + };
> +
> +The fs_context fields are as follows:
> +
> + (*) const struct fs_context_operations *ops
> +
> + These are operations that can be done on a filesystem context (see
> + below). This must be set by the ->init_fs_context() file_system_type
> + operation.
> +
> + (*) struct file_system_type *fs
> +
> + A pointer to the file_system_type of the filesystem that is being
> + constructed or reconfigured. This retains a ref on the type owner.
> +
> + (*) struct dentry *root
> +
> + A pointer to the root of the mountable tree (and indirectly, the
> + superblock thereof). This is filled in by the ->get_tree() op.
> +
> + (*) struct user_namespace *user_ns
> + (*) struct net *net_ns
> +
> + This is a subset of the namespaces in use by the invoking process. This
> + retains a ref on each namespace. The subscribed namespaces may be
> + replaced by the filesystem to reflect other sources, such as the parent
> + mount superblock on an automount.
> +
> + (*) struct cred *cred
> +
> + The mounter's credentials. This retains a ref on the credentials.
> +
> + (*) char *device
> +
> + This is the device to be mounted. It may be a block device
> + (e.g. /dev/sda1) or something more exotic, such as the "host:/path" that
> + NFS desires.
> +
> + (*) void *security
> +
> + A place for the LSMs to hang their security data for the superblock. The
> + relevant security operations are described below.
> +
> + (*) unsigned int sb_flags
> +
> + This holds the MS_* flags mount flags.
> +
> + (*) bool sloppy
> + (*) bool silent
> +
> + These are set if the sloppy or silent mount options are given.
> +
> + [NOTE] sloppy is probably unnecessary when userspace passes over one
> + option at a time since the error can just be ignored if userspace deems it
> + to be unimportant.
> +
> + [NOTE] silent is probably redundant with ms_flags & MS_SILENT.
> +
> + (*) bool degraded
> +
> + This is set if any preallocated resources in the context have been used
> + up, thereby rendering it unreusable for the ->get_tree() op.
> +
> + (*) enum fs_context_purpose
> +
> + This indicates the purpose for which the context is intended. The
> + available values are:
> +
> + FS_CONTEXT_FOR_NEW -- New mount
> + FS_CONTEXT_FOR_SUBMOUNT -- New automatic submount of extant mount
> + FS_CONTEXT_FOR_REMOUNT -- Change an existing mount
> +
> +The mount context is created by calling vfs_new_fs_context(), vfs_sb_reconfig()
> +or vfs_dup_fs_context() and is destroyed with put_fs_context(). Note that the
> +structure is not refcounted.
> +
> +VFS, security and filesystem mount options are set individually with
> +vfs_parse_mount_option(). Options provided by the old mount(2) system call as
> +a page of data can be parsed with generic_monolithic_mount_data().
> +
> +When mounting, the filesystem is allowed to take data from any of the pointers
> +and attach it to the superblock (or whatever), provided it clears the pointer
> +in the mount context.
> +
> +The filesystem is also allowed to allocate resources and pin them with the
> +mount context. For instance, NFS might pin the appropriate protocol version
> +module.
> +
> +
> +=================================
> +THE FILESYSTEM CONTEXT OPERATIONS
> +=================================
> +
> +The filesystem context points to a table of operations:
> +
> + struct fs_context_operations {
> + void (*free)(struct fs_context *fc);
> + int (*dup)(struct fs_context *fc, struct fs_context *src_fc);
> + int (*parse_option)(struct fs_context *fc, char *p);
> + int (*monolithic_mount_data)(struct fs_context *fc, void *data);
> + int (*validate)(struct fs_context *fc);
> + int (*get_tree)(struct fs_context *fc);
> + };
> +
> +These operations are invoked by the various stages of the mount procedure to
> +manage the filesystem context. They are as follows:
> +
> + (*) void (*free)(struct fs_context *fc);
> +
> + Called to clean up the filesystem-specific part of the filesystem context
> + when the context is destroyed. It should be aware that parts of the
> + context may have been removed and NULL'd out by ->get_tree().
> +
> + (*) int (*dup)(struct fs_context *fc, struct fs_context *src_fc);
> +
> + Called when a filesystem context has been duplicated to get any refs or
> + copy any non-referenced resources held in the filesystem-specific part of
> + the filesystem context. An error may be returned to indicate failure to
> + do this.
> +
> + [!] Note that even if this fails, put_fs_context() will be called
> + immediately thereafter, so ->dup() *must* make the
> + filesystem-specific part safe for ->free().
> +
> + (*) int (*parse_option)(struct fs_context *fc, char *p);
> +
> + Called when an option is to be added to the filesystem context. p points
> + to the option string, likely in "key[=val]" format. VFS-specific options
> + will have been weeded out and fc->sb_flags updated in the context.
> + Security options will also have been weeded out and fc->security updated.
> +
> + If successful, 0 should be returned and a negative error code otherwise.
> + If an ambiguous error (such as -EINVAL) is returned, sb_cfg_error() or
> + sb_cfg_inval() should be used to provide a string that provides more
> + information.
> +
> + (*) int (*monolithic_mount_data)(struct fs_context *fc, void *data);
> +
> + Called when the mount(2) system call is invoked to pass the entire data
> + page in one go. If this is expected to be just a list of "key[=val]"
> + items separated by commas, then this may be set to NULL.
> +
> + The return value is as for ->parse_option().
> +
> + If the filesystem (eg. NFS) needs to examine the data first and then finds
> + it's the standard key-val list then it may pass it off to
> + generic_monolithic_mount_data().
> +
> + (*) int (*validate)(struct fs_context *fc);
> +
> + Called when all the options have been applied and the mount is about to
> + take place. It is should check for inconsistencies from mount options and
> + it is also allowed to do preliminary resource acquisition. For instance,
> + the core NFS module could load the NFS protocol module here.
> +
> + Note that if fc->mount_type == FS_CONTEXT_FOR_REMOUNT, some of the options
> + necessary for a new mount may not be set.
> +
> + The return value is as for ->parse_option().
> +
> + (*) int (*get_tree)(struct fs_context *fc);
> +
> + Called to get or create the mountable root and superblock, using the
> + information stored in the filesystem context (remounts go
> + via a different vector). It may detach any resources it desires from the
> + filesystem context and transfer them to the superblock it
> + creates.
> +
> + On success it should set fc->root to the mountable root.
> +
> + In the case of an error, it should return a negative error code and
> + consider invoking sb_cfg_inval() or sb_cfg_error().
> +
> +
> +=========================================
> +FILESYSTEM CONTEXT SECURITY
> +========================================
> +
> +The filesystem context contains a security points that the LSMs
> +can use for building up a security context for the superblock to be mounted.
> +There are a number of operations used by the new mount code for this purpose:
> +
> + (*) int security_fs_context_alloc(struct fs_context *fc,
> + struct super_block *src_sb);
> +
> + Called to initialise fc->security (which is preset to NULL) and allocate
> + any resources needed. It should return 0 on success and a negative error
> + code on failure.
> +
> + src_sb is non-NULL in the case of a remount (FS_CONTEXT_FOR_REMOUNT) in
> + which case it indicates the superblock to be remounted or in the case of a
> + submount (FS_CONTEXT_FOR_SUBMOUNT) in which case it indicates the parent
> + superblock.
> +
> + (*) int security_fs_context_dup(struct fs_context *fc,
> + struct fs_context *src_mc);
> +
> + Called to initialise fc->security (which is preset to NULL) and allocate
> + any resources needed. The original filesystem context is
> + pointed to by src_mc and may be used for reference. It should return 0 on
> + success and a negative error code on failure.
> +
> + (*) void security_fs_context_free(struct fs_context *fc);
> +
> + Called to clean up anything attached to fc->security. Note that the
> + contents may have been transferred to a superblock and the pointer NULL'd
> + out during mount.
> +
> + (*) int security_fs_context_parse_option(struct fs_context *fc, char *opt);
> +
> + Called for each mount option. The mount options are in "key[=val]" form.
> + An active LSM may reject one with an error, pass one over and return 0 or
> + consume one and return 1. If consumed, the option isn't passed on to the
> + filesystem.
> +
> + If it returns an error, more information can be returned with
> + sb_cfg_inval() or sb_cfg_error().
> +
> + (*) int security_sb_get_tree(struct fs_context *fc);
> +
> + Called during the mount procedure to verify that the specified superblock
> + is allowed to be mounted and to transfer the security data there.
> +
> + On success, it should return 0; otherwise it should return an error and
> + perhaps call invalf() or errorf() to indicate the problem. It should not
> + return -ENOMEM as this should be taken care of in advance.
> +
> + [NOTE] Should I add a security_fs_context_validate() operation so that the
> + LSM has the opportunity to allocate stuff and check the options as a
> + whole?
> +
> +
> +=================================
> +VFS FILESYSTEM CONTEXT OPERATIONS
> +=================================
> +
> +There are four operations for creating a filesystem context and
> +one for destroying a context:
> +
> + (*) struct fs_context *__vfs_new_fs_context(struct file_system_type *fs_type,
> + struct super_block *src_sb;
> + unsigned int ms_flags);
> +
> + Create a filesystem context given a filesystem type pointer.
> + This allocates the filesystem context, sets the flags,
> + initialises the security and calls fs_type->init_fs_context() to initialise
> + the filesystem context.
> +
> + src_sb can be NULL or it may indicate a superblock that is going to be
> + remounted (FS_CONTEXT_FOR_REMOUNT) or a superblock that is the parent of a
> + submount (FS_CONTEXT_FOR_SUBMOUNT). This superblock is provided as a
> + source of namespace information.
> +
> + (*) struct fs_context *vfs_sb_reconfig(struct vfsmount *mnt,
> + unsigned int ms_flags);
> +
> + Create a filesystem context from the same filesystem as an
> + extant mount and initialise the mount parameters from the superblock
> + underlying that mount. This is for use by remount.
> +
> + (*) struct fs_context *vfs_new_fs_context(const char *fs_name);
> +
> + Create a filesystem context given a filesystem name. It is assumed that
> + the mount flags will be passed in as text options or set directly later.
> + This is intended to be called from sys_mount() or sys_fsopen(). This
> + copies current's namespaces to the context.
> +
> + (*) struct fs_context *vfs_dup_fs_context(struct fs_context *src_fc);
> +
> + Duplicate a filesystem context, copying any options noted and duplicating
> + or additionally referencing any resources held therein. This is
> + available for use where a filesystem has to get a mount within a mount,
> + such as NFS4 does by internally mounting the root of the target server
> + and then doing a private pathwalk to the target directory.
> +
> + (*) void put_fs_context(struct fs_context *fc);
> +
> + Destroy a filesystem context, releasing any resources it holds. This
> + calls the ->free() operation. This is intended to be called by anyone
> + who created a filesystem context.
> +
> + [!] filesystem contexts are not refcounted, so this causes unconditional
> + destruction.
> +
> +In all the above operations, apart from the put op, the return is a mount
> +context pointer or a negative error code. No error string is saved as the
> +error string is only guaranteed as long as the file_system_type is pinned (and
> +thus the module).
> +
> +In the remaining operations, if an error occurs, a negative error code is
> +returned and, if not obvious, fc->error_msg may have been set to point to a
> +useful string. This string should not be freed.
> +
> + (*) int vfs_get_tree(struct fs_context *fc);
> +
> + Get or create the mountable root and superblock, using the parameters in
> + the filesystem context to select/configure the superblock. This invokes
> + the ->validate() op and then the ->get_tree() op.
> +
> + [NOTE] ->validate() can probably be rolled into ->get_tree() and
> + ->remount_fs_fc().
> +
> + (*) struct vfsmount *vfs_kern_mount_fc(struct fs_context *fc);
> +
> + Create a mount given the parameters in the specified filesystem context.
> +
> + (*) struct vfsmount *vfs_submount_fc(const struct dentry *mountpoint,
> + struct fs_context *fc);
> +
> + Create a mount given a filesystem context and set MS_SUBMOUNT on it. A
> + wrapper around vfs_kern_mount_fc(). This is intended to be called from
> + filesystems that have automount points (NFS, AFS, ...).
> +
> + (*) int vfs_parse_mount_option(struct fs_context *fc, char *data);
> +
> + Supply a single mount option to the filesystem context. The mount option
> + should likely be in a "key[=val]" string form. The option is first
> + checked to see if it corresponds to a standard mount flag (in which case
> + it is used to mark an MS_xxx flag and consumed) or a security option (in
> + which case the LSM consumes it) before it is passed on to the filesystem.
> +
> + (*) int generic_monolithic_mount_data(struct fs_context *fc, void *data);
> +
> + Parse a sys_mount() data page, assuming the form to be a text list
> + consisting of key[=val] options separated by commas. Each item in the
> + list is passed to vfs_mount_option(). This is the default when the
> + ->monolithic_mount_data() operation is NULL.
> diff --git a/include/linux/fs_context.h b/include/linux/fs_context.h
> new file mode 100644
> index 000000000000..429c40be2c9e
> --- /dev/null
> +++ b/include/linux/fs_context.h
> @@ -0,0 +1,72 @@
> +/* Filesystem superblock creation and reconfiguration context.
> + *
> + * Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
> + * Written by David Howells (dhowells@redhat.com)
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public Licence
> + * as published by the Free Software Foundation; either version
> + * 2 of the Licence, or (at your option) any later version.
> + */
> +
> +#ifndef _LINUX_FS_CONTEXT_H
> +#define _LINUX_FS_CONTEXT_H
> +
> +#include <linux/kernel.h>
> +#include <linux/errno.h>
> +
> +struct cred;
> +struct dentry;
> +struct file_operations;
> +struct file_system_type;
> +struct mnt_namespace;
> +struct net;
> +struct pid_namespace;
> +struct super_block;
> +struct user_namespace;
> +struct vfsmount;
> +
> +enum fs_context_purpose {
> + FS_CONTEXT_FOR_NEW, /* New superblock for direct mount */
> + FS_CONTEXT_FOR_SUBMOUNT, /* New superblock for automatic submount */
> + FS_CONTEXT_FOR_REMOUNT, /* Superblock reconfiguration for remount */
> +};
> +
> +/*
> + * Filesystem context as allocated and constructed by the ->init_fs_context()
> + * file_system_type operation. The size of the object allocated is specified
> + * in struct file_system_type::fs_context_size and this must include sufficient
> + * space for the fs_context struct.
> + *
> + * Superblock creation fills in ->root whereas reconfiguration begins with this
> + * already set.
> + *
> + * See Documentation/filesystems/mounting.txt
> + */
> +struct fs_context {
> + const struct fs_context_operations *ops;
> + struct file_system_type *fs_type;
> + struct dentry *root; /* The root and superblock */
> + struct user_namespace *user_ns; /* The user namespace for this mount */
> + struct net *net_ns; /* The network namespace for this mount */
> + const struct cred *cred; /* The mounter's credentials */
> + char *device; /* The device name or mount target */
> + char *subtype; /* The subtype to set on the superblock */
> + void *security; /* The LSM context */
> + unsigned int sb_flags; /* The superblock flags (MS_*) */
> + bool sloppy; /* Unrecognised options are okay */
> + bool silent;
> + bool degraded; /* True if the context can't be reused */
> + enum fs_context_purpose purpose : 8;
> +};
> +
> +struct fs_context_operations {
> + void (*free)(struct fs_context *fc);
> + int (*dup)(struct fs_context *fc, struct fs_context *src_fc);
> + int (*parse_option)(struct fs_context *fc, char *p);
> + int (*monolithic_mount_data)(struct fs_context *fc, void *data);
> + int (*validate)(struct fs_context *fc);
> + int (*get_tree)(struct fs_context *fc);
> +};
> +
> +#endif /* _LINUX_FS_CONTEXT_H */
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
[toc] | [prev] | [next] | [standalone]
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2017-06-14 22:50 +0200 |
| Subject | Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] |
| Message-ID | <tSnoK-1uG-13@gated-at.bofh.it> |
| In reply to | #1666191 |
Casey Schaufler <casey@schaufler-ca.com> wrote: > Could you namespace the fields of this structure? > e.g. fs_cred, fs_security Linus objects to that practice. David
[toc] | [prev] | [next] | [standalone]
| From | Casey Schaufler <casey@schaufler-ca.com> |
|---|---|
| Date | 2017-06-14 23:00 +0200 |
| Subject | Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] |
| Message-ID | <tSnyq-1xS-23@gated-at.bofh.it> |
| In reply to | #1666219 |
On 6/14/2017 1:42 PM, David Howells wrote: > Casey Schaufler <casey@schaufler-ca.com> wrote: > >> Could you namespace the fields of this structure? >> e.g. fs_cred, fs_security > Linus objects to that practice. Sigh. Never mind. Thank you. > > David >
[toc] | [prev] | [next] | [standalone]
| From | Theodore Ts'o <tytso@mit.edu> |
|---|---|
| Date | 2017-06-17 12:00 +0200 |
| Subject | Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] |
| Message-ID | <tTiGl-5lx-1@gated-at.bofh.it> |
| In reply to | #1666227 |
On Wed, Jun 14, 2017 at 01:53:09PM -0700, Casey Schaufler wrote: > On 6/14/2017 1:42 PM, David Howells wrote: > > Casey Schaufler <casey@schaufler-ca.com> wrote: > > > >> Could you namespace the fields of this structure? > >> e.g. fs_cred, fs_security > > Linus objects to that practice. > > Sigh. Never mind. Thank you. I don't know that this is a hard and fast rule. Struct bio uses a "bi_" prefix (e.g., bi_error, bi_opf, bi_iter, etc.). I find it's really helpful when I'm doing a "git grep" over the whole tree; "git grep bi_flags" returns a much more specific and focused results than "git grep flags". :-) - Ted
[toc] | [prev] | [next] | [standalone]
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2017-06-17 16:20 +0200 |
| Subject | Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] |
| Message-ID | <tTmJX-8hC-1@gated-at.bofh.it> |
| In reply to | #1668211 |
Theodore Ts'o <tytso@mit.edu> wrote: > I don't know that this is a hard and fast rule. Struct bio uses a > "bi_" prefix (e.g., bi_error, bi_opf, bi_iter, etc.). Linus told me to stop doing it. David
[toc] | [prev] | [next] | [standalone]
| From | Jeff Layton <jlayton@redhat.com> |
|---|---|
| Date | 2017-06-17 17:00 +0200 |
| Subject | Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] |
| Message-ID | <tTnmF-65-1@gated-at.bofh.it> |
| In reply to | #1668260 |
On Sat, 2017-06-17 at 15:18 +0100, David Howells wrote: > Theodore Ts'o <tytso@mit.edu> wrote: > > > I don't know that this is a hard and fast rule. Struct bio uses a > > "bi_" prefix (e.g., bi_error, bi_opf, bi_iter, etc.). > > Linus told me to stop doing it. > > David That's a pity... I tend to like little prefixes on fields too. Trying to find all occurrences of a symbol called "flags" in cscope is a losing exercise. Do you have a reference to the discussion so I can understand the rationale there? Thanks, -- Jeff Layton <jlayton@redhat.com>
[toc] | [prev] | [next] | [standalone]
| From | Randy Dunlap <rdunlap@infradead.org> |
|---|---|
| Date | 2017-06-17 17:20 +0200 |
| Subject | Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] |
| Message-ID | <tTnG1-tN-9@gated-at.bofh.it> |
| In reply to | #1668265 |
On 06/17/2017 07:56 AM, Jeff Layton wrote: > On Sat, 2017-06-17 at 15:18 +0100, David Howells wrote: >> Theodore Ts'o <tytso@mit.edu> wrote: >> >>> I don't know that this is a hard and fast rule. Struct bio uses a >>> "bi_" prefix (e.g., bi_error, bi_opf, bi_iter, etc.). >> >> Linus told me to stop doing it. >> >> David > > > That's a pity... I tend to like little prefixes on fields too. Trying to > find all occurrences of a symbol called "flags" in cscope is a losing > exercise. > > Do you have a reference to the discussion so I can understand the > rationale there? Ack. This doesn't seem helpful. He also objected to drivers with file names that begin with the parent directory name, but we still have hundreds of those (see clk/, extcon/, gpio/, hid/, i2c/, leds/ [then I stopped looking]). -- ~Randy
[toc] | [prev] | [next] | [standalone]
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2017-06-19 09:50 +0200 |
| Subject | Re: [PATCH 08/27] VFS: Introduce the structs and doc for a filesystem context [ver #5] |
| Message-ID | <tTZBE-89S-21@gated-at.bofh.it> |
| In reply to | #1668265 |
Jeff Layton <jlayton@redhat.com> wrote: > Do you have a reference to the discussion so I can understand the > rationale there? I'm afraid not - it was around 15-20 years ago, I think. I seem to remember the rationale being something like "because it's a stupid idea". David
[toc] | [prev] | [next] | [standalone]
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2017-06-14 17:30 +0200 |
| Subject | [PATCH 21/27] NFS: Deindent nfs_fs_context_parse_option() [ver #5] |
| Message-ID | <tSip4-6TQ-25@gated-at.bofh.it> |
| In reply to | #1665947 |
Deindent nfs_fs_context_parse_option().
Signed-off-by: David Howells <dhowells@redhat.com>
---
fs/nfs/fs_context.c | 706 +++++++++++++++++++++++++--------------------------
1 file changed, 351 insertions(+), 355 deletions(-)
diff --git a/fs/nfs/fs_context.c b/fs/nfs/fs_context.c
index e3e431e3a1fc..a2ff9c30ff5a 100644
--- a/fs/nfs/fs_context.c
+++ b/fs/nfs/fs_context.c
@@ -498,395 +498,391 @@ static int nfs_get_option_ul_bound(substring_t args[], unsigned long *option,
*/
static int nfs_fs_context_parse_option(struct nfs_fs_context *ctx, char *p)
{
+ substring_t args[MAX_OPT_ARGS];
+ unsigned long option;
char *string;
- int rc;
-
- {
- substring_t args[MAX_OPT_ARGS];
- unsigned long option;
- int token;
+ int rc, token;
- dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
+ dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
- token = match_token(p, nfs_mount_option_tokens, args);
- switch (token) {
+ token = match_token(p, nfs_mount_option_tokens, args);
+ switch (token) {
/*
* boolean options: foo/nofoo
*/
- case Opt_soft:
- ctx->flags |= NFS_MOUNT_SOFT;
- break;
- case Opt_hard:
- ctx->flags &= ~NFS_MOUNT_SOFT;
- break;
- case Opt_posix:
- ctx->flags |= NFS_MOUNT_POSIX;
- break;
- case Opt_noposix:
- ctx->flags &= ~NFS_MOUNT_POSIX;
- break;
- case Opt_cto:
- ctx->flags &= ~NFS_MOUNT_NOCTO;
- break;
- case Opt_nocto:
- ctx->flags |= NFS_MOUNT_NOCTO;
- break;
- case Opt_ac:
- ctx->flags &= ~NFS_MOUNT_NOAC;
- break;
- case Opt_noac:
- ctx->flags |= NFS_MOUNT_NOAC;
- break;
- case Opt_lock:
- ctx->flags &= ~NFS_MOUNT_NONLM;
- ctx->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
- NFS_MOUNT_LOCAL_FCNTL);
- break;
- case Opt_nolock:
- ctx->flags |= NFS_MOUNT_NONLM;
- ctx->flags |= (NFS_MOUNT_LOCAL_FLOCK |
- NFS_MOUNT_LOCAL_FCNTL);
- break;
- case Opt_udp:
- ctx->flags &= ~NFS_MOUNT_TCP;
- ctx->nfs_server.protocol = XPRT_TRANSPORT_UDP;
- break;
- case Opt_tcp:
- ctx->flags |= NFS_MOUNT_TCP;
- ctx->nfs_server.protocol = XPRT_TRANSPORT_TCP;
- break;
- case Opt_rdma:
- ctx->flags |= NFS_MOUNT_TCP; /* for side protocols */
- ctx->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
- xprt_load_transport(p);
- break;
- case Opt_acl:
- ctx->flags &= ~NFS_MOUNT_NOACL;
- break;
- case Opt_noacl:
- ctx->flags |= NFS_MOUNT_NOACL;
- break;
- case Opt_rdirplus:
- ctx->flags &= ~NFS_MOUNT_NORDIRPLUS;
- break;
- case Opt_nordirplus:
- ctx->flags |= NFS_MOUNT_NORDIRPLUS;
- break;
- case Opt_sharecache:
- ctx->flags &= ~NFS_MOUNT_UNSHARED;
- break;
- case Opt_nosharecache:
- ctx->flags |= NFS_MOUNT_UNSHARED;
- break;
- case Opt_resvport:
- ctx->flags &= ~NFS_MOUNT_NORESVPORT;
- break;
- case Opt_noresvport:
- ctx->flags |= NFS_MOUNT_NORESVPORT;
- break;
- case Opt_fscache:
- ctx->options |= NFS_OPTION_FSCACHE;
- kfree(ctx->fscache_uniq);
- ctx->fscache_uniq = NULL;
- break;
- case Opt_nofscache:
- ctx->options &= ~NFS_OPTION_FSCACHE;
- kfree(ctx->fscache_uniq);
- ctx->fscache_uniq = NULL;
- break;
- case Opt_migration:
- ctx->options |= NFS_OPTION_MIGRATION;
- break;
- case Opt_nomigration:
- ctx->options &= NFS_OPTION_MIGRATION;
- break;
+ case Opt_soft:
+ ctx->flags |= NFS_MOUNT_SOFT;
+ break;
+ case Opt_hard:
+ ctx->flags &= ~NFS_MOUNT_SOFT;
+ break;
+ case Opt_posix:
+ ctx->flags |= NFS_MOUNT_POSIX;
+ break;
+ case Opt_noposix:
+ ctx->flags &= ~NFS_MOUNT_POSIX;
+ break;
+ case Opt_cto:
+ ctx->flags &= ~NFS_MOUNT_NOCTO;
+ break;
+ case Opt_nocto:
+ ctx->flags |= NFS_MOUNT_NOCTO;
+ break;
+ case Opt_ac:
+ ctx->flags &= ~NFS_MOUNT_NOAC;
+ break;
+ case Opt_noac:
+ ctx->flags |= NFS_MOUNT_NOAC;
+ break;
+ case Opt_lock:
+ ctx->flags &= ~NFS_MOUNT_NONLM;
+ ctx->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
+ NFS_MOUNT_LOCAL_FCNTL);
+ break;
+ case Opt_nolock:
+ ctx->flags |= NFS_MOUNT_NONLM;
+ ctx->flags |= (NFS_MOUNT_LOCAL_FLOCK |
+ NFS_MOUNT_LOCAL_FCNTL);
+ break;
+ case Opt_udp:
+ ctx->flags &= ~NFS_MOUNT_TCP;
+ ctx->nfs_server.protocol = XPRT_TRANSPORT_UDP;
+ break;
+ case Opt_tcp:
+ ctx->flags |= NFS_MOUNT_TCP;
+ ctx->nfs_server.protocol = XPRT_TRANSPORT_TCP;
+ break;
+ case Opt_rdma:
+ ctx->flags |= NFS_MOUNT_TCP; /* for side protocols */
+ ctx->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
+ xprt_load_transport(p);
+ break;
+ case Opt_acl:
+ ctx->flags &= ~NFS_MOUNT_NOACL;
+ break;
+ case Opt_noacl:
+ ctx->flags |= NFS_MOUNT_NOACL;
+ break;
+ case Opt_rdirplus:
+ ctx->flags &= ~NFS_MOUNT_NORDIRPLUS;
+ break;
+ case Opt_nordirplus:
+ ctx->flags |= NFS_MOUNT_NORDIRPLUS;
+ break;
+ case Opt_sharecache:
+ ctx->flags &= ~NFS_MOUNT_UNSHARED;
+ break;
+ case Opt_nosharecache:
+ ctx->flags |= NFS_MOUNT_UNSHARED;
+ break;
+ case Opt_resvport:
+ ctx->flags &= ~NFS_MOUNT_NORESVPORT;
+ break;
+ case Opt_noresvport:
+ ctx->flags |= NFS_MOUNT_NORESVPORT;
+ break;
+ case Opt_fscache:
+ ctx->options |= NFS_OPTION_FSCACHE;
+ kfree(ctx->fscache_uniq);
+ ctx->fscache_uniq = NULL;
+ break;
+ case Opt_nofscache:
+ ctx->options &= ~NFS_OPTION_FSCACHE;
+ kfree(ctx->fscache_uniq);
+ ctx->fscache_uniq = NULL;
+ break;
+ case Opt_migration:
+ ctx->options |= NFS_OPTION_MIGRATION;
+ break;
+ case Opt_nomigration:
+ ctx->options &= NFS_OPTION_MIGRATION;
+ break;
/*
* options that take numeric values
*/
- case Opt_port:
- if (nfs_get_option_ul(args, &option) ||
- option > USHRT_MAX)
- goto out_invalid_value;
- ctx->nfs_server.port = option;
- break;
- case Opt_rsize:
- if (nfs_get_option_ul(args, &option))
- goto out_invalid_value;
- ctx->rsize = option;
- break;
- case Opt_wsize:
- if (nfs_get_option_ul(args, &option))
- goto out_invalid_value;
- ctx->wsize = option;
- break;
- case Opt_bsize:
- if (nfs_get_option_ul(args, &option))
- goto out_invalid_value;
- ctx->bsize = option;
- break;
- case Opt_timeo:
- if (nfs_get_option_ul_bound(args, &option, 1, INT_MAX))
- goto out_invalid_value;
- ctx->timeo = option;
- break;
- case Opt_retrans:
- if (nfs_get_option_ul_bound(args, &option, 0, INT_MAX))
- goto out_invalid_value;
- ctx->retrans = option;
- break;
- case Opt_acregmin:
- if (nfs_get_option_ul(args, &option))
- goto out_invalid_value;
- ctx->acregmin = option;
- break;
- case Opt_acregmax:
- if (nfs_get_option_ul(args, &option))
- goto out_invalid_value;
- ctx->acregmax = option;
- break;
- case Opt_acdirmin:
- if (nfs_get_option_ul(args, &option))
- goto out_invalid_value;
- ctx->acdirmin = option;
- break;
- case Opt_acdirmax:
- if (nfs_get_option_ul(args, &option))
- goto out_invalid_value;
- ctx->acdirmax = option;
- break;
- case Opt_actimeo:
- if (nfs_get_option_ul(args, &option))
- goto out_invalid_value;
- ctx->acregmin = ctx->acregmax =
+ case Opt_port:
+ if (nfs_get_option_ul(args, &option) ||
+ option > USHRT_MAX)
+ goto out_invalid_value;
+ ctx->nfs_server.port = option;
+ break;
+ case Opt_rsize:
+ if (nfs_get_option_ul(args, &option))
+ goto out_invalid_value;
+ ctx->rsize = option;
+ break;
+ case Opt_wsize:
+ if (nfs_get_option_ul(args, &option))
+ goto out_invalid_value;
+ ctx->wsize = option;
+ break;
+ case Opt_bsize:
+ if (nfs_get_option_ul(args, &option))
+ goto out_invalid_value;
+ ctx->bsize = option;
+ break;
+ case Opt_timeo:
+ if (nfs_get_option_ul_bound(args, &option, 1, INT_MAX))
+ goto out_invalid_value;
+ ctx->timeo = option;
+ break;
+ case Opt_retrans:
+ if (nfs_get_option_ul_bound(args, &option, 0, INT_MAX))
+ goto out_invalid_value;
+ ctx->retrans = option;
+ break;
+ case Opt_acregmin:
+ if (nfs_get_option_ul(args, &option))
+ goto out_invalid_value;
+ ctx->acregmin = option;
+ break;
+ case Opt_acregmax:
+ if (nfs_get_option_ul(args, &option))
+ goto out_invalid_value;
+ ctx->acregmax = option;
+ break;
+ case Opt_acdirmin:
+ if (nfs_get_option_ul(args, &option))
+ goto out_invalid_value;
+ ctx->acdirmin = option;
+ break;
+ case Opt_acdirmax:
+ if (nfs_get_option_ul(args, &option))
+ goto out_invalid_value;
+ ctx->acdirmax = option;
+ break;
+ case Opt_actimeo:
+ if (nfs_get_option_ul(args, &option))
+ goto out_invalid_value;
+ ctx->acregmin = ctx->acregmax =
ctx->acdirmin = ctx->acdirmax = option;
- break;
- case Opt_namelen:
- if (nfs_get_option_ul(args, &option))
- goto out_invalid_value;
- ctx->namlen = option;
- break;
- case Opt_mountport:
- if (nfs_get_option_ul(args, &option) ||
- option > USHRT_MAX)
- goto out_invalid_value;
- ctx->mount_server.port = option;
- break;
- case Opt_mountvers:
- if (nfs_get_option_ul(args, &option) ||
- option < NFS_MNT_VERSION ||
- option > NFS_MNT3_VERSION)
- goto out_invalid_value;
- ctx->mount_server.version = option;
- break;
- case Opt_minorversion:
- if (nfs_get_option_ul(args, &option))
- goto out_invalid_value;
- if (option > NFS4_MAX_MINOR_VERSION)
- goto out_invalid_value;
- ctx->minorversion = option;
- break;
+ break;
+ case Opt_namelen:
+ if (nfs_get_option_ul(args, &option))
+ goto out_invalid_value;
+ ctx->namlen = option;
+ break;
+ case Opt_mountport:
+ if (nfs_get_option_ul(args, &option) ||
+ option > USHRT_MAX)
+ goto out_invalid_value;
+ ctx->mount_server.port = option;
+ break;
+ case Opt_mountvers:
+ if (nfs_get_option_ul(args, &option) ||
+ option < NFS_MNT_VERSION ||
+ option > NFS_MNT3_VERSION)
+ goto out_invalid_value;
+ ctx->mount_server.version = option;
+ break;
+ case Opt_minorversion:
+ if (nfs_get_option_ul(args, &option))
+ goto out_invalid_value;
+ if (option > NFS4_MAX_MINOR_VERSION)
+ goto out_invalid_value;
+ ctx->minorversion = option;
+ break;
/*
* options that take text values
*/
- case Opt_nfsvers:
- string = match_strdup(args);
- if (string == NULL)
- goto out_nomem;
- rc = nfs_parse_version_string(string, ctx, args);
- kfree(string);
- if (!rc)
- goto out_invalid_value;
+ case Opt_nfsvers:
+ string = match_strdup(args);
+ if (string == NULL)
+ goto out_nomem;
+ rc = nfs_parse_version_string(string, ctx, args);
+ kfree(string);
+ if (!rc)
+ goto out_invalid_value;
+ break;
+ case Opt_sec:
+ string = match_strdup(args);
+ if (string == NULL)
+ goto out_nomem;
+ rc = nfs_parse_security_flavors(string, ctx);
+ kfree(string);
+ if (!rc) {
+ dfprintk(MOUNT, "NFS: unrecognized "
+ "security flavor\n");
+ return -EINVAL;
+ }
+ break;
+ case Opt_proto:
+ string = match_strdup(args);
+ if (string == NULL)
+ goto out_nomem;
+ token = match_token(string,
+ nfs_xprt_protocol_tokens, args);
+
+ ctx->protofamily = AF_INET;
+ switch (token) {
+ case Opt_xprt_udp6:
+ ctx->protofamily = AF_INET6;
+ case Opt_xprt_udp:
+ ctx->flags &= ~NFS_MOUNT_TCP;
+ ctx->nfs_server.protocol = XPRT_TRANSPORT_UDP;
break;
- case Opt_sec:
- string = match_strdup(args);
- if (string == NULL)
- goto out_nomem;
- rc = nfs_parse_security_flavors(string, ctx);
- kfree(string);
- if (!rc) {
- dfprintk(MOUNT, "NFS: unrecognized "
- "security flavor\n");
- return -EINVAL;
- }
+ case Opt_xprt_tcp6:
+ ctx->protofamily = AF_INET6;
+ case Opt_xprt_tcp:
+ ctx->flags |= NFS_MOUNT_TCP;
+ ctx->nfs_server.protocol = XPRT_TRANSPORT_TCP;
break;
- case Opt_proto:
- string = match_strdup(args);
- if (string == NULL)
- goto out_nomem;
- token = match_token(string,
- nfs_xprt_protocol_tokens, args);
-
- ctx->protofamily = AF_INET;
- switch (token) {
- case Opt_xprt_udp6:
- ctx->protofamily = AF_INET6;
- case Opt_xprt_udp:
- ctx->flags &= ~NFS_MOUNT_TCP;
- ctx->nfs_server.protocol = XPRT_TRANSPORT_UDP;
- break;
- case Opt_xprt_tcp6:
- ctx->protofamily = AF_INET6;
- case Opt_xprt_tcp:
- ctx->flags |= NFS_MOUNT_TCP;
- ctx->nfs_server.protocol = XPRT_TRANSPORT_TCP;
- break;
- case Opt_xprt_rdma6:
- ctx->protofamily = AF_INET6;
- case Opt_xprt_rdma:
- /* vector side protocols to TCP */
- ctx->flags |= NFS_MOUNT_TCP;
- ctx->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
- xprt_load_transport(string);
- break;
- default:
- dfprintk(MOUNT, "NFS: unrecognized "
- "transport protocol\n");
- kfree(string);
- return -EINVAL;
- }
- kfree(string);
+ case Opt_xprt_rdma6:
+ ctx->protofamily = AF_INET6;
+ case Opt_xprt_rdma:
+ /* vector side protocols to TCP */
+ ctx->flags |= NFS_MOUNT_TCP;
+ ctx->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
+ xprt_load_transport(string);
break;
- case Opt_mountproto:
- string = match_strdup(args);
- if (string == NULL)
- goto out_nomem;
- token = match_token(string,
- nfs_xprt_protocol_tokens, args);
+ default:
+ dfprintk(MOUNT, "NFS: unrecognized "
+ "transport protocol\n");
kfree(string);
+ return -EINVAL;
+ }
+ kfree(string);
+ break;
+ case Opt_mountproto:
+ string = match_strdup(args);
+ if (string == NULL)
+ goto out_nomem;
+ token = match_token(string,
+ nfs_xprt_protocol_tokens, args);
+ kfree(string);
- ctx->mountfamily = AF_INET;
- switch (token) {
- case Opt_xprt_udp6:
- ctx->mountfamily = AF_INET6;
- case Opt_xprt_udp:
- ctx->mount_server.protocol = XPRT_TRANSPORT_UDP;
- break;
- case Opt_xprt_tcp6:
- ctx->mountfamily = AF_INET6;
- case Opt_xprt_tcp:
- ctx->mount_server.protocol = XPRT_TRANSPORT_TCP;
- break;
- case Opt_xprt_rdma: /* not used for side protocols */
- default:
- dfprintk(MOUNT, "NFS: unrecognized "
- "transport protocol\n");
- return -EINVAL;
- }
+ ctx->mountfamily = AF_INET;
+ switch (token) {
+ case Opt_xprt_udp6:
+ ctx->mountfamily = AF_INET6;
+ case Opt_xprt_udp:
+ ctx->mount_server.protocol = XPRT_TRANSPORT_UDP;
break;
- case Opt_addr:
- string = match_strdup(args);
- if (string == NULL)
- goto out_nomem;
- ctx->nfs_server.addrlen =
- rpc_pton(ctx->net, string, strlen(string),
- (struct sockaddr *)
- &ctx->nfs_server.address,
- sizeof(ctx->nfs_server.address));
- kfree(string);
- if (ctx->nfs_server.addrlen == 0)
- goto out_invalid_address;
+ case Opt_xprt_tcp6:
+ ctx->mountfamily = AF_INET6;
+ case Opt_xprt_tcp:
+ ctx->mount_server.protocol = XPRT_TRANSPORT_TCP;
break;
- case Opt_clientaddr:
- if (nfs_get_option_str(args, &ctx->client_address))
- goto out_nomem;
+ case Opt_xprt_rdma: /* not used for side protocols */
+ default:
+ dfprintk(MOUNT, "NFS: unrecognized "
+ "transport protocol\n");
+ return -EINVAL;
+ }
+ break;
+ case Opt_addr:
+ string = match_strdup(args);
+ if (string == NULL)
+ goto out_nomem;
+ ctx->nfs_server.addrlen =
+ rpc_pton(ctx->net, string, strlen(string),
+ (struct sockaddr *)
+ &ctx->nfs_server.address,
+ sizeof(ctx->nfs_server.address));
+ kfree(string);
+ if (ctx->nfs_server.addrlen == 0)
+ goto out_invalid_address;
+ break;
+ case Opt_clientaddr:
+ if (nfs_get_option_str(args, &ctx->client_address))
+ goto out_nomem;
+ break;
+ case Opt_mounthost:
+ if (nfs_get_option_str(args,
+ &ctx->mount_server.hostname))
+ goto out_nomem;
+ break;
+ case Opt_mountaddr:
+ string = match_strdup(args);
+ if (string == NULL)
+ goto out_nomem;
+ ctx->mount_server.addrlen =
+ rpc_pton(ctx->net, string, strlen(string),
+ (struct sockaddr *)
+ &ctx->mount_server.address,
+ sizeof(ctx->mount_server.address));
+ kfree(string);
+ if (ctx->mount_server.addrlen == 0)
+ goto out_invalid_address;
+ break;
+ case Opt_lookupcache:
+ string = match_strdup(args);
+ if (string == NULL)
+ goto out_nomem;
+ token = match_token(string,
+ nfs_lookupcache_tokens, args);
+ kfree(string);
+ switch (token) {
+ case Opt_lookupcache_all:
+ ctx->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
break;
- case Opt_mounthost:
- if (nfs_get_option_str(args,
- &ctx->mount_server.hostname))
- goto out_nomem;
+ case Opt_lookupcache_positive:
+ ctx->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
+ ctx->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
break;
- case Opt_mountaddr:
- string = match_strdup(args);
- if (string == NULL)
- goto out_nomem;
- ctx->mount_server.addrlen =
- rpc_pton(ctx->net, string, strlen(string),
- (struct sockaddr *)
- &ctx->mount_server.address,
- sizeof(ctx->mount_server.address));
- kfree(string);
- if (ctx->mount_server.addrlen == 0)
- goto out_invalid_address;
+ case Opt_lookupcache_none:
+ ctx->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
break;
- case Opt_lookupcache:
- string = match_strdup(args);
- if (string == NULL)
- goto out_nomem;
- token = match_token(string,
- nfs_lookupcache_tokens, args);
- kfree(string);
- switch (token) {
- case Opt_lookupcache_all:
- ctx->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
- break;
- case Opt_lookupcache_positive:
- ctx->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
- ctx->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
- break;
- case Opt_lookupcache_none:
- ctx->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
- break;
- default:
- dfprintk(MOUNT, "NFS: invalid "
- "lookupcache argument\n");
- return -EINVAL;
- };
+ default:
+ dfprintk(MOUNT, "NFS: invalid "
+ "lookupcache argument\n");
+ return -EINVAL;
+ };
+ break;
+ case Opt_fscache_uniq:
+ if (nfs_get_option_str(args, &ctx->fscache_uniq))
+ goto out_nomem;
+ ctx->options |= NFS_OPTION_FSCACHE;
+ break;
+ case Opt_local_lock:
+ string = match_strdup(args);
+ if (string == NULL)
+ goto out_nomem;
+ token = match_token(string, nfs_local_lock_tokens,
+ args);
+ kfree(string);
+ switch (token) {
+ case Opt_local_lock_all:
+ ctx->flags |= (NFS_MOUNT_LOCAL_FLOCK |
+ NFS_MOUNT_LOCAL_FCNTL);
break;
- case Opt_fscache_uniq:
- if (nfs_get_option_str(args, &ctx->fscache_uniq))
- goto out_nomem;
- ctx->options |= NFS_OPTION_FSCACHE;
+ case Opt_local_lock_flock:
+ ctx->flags |= NFS_MOUNT_LOCAL_FLOCK;
break;
- case Opt_local_lock:
- string = match_strdup(args);
- if (string == NULL)
- goto out_nomem;
- token = match_token(string, nfs_local_lock_tokens,
- args);
- kfree(string);
- switch (token) {
- case Opt_local_lock_all:
- ctx->flags |= (NFS_MOUNT_LOCAL_FLOCK |
- NFS_MOUNT_LOCAL_FCNTL);
- break;
- case Opt_local_lock_flock:
- ctx->flags |= NFS_MOUNT_LOCAL_FLOCK;
- break;
- case Opt_local_lock_posix:
- ctx->flags |= NFS_MOUNT_LOCAL_FCNTL;
- break;
- case Opt_local_lock_none:
- ctx->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
- NFS_MOUNT_LOCAL_FCNTL);
- break;
- default:
- dfprintk(MOUNT, "NFS: invalid "
- "local_lock argument\n");
- return -EINVAL;
- };
+ case Opt_local_lock_posix:
+ ctx->flags |= NFS_MOUNT_LOCAL_FCNTL;
break;
+ case Opt_local_lock_none:
+ ctx->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
+ NFS_MOUNT_LOCAL_FCNTL);
+ break;
+ default:
+ dfprintk(MOUNT, "NFS: invalid "
+ "local_lock argument\n");
+ return -EINVAL;
+ };
+ break;
/*
* Special options
*/
- case Opt_sloppy:
- ctx->sloppy = 1;
- dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
- break;
- case Opt_userspace:
- case Opt_deprecated:
- dfprintk(MOUNT, "NFS: ignoring mount option "
- "'%s'\n", p);
- break;
+ case Opt_sloppy:
+ ctx->sloppy = 1;
+ dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
+ break;
+ case Opt_userspace:
+ case Opt_deprecated:
+ dfprintk(MOUNT, "NFS: ignoring mount option "
+ "'%s'\n", p);
+ break;
- default:
- dfprintk(MOUNT, "NFS: unrecognized mount option "
- "'%s'\n", p);
- return -EINVAL;
- }
+ default:
+ dfprintk(MOUNT, "NFS: unrecognized mount option "
+ "'%s'\n", p);
+ return -EINVAL;
}
return 0;
[toc] | [prev] | [next] | [standalone]
| From | Al Viro <viro@ZenIV.linux.org.uk> |
|---|---|
| Date | 2017-06-15 11:50 +0200 |
| Subject | Re: [PATCH 07/27] VFS: Differentiate mount flags (MS_*) from internal superblock flags [ver #5] |
| Message-ID | <tSzzA-MV-15@gated-at.bofh.it> |
| In reply to | #1665947 |
On Wed, Jun 14, 2017 at 04:16:22PM +0100, David Howells wrote:
> diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
> index d2fb9c8ed205..e831c115daf9 100644
> --- a/drivers/base/devtmpfs.c
> +++ b/drivers/base/devtmpfs.c
> @@ -355,7 +355,7 @@ int devtmpfs_mount(const char *mntdir)
> if (!thread)
> return 0;
>
> - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
> + err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", SB_SILENT, NULL);
> if (err)
> printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
> else
> @@ -381,7 +381,7 @@ static int devtmpfsd(void *p)
> *err = sys_unshare(CLONE_NEWNS);
> if (*err)
> goto out;
> - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
> + *err = sys_mount("devtmpfs", "/", "devtmpfs", SB_SILENT, options);
Er... These really should be MS_SILENT.
> @@ -311,14 +311,14 @@ static void get_dpms_capabilities(unsigned char flags,
> struct fb_monspecs *specs)
> {
> specs->dpms = 0;
> - if (flags & DPMS_ACTIVE_OFF)
> - specs->dpms |= FB_DPMS_ACTIVE_OFF;
> + if (flags & DPSB_ACTIVE_OFF)
> + specs->dpms |= FB_DPSB_ACTIVE_OFF;
... the hell?
> - if (sb->s_flags & MS_RDONLY)
> + if (sb->s_flags & SB_RDONLY)
TBH, it looks like something along the lines of sb_rdonly(sb) for the above would
make more sense.
> static int flags_to_propagation_type(int flags)
> {
> - int type = flags & ~(MS_REC | MS_SILENT);
> + int type = flags & ~(MS_REC | SB_SILENT);
Huh?
> - flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
> - MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
> - MS_STRICTATIME | MS_NOREMOTELOCK | MS_SUBMOUNT);
> + flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | SB_ACTIVE | SB_BORN |
> + MS_NOATIME | MS_NODIRATIME | MS_RELATIME| SB_KERNMOUNT |
> + MS_STRICTATIME | SB_NOREMOTELOCK | SB_SUBMOUNT);
This is complete bullshit. _IF_ you want to separate these sets, do that
consistently. Mixing MS_... with SB_... in a mask is obviously wrong.
Sure, you can use the fact that such-and-such SB_ flag is the same value
as MS_... one; worth a BUILD_BUG_ON() somewhere to enforce that. However,
please separate the places where you have mount(2) flags argument from
those where you have a set of SB_... bits.
In this case you certainly have MS_... bunch. What's more, I would rather
do it as "we look only at..." instead of "we ignore the following..." - and
probably do it in do_...() functions instead. Note that they already
have parsing and validation of their own...
> diff --git a/tools/testing/selftests/mount/unprivileged-remount-test.c b/tools/testing/selftests/mount/unprivileged-remount-test.c
> index 517785052f1c..65489157f8d7 100644
> --- a/tools/testing/selftests/mount/unprivileged-remount-test.c
> +++ b/tools/testing/selftests/mount/unprivileged-remount-test.c
> @@ -129,7 +129,7 @@ static int read_mnt_flags(const char *path)
> }
> mnt_flags = 0;
> if (stat.f_flag & ST_RDONLY)
> - mnt_flags |= MS_RDONLY;
> + mnt_flags |= SB_RDONLY;
> if (stat.f_flag & ST_NOSUID)
> mnt_flags |= MS_NOSUID;
> if (stat.f_flag & ST_NODEV)
> @@ -143,7 +143,7 @@ static int read_mnt_flags(const char *path)
> if (stat.f_flag & ST_RELATIME)
> mnt_flags |= MS_RELATIME;
> if (stat.f_flag & ST_SYNCHRONOUS)
> - mnt_flags |= MS_SYNCHRONOUS;
> + mnt_flags |= SB_SYNCHRONOUS;
> if (stat.f_flag & ST_MANDLOCK)
> mnt_flags |= ST_MANDLOCK;
Really? That's userland code, isn't it?
[toc] | [prev] | [next] | [standalone]
| From | Christoph Hellwig <hch@infradead.org> |
|---|---|
| Date | 2017-06-16 11:10 +0200 |
| Subject | Re: [PATCH 07/27] VFS: Differentiate mount flags (MS_*) from internal superblock flags [ver #5] |
| Message-ID | <tSVqr-6tS-35@gated-at.bofh.it> |
| In reply to | #1666605 |
FYI, this patch didn't seem to make it through to the list, probably because it was too large. It might be good to just introduce the internal flags field first, populate it with the translated flags, then switch users over to it, and last but not least remove the old flags field and the MS_* values that were only used internally. Also if would be good to sort this out in a separate series without all the mount context stuff.
[toc] | [prev] | [next] | [standalone]
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2017-06-16 17:00 +0200 |
| Subject | Re: [PATCH 07/27] VFS: Differentiate mount flags (MS_*) from internal superblock flags [ver #5] |
| Message-ID | <tT0T7-1p7-13@gated-at.bofh.it> |
| In reply to | #1667553 |
Christoph Hellwig <hch@infradead.org> wrote: > It might be good to just introduce the internal flags field first, Internal flags field? Did you mean Al's suggested sb_readonly() wrapper? David
[toc] | [prev] | [next] | [standalone]
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
Back to top | Article view | linux.kernel
csiph-web