sysfs: Create mountpoints with sysfs_create_mount_point
authorEric W. Biederman <ebiederm@xmission.com>
Wed, 13 May 2015 22:35:41 +0000 (17:35 -0500)
committerEric W. Biederman <ebiederm@xmission.com>
Wed, 1 Jul 2015 15:36:47 +0000 (10:36 -0500)
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

Cc: stable@vger.kernel.org
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
arch/s390/hypfs/inode.c
drivers/firmware/efi/efi.c
fs/configfs/mount.c
fs/debugfs/inode.c
fs/fuse/inode.c
fs/pstore/inode.c
fs/tracefs/inode.c
kernel/cgroup.c
security/inode.c
security/selinux/selinuxfs.c
security/smack/smackfs.c

index d3f896a35b9813080351f1bb7be178f127114c19..2eeb0a0f506d5d54a90b0f98da581468962c0399 100644 (file)
@@ -456,8 +456,6 @@ static const struct super_operations hypfs_s_ops = {
        .show_options   = hypfs_show_options,
 };
 
-static struct kobject *s390_kobj;
-
 static int __init hypfs_init(void)
 {
        int rc;
@@ -481,18 +479,16 @@ static int __init hypfs_init(void)
                rc = -ENODATA;
                goto fail_hypfs_sprp_exit;
        }
-       s390_kobj = kobject_create_and_add("s390", hypervisor_kobj);
-       if (!s390_kobj) {
-               rc = -ENOMEM;
+       rc = sysfs_create_mount_point(hypervisor_kobj, "s390");
+       if (rc)
                goto fail_hypfs_diag0c_exit;
-       }
        rc = register_filesystem(&hypfs_type);
        if (rc)
                goto fail_filesystem;
        return 0;
 
 fail_filesystem:
-       kobject_put(s390_kobj);
+       sysfs_remove_mount_point(hypervisor_kobj, "s390");
 fail_hypfs_diag0c_exit:
        hypfs_diag0c_exit();
 fail_hypfs_sprp_exit:
