linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: linux-fsdevel@vger.kernel.org
Cc: torvalds@linux-foundation.org, brauner@kernel.org, jack@suse.cz,
	raven@themaw.net, miklos@szeredi.hu, a.hindborg@kernel.org,
	linux-mm@kvack.org, linux-efi@vger.kernel.org,
	ocfs2-devel@lists.linux.dev, kees@kernel.org,
	rostedt@goodmis.org, gregkh@linuxfoundation.org,
	linux-usb@vger.kernel.org, paul@paul-moore.com,
	casey@schaufler-ca.com, linuxppc-dev@lists.ozlabs.org,
	borntraeger@linux.ibm.com
Subject: [PATCH 36/39] hypfs: don't pin dentries twice
Date: Sat, 20 Sep 2025 08:47:55 +0100	[thread overview]
Message-ID: <20250920074759.3564072-36-viro@zeniv.linux.org.uk> (raw)
In-Reply-To: <20250920074759.3564072-1-viro@zeniv.linux.org.uk>

hypfs dentries end up with refcount 2 when they are not busy.
Refcount 1 is enough to keep them pinned, and going that way
allows to simplify things nicely:
	* don't need to drop an extra reference before the
call of kill_litter_super() in ->kill_sb(); all we need
there is to reset the cleanup list - everything on it will
be taken out automatically.
	* we can make use of simple_recursive_removal() on
tree rebuilds; just make sure that only children of root
end up in the cleanup list and hypfs_delete_tree() becomes
much simpler

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 arch/s390/hypfs/inode.c | 41 ++++++++++-------------------------------
 1 file changed, 10 insertions(+), 31 deletions(-)

diff --git a/arch/s390/hypfs/inode.c b/arch/s390/hypfs/inode.c
index 96409573c75d..a4dc8e13d999 100644
--- a/arch/s390/hypfs/inode.c
+++ b/arch/s390/hypfs/inode.c
@@ -61,33 +61,17 @@ static void hypfs_update_update(struct super_block *sb)
 
 static void hypfs_add_dentry(struct dentry *dentry)
 {
-	dentry->d_fsdata = hypfs_last_dentry;
-	hypfs_last_dentry = dentry;
-}
-
-static void hypfs_remove(struct dentry *dentry)
-{
-	struct dentry *parent;
-
-	parent = dentry->d_parent;
-	inode_lock(d_inode(parent));
-	if (simple_positive(dentry)) {
-		if (d_is_dir(dentry))
-			simple_rmdir(d_inode(parent), dentry);
-		else
-			simple_unlink(d_inode(parent), dentry);
+	if (IS_ROOT(dentry->d_parent)) {
+		dentry->d_fsdata = hypfs_last_dentry;
+		hypfs_last_dentry = dentry;
 	}
-	d_drop(dentry);
-	dput(dentry);
-	inode_unlock(d_inode(parent));
 }
 
-static void hypfs_delete_tree(struct dentry *root)
+static void hypfs_delete_tree(void)
 {
 	while (hypfs_last_dentry) {
-		struct dentry *next_dentry;
-		next_dentry = hypfs_last_dentry->d_fsdata;
-		hypfs_remove(hypfs_last_dentry);
+		struct dentry *next_dentry = hypfs_last_dentry->d_fsdata;
+		simple_recursive_removal(hypfs_last_dentry, NULL);
 		hypfs_last_dentry = next_dentry;
 	}
 }
@@ -184,14 +168,14 @@ static ssize_t hypfs_write_iter(struct kiocb *iocb, struct iov_iter *from)
 		rc = -EBUSY;
 		goto out;
 	}
-	hypfs_delete_tree(sb->s_root);
+	hypfs_delete_tree();
 	if (machine_is_vm())
 		rc = hypfs_vm_create_files(sb->s_root);
 	else
 		rc = hypfs_diag_create_files(sb->s_root);
 	if (rc) {
 		pr_err("Updating the hypfs tree failed\n");
-		hypfs_delete_tree(sb->s_root);
+		hypfs_delete_tree();
 		goto out;
 	}
 	hypfs_update_update(sb);
