From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: David Howells <dhowells@redhat.com>
Cc: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org,
linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
mszeredi@redhat.com
Subject: Re: [PATCH 3/9] VFS: Introduce a mount context
Date: Wed, 03 May 2017 23:43:47 +0200 [thread overview]
Message-ID: <87bmr939bg.fsf@rasmusvillemoes.dk> (raw)
In-Reply-To: <149382749941.30481.11685229083280551867.stgit@warthog.procyon.org.uk> (David Howells's message of "Wed, 03 May 2017 17:04:59 +0100")
On Wed, May 03 2017, David Howells <dhowells@redhat.com> wrote:
> fs_type->fsopen() is called to set it up. fs_type->mc_size says how much
> should be added on to the mount context for the filesystem's use.
This is repeated several times in the documentation, but the code says
that ->mc_size should be the full size of the struct wrapping struct
mount_context.
> diff --git a/fs/mount.h b/fs/mount.h
> index 2826543a131d..b1e99b38f2ee 100644
> --- a/fs/mount.h
> +++ b/fs/mount.h
> @@ -108,9 +108,10 @@ static inline void detach_mounts(struct dentry *dentry)
> __detach_mounts(dentry);
> }
>
> -static inline void get_mnt_ns(struct mnt_namespace *ns)
> +static inline struct mnt_namespace *get_mnt_ns(struct mnt_namespace *ns)
> {
> atomic_inc(&ns->count);
> + return ns;
> }
>
> extern seqlock_t mount_lock;
it's not much, but at least this could go into a patch of its own.
> +/**
> + * __vfs_fsopen - Open a filesystem and create a mount context
> + * @fs_type: The filesystem type
> + * @src_sb: A superblock from which this one derives (or NULL)
> + * @ms_flags: Superblock flags and op flags (such as MS_REMOUNT)
> + * @mnt_flags: Mountpoint flags, such as MNT_READONLY
> + * @mount_type: Type of mount
> + *
> + * Open a filesystem and create a mount context. The mount context is
> + * initialised with the supplied flags and, if a submount/automount from
> + * another superblock (@src_sb), may have parameters such as namespaces copied
> + * across from that superblock.
> + */
> +struct mount_context *__vfs_fsopen(struct file_system_type *fs_type,
> + struct super_block *src_sb,
> + unsigned int ms_flags, unsigned int mnt_flags,
> + enum mount_type mount_type)
> +{
> + struct mount_context *mc;
> + int ret;
> +
> + if (fs_type->fsopen && fs_type->mc_size < sizeof(*mc))
> + BUG();
So ->mc_size can be 0 (i.e. not explicitly initialized) if fs_type does
not have ->fsopen. OK.
> + mc = kzalloc(max_t(size_t, fs_type->mc_size, sizeof(*mc)), GFP_KERNEL);
In which case we round up to sizeof(*mc). OK.
> + if (!mc)
> + return ERR_PTR(-ENOMEM);
> +
> + mc->mount_type = mount_type;
> + mc->ms_flags = ms_flags;
> + mc->mnt_flags = mnt_flags;
> + mc->fs_type = fs_type;
> + get_filesystem(fs_type);
Maybe get_filesystem should also be taught to return its argument so
this could be written like the below assignments.
> + mc->mnt_ns = get_mnt_ns(current->nsproxy->mnt_ns);
> + mc->pid_ns = get_pid_ns(task_active_pid_ns(current));
> + mc->net_ns = get_net(current->nsproxy->net_ns);
> + mc->user_ns = get_user_ns(current_user_ns());
> + mc->cred = get_current_cred();
> +
> +
> +/**
> + * vfs_dup_mount_context: Duplicate a mount context.
> + * @src: The mount context to copy.
> + */
> +struct mount_context *vfs_dup_mount_context(struct mount_context *src)
> +{
> + struct mount_context *mc;
> + int ret;
> +
> + if (!src->ops->dup)
> + return ERR_PTR(-ENOTSUPP);
> +
> + mc = kmemdup(src, src->fs_type->mc_size, GFP_KERNEL);
So this assumes that vfs_dup_mount_context is only used if ->mc_size is
explicitly initialized. A max_t here as well probably wouldn't hurt.
> + unsigned short mc_size; /* Size of mount context to allocate */
Any particular reason to use a short? The struct doesn't pack any better.
> +static int selinux_mount_ctx_dup(struct mount_context *mc,
> + struct mount_context *src_mc)
> +{
> + const struct security_mnt_opts *src = src_mc->security;
> + struct security_mnt_opts *opts;
> + int i, n;
> +
> + opts = kzalloc(sizeof(*opts), GFP_KERNEL);
> + if (!opts)
> + return -ENOMEM;
> + mc->security = opts;
> +
> + if (!src || !src->num_mnt_opts)
> + return 0;
> + n = opts->num_mnt_opts = src->num_mnt_opts;
> +
> + if (opts->mnt_opts) {
should probably be src->mnt_opts
next prev parent reply other threads:[~2017-05-03 21:43 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-03 16:04 [RFC][PATCH 0/9] VFS: Introduce " David Howells
2017-05-03 16:04 ` [PATCH 1/9] Provide a function to create a NUL-terminated string from unterminated data David Howells
2017-05-03 16:55 ` Jeff Layton
2017-05-03 19:26 ` Rasmus Villemoes
2017-05-03 20:13 ` David Howells
2017-05-03 16:04 ` [PATCH 2/9] Clean up whitespace in fs/namespace.c David Howells
2017-05-03 16:04 ` [PATCH 3/9] VFS: Introduce a mount context David Howells
2017-05-03 18:13 ` Jeff Layton
2017-05-03 18:26 ` Joe Perches
2017-05-03 20:38 ` Matthew Wilcox
2017-05-03 21:36 ` Joe Perches
2017-05-04 6:28 ` Julia Lawall
2017-05-03 21:17 ` David Howells
2017-05-03 18:37 ` David Howells
2017-05-03 18:43 ` Joe Perches
2017-05-03 20:11 ` David Howells
2017-05-04 9:27 ` David Howells
2017-05-04 14:34 ` Joe Perches
2017-05-03 21:43 ` Rasmus Villemoes [this message]
2017-05-04 10:22 ` David Howells
2017-05-08 15:05 ` Miklos Szeredi
2017-05-08 22:57 ` David Howells
2017-05-09 8:03 ` Miklos Szeredi
2017-05-10 12:41 ` Karel Zak
2017-05-09 9:32 ` David Howells
2017-05-09 11:04 ` Miklos Szeredi
2017-05-09 9:41 ` David Howells
2017-05-09 12:02 ` Miklos Szeredi
2017-05-09 18:51 ` Jeff Layton
2017-05-10 7:24 ` Miklos Szeredi
2017-05-10 8:05 ` David Howells
2017-05-10 13:20 ` Jeff Layton
2017-05-10 13:30 ` Miklos Szeredi
2017-05-10 13:33 ` Miklos Szeredi
2017-05-10 13:48 ` Jeff Layton
2017-05-12 8:15 ` Miklos Szeredi
2017-05-10 13:31 ` David Howells
2017-05-10 13:37 ` Jeff Layton
2017-05-09 9:56 ` David Howells
2017-05-09 12:38 ` Miklos Szeredi
2017-05-03 16:05 ` [PATCH 4/9] Implement fsopen() to prepare for a mount David Howells
2017-05-03 18:37 ` Jeff Layton
2017-05-03 18:41 ` David Howells
2017-05-03 20:44 ` Rasmus Villemoes
2017-05-04 10:40 ` Karel Zak
2017-05-04 12:55 ` David Howells
2017-05-04 12:58 ` David Howells
2017-05-04 13:06 ` David Howells
2017-05-04 13:34 ` Karel Zak
2017-05-09 18:40 ` Jeff Layton
2017-05-08 15:10 ` Miklos Szeredi
2017-05-08 23:09 ` David Howells
2017-05-03 16:05 ` [PATCH 5/9] Implement fsmount() to effect a pre-configured mount David Howells
2017-05-03 16:05 ` [PATCH 6/9] Sample program for driving fsopen/fsmount David Howells
2017-05-03 16:05 ` [PATCH 7/9] procfs: Move proc_fill_super() to fs/proc/root.c David Howells
2017-05-03 16:05 ` [PATCH 8/9] proc: Support the mount context in procfs David Howells
2017-05-03 16:05 ` [PATCH 9/9] NFS: Support the mount context and fsopen() David Howells
2017-05-03 16:44 ` [RFC][PATCH 0/9] VFS: Introduce mount context Jeff Layton
2017-05-03 16:50 ` David Howells
2017-05-03 17:27 ` Jeff Layton
2017-05-05 14:35 ` Miklos Szeredi
2017-05-05 15:47 ` David Howells
2017-05-08 8:25 ` Miklos Szeredi
2017-05-08 8:35 ` David Howells
2017-05-08 8:43 ` Miklos Szeredi
2017-05-08 17:03 ` Djalal Harouni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bmr939bg.fsf@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=dhowells@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=mszeredi@redhat.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®