diff options
author | Tejun Heo <tj@kernel.org> | 2013-09-18 17:15:38 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-10-03 19:38:52 -0400 |
commit | 250f7c3fee52b71457b4aa2cafadbd9f8b320b31 (patch) | |
tree | 7240e1eddbcbddf59eb22d0d9ed14f18644ae738 | |
parent | bcdde7e221a8750f9b62b6d0bd31b72ea4ad9309 (diff) |
sysfs: introduce [__]sysfs_remove()
Given a sysfs_dirent, there is no reason to have multiple versions of
removal functions. A function which removes the specified
sysfs_dirent and its descendants is enough.
This patch intorduces [__}sysfs_remove() which replaces all internal
variations of removal functions. This will be the only removal
function in the planned new sysfs_dirent based interface.
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | fs/sysfs/dir.c | 47 | ||||
-rw-r--r-- | fs/sysfs/group.c | 4 | ||||
-rw-r--r-- | fs/sysfs/inode.c | 2 | ||||
-rw-r--r-- | fs/sysfs/sysfs.h | 4 |
4 files changed, 29 insertions, 28 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index 0cdfd8128d3e..b518afd0d11e 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c | |||
@@ -545,7 +545,8 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd, | |||
545 | * LOCKING: | 545 | * LOCKING: |
546 | * Determined by sysfs_addrm_start(). | 546 | * Determined by sysfs_addrm_start(). |
547 | */ | 547 | */ |
548 | void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd) | 548 | static void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, |
549 | struct sysfs_dirent *sd) | ||
549 | { | 550 | { |
550 | struct sysfs_inode_attrs *ps_iattr; | 551 | struct sysfs_inode_attrs *ps_iattr; |
551 | 552 | ||
@@ -775,20 +776,6 @@ const struct inode_operations sysfs_dir_inode_operations = { | |||
775 | .setxattr = sysfs_setxattr, | 776 | .setxattr = sysfs_setxattr, |
776 | }; | 777 | }; |
777 | 778 | ||
778 | static void remove_dir(struct sysfs_dirent *sd) | ||
779 | { | ||
780 | struct sysfs_addrm_cxt acxt; | ||
781 | |||
782 | sysfs_addrm_start(&acxt); | ||
783 | sysfs_remove_one(&acxt, sd); | ||
784 | sysfs_addrm_finish(&acxt); | ||
785 | } | ||
786 | |||
787 | void sysfs_remove_subdir(struct sysfs_dirent *sd) | ||
788 | { | ||
789 | remove_dir(sd); | ||
790 | } | ||
791 | |||
792 | static struct sysfs_dirent *sysfs_leftmost_descendant(struct sysfs_dirent *pos) | 779 | static struct sysfs_dirent *sysfs_leftmost_descendant(struct sysfs_dirent *pos) |
793 | { | 780 | { |
794 | struct sysfs_dirent *last; | 781 | struct sysfs_dirent *last; |
@@ -844,25 +831,36 @@ static struct sysfs_dirent *sysfs_next_descendant_post(struct sysfs_dirent *pos, | |||
844 | return pos->s_parent; | 831 | return pos->s_parent; |
845 | } | 832 | } |
846 | 833 | ||
847 | static void __sysfs_remove_dir(struct sysfs_dirent *dir_sd) | 834 | void __sysfs_remove(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd) |
848 | { | 835 | { |
849 | struct sysfs_addrm_cxt acxt; | ||
850 | struct sysfs_dirent *pos, *next; | 836 | struct sysfs_dirent *pos, *next; |
851 | 837 | ||
852 | if (!dir_sd) | 838 | if (!sd) |
853 | return; | 839 | return; |
854 | 840 | ||
855 | pr_debug("sysfs %s: removing dir\n", dir_sd->s_name); | 841 | pr_debug("sysfs %s: removing\n", sd->s_name); |
856 | sysfs_addrm_start(&acxt); | ||
857 | 842 | ||
858 | next = NULL; | 843 | next = NULL; |
859 | do { | 844 | do { |
860 | pos = next; | 845 | pos = next; |
861 | next = sysfs_next_descendant_post(pos, dir_sd); | 846 | next = sysfs_next_descendant_post(pos, sd); |
862 | if (pos) | 847 | if (pos) |
863 | sysfs_remove_one(&acxt, pos); | 848 | sysfs_remove_one(acxt, pos); |
864 | } while (next); | 849 | } while (next); |
850 | } | ||
865 | 851 | ||
852 | /** | ||
853 | * sysfs_remove - remove a sysfs_dirent recursively | ||
854 | * @sd: the sysfs_dirent to remove | ||
855 | * | ||
856 | * Remove @sd along with all its subdirectories and files. | ||
857 | */ | ||
858 | void sysfs_remove(struct sysfs_dirent *sd) | ||
859 | { | ||
860 | struct sysfs_addrm_cxt acxt; | ||
861 | |||
862 | sysfs_addrm_start(&acxt); | ||
863 | __sysfs_remove(&acxt, sd); | ||
866 | sysfs_addrm_finish(&acxt); | 864 | sysfs_addrm_finish(&acxt); |
867 | } | 865 | } |
868 | 866 | ||
@@ -882,7 +880,10 @@ void sysfs_remove_dir(struct kobject *kobj) | |||
882 | kobj->sd = NULL; | 880 | kobj->sd = NULL; |
883 | spin_unlock(&sysfs_assoc_lock); | 881 | spin_unlock(&sysfs_assoc_lock); |
884 | 882 | ||
885 | __sysfs_remove_dir(sd); | 883 | if (sd) { |
884 | WARN_ON_ONCE(sysfs_type(sd) != SYSFS_DIR); | ||
885 | sysfs_remove(sd); | ||
886 | } | ||
886 | } | 887 | } |
887 | 888 | ||
888 | int sysfs_rename(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent_sd, | 889 | int sysfs_rename(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent_sd, |
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 2dae55c4f7dc..1898a10e38ce 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c | |||
@@ -111,7 +111,7 @@ static int internal_create_group(struct kobject *kobj, int update, | |||
111 | error = create_files(sd, kobj, grp, update); | 111 | error = create_files(sd, kobj, grp, update); |
112 | if (error) { | 112 | if (error) { |
113 | if (grp->name) | 113 | if (grp->name) |
114 | sysfs_remove_subdir(sd); | 114 | sysfs_remove(sd); |
115 | } | 115 | } |
116 | sysfs_put(sd); | 116 | sysfs_put(sd); |
117 | return error; | 117 | return error; |
@@ -219,7 +219,7 @@ void sysfs_remove_group(struct kobject *kobj, | |||
219 | 219 | ||
220 | remove_files(sd, kobj, grp); | 220 | remove_files(sd, kobj, grp); |
221 | if (grp->name) | 221 | if (grp->name) |
222 | sysfs_remove_subdir(sd); | 222 | sysfs_remove(sd); |
223 | 223 | ||
224 | sysfs_put(sd); | 224 | sysfs_put(sd); |
225 | } | 225 | } |
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c index 364c8873fbda..63f755ef71dd 100644 --- a/fs/sysfs/inode.c +++ b/fs/sysfs/inode.c | |||
@@ -330,7 +330,7 @@ int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name, | |||
330 | 330 | ||
331 | sd = sysfs_find_dirent(dir_sd, name, ns); | 331 | sd = sysfs_find_dirent(dir_sd, name, ns); |
332 | if (sd) | 332 | if (sd) |
333 | sysfs_remove_one(&acxt, sd); | 333 | __sysfs_remove(&acxt, sd); |
334 | 334 | ||
335 | sysfs_addrm_finish(&acxt); | 335 | sysfs_addrm_finish(&acxt); |
336 | 336 | ||
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h index 4d1154411cdb..4b1d8258b071 100644 --- a/fs/sysfs/sysfs.h +++ b/fs/sysfs/sysfs.h | |||
@@ -158,7 +158,8 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd, | |||
158 | struct sysfs_dirent *parent_sd); | 158 | struct sysfs_dirent *parent_sd); |
159 | int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd, | 159 | int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd, |
160 | struct sysfs_dirent *parent_sd); | 160 | struct sysfs_dirent *parent_sd); |
161 | void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd); | 161 | void __sysfs_remove(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd); |
162 | void sysfs_remove(struct sysfs_dirent *sd); | ||
162 | void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt); | 163 | void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt); |
163 | 164 | ||
164 | struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd, | 165 | struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd, |
@@ -170,7 +171,6 @@ void release_sysfs_dirent(struct sysfs_dirent *sd); | |||
170 | 171 | ||
171 | int sysfs_create_subdir(struct kobject *kobj, const char *name, | 172 | int sysfs_create_subdir(struct kobject *kobj, const char *name, |
172 | struct sysfs_dirent **p_sd); | 173 | struct sysfs_dirent **p_sd); |
173 | void sysfs_remove_subdir(struct sysfs_dirent *sd); | ||
174 | 174 | ||
175 | int sysfs_rename(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent_sd, | 175 | int sysfs_rename(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent_sd, |
176 | const char *new_name, const void *new_ns); | 176 | const char *new_name, const void *new_ns); |