@@ -326,13 +310,9 @@ static void hypfs_kill_super(struct super_block *sb)
 {
 	struct hypfs_sb_info *sb_info = sb->s_fs_info;
 
-	if (sb->s_root)
-		hypfs_delete_tree(sb->s_root);
-	if (sb_info && sb_info->update_file)
-		hypfs_remove(sb_info->update_file);
-	kfree(sb->s_fs_info);
-	sb->s_fs_info = NULL;
+	hypfs_last_dentry = NULL;
 	kill_litter_super(sb);
+	kfree(sb_info);
 }
 
 static struct dentry *hypfs_create_file(struct dentry *parent, const char *name,
@@ -367,7 +347,6 @@ static struct dentry *hypfs_create_file(struct dentry *parent, const char *name,
 		BUG();
 	inode->i_private = data;
 	d_instantiate(dentry, inode);
-	dget(dentry);
 fail:
 	inode_unlock(d_inode(parent));
 	return dentry;
-- 
2.47.3



  parent reply	other threads:[~2025-09-20  7:51 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-20  7:41 [PATCHES][RFC] the meat of tree-in-dcache series Al Viro
2025-09-20  7:47 ` [PATCH 01/39] new helper: simple_remove_by_name() Al Viro
2025-09-20  7:47   ` [PATCH 02/39] new helper: simple_done_creating() Al Viro
2025-09-20  7:47   ` [PATCH 03/39] introduce a flag for explicitly marking persistently pinned dentries Al Viro
2025-09-20  7:47   ` [PATCH 04/39] primitives for maintaining persisitency Al Viro
2025-09-20  7:47   ` [PATCH 05/39] convert simple_{link,unlink,rmdir,rename,fill_super}() to new primitives Al Viro
2025-09-20  7:47   ` [PATCH 06/39] convert ramfs and tmpfs Al Viro
2025-09-20  7:47   ` [PATCH 07/39] procfs: make /self and /thread_self dentries persistent Al Viro
2025-09-20  7:47   ` [PATCH 08/39] configfs, securityfs: kill_litter_super() not needed Al Viro
2025-09-24 16:56     ` Joel Becker
2025-09-20  7:47   ` [PATCH 09/39] convert xenfs Al Viro
2025-09-20  7:47   ` [PATCH 10/39] convert smackfs Al Viro
2025-09-22 15:11     ` Casey Schaufler
2025-09-20  7:47   ` [PATCH 11/39] convert hugetlbfs Al Viro
2025-09-20  7:47   ` [PATCH 12/39] convert mqueue Al Viro
2025-09-20  7:47   ` [PATCH 13/39] convert bpf Al Viro
2025-09-20  7:47   ` [PATCH 14/39] convert dlmfs Al Viro
2025-09-20  7:47   ` [PATCH 15/39] convert fuse_ctl Al Viro
2025-09-20  7:47   ` [PATCH 16/39] convert pstore Al Viro
2025-09-20  7:47   ` [PATCH 17/39] convert tracefs Al Viro
2025-09-20  7:47   ` [PATCH 18/39] convert debugfs Al Viro
2025-09-23  8:10     ` Greg KH
2025-09-20  7:47   ` [PATCH 19/39] debugfs: remove duplicate checks in callers of start_creating() Al Viro
2025-09-23  8:10     ` Greg KH
2025-09-20  7:47   ` [PATCH 20/39] convert efivarfs Al Viro
2025-09-20  7:47   ` [PATCH 21/39] convert spufs Al Viro
2025-09-20  7:47   ` [PATCH 22/39] convert ibmasmfs Al Viro
2025-09-20  7:47   ` [PATCH 23/39] ibmasmfs: get rid of ibmasmfs_dir_ops Al Viro
2025-09-20  7:47   ` [PATCH 24/39] convert devpts Al Viro
2025-09-20  7:47   ` [PATCH 25/39] binderfs: use simple_start_creating() Al Viro
2025-09-20  7:47   ` [PATCH 26/39] binderfs_binder_ctl_create(): kill a bogus check Al Viro
2025-09-20  7:47   ` [PATCH 27/39] convert binderfs Al Viro
2025-09-20  7:47   ` [PATCH 28/39] autofs_{rmdir,unlink}: dentry->d_fsdata->dentry == dentry there Al Viro
2025-09-20  7:47   ` [PATCH 29/39] convert autofs Al Viro
2025-09-20  7:47   ` [PATCH 30/39] convert binfmt_misc Al Viro
2025-09-20  7:47   ` [PATCH 31/39] convert selinuxfs Al Viro
2025-09-21 20:44     ` Paul Moore
2025-09-21 22:26       ` Al Viro
2025-09-22  2:50         ` Paul Moore
2025-09-22  3:52           ` Al Viro
2025-09-20  7:47   ` [PATCH 32/39] functionfs: switch to simple_remove_by_name() Al Viro
2025-09-20  7:47   ` [PATCH 33/39] convert functionfs Al Viro
2025-09-20  7:47   ` [PATCH 34/39] gadgetfs: switch to simple_remove_by_name() Al Viro
2025-09-20  7:47   ` [PATCH 35/39] convert gadgetfs Al Viro
2025-09-20  7:47   ` Al Viro [this message]
2025-09-20  7:47   ` [PATCH 37/39] hypfs: switch hypfs_create_str() to returning int Al Viro
2025-09-20  7:47   ` [PATCH 38/39] hypfs: swich hypfs_create_u64() " Al Viro
2025-09-20  7:47   ` [PATCH 39/39] convert hypfs Al Viro
2025-09-20 16:26 ` [PATCHES][RFC] the meat of tree-in-dcache series Linus Torvalds
2025-09-20 18:09   ` Al Viro

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=20250920074759.3564072-36-viro@zeniv.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=a.hindborg@kernel.org \
    --cc=borntraeger@linux.ibm.com \
    --cc=brauner@kernel.org \
    --cc=casey@schaufler-ca.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jack@suse.cz \
    --cc=kees@kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=miklos@szeredi.hu \
    --cc=ocfs2-devel@lists.linux.dev \
    --cc=paul@paul-moore.com \
    --cc=raven@themaw.net \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.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