aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-08-02 08:38:03 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-10-12 17:51:03 -0400
commit41fc1c27452e041a18e5141b8203ee0ea72bc483 (patch)
treefc81138ca37182c25931818681630c90b018b127
parentff869de7bf5e76adffebd3a176c1c73bca7eddb7 (diff)
sysfs: make sysfs_add/remove_one() call link/unlink_sibling() implictly
When adding or removing a sysfs_dirent, the user used to be required to call link/unlink separately. It was for two reasons - code looked like that before sysfs_addrm_cxt conversion and to avoid looping through parent_sd->children list twice during removal. Performance optimization during removal just isn't worth it. Make sysfs_add/remove_one() call sysfs_link/unlink_sibing() implicitly. This makes code simpler albeit slightly less efficient. This change doesn't introduce any noticeable behavior change. Signed-off-by: Tejun Heo <htejun@gmail.com> Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--fs/sysfs/dir.c21
-rw-r--r--fs/sysfs/file.c4
-rw-r--r--fs/sysfs/inode.c17
-rw-r--r--fs/sysfs/symlink.c4
-rw-r--r--fs/sysfs/sysfs.h2
5 files changed, 16 insertions, 32 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 9504d4cb63eb..354675ad0965 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -30,7 +30,7 @@ static DEFINE_IDA(sysfs_ino_ida);
30 * Locking: 30 * Locking:
31 * mutex_lock(sysfs_mutex) 31 * mutex_lock(sysfs_mutex)
32 */ 32 */
33void sysfs_link_sibling(struct sysfs_dirent *sd) 33static void sysfs_link_sibling(struct sysfs_dirent *sd)
34{ 34{
35 struct sysfs_dirent *parent_sd = sd->s_parent; 35 struct sysfs_dirent *parent_sd = sd->s_parent;
36 36
@@ -49,7 +49,7 @@ void sysfs_link_sibling(struct sysfs_dirent *sd)
49 * Locking: 49 * Locking:
50 * mutex_lock(sysfs_mutex) 50 * mutex_lock(sysfs_mutex)
51 */ 51 */
52void sysfs_unlink_sibling(struct sysfs_dirent *sd) 52static void sysfs_unlink_sibling(struct sysfs_dirent *sd)
53{ 53{
54 struct sysfs_dirent **pos; 54 struct sysfs_dirent **pos;
55 55
@@ -500,6 +500,8 @@ void sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
500 inc_nlink(acxt->parent_inode); 500 inc_nlink(acxt->parent_inode);
501 501
502 acxt->cnt++; 502 acxt->cnt++;
503
504 sysfs_link_sibling(sd);
503} 505}
504 506
505/** 507/**
@@ -521,7 +523,9 @@ void sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
521 */ 523 */
522void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd) 524void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
523{ 525{
524 BUG_ON(sd->s_sibling || (sd->s_flags & SYSFS_FLAG_REMOVED)); 526 BUG_ON(sd->s_flags & SYSFS_FLAG_REMOVED);
527
528 sysfs_unlink_sibling(sd);
525 529
526 sd->s_flags |= SYSFS_FLAG_REMOVED; 530 sd->s_flags |= SYSFS_FLAG_REMOVED;
527 sd->s_sibling = acxt->removed; 531 sd->s_sibling = acxt->removed;
@@ -697,10 +701,8 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
697 /* link in */ 701 /* link in */
698 sysfs_addrm_start(&acxt, parent_sd); 702 sysfs_addrm_start(&acxt, parent_sd);
699 703
700 if (!sysfs_find_dirent(parent_sd, name)) { 704 if (!sysfs_find_dirent(parent_sd, name))
701 sysfs_add_one(&acxt, sd); 705 sysfs_add_one(&acxt, sd);
702 sysfs_link_sibling(sd);
703 }
704 706
705 if (!sysfs_addrm_finish(&acxt)) { 707 if (!sysfs_addrm_finish(&acxt)) {
706 sysfs_put(sd); 708 sysfs_put(sd);
@@ -821,7 +823,6 @@ static void remove_dir(struct sysfs_dirent *sd)
821 struct sysfs_addrm_cxt acxt; 823 struct sysfs_addrm_cxt acxt;
822 824
823 sysfs_addrm_start(&acxt, sd->s_parent); 825 sysfs_addrm_start(&acxt, sd->s_parent);
824 sysfs_unlink_sibling(sd);
825 sysfs_remove_one(&acxt, sd); 826 sysfs_remove_one(&acxt, sd);
826 sysfs_addrm_finish(&acxt); 827 sysfs_addrm_finish(&acxt);
827} 828}
@@ -846,11 +847,9 @@ static void __sysfs_remove_dir(struct sysfs_dirent *dir_sd)
846 while (*pos) { 847 while (*pos) {
847 struct sysfs_dirent *sd = *pos; 848 struct sysfs_dirent *sd = *pos;
848 849
849 if (sysfs_type(sd) && sysfs_type(sd) != SYSFS_DIR) { 850 if (sysfs_type(sd) && sysfs_type(sd) != SYSFS_DIR)
850 *pos = sd->s_sibling;
851 sd->s_sibling = NULL;
852 sysfs_remove_one(&acxt, sd); 851 sysfs_remove_one(&acxt, sd);
853 } else 852 else
854 pos = &(*pos)->s_sibling; 853 pos = &(*pos)->s_sibling;
855 } 854 }
856 sysfs_addrm_finish(&acxt); 855 sysfs_addrm_finish(&acxt);
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index b21d11b46754..ea0e494d7d58 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -405,10 +405,8 @@ int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr,
405 405
406 sysfs_addrm_start(&acxt, dir_sd); 406 sysfs_addrm_start(&acxt, dir_sd);
407 407
408 if (!sysfs_find_dirent(dir_sd, attr->name)) { 408 if (!sysfs_find_dirent(dir_sd, attr->name))
409 sysfs_add_one(&acxt, sd); 409 sysfs_add_one(&acxt, sd);
410 sysfs_link_sibling(sd);
411 }
412 410
413 if (!sysfs_addrm_finish(&acxt)) { 411 if (!sysfs_addrm_finish(&acxt)) {
414 sysfs_put(sd); 412 sysfs_put(sd);
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index 45128b79bc68..efb4062fe099 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -189,25 +189,16 @@ void sysfs_instantiate(struct dentry *dentry, struct inode *inode)
189int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name) 189int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name)
190{ 190{
191 struct sysfs_addrm_cxt acxt; 191 struct sysfs_addrm_cxt acxt;
192 struct sysfs_dirent **pos, *sd; 192 struct sysfs_dirent *sd;
193 193
194 if (!dir_sd) 194 if (!dir_sd)
195 return -ENOENT; 195 return -ENOENT;
196 196
197 sysfs_addrm_start(&acxt, dir_sd); 197 sysfs_addrm_start(&acxt, dir_sd);
198 198
199 for (pos = &dir_sd->s_children; *pos; pos = &(*pos)->s_sibling) { 199 sd = sysfs_find_dirent(dir_sd, name);
200 sd = *pos; 200 if (sd)
201 201 sysfs_remove_one(&acxt, sd);
202 if (!sysfs_type(sd))
203 continue;
204 if (!strcmp(sd->s_name, name)) {
205 *pos = sd->s_sibling;
206 sd->s_sibling = NULL;
207 sysfs_remove_one(&acxt, sd);
208 break;
209 }
210 }
211 202
212 if (sysfs_addrm_finish(&acxt)) 203 if (sysfs_addrm_finish(&acxt))
213 return 0; 204 return 0;
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index 90484533801e..c129f307936a 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -92,10 +92,8 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char
92 92
93 sysfs_addrm_start(&acxt, parent_sd); 93 sysfs_addrm_start(&acxt, parent_sd);
94 94
95 if (!sysfs_find_dirent(parent_sd, name)) { 95 if (!sysfs_find_dirent(parent_sd, name))
96 sysfs_add_one(&acxt, sd); 96 sysfs_add_one(&acxt, sd);
97 sysfs_link_sibling(sd);
98 }
99 97
100 if (!sysfs_addrm_finish(&acxt)) { 98 if (!sysfs_addrm_finish(&acxt)) {
101 error = -EEXIST; 99 error = -EEXIST;
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index b55e510ea239..32b8b64e5cf1 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -56,8 +56,6 @@ extern struct sysfs_dirent sysfs_root;
56extern struct kmem_cache *sysfs_dir_cachep; 56extern struct kmem_cache *sysfs_dir_cachep;
57 57
58extern struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd); 58extern struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd);
59extern void sysfs_link_sibling(struct sysfs_dirent *sd);
60extern void sysfs_unlink_sibling(struct sysfs_dirent *sd);
61extern struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd); 59extern struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
62extern void sysfs_put_active(struct sysfs_dirent *sd); 60extern void sysfs_put_active(struct sysfs_dirent *sd);
63extern struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd); 61extern struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd);