mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shang XiaoJing <shangxiaojing@huawei.com>
To: <jlbec@evilplan.org>, <hch@lst.de>, <linux-kernel@vger.kernel.org>
Cc: <shangxiaojing@huawei.com>
Subject: [PATCH -next 1/3] configfs: Add configfs_remove_drop_dirent helper
Date: Fri, 9 Sep 2022 14:56:09 +0800	[thread overview]
Message-ID: <20220909065611.31695-2-shangxiaojing@huawei.com> (raw)
In-Reply-To: <20220909065611.31695-1-shangxiaojing@huawei.com>

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

Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
---
 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


  reply	other threads:[~2022-09-09  6:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-09  6:56 [PATCH -next 0/3] configfs: Clean up by adding helpers Shang XiaoJing
2022-09-09  6:56 ` Shang XiaoJing [this message]
2022-09-09  6:56 ` [PATCH -next 2/3] configfs: Add group_to_dentry helper Shang XiaoJing
2022-09-09  6:56 ` [PATCH -next 3/3] configfs: Add subsys_to_item helper Shang XiaoJing

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220909065611.31695-2-shangxiaojing@huawei.com \
    --to=shangxiaojing@huawei.com \
    --cc=hch@lst.de \
    --cc=jlbec@evilplan.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®