summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorShaohua Li <shli@fb.com>2017-07-12 14:49:46 -0400
committerJens Axboe <axboe@kernel.dk>2017-07-29 11:00:03 -0400
commit7d35079f8277b653d6a3075eea9edd4dbf7c2b29 (patch)
treeba7fa95ee75d62694c4fa83e936709e9b4279954 /fs
parent0a07b238e5f488b459b6113a62e06b6aab017f71 (diff)
kernfs: use idr instead of ida to manage inode number
kernfs uses ida to manage inode number. The problem is we can't get kernfs_node from inode number with ida. Switching to use idr, next patch will add an API to get kernfs_node from inode number. Acked-by: Tejun Heo <tj@kernel.org> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Shaohua Li <shli@fb.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'fs')
-rw-r--r--fs/kernfs/dir.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index db5900aaa55a..8ad7a17895fe 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -21,6 +21,7 @@
21DEFINE_MUTEX(kernfs_mutex); 21DEFINE_MUTEX(kernfs_mutex);
22static DEFINE_SPINLOCK(kernfs_rename_lock); /* kn->parent and ->name */ 22static DEFINE_SPINLOCK(kernfs_rename_lock); /* kn->parent and ->name */
23static char kernfs_pr_cont_buf[PATH_MAX]; /* protected by rename_lock */ 23static char kernfs_pr_cont_buf[PATH_MAX]; /* protected by rename_lock */
24static DEFINE_SPINLOCK(kernfs_idr_lock); /* root->ino_idr */
24 25
25#define rb_to_kn(X) rb_entry((X), struct kernfs_node, rb) 26#define rb_to_kn(X) rb_entry((X), struct kernfs_node, rb)
26 27
@@ -533,7 +534,9 @@ void kernfs_put(struct kernfs_node *kn)
533 simple_xattrs_free(&kn->iattr->xattrs); 534 simple_xattrs_free(&kn->iattr->xattrs);
534 } 535 }
535 kfree(kn->iattr); 536 kfree(kn->iattr);
536 ida_simple_remove(&root->ino_ida, kn->ino); 537 spin_lock(&kernfs_idr_lock);
538 idr_remove(&root->ino_idr, kn->ino);
539 spin_unlock(&kernfs_idr_lock);
537 kmem_cache_free(kernfs_node_cache, kn); 540 kmem_cache_free(kernfs_node_cache, kn);
538 541
539 kn = parent; 542 kn = parent;
@@ -542,7 +545,7 @@ void kernfs_put(struct kernfs_node *kn)
542 goto repeat; 545 goto repeat;
543 } else { 546 } else {
544 /* just released the root kn, free @root too */ 547 /* just released the root kn, free @root too */
545 ida_destroy(&root->ino_ida); 548 idr_destroy(&root->ino_idr);
546 kfree(root); 549 kfree(root);
547 } 550 }
548} 551}
@@ -630,7 +633,11 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
630 if (!kn) 633 if (!kn)
631 goto err_out1; 634 goto err_out1;
632 635
633 ret = ida_simple_get(&root->ino_ida, 1, 0, GFP_KERNEL); 636 idr_preload(GFP_KERNEL);
637 spin_lock(&kernfs_idr_lock);
638 ret = idr_alloc(&root->ino_idr, kn, 1, 0, GFP_ATOMIC);
639 spin_unlock(&kernfs_idr_lock);
640 idr_preload_end();
634 if (ret < 0) 641 if (ret < 0)
635 goto err_out2; 642 goto err_out2;
636 kn->ino = ret; 643 kn->ino = ret;
@@ -875,13 +882,13 @@ struct kernfs_root *kernfs_create_root(struct kernfs_syscall_ops *scops,
875 if (!root) 882 if (!root)
876 return ERR_PTR(-ENOMEM); 883 return ERR_PTR(-ENOMEM);
877 884
878 ida_init(&root->ino_ida); 885 idr_init(&root->ino_idr);
879 INIT_LIST_HEAD(&root->supers); 886 INIT_LIST_HEAD(&root->supers);
880 887
881 kn = __kernfs_new_node(root, "", S_IFDIR | S_IRUGO | S_IXUGO, 888 kn = __kernfs_new_node(root, "", S_IFDIR | S_IRUGO | S_IXUGO,
882 KERNFS_DIR); 889 KERNFS_DIR);
883 if (!kn) { 890 if (!kn) {
884 ida_destroy(&root->ino_ida); 891 idr_destroy(&root->ino_idr);
885 kfree(root); 892 kfree(root);
886 return ERR_PTR(-ENOMEM); 893 return ERR_PTR(-ENOMEM);
887 } 894 }