aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs/mount.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/sysfs/mount.c')
-rw-r--r--fs/sysfs/mount.c69
1 files changed, 24 insertions, 45 deletions
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index f2af22574c50..e34f0d99ea4e 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -23,7 +23,7 @@
23#include "sysfs.h" 23#include "sysfs.h"
24 24
25 25
26static struct vfsmount *sysfs_mount; 26static struct vfsmount *sysfs_mnt;
27struct kmem_cache *sysfs_dir_cachep; 27struct kmem_cache *sysfs_dir_cachep;
28 28
29static const struct super_operations sysfs_ops = { 29static const struct super_operations sysfs_ops = {
@@ -95,84 +95,63 @@ static int sysfs_set_super(struct super_block *sb, void *data)
95 return error; 95 return error;
96} 96}
97 97
98static int sysfs_get_sb(struct file_system_type *fs_type, 98static void free_sysfs_super_info(struct sysfs_super_info *info)
99 int flags, const char *dev_name, void *data, struct vfsmount *mnt) 99{
100 int type;
101 for (type = KOBJ_NS_TYPE_NONE; type < KOBJ_NS_TYPES; type++)
102 kobj_ns_drop(type, info->ns[type]);
103 kfree(info);
104}
105
106static struct dentry *sysfs_mount(struct file_system_type *fs_type,
107 int flags, const char *dev_name, void *data)
100{ 108{
101 struct sysfs_super_info *info; 109 struct sysfs_super_info *info;
102 enum kobj_ns_type type; 110 enum kobj_ns_type type;
103 struct super_block *sb; 111 struct super_block *sb;
104 int error; 112 int error;
105 113
106 error = -ENOMEM;
107 info = kzalloc(sizeof(*info), GFP_KERNEL); 114 info = kzalloc(sizeof(*info), GFP_KERNEL);
108 if (!info) 115 if (!info)
109 goto out; 116 return ERR_PTR(-ENOMEM);
110 117
111 for (type = KOBJ_NS_TYPE_NONE; type < KOBJ_NS_TYPES; type++) 118 for (type = KOBJ_NS_TYPE_NONE; type < KOBJ_NS_TYPES; type++)
112 info->ns[type] = kobj_ns_current(type); 119 info->ns[type] = kobj_ns_grab_current(type);
113 120
114 sb = sget(fs_type, sysfs_test_super, sysfs_set_super, info); 121 sb = sget(fs_type, sysfs_test_super, sysfs_set_super, info);
115 if (IS_ERR(sb) || sb->s_fs_info != info) 122 if (IS_ERR(sb) || sb->s_fs_info != info)
116 kfree(info); 123 free_sysfs_super_info(info);
117 if (IS_ERR(sb)) { 124 if (IS_ERR(sb))
118 error = PTR_ERR(sb); 125 return ERR_CAST(sb);
119 goto out;
120 }
121 if (!sb->s_root) { 126 if (!sb->s_root) {
122 sb->s_flags = flags; 127 sb->s_flags = flags;
123 error = sysfs_fill_super(sb, data, flags & MS_SILENT ? 1 : 0); 128 error = sysfs_fill_super(sb, data, flags & MS_SILENT ? 1 : 0);
124 if (error) { 129 if (error) {
125 deactivate_locked_super(sb); 130 deactivate_locked_super(sb);
126 goto out; 131 return ERR_PTR(error);
127 } 132 }
128 sb->s_flags |= MS_ACTIVE; 133 sb->s_flags |= MS_ACTIVE;
129 } 134 }
130 135
131 simple_set_mnt(mnt, sb); 136 return dget(sb->s_root);
132 error = 0;
133out:
134 return error;
135} 137}
136 138
137static void sysfs_kill_sb(struct super_block *sb) 139static void sysfs_kill_sb(struct super_block *sb)
138{ 140{
139 struct sysfs_super_info *info = sysfs_info(sb); 141 struct sysfs_super_info *info = sysfs_info(sb);
140
141 /* Remove the superblock from fs_supers/s_instances 142 /* Remove the superblock from fs_supers/s_instances
142 * so we can't find it, before freeing sysfs_super_info. 143 * so we can't find it, before freeing sysfs_super_info.
143 */ 144 */
144 kill_anon_super(sb); 145 kill_anon_super(sb);
145 kfree(info); 146 free_sysfs_super_info(info);
146} 147}
147 148
148static struct file_system_type sysfs_fs_type = { 149static struct file_system_type sysfs_fs_type = {
149 .name = "sysfs", 150 .name = "sysfs",
150 .get_sb = sysfs_get_sb, 151 .mount = sysfs_mount,
151 .kill_sb = sysfs_kill_sb, 152 .kill_sb = sysfs_kill_sb,
152}; 153};
153 154
154void sysfs_exit_ns(enum kobj_ns_type type, const void *ns)
155{
156 struct super_block *sb;
157
158 mutex_lock(&sysfs_mutex);
159 spin_lock(&sb_lock);
160 list_for_each_entry(sb, &sysfs_fs_type.fs_supers, s_instances) {
161 struct sysfs_super_info *info = sysfs_info(sb);
162 /*
163 * If we see a superblock on the fs_supers/s_instances
164 * list the unmount has not completed and sb->s_fs_info
165 * points to a valid struct sysfs_super_info.
166 */
167 /* Ignore superblocks with the wrong ns */
168 if (info->ns[type] != ns)
169 continue;
170 info->ns[type] = NULL;
171 }
172 spin_unlock(&sb_lock);
173 mutex_unlock(&sysfs_mutex);
174}
175
176int __init sysfs_init(void) 155int __init sysfs_init(void)
177{ 156{
178 int err = -ENOMEM; 157 int err = -ENOMEM;
@@ -189,11 +168,11 @@ int __init sysfs_init(void)
189 168
190 err = register_filesystem(&sysfs_fs_type); 169 err = register_filesystem(&sysfs_fs_type);
191 if (!err) { 170 if (!err) {
192 sysfs_mount = kern_mount(&sysfs_fs_type); 171 sysfs_mnt = kern_mount(&sysfs_fs_type);
193 if (IS_ERR(sysfs_mount)) { 172 if (IS_ERR(sysfs_mnt)) {
194 printk(KERN_ERR "sysfs: could not mount!\n"); 173 printk(KERN_ERR "sysfs: could not mount!\n");
195 err = PTR_ERR(sysfs_mount); 174 err = PTR_ERR(sysfs_mnt);
196 sysfs_mount = NULL; 175 sysfs_mnt = NULL;
197 unregister_filesystem(&sysfs_fs_type); 176 unregister_filesystem(&sysfs_fs_type);
198 goto out_err; 177 goto out_err;
199 } 178 }