aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs/dir.c
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 /fs/sysfs/dir.c
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>
Diffstat (limited to 'fs/sysfs/dir.c')
-rw-r--r--fs/sysfs/dir.c21
1 files changed, 10 insertions, 11 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);