Skip to content

Commit d401727

Browse files
author
Al Viro
committed
devtmpfs: don't mix {ramfs,shmem}_fill_super() with mount_single()
Create an internal-only type matching the current devtmpfs, never register it and have one kernel-internal mount done. That thing gets mounted only once, so it is free to use mount_nodev(). The "public" devtmpfs (the one we do register, and only after the internal mount of the real thing is done) simply gets and returns an extra reference to the internal superblock. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 5a2be12 commit d401727

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

‎drivers/base/devtmpfs.c‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,38 @@ static int __init mount_param(char *str)
5656
}
5757
__setup("devtmpfs.mount=", mount_param);
5858

59+
static struct vfsmount *mnt;
60+
61+
static struct dentry *public_dev_mount(struct file_system_type *fs_type, int flags,
62+
const char *dev_name, void *data)
63+
{
64+
struct super_block *s = mnt->mnt_sb;
65+
atomic_inc(&s->s_active);
66+
down_write(&s->s_umount);
67+
return dget(s->s_root);
68+
}
69+
5970
static struct dentry *dev_mount(struct file_system_type *fs_type, int flags,
6071
const char *dev_name, void *data)
6172
{
6273
#ifdef CONFIG_TMPFS
63-
return mount_single(fs_type, flags, data, shmem_fill_super);
74+
return mount_nodev(fs_type, flags, data, shmem_fill_super);
6475
#else
65-
return mount_single(fs_type, flags, data, ramfs_fill_super);
76+
return ramfs_mount(fs_type, flags, dev_name, data);
6677
#endif
6778
}
6879

69-
static struct file_system_type dev_fs_type = {
80+
static struct file_system_type internal_fs_type = {
7081
.name = "devtmpfs",
7182
.mount = dev_mount,
7283
.kill_sb = kill_litter_super,
7384
};
7485

86+
static struct file_system_type dev_fs_type = {
87+
.name = "devtmpfs",
88+
.mount = public_dev_mount,
89+
};
90+
7591
#ifdef CONFIG_BLOCK
7692
static inline int is_blockdev(struct device *dev)
7793
{
@@ -378,12 +394,11 @@ static int handle(const char *name, umode_t mode, kuid_t uid, kgid_t gid,
378394

379395
static int devtmpfsd(void *p)
380396
{
381-
char options[] = "mode=0755";
382397
int *err = p;
383398
*err = ksys_unshare(CLONE_NEWNS);
384399
if (*err)
385400
goto out;
386-
*err = ksys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
401+
*err = ksys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, NULL);
387402
if (*err)
388403
goto out;
389404
ksys_chdir("/.."); /* will traverse into overmounted root */
@@ -420,7 +435,16 @@ static int devtmpfsd(void *p)
420435
*/
421436
int __init devtmpfs_init(void)
422437
{
423-
int err = register_filesystem(&dev_fs_type);
438+
char opts[] = "mode=0755";
439+
int err;
440+
441+
mnt = vfs_kern_mount(&internal_fs_type, 0, "devtmpfs", opts);
442+
if (IS_ERR(mnt)) {
443+
printk(KERN_ERR "devtmpfs: unable to create devtmpfs %ld\n",
444+
PTR_ERR(mnt));
445+
return PTR_ERR(mnt);
446+
}
447+
err = register_filesystem(&dev_fs_type);
424448
if (err) {
425449
printk(KERN_ERR "devtmpfs: unable to register devtmpfs "
426450
"type %i\n", err);

0 commit comments

Comments
 (0)