diff options
author | Tejun Heo <tj@kernel.org> | 2013-11-28 14:54:41 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-11-29 21:10:48 -0500 |
commit | bc755553df9ab33f389c1a0a8bd0b4f4646e80ef (patch) | |
tree | a77c1a97948ebaa6f9a31e9b580ccc0fb254bead /fs/kernfs/dir.c | |
parent | ba7443bc656e5236c316b2acacc8b551f872910f (diff) |
sysfs, kernfs: make inode number ida per kernfs_root
kernfs is being updated to allow multiple sysfs_dirent hierarchies so
that it can also be used by other users. Currently, inode number is
allocated using a global ida, sysfs_ino_ida; however, inos for
different hierarchies should be handled separately.
This patch makes ino allocation per kernfs_root. sysfs_ino_ida is
replaced by kernfs_root->ino_ida and sysfs_new_dirent() is updated to
take @root and allocate ino from it. ida_simple_get/remove() are used
instead of sysfs_ino_lock and sysfs_alloc/free_ino().
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/kernfs/dir.c')
-rw-r--r-- | fs/kernfs/dir.c | 47 |
1 files changed, 13 insertions, 34 deletions
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 246740a741ef..eaffa83719d5 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c | |||
@@ -21,9 +21,6 @@ DEFINE_MUTEX(sysfs_mutex); | |||
21 | 21 | ||
22 | #define to_sysfs_dirent(X) rb_entry((X), struct sysfs_dirent, s_rb) | 22 | #define to_sysfs_dirent(X) rb_entry((X), struct sysfs_dirent, s_rb) |
23 | 23 | ||
24 | static DEFINE_SPINLOCK(sysfs_ino_lock); | ||
25 | static DEFINE_IDA(sysfs_ino_ida); | ||
26 | |||
27 | /** | 24 | /** |
28 | * sysfs_name_hash | 25 | * sysfs_name_hash |
29 | * @name: Null terminated string to hash | 26 | * @name: Null terminated string to hash |
@@ -205,32 +202,6 @@ static void sysfs_deactivate(struct sysfs_dirent *sd) | |||
205 | rwsem_release(&sd->dep_map, 1, _RET_IP_); | 202 | rwsem_release(&sd->dep_map, 1, _RET_IP_); |
206 | } | 203 | } |
207 | 204 | ||
208 | static int sysfs_alloc_ino(unsigned int *pino) | ||
209 | { | ||
210 | int ino, rc; | ||
211 | |||
212 | retry: | ||
213 | spin_lock(&sysfs_ino_lock); | ||
214 | rc = ida_get_new_above(&sysfs_ino_ida, 1, &ino); | ||
215 | spin_unlock(&sysfs_ino_lock); | ||
216 | |||
217 | if (rc == -EAGAIN) { | ||
218 | if (ida_pre_get(&sysfs_ino_ida, GFP_KERNEL)) | ||
219 | goto retry; | ||
220 | rc = -ENOMEM; | ||
221 | } | ||
222 | |||
223 | *pino = ino; | ||
224 | return rc; | ||
225 | } | ||
226 | |||
227 | static void sysfs_free_ino(unsigned int ino) | ||
228 | { | ||
229 | spin_lock(&sysfs_ino_lock); | ||
230 | ida_remove(&sysfs_ino_ida, ino); | ||
231 | spin_unlock(&sysfs_ino_lock); | ||
232 | } | ||
233 | |||
234 | /** | 205 | /** |
235 | * kernfs_get - get a reference count on a sysfs_dirent | 206 | * kernfs_get - get a reference count on a sysfs_dirent |
236 | * @sd: the target sysfs_dirent | 207 | * @sd: the target sysfs_dirent |
@@ -276,7 +247,7 @@ void kernfs_put(struct sysfs_dirent *sd) | |||
276 | security_release_secctx(sd->s_iattr->ia_secdata, | 247 | security_release_secctx(sd->s_iattr->ia_secdata, |
277 | sd->s_iattr->ia_secdata_len); | 248 | sd->s_iattr->ia_secdata_len); |
278 | kfree(sd->s_iattr); | 249 | kfree(sd->s_iattr); |
279 | sysfs_free_ino(sd->s_ino); | 250 | ida_simple_remove(&root->ino_ida, sd->s_ino); |
280 | kmem_cache_free(sysfs_dir_cachep, sd); | 251 | kmem_cache_free(sysfs_dir_cachep, sd); |
281 | 252 | ||
282 | sd = parent_sd; | 253 | sd = parent_sd; |
@@ -285,6 +256,7 @@ void kernfs_put(struct sysfs_dirent *sd) | |||
285 | goto repeat; | 256 | goto repeat; |
286 | } else { | 257 | } else { |
287 | /* just released the root sd, free @root too */ | 258 | /* just released the root sd, free @root too */ |
259 | ida_destroy(&root->ino_ida); | ||
288 | kfree(root); | 260 | kfree(root); |
289 | } | 261 | } |
290 | } | 262 | } |
@@ -360,10 +332,12 @@ const struct dentry_operations sysfs_dentry_ops = { | |||
360 | .d_release = sysfs_dentry_release, | 332 | .d_release = sysfs_dentry_release, |
361 | }; | 333 | }; |
362 | 334 | ||
363 | struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type) | 335 | struct sysfs_dirent *sysfs_new_dirent(struct kernfs_root *root, |
336 | const char *name, umode_t mode, int type) | ||
364 | { | 337 | { |
365 | char *dup_name = NULL; | 338 | char *dup_name = NULL; |
366 | struct sysfs_dirent *sd; | 339 | struct sysfs_dirent *sd; |
340 | int ret; | ||
367 | 341 | ||
368 | if (type & SYSFS_COPY_NAME) { | 342 | if (type & SYSFS_COPY_NAME) { |
369 | name = dup_name = kstrdup(name, GFP_KERNEL); | 343 | name = dup_name = kstrdup(name, GFP_KERNEL); |
@@ -375,8 +349,10 @@ struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type) | |||
375 | if (!sd) | 349 | if (!sd) |
376 | goto err_out1; | 350 | goto err_out1; |
377 | 351 | ||
378 | if (sysfs_alloc_ino(&sd->s_ino)) | 352 | ret = ida_simple_get(&root->ino_ida, 1, 0, GFP_KERNEL); |
353 | if (ret < 0) | ||
379 | goto err_out2; | 354 | goto err_out2; |
355 | sd->s_ino = ret; | ||
380 | 356 | ||
381 | atomic_set(&sd->s_count, 1); | 357 | atomic_set(&sd->s_count, 1); |
382 | atomic_set(&sd->s_active, 0); | 358 | atomic_set(&sd->s_active, 0); |
@@ -628,8 +604,11 @@ struct kernfs_root *kernfs_create_root(void *priv) | |||
628 | if (!root) | 604 | if (!root) |
629 | return ERR_PTR(-ENOMEM); | 605 | return ERR_PTR(-ENOMEM); |
630 | 606 | ||
631 | sd = sysfs_new_dirent("", S_IFDIR | S_IRUGO | S_IXUGO, SYSFS_DIR); | 607 | ida_init(&root->ino_ida); |
608 | |||
609 | sd = sysfs_new_dirent(root, "", S_IFDIR | S_IRUGO | S_IXUGO, SYSFS_DIR); | ||
632 | if (!sd) { | 610 | if (!sd) { |
611 | ida_destroy(&root->ino_ida); | ||
633 | kfree(root); | 612 | kfree(root); |
634 | return ERR_PTR(-ENOMEM); | 613 | return ERR_PTR(-ENOMEM); |
635 | } | 614 | } |
@@ -674,7 +653,7 @@ struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent, | |||
674 | int rc; | 653 | int rc; |
675 | 654 | ||
676 | /* allocate */ | 655 | /* allocate */ |
677 | sd = sysfs_new_dirent(name, mode, SYSFS_DIR); | 656 | sd = sysfs_new_dirent(kernfs_root(parent), name, mode, SYSFS_DIR); |
678 | if (!sd) | 657 | if (!sd) |
679 | return ERR_PTR(-ENOMEM); | 658 | return ERR_PTR(-ENOMEM); |
680 | 659 | ||