Commit b8ad501a authored by Eric W. Biederman's avatar Eric W. Biederman Committed by Luis Henriques

sysfs: Create mountpoints with sysfs_create_mount_point

commit f9bb4882 upstream.

This allows for better documentation in the code and
it allows for a simpler and fully correct version of
fs_fully_visible to be written.

The mount points converted and their filesystems are:
/sys/hypervisor/s390/       s390_hypfs
/sys/kernel/config/         configfs
/sys/kernel/debug/          debugfs
/sys/firmware/efi/efivars/  efivarfs
/sys/fs/fuse/connections/   fusectl
/sys/fs/pstore/             pstore
/sys/kernel/tracing/        tracefs
/sys/fs/cgroup/             cgroup
/sys/kernel/security/       securityfs
/sys/fs/selinux/            selinuxfs
/sys/fs/smackfs/            smackfs
Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: default avatarSeth Forshee <seth.forshee@canonical.com>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 3b9378cc
...@@ -461,8 +461,6 @@ static const struct super_operations hypfs_s_ops = { ...@@ -461,8 +461,6 @@ static const struct super_operations hypfs_s_ops = {
.show_options = hypfs_show_options, .show_options = hypfs_show_options,
}; };
static struct kobject *s390_kobj;
static int __init hypfs_init(void) static int __init hypfs_init(void)
{ {
int rc; int rc;
...@@ -482,18 +480,16 @@ static int __init hypfs_init(void) ...@@ -482,18 +480,16 @@ static int __init hypfs_init(void)
rc = -ENODATA; rc = -ENODATA;
goto fail_hypfs_vm_exit; goto fail_hypfs_vm_exit;
} }
s390_kobj = kobject_create_and_add("s390", hypervisor_kobj); rc = sysfs_create_mount_point(hypervisor_kobj, "s390");
if (!s390_kobj) { if (rc)
rc = -ENOMEM;
goto fail_hypfs_sprp_exit; goto fail_hypfs_sprp_exit;
}
rc = register_filesystem(&hypfs_type); rc = register_filesystem(&hypfs_type);
if (rc) if (rc)
goto fail_filesystem; goto fail_filesystem;
return 0; return 0;
fail_filesystem: fail_filesystem:
kobject_put(s390_kobj); sysfs_remove_mount_point(hypervisor_kobj, "s390");
fail_hypfs_sprp_exit: fail_hypfs_sprp_exit:
hypfs_sprp_exit(); hypfs_sprp_exit();
fail_hypfs_vm_exit: fail_hypfs_vm_exit:
...@@ -509,7 +505,7 @@ static int __init hypfs_init(void) ...@@ -509,7 +505,7 @@ static int __init hypfs_init(void)
static void __exit hypfs_exit(void) static void __exit hypfs_exit(void)
{ {
unregister_filesystem(&hypfs_type); unregister_filesystem(&hypfs_type);
kobject_put(s390_kobj); sysfs_remove_mount_point(hypervisor_kobj, "s390");
hypfs_sprp_exit(); hypfs_sprp_exit();
hypfs_vm_exit(); hypfs_vm_exit();
hypfs_diag_exit(); hypfs_diag_exit();
......
...@@ -41,7 +41,6 @@ struct efi __read_mostly efi = { ...@@ -41,7 +41,6 @@ struct efi __read_mostly efi = {
EXPORT_SYMBOL(efi); EXPORT_SYMBOL(efi);
static struct kobject *efi_kobj; static struct kobject *efi_kobj;
static struct kobject *efivars_kobj;
/* /*
* Let's not leave out systab information that snuck into * Let's not leave out systab information that snuck into
...@@ -174,10 +173,9 @@ static int __init efisubsys_init(void) ...@@ -174,10 +173,9 @@ static int __init efisubsys_init(void)
goto err_remove_group; goto err_remove_group;
/* and the standard mountpoint for efivarfs */ /* and the standard mountpoint for efivarfs */
efivars_kobj = kobject_create_and_add("efivars", efi_kobj); error = sysfs_create_mount_point(efi_kobj, "efivars");
if (!efivars_kobj) { if (error) {
pr_err("efivars: Subsystem registration failed.\n"); pr_err("efivars: Subsystem registration failed.\n");
error = -ENOMEM;
goto err_remove_group; goto err_remove_group;
} }
......
...@@ -129,8 +129,6 @@ void configfs_release_fs(void) ...@@ -129,8 +129,6 @@ void configfs_release_fs(void)
} }
static struct kobject *config_kobj;
static int __init configfs_init(void) static int __init configfs_init(void)
{ {
int err = -ENOMEM; int err = -ENOMEM;
...@@ -141,8 +139,8 @@ static int __init configfs_init(void) ...@@ -141,8 +139,8 @@ static int __init configfs_init(void)
if (!configfs_dir_cachep) if (!configfs_dir_cachep)
goto out; goto out;
config_kobj = kobject_create_and_add("config", kernel_kobj); err = sysfs_create_mount_point(kernel_kobj, "config");
if (!config_kobj) if (err)
goto out2; goto out2;
err = configfs_inode_init(); err = configfs_inode_init();
...@@ -158,7 +156,7 @@ static int __init configfs_init(void) ...@@ -158,7 +156,7 @@ static int __init configfs_init(void)
pr_err("Unable to register filesystem!\n"); pr_err("Unable to register filesystem!\n");
configfs_inode_exit(); configfs_inode_exit();
out3: out3:
kobject_put(config_kobj); sysfs_remove_mount_point(kernel_kobj, "config");
out2: out2:
kmem_cache_destroy(configfs_dir_cachep); kmem_cache_destroy(configfs_dir_cachep);
configfs_dir_cachep = NULL; configfs_dir_cachep = NULL;
...@@ -169,7 +167,7 @@ static int __init configfs_init(void) ...@@ -169,7 +167,7 @@ static int __init configfs_init(void)
static void __exit configfs_exit(void) static void __exit configfs_exit(void)
{ {
unregister_filesystem(&configfs_fs_type); unregister_filesystem(&configfs_fs_type);
kobject_put(config_kobj); sysfs_remove_mount_point(kernel_kobj, "config");
kmem_cache_destroy(configfs_dir_cachep); kmem_cache_destroy(configfs_dir_cachep);
configfs_dir_cachep = NULL; configfs_dir_cachep = NULL;
configfs_inode_exit(); configfs_inode_exit();
......
...@@ -668,20 +668,17 @@ bool debugfs_initialized(void) ...@@ -668,20 +668,17 @@ bool debugfs_initialized(void)
} }
EXPORT_SYMBOL_GPL(debugfs_initialized); EXPORT_SYMBOL_GPL(debugfs_initialized);
static struct kobject *debug_kobj;
static int __init debugfs_init(void) static int __init debugfs_init(void)
{ {
int retval; int retval;
debug_kobj = kobject_create_and_add("debug", kernel_kobj); retval = sysfs_create_mount_point(kernel_kobj, "debug");
if (!debug_kobj) if (retval)
return -EINVAL; return retval;
retval = register_filesystem(&debug_fs_type); retval = register_filesystem(&debug_fs_type);
if (retval) if (retval)
kobject_put(debug_kobj); sysfs_remove_mount_point(kernel_kobj, "debug");
else else
debugfs_registered = true; debugfs_registered = true;
......
...@@ -1261,7 +1261,6 @@ static void fuse_fs_cleanup(void) ...@@ -1261,7 +1261,6 @@ static void fuse_fs_cleanup(void)
} }
static struct kobject *fuse_kobj; static struct kobject *fuse_kobj;
static struct kobject *connections_kobj;
static int fuse_sysfs_init(void) static int fuse_sysfs_init(void)
{ {
...@@ -1273,11 +1272,9 @@ static int fuse_sysfs_init(void) ...@@ -1273,11 +1272,9 @@ static int fuse_sysfs_init(void)
goto out_err; goto out_err;
} }
connections_kobj = kobject_create_and_add("connections", fuse_kobj); err = sysfs_create_mount_point(fuse_kobj, "connections");
if (!connections_kobj) { if (err)
err = -ENOMEM;
goto out_fuse_unregister; goto out_fuse_unregister;
}
return 0; return 0;
...@@ -1289,7 +1286,7 @@ static int fuse_sysfs_init(void) ...@@ -1289,7 +1286,7 @@ static int fuse_sysfs_init(void)
static void fuse_sysfs_cleanup(void) static void fuse_sysfs_cleanup(void)
{ {
kobject_put(connections_kobj); sysfs_remove_mount_point(fuse_kobj, "connections");
kobject_put(fuse_kobj); kobject_put(fuse_kobj);
} }
......
...@@ -430,22 +430,18 @@ static struct file_system_type pstore_fs_type = { ...@@ -430,22 +430,18 @@ static struct file_system_type pstore_fs_type = {
.kill_sb = pstore_kill_sb, .kill_sb = pstore_kill_sb,
}; };
static struct kobject *pstore_kobj;
static int __init init_pstore_fs(void) static int __init init_pstore_fs(void)
{ {
int err = 0; int err;
/* Create a convenient mount point for people to access pstore */ /* Create a convenient mount point for people to access pstore */
pstore_kobj = kobject_create_and_add("pstore", fs_kobj); err = sysfs_create_mount_point(fs_kobj, "pstore");
if (!pstore_kobj) { if (err)
err = -ENOMEM;
goto out; goto out;
}
err = register_filesystem(&pstore_fs_type); err = register_filesystem(&pstore_fs_type);
if (err < 0) if (err < 0)
kobject_put(pstore_kobj); sysfs_remove_mount_point(fs_kobj, "pstore");
out: out:
return err; return err;
......
...@@ -1848,8 +1848,6 @@ static struct file_system_type cgroup_fs_type = { ...@@ -1848,8 +1848,6 @@ static struct file_system_type cgroup_fs_type = {
.kill_sb = cgroup_kill_sb, .kill_sb = cgroup_kill_sb,
}; };
static struct kobject *cgroup_kobj;
/** /**
* task_cgroup_path - cgroup path of a task in the first cgroup hierarchy * task_cgroup_path - cgroup path of a task in the first cgroup hierarchy
* @task: target task * @task: target task
...@@ -4822,13 +4820,13 @@ int __init cgroup_init(void) ...@@ -4822,13 +4820,13 @@ int __init cgroup_init(void)
} }
} }
cgroup_kobj = kobject_create_and_add("cgroup", fs_kobj); err = sysfs_create_mount_point(fs_kobj, "cgroup");
if (!cgroup_kobj) if (err)
return -ENOMEM; return err;
err = register_filesystem(&cgroup_fs_type); err = register_filesystem(&cgroup_fs_type);
if (err < 0) { if (err < 0) {
kobject_put(cgroup_kobj); sysfs_remove_mount_point(fs_kobj, "cgroup");
return err; return err;
} }
......
...@@ -215,19 +215,17 @@ void securityfs_remove(struct dentry *dentry) ...@@ -215,19 +215,17 @@ void securityfs_remove(struct dentry *dentry)
} }
EXPORT_SYMBOL_GPL(securityfs_remove); EXPORT_SYMBOL_GPL(securityfs_remove);
static struct kobject *security_kobj;
static int __init securityfs_init(void) static int __init securityfs_init(void)
{ {
int retval; int retval;
security_kobj = kobject_create_and_add("security", kernel_kobj); retval = sysfs_create_mount_point(kernel_kobj, "security");
if (!security_kobj) if (retval)
return -EINVAL; return retval;
retval = register_filesystem(&fs_type); retval = register_filesystem(&fs_type);
if (retval) if (retval)
kobject_put(security_kobj); sysfs_remove_mount_point(kernel_kobj, "security");
return retval; return retval;
} }
......
...@@ -1899,7 +1899,6 @@ static struct file_system_type sel_fs_type = { ...@@ -1899,7 +1899,6 @@ static struct file_system_type sel_fs_type = {
}; };
struct vfsmount *selinuxfs_mount; struct vfsmount *selinuxfs_mount;
static struct kobject *selinuxfs_kobj;
static int __init init_sel_fs(void) static int __init init_sel_fs(void)
{ {
...@@ -1908,13 +1907,13 @@ static int __init init_sel_fs(void) ...@@ -1908,13 +1907,13 @@ static int __init init_sel_fs(void)
if (!selinux_enabled) if (!selinux_enabled)
return 0; return 0;
selinuxfs_kobj = kobject_create_and_add("selinux", fs_kobj); err = sysfs_create_mount_point(fs_kobj, "selinux");
if (!selinuxfs_kobj) if (err)
return -ENOMEM; return err;
err = register_filesystem(&sel_fs_type); err = register_filesystem(&sel_fs_type);
if (err) { if (err) {
kobject_put(selinuxfs_kobj); sysfs_remove_mount_point(fs_kobj, "selinux");
return err; return err;
} }
...@@ -1933,7 +1932,7 @@ __initcall(init_sel_fs); ...@@ -1933,7 +1932,7 @@ __initcall(init_sel_fs);
#ifdef CONFIG_SECURITY_SELINUX_DISABLE #ifdef CONFIG_SECURITY_SELINUX_DISABLE
void exit_sel_fs(void) void exit_sel_fs(void)
{ {
kobject_put(selinuxfs_kobj); sysfs_remove_mount_point(fs_kobj, "selinux");
kern_unmount(selinuxfs_mount); kern_unmount(selinuxfs_mount);
unregister_filesystem(&sel_fs_type); unregister_filesystem(&sel_fs_type);
} }
......
...@@ -2136,16 +2136,16 @@ static const struct file_operations smk_revoke_subj_ops = { ...@@ -2136,16 +2136,16 @@ static const struct file_operations smk_revoke_subj_ops = {
.llseek = generic_file_llseek, .llseek = generic_file_llseek,
}; };
static struct kset *smackfs_kset;
/** /**
* smk_init_sysfs - initialize /sys/fs/smackfs * smk_init_sysfs - initialize /sys/fs/smackfs
* *
*/ */
static int smk_init_sysfs(void) static int smk_init_sysfs(void)
{ {
smackfs_kset = kset_create_and_add("smackfs", NULL, fs_kobj); int err;
if (!smackfs_kset) err = sysfs_create_mount_point(fs_kobj, "smackfs");
return -ENOMEM; if (err)
return err;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment