aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs
diff options
context:
space:
mode:
authorMikulas Patocka <mpatocka@redhat.com>2011-07-25 17:55:57 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2011-08-22 20:43:52 -0400
commit4f72c0cab40536a0be501d85ea4918467ab82ad5 (patch)
treef5f0cc385fed9a32f7fc4451f8618c3b4120bc3d /fs/sysfs
parent7f9838fd01833ffb30177d964983076924344c9e (diff)
sysfs: use rb-tree for name lookups
sysfs: use rb-tree for name lookups Use red-black tree for name lookups. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'fs/sysfs')
-rw-r--r--fs/sysfs/dir.c57
-rw-r--r--fs/sysfs/sysfs.h5
2 files changed, 55 insertions, 7 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 7d240e6b7176..3e937da224d4 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -45,6 +45,9 @@ static void sysfs_link_sibling(struct sysfs_dirent *sd)
45 struct sysfs_dirent *parent_sd = sd->s_parent; 45 struct sysfs_dirent *parent_sd = sd->s_parent;
46 struct sysfs_dirent **pos; 46 struct sysfs_dirent **pos;
47 47
48 struct rb_node **p;
49 struct rb_node *parent;
50
48 BUG_ON(sd->s_sibling); 51 BUG_ON(sd->s_sibling);
49 52
50 if (sysfs_type(sd) == SYSFS_DIR) 53 if (sysfs_type(sd) == SYSFS_DIR)
@@ -60,6 +63,23 @@ static void sysfs_link_sibling(struct sysfs_dirent *sd)
60 } 63 }
61 sd->s_sibling = *pos; 64 sd->s_sibling = *pos;
62 *pos = sd; 65 *pos = sd;
66
67 p = &parent_sd->s_dir.name_tree.rb_node;
68 parent = NULL;
69 while (*p) {
70 int c;
71 parent = *p;
72#define node rb_entry(parent, struct sysfs_dirent, name_node)
73 c = strcmp(sd->s_name, node->s_name);
74 if (c < 0) {
75 p = &node->name_node.rb_left;
76 } else {
77 p = &node->name_node.rb_right;
78 }
79#undef node
80 }
81 rb_link_node(&sd->name_node, parent, p);
82 rb_insert_color(&sd->name_node, &parent_sd->s_dir.name_tree);
63} 83}
64 84
65/** 85/**
@@ -87,6 +107,8 @@ static void sysfs_unlink_sibling(struct sysfs_dirent *sd)
87 break; 107 break;
88 } 108 }
89 } 109 }
110
111 rb_erase(&sd->name_node, &sd->s_parent->s_dir.name_tree);
90} 112}
91 113
92/** 114/**
@@ -546,15 +568,36 @@ struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
546 const void *ns, 568 const void *ns,
547 const unsigned char *name) 569 const unsigned char *name)
548{ 570{
549 struct sysfs_dirent *sd; 571 struct rb_node *p = parent_sd->s_dir.name_tree.rb_node;
572 struct sysfs_dirent *found = NULL;
573
574 while (p) {
575 int c;
576#define node rb_entry(p, struct sysfs_dirent, name_node)
577 c = strcmp(name, node->s_name);
578 if (c < 0) {
579 p = node->name_node.rb_left;
580 } else if (c > 0) {
581 p = node->name_node.rb_right;
582 } else {
583 found = node;
584 p = node->name_node.rb_left;
585 }
586#undef node
587 }
550 588
551 for (sd = parent_sd->s_dir.children; sd; sd = sd->s_sibling) { 589 if (found && ns) {
552 if (ns && sd->s_ns && (sd->s_ns != ns)) 590 while (found->s_ns && found->s_ns != ns) {
553 continue; 591 p = rb_next(&found->name_node);
554 if (!strcmp(sd->s_name, name)) 592 if (!p)
555 return sd; 593 return NULL;
594 found = rb_entry(p, struct sysfs_dirent, name_node);
595 if (strcmp(name, found->s_name))
596 return NULL;
597 }
556 } 598 }
557 return NULL; 599
600 return found;
558} 601}
559 602
560/** 603/**
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index 6348e2c753f6..fe1a9e8650bf 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -11,6 +11,7 @@
11#include <linux/lockdep.h> 11#include <linux/lockdep.h>
12#include <linux/kobject_ns.h> 12#include <linux/kobject_ns.h>
13#include <linux/fs.h> 13#include <linux/fs.h>
14#include <linux/rbtree.h>
14 15
15struct sysfs_open_dirent; 16struct sysfs_open_dirent;
16 17
@@ -21,6 +22,8 @@ struct sysfs_elem_dir {
21 struct sysfs_dirent *children; 22 struct sysfs_dirent *children;
22 23
23 unsigned long subdirs; 24 unsigned long subdirs;
25
26 struct rb_root name_tree;
24}; 27};
25 28
26struct sysfs_elem_symlink { 29struct sysfs_elem_symlink {
@@ -61,6 +64,8 @@ struct sysfs_dirent {
61 struct sysfs_dirent *s_sibling; 64 struct sysfs_dirent *s_sibling;
62 const char *s_name; 65 const char *s_name;
63 66
67 struct rb_node name_node;
68
64 const void *s_ns; /* namespace tag */ 69 const void *s_ns; /* namespace tag */
65 union { 70 union {
66 struct sysfs_elem_dir s_dir; 71 struct sysfs_elem_dir s_dir;