@@ -510,7 +506,7 @@ fail_dbfs_exit:
 static void __exit hypfs_exit(void)
 {
        unregister_filesystem(&hypfs_type);
-       kobject_put(s390_kobj);
+       sysfs_remove_mount_point(hypervisor_kobj, "s390");
        hypfs_diag0c_exit();
        hypfs_sprp_exit();
        hypfs_vm_exit();
index 3061bb8629dc3fbdf19e19d373d75b2286cf8376..e14363d126906b1b56cd7b602b6d7b51c90cd046 100644 (file)
@@ -65,7 +65,6 @@ static int __init parse_efi_cmdline(char *str)
 early_param("efi", parse_efi_cmdline);
 
 static struct kobject *efi_kobj;
-static struct kobject *efivars_kobj;
 
 /*
  * Let's not leave out systab information that snuck into
@@ -212,10 +211,9 @@ static int __init efisubsys_init(void)
                goto err_remove_group;
 
        /* and the standard mountpoint for efivarfs */
-       efivars_kobj = kobject_create_and_add("efivars", efi_kobj);
-       if (!efivars_kobj) {
+       error = sysfs_create_mount_point(efi_kobj, "efivars");
+       if (error) {
                pr_err("efivars: Subsystem registration failed.\n");
-               error = -ENOMEM;
                goto err_remove_group;
        }
 
index da94e41bdbf685b02b567e95e3c0f37db33c2795..bca58da65e2b470d9f5ab47d3332f11bb06bacfc 100644 (file)
@@ -129,8 +129,6 @@ void configfs_release_fs(void)
 }
 
 
-static struct kobject *config_kobj;
-
 static int __init configfs_init(void)
 {
        int err = -ENOMEM;
@@ -141,8 +139,8 @@ static int __init configfs_init(void)
        if (!configfs_dir_cachep)
                goto out;
 
-       config_kobj = kobject_create_and_add("config", kernel_kobj);
-       if (!config_kobj)
+       err = sysfs_create_mount_point(kernel_kobj, "config");
+       if (err)
                goto out2;
 
        err = register_filesystem(&configfs_fs_type);
@@ -152,7 +150,7 @@ static int __init configfs_init(void)
        return 0;
 out3:
        pr_err("Unable to register filesystem!\n");
-       kobject_put(config_kobj);
+       sysfs_remove_mount_point(kernel_kobj, "config");
 out2:
        kmem_cache_destroy(configfs_dir_cachep);
        configfs_dir_cachep = NULL;
@@ -163,7 +161,7 @@ out:
 static void __exit configfs_exit(void)
 {
        unregister_filesystem(&configfs_fs_type);
-       kobject_put(config_kobj);
+       sysfs_remove_mount_point(kernel_kobj, "config");
        kmem_cache_destroy(configfs_dir_cachep);
        configfs_dir_cachep = NULL;
 }
index c1e7ffb0dab658ecd21c449bf36467b14e0b75d6..12756040ca201db858e901b411f69aa02b6ae26d 100644 (file)
@@ -716,20 +716,17 @@ bool debugfs_initialized(void)
 }
 EXPORT_SYMBOL_GPL(debugfs_initialized);
 
-
-static struct kobject *debug_kobj;
-
 static int __init debugfs_init(void)
 {
        int retval;
 
-       debug_kobj = kobject_create_and_add("debug", kernel_kobj);
-       if (!debug_kobj)
-               return -EINVAL;
+       retval = sysfs_create_mount_point(kernel_kobj, "debug");
+       if (retval)
+               return retval;
 
        retval = register_filesystem(&debug_fs_type);
        if (retval)
-               kobject_put(debug_kobj);
+               sysfs_remove_mount_point(kernel_kobj, "debug");
        else
                debugfs_registered = true;
 
index 082ac1c97f397f7f8014c7896123f8c7a5eebe8f..18dacf9ed8ff353813e099fb577771a75d47fc42 100644 (file)
@@ -1238,7 +1238,6 @@ static void fuse_fs_cleanup(void)
 }
 
 static struct kobject *fuse_kobj;
-static struct kobject *connections_kobj;
 
 static int fuse_sysfs_init(void)
 {
@@ -1250,11 +1249,9 @@ static int fuse_sysfs_init(void)
                goto out_err;
        }
 
-       connections_kobj = kobject_create_and_add("connections", fuse_kobj);
-       if (!connections_kobj) {
-               err = -ENOMEM;
+       err = sysfs_create_mount_point(fuse_kobj, "connections");
+       if (err)
                goto out_fuse_unregister;
-       }
 
        return 0;
 
@@ -1266,7 +1263,7 @@ static int fuse_sysfs_init(void)
 
 static void fuse_sysfs_cleanup(void)
 {
-       kobject_put(connections_kobj);
+       sysfs_remove_mount_point(fuse_kobj, "connections");
        kobject_put(fuse_kobj);
 }
 
index dc43b5f29305efdd7ee94b72035b3e5b3ba11d17..3adcc4669faca29785a663f63e39de22a65ae9c1 100644 (file)
@@ -461,22 +461,18 @@ static struct file_system_type pstore_fs_type = {
        .kill_sb        = pstore_kill_sb,
 };
 
-static struct kobject *pstore_kobj;
-
 static int __init init_pstore_fs(void)
 {
-       int err = 0;
+       int err;
 
        /* Create a convenient mount point for people to access pstore */
-       pstore_kobj = kobject_create_and_add("pstore", fs_kobj);
-       if (!pstore_kobj) {
-               err = -ENOMEM;
+       err = sysfs_create_mount_point(fs_kobj, "pstore");
+       if (err)
                goto out;
-       }
 
        err = register_filesystem(&pstore_fs_type);
        if (err < 0)
-               kobject_put(pstore_kobj);
+               sysfs_remove_mount_point(fs_kobj, "pstore");
 
 out:
        return err;
index d92bdf3b079a79d5a5ff88bd41207894a11cc483..a43df11a163f17fb743a23aaca2c84a296ec50b0 100644 (file)
@@ -631,14 +631,12 @@ bool tracefs_initialized(void)
        return tracefs_registered;
 }
 
-static struct kobject *trace_kobj;
-
 static int __init tracefs_init(void)
 {
        int retval;
 
-       trace_kobj = kobject_create_and_add("tracing", kernel_kobj);
-       if (!trace_kobj)
+       retval = sysfs_create_mount_point(kernel_kobj, "tracing");
+       if (retval)
                return -EINVAL;
 
        retval = register_filesystem(&trace_fs_type);
index 469dd547770ca352fe5aae2f22c689366b721c26..e8a5491be756af4999df442417f7c40862c8fc37 100644 (file)
@@ -1924,8 +1924,6 @@ static struct file_system_type cgroup_fs_type = {
        .kill_sb = cgroup_kill_sb,
 };
 
-static struct kobject *cgroup_kobj;
-
 /**
  * task_cgroup_path - cgroup path of a task in the first cgroup hierarchy
  * @task: target task
@@ -5044,13 +5042,13 @@ int __init cgroup_init(void)
                        ss->bind(init_css_set.subsys[ssid]);
        }
 
-       cgroup_kobj = kobject_create_and_add("cgroup", fs_kobj);
-       if (!cgroup_kobj)
-               return -ENOMEM;
+       err = sysfs_create_mount_point(fs_kobj, "cgroup");
+       if (err)
+               return err;
 
        err = register_filesystem(&cgroup_fs_type);
        if (err < 0) {
-               kobject_put(cgroup_kobj);
+               sysfs_remove_mount_point(fs_kobj, "cgroup");
                return err;
        }
 
index 91503b79c5f8f8d373920da4b16854c590774799..0e37e4fba8faca36d118ab5a1dc75c139bf3ea2f 100644 (file)
@@ -215,19 +215,17 @@ void securityfs_remove(struct dentry *dentry)
 }
 EXPORT_SYMBOL_GPL(securityfs_remove);
 
-static struct kobject *security_kobj;
-
 static int __init securityfs_init(void)
 {
        int retval;
 
-       security_kobj = kobject_create_and_add("security", kernel_kobj);
-       if (!security_kobj)
-               return -EINVAL;
+       retval = sysfs_create_mount_point(kernel_kobj, "security");
+       if (retval)
+               return retval;
 
        retval = register_filesystem(&fs_type);
        if (retval)
-               kobject_put(security_kobj);
+               sysfs_remove_mount_point(kernel_kobj, "security");
        return retval;
 }
 
index d2787cca1fcb94aea94f73f1535d4a57f2907129..3d22014130289d2904dee4fb3c831223437864d2 100644 (file)
@@ -1853,7 +1853,6 @@ static struct file_system_type sel_fs_type = {
 };
 
 struct vfsmount *selinuxfs_mount;
-static struct kobject *selinuxfs_kobj;
 
 static int __init init_sel_fs(void)
 {
@@ -1862,13 +1861,13 @@ static int __init init_sel_fs(void)
        if (!selinux_enabled)
                return 0;
 
-       selinuxfs_kobj = kobject_create_and_add("selinux", fs_kobj);
-       if (!selinuxfs_kobj)
-               return -ENOMEM;
+       err = sysfs_create_mount_point(fs_kobj, "selinux");
+       if (err)
+               return err;
 
        err = register_filesystem(&sel_fs_type);
        if (err) {
-               kobject_put(selinuxfs_kobj);
+               sysfs_remove_mount_point(fs_kobj, "selinux");
                return err;
        }
 
@@ -1887,7 +1886,7 @@ __initcall(init_sel_fs);
 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
 void exit_sel_fs(void)
 {
-       kobject_put(selinuxfs_kobj);
+       sysfs_remove_mount_point(fs_kobj, "selinux");
        kern_unmount(selinuxfs_mount);
        unregister_filesystem(&sel_fs_type);
 }
index d9682985349e6ec182407b94e57a3f4d59af766f..ac4cac7c661a34108350e73c86bcd974fce22968 100644 (file)
@@ -2241,16 +2241,16 @@ static const struct file_operations smk_revoke_subj_ops = {
        .llseek         = generic_file_llseek,
 };
 
-static struct kset *smackfs_kset;
 /**
  * smk_init_sysfs - initialize /sys/fs/smackfs
  *
  */
 static int smk_init_sysfs(void)
 {
-       smackfs_kset = kset_create_and_add("smackfs", NULL, fs_kobj);
-       if (!smackfs_kset)
-               return -ENOMEM;
+       int err;
+       err = sysfs_create_mount_point(fs_kobj, "smackfs");
+       if (err)
+               return err;
        return 0;
 }