[PATCH -next 1/3] configfs: Add configfs_remove_drop_dirent helper

From: Shang XiaoJing
Date: Fri Sep 09 2022 - 02:21:43 EST


Wrap repeated code in helper function configf_remove_drop_dirent, which
remove dirent and drop dentry.

Signed-off-by: Shang XiaoJing <shangxiaojing@xxxxxxxxxx>
---
fs/configfs/configfs_internal.h | 1 +
fs/configfs/dir.c | 16 +++++++++++-----
fs/configfs/inode.c | 6 +-----
fs/configfs/symlink.c | 6 +-----
4 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/fs/configfs/configfs_internal.h b/fs/configfs/configfs_internal.h
index c0395363eab9..4905b6d35dda 100644
--- a/fs/configfs/configfs_internal.h
+++ b/fs/configfs/configfs_internal.h
@@ -76,6 +76,7 @@ extern int configfs_dirent_is_ready(struct configfs_dirent *);
extern void configfs_hash_and_remove(struct dentry * dir, const char * name);

extern const unsigned char * configfs_get_name(struct configfs_dirent *sd);
+extern void configfs_remove_drop_dirent(struct configfs_dirent *sd, struct dentry *dentry);
extern void configfs_drop_dentry(struct configfs_dirent *sd, struct dentry *parent);
extern int configfs_setattr(struct user_namespace *mnt_userns,
struct dentry *dentry, struct iattr *iattr);
diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
index d1f9d2632202..4e086635b3ed 100644
--- a/fs/configfs/dir.c
+++ b/fs/configfs/dir.c
@@ -257,6 +257,16 @@ int configfs_make_dirent(struct configfs_dirent * parent_sd,
return 0;
}

+void configfs_remove_drop_dirent(struct configfs_dirent *sd,
+ struct dentry *dentry)
+{
+ spin_lock(&configfs_dirent_lock);
+ list_del_init(&sd->s_sibling);
+ spin_unlock(&configfs_dirent_lock);
+ configfs_drop_dentry(sd, dentry);
+ configfs_put(sd);
+}
+
static void configfs_remove_dirent(struct dentry *dentry)
{
struct configfs_dirent *sd = dentry->d_fsdata;
@@ -562,11 +572,7 @@ static void detach_attrs(struct config_item * item)
list_for_each_entry_safe(sd, tmp, &parent_sd->s_children, s_sibling) {
if (!sd->s_element || !(sd->s_type & CONFIGFS_NOT_PINNED))
continue;
- spin_lock(&configfs_dirent_lock);
- list_del_init(&sd->s_sibling);
- spin_unlock(&configfs_dirent_lock);
- configfs_drop_dentry(sd, dentry);
- configfs_put(sd);
+ configfs_remove_drop_dirent(sd, dentry);
}

/**
diff --git a/fs/configfs/inode.c b/fs/configfs/inode.c
index b601610e9907..c91fe11e4450 100644
--- a/fs/configfs/inode.c
+++ b/fs/configfs/inode.c
@@ -232,11 +232,7 @@ void configfs_hash_and_remove(struct dentry * dir, const char * name)
if (!sd->s_element)
continue;
if (!strcmp(configfs_get_name(sd), name)) {
- spin_lock(&configfs_dirent_lock);
- list_del_init(&sd->s_sibling);
- spin_unlock(&configfs_dirent_lock);
- configfs_drop_dentry(sd, dir);
- configfs_put(sd);
+ configfs_remove_drop_dirent(sd, dir);
break;
}
}
diff --git a/fs/configfs/symlink.c b/fs/configfs/symlink.c
index 0623c3edcfb9..529d204b807f 100644
--- a/fs/configfs/symlink.c
+++ b/fs/configfs/symlink.c
@@ -233,12 +233,8 @@ int configfs_unlink(struct inode *dir, struct dentry *dentry)
parent_item = configfs_get_config_item(dentry->d_parent);
type = parent_item->ci_type;

- spin_lock(&configfs_dirent_lock);
- list_del_init(&sd->s_sibling);
- spin_unlock(&configfs_dirent_lock);
- configfs_drop_dentry(sd, dentry->d_parent);
+ configfs_remove_drop_dirent(sd, dentry->d_parent);
dput(dentry);
- configfs_put(sd);

/*
* drop_link() must be called before
--
2.17.1