Skip to content

Commit 7eed6ec

Browse files
htejungregkh
authored andcommitted
sysfs: move sysfs_hash_and_remove() to fs/sysfs/dir.c
Most removal related logic is implemented in fs/sysfs/dir.c. Move sysfs_hash_and_remove() to fs/sysfs/dir.c so that __sysfs_remove() doesn't have to be public. This is pure relocation. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent baa97cb commit 7eed6ec

3 files changed

Lines changed: 39 additions & 30 deletions

File tree

‎fs/sysfs/dir.c‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,8 @@ static struct sysfs_dirent *sysfs_next_descendant_post(struct sysfs_dirent *pos,
813813
return pos->s_parent;
814814
}
815815

816-
void __sysfs_remove(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
816+
static void __sysfs_remove(struct sysfs_addrm_cxt *acxt,
817+
struct sysfs_dirent *sd)
817818
{
818819
struct sysfs_dirent *pos, *next;
819820

@@ -846,6 +847,41 @@ void sysfs_remove(struct sysfs_dirent *sd)
846847
sysfs_addrm_finish(&acxt);
847848
}
848849

850+
/**
851+
* sysfs_hash_and_remove - find a sysfs_dirent by name and remove it
852+
* @dir_sd: parent of the target
853+
* @name: name of the sysfs_dirent to remove
854+
* @ns: namespace tag of the sysfs_dirent to remove
855+
*
856+
* Look for the sysfs_dirent with @name and @ns under @dir_sd and remove
857+
* it. Returns 0 on success, -ENOENT if such entry doesn't exist.
858+
*/
859+
int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name,
860+
const void *ns)
861+
{
862+
struct sysfs_addrm_cxt acxt;
863+
struct sysfs_dirent *sd;
864+
865+
if (!dir_sd) {
866+
WARN(1, KERN_WARNING "sysfs: can not remove '%s', no directory\n",
867+
name);
868+
return -ENOENT;
869+
}
870+
871+
sysfs_addrm_start(&acxt);
872+
873+
sd = sysfs_find_dirent(dir_sd, name, ns);
874+
if (sd)
875+
__sysfs_remove(&acxt, sd);
876+
877+
sysfs_addrm_finish(&acxt);
878+
879+
if (sd)
880+
return 0;
881+
else
882+
return -ENOENT;
883+
}
884+
849885
/**
850886
* sysfs_remove_dir - remove an object's directory.
851887
* @kobj: object.

‎fs/sysfs/inode.c‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -314,32 +314,6 @@ void sysfs_evict_inode(struct inode *inode)
314314
sysfs_put(sd);
315315
}
316316

317-
int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name,
318-
const void *ns)
319-
{
320-
struct sysfs_addrm_cxt acxt;
321-
struct sysfs_dirent *sd;
322-
323-
if (!dir_sd) {
324-
WARN(1, KERN_WARNING "sysfs: can not remove '%s', no directory\n",
325-
name);
326-
return -ENOENT;
327-
}
328-
329-
sysfs_addrm_start(&acxt);
330-
331-
sd = sysfs_find_dirent(dir_sd, name, ns);
332-
if (sd)
333-
__sysfs_remove(&acxt, sd);
334-
335-
sysfs_addrm_finish(&acxt);
336-
337-
if (sd)
338-
return 0;
339-
else
340-
return -ENOENT;
341-
}
342-
343317
int sysfs_permission(struct inode *inode, int mask)
344318
{
345319
struct sysfs_dirent *sd;

‎fs/sysfs/sysfs.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
172172
struct sysfs_dirent *parent_sd);
173173
int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
174174
struct sysfs_dirent *parent_sd);
175-
void __sysfs_remove(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
176175
void sysfs_remove(struct sysfs_dirent *sd);
176+
int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name,
177+
const void *ns);
177178
void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
178179

179180
struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
@@ -218,8 +219,6 @@ int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
218219
struct kstat *stat);
219220
int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
220221
size_t size, int flags);
221-
int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name,
222-
const void *ns);
223222
int sysfs_inode_init(void);
224223

225224
/*

0 commit comments

Comments
 (0)