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, neil@brown.name,
	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,
	john.johansen@canonical.com, selinux@vger.kernel.org,
	borntraeger@linux.ibm.com, bpf@vger.kernel.org
Subject: [PATCH v2 08/50] convert ramfs and tmpfs
Date: Tue, 28 Oct 2025 00:45:27 +0000	[thread overview]
Message-ID: <20251028004614.393374-9-viro@zeniv.linux.org.uk> (raw)
In-Reply-To: <20251028004614.393374-1-viro@zeniv.linux.org.uk>

Quite a bit is already done by infrastructure changes (simple_link(),
simple_unlink()) - all that is left is replacing d_instantiate() +
pinning dget() (in ->symlink() and ->mknod()) with d_make_persistent(),
and, in case of shmem, using simple_unlink() and simple_link() in
->unlink() and ->link() resp., instead of open-coding those there.
Since d_make_persistent() accepts (and hashes) unhashed ones, shmem
situation gets simpler - we no longer care whether ->lookup() has hashed
the sucker.

With that done, we don't need kill_litter_super() for these filesystems
anymore - by the umount time all remaining dentries will be marked
persistent and kill_litter_super() will boil down to call of
kill_anon_super().

The same goes for devtmpfs and rootfs - they are handled by
ramfs or by shmem, depending upon config.

NB: strictly speaking, both devtmpfs and rootfs ought to use
ramfs_kill_sb() if they end up using ramfs; that's a separate
story and the only impact of "just use kill_{litter,anon}_super()"
is that we fail to free their sb->s_fs_info... on reboot.
That's orthogonal to the changes in this series - kill_litter_super()
is identical to kill_anon_super() for those at this point.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 drivers/base/devtmpfs.c |  2 +-
 fs/ramfs/inode.c        |  8 +++-----
 init/do_mounts.c        |  2 +-
 mm/shmem.c              | 38 ++++++++------------------------------
 4 files changed, 13 insertions(+), 37 deletions(-)

diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
index 9d4e46ad8352..a63b0ff0c432 100644
--- a/drivers/base/devtmpfs.c
+++ b/drivers/base/devtmpfs.c
@@ -70,7 +70,7 @@ static struct file_system_type internal_fs_type = {
 #else
 	.init_fs_context = ramfs_init_fs_context,
 #endif
-	.kill_sb = kill_litter_super,
+	.kill_sb = kill_anon_super,
 };
 
 /* Simply take a ref on the existing mount */
diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index 41f9995da7ca..505d10a0cb36 100644
--- a/fs/ramfs/inode.c
+++ b/fs/ramfs/inode.c
@@ -110,8 +110,7 @@ ramfs_mknod(struct mnt_idmap *idmap, struct inode *dir,
 			goto out;
 		}
 
-		d_instantiate(dentry, inode);
-		dget(dentry);	/* Extra count - pin the dentry in core */
+		d_make_persistent(dentry, inode);
 		error = 0;
 		inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
 	}
@@ -154,8 +153,7 @@ static int ramfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
 
 		error = page_symlink(inode, symname, l);
 		if (!error) {
-			d_instantiate(dentry, inode);
-			dget(dentry);
+			d_make_persistent(dentry, inode);
 			inode_set_mtime_to_ts(dir,
 					      inode_set_ctime_current(dir));
 		} else
@@ -313,7 +311,7 @@ int ramfs_init_fs_context(struct fs_context *fc)
 void ramfs_kill_sb(struct super_block *sb)
 {
 	kfree(sb->s_fs_info);
-	kill_litter_super(sb);
+	kill_anon_super(sb);
 }
 
 static struct file_system_type ramfs_fs_type = {
diff --git a/init/do_mounts.c b/init/do_mounts.c
index 6af29da8889e..810878fb55b6 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -507,7 +507,7 @@ static int rootfs_init_fs_context(struct fs_context *fc)
 struct file_system_type rootfs_fs_type = {
 	.name		= "rootfs",
 	.init_fs_context = rootfs_init_fs_context,
-	.kill_sb	= kill_litter_super,
+	.kill_sb	= kill_anon_super,
 };
 
 void __init init_rootfs(void)
diff --git a/mm/shmem.c b/mm/shmem.c
index b9081b817d28..a38f71519813 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -3858,12 +3858,7 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *dir,
 	inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
 	inode_inc_iversion(dir);
 
-	if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir))
-		d_add(dentry, inode);
-	else
-		d_instantiate(dentry, inode);
-
-	dget(dentry); /* Extra count - pin the dentry in core */
+	d_make_persistent(dentry, inode);
 	return error;
 
 out_iput:
@@ -3924,7 +3919,7 @@ static int shmem_link(struct dentry *old_dentry, struct inode *dir,
 		      struct dentry *dentry)
 {
 	struct inode *inode = d_inode(old_dentry);
-	int ret = 0;
+	int ret;
 
 	/*
 	 * No ordinary (disk based) filesystem counts links as inodes;
@@ -3936,29 +3931,19 @@ static int shmem_link(struct dentry *old_dentry, struct inode *dir,
 	if (inode->i_nlink) {
 		ret = shmem_reserve_inode(inode->i_sb, NULL);
 		if (ret)
-			goto out;
+			return ret;
 	}
 
 	ret = simple_offset_add(shmem_get_offset_ctx(dir), dentry);
 	if (ret) {
 		if (inode->i_nlink)
 			shmem_free_inode(inode->i_sb, 0);
-		goto out;
+		return ret;
 	}
 
 	dir->i_size += BOGO_DIRENT_SIZE;
-	inode_set_mtime_to_ts(dir,
-			      inode_set_ctime_to_ts(dir, inode_set_ctime_current(inode)));
 	inode_inc_iversion(dir);
-	inc_nlink(inode);
-	ihold(inode);	/* New dentry reference */
-	dget(dentry);	/* Extra pinning count for the created dentry */
-	if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir))
-		d_add(dentry, inode);
-	else
-		d_instantiate(dentry, inode);
-out:
-	return ret;
+	return simple_link(old_dentry, dir, dentry);
 }
 
 static int shmem_unlink(struct inode *dir, struct dentry *dentry)
@@ -3971,11 +3956,8 @@ static int shmem_unlink(struct inode *dir, struct dentry *dentry)
 	simple_offset_remove(shmem_get_offset_ctx(dir), dentry);
 
 	dir->i_size -= BOGO_DIRENT_SIZE;
-	inode_set_mtime_to_ts(dir,
-			      inode_set_ctime_to_ts(dir, inode_set_ctime_current(inode)));
 	inode_inc_iversion(dir);
-	drop_nlink(inode);
-	dput(dentry);	/* Undo the count from "create" - does all the work */
+	simple_unlink(dir, dentry);
 
 	/*
 	 * For now, VFS can't deal with case-insensitive negative dentries, so
@@ -4130,11 +4112,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
 	dir->i_size += BOGO_DIRENT_SIZE;
 	inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
 	inode_inc_iversion(dir);
-	if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir))
-		d_add(dentry, inode);
-	else
-		d_instantiate(dentry, inode);
-	dget(dentry);
+	d_make_persistent(dentry, inode);
 	return 0;
 
 out_remove_offset:
@@ -5334,7 +5312,7 @@ static struct file_system_type shmem_fs_type = {
 #ifdef CONFIG_TMPFS
 	.parameters	= shmem_fs_parameters,
 #endif
-	.kill_sb	= kill_litter_super,
+	.kill_sb	= kill_anon_super,
 	.fs_flags	= FS_USERNS_MOUNT | FS_ALLOW_IDMAP | FS_MGTIME,
 };
 
-- 
2.47.3



  parent reply	other threads:[~2025-10-28  0:46 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-28  0:45 [PATCH v2 00/50] tree-in-dcache stuff Al Viro
2025-10-28  0:45 ` [PATCH v2 01/50] fuse_ctl_add_conn(): fix nlink breakage in case of early failure Al Viro
2025-10-28  0:45 ` [PATCH v2 02/50] tracefs: fix a leak in eventfs_create_events_dir() Al Viro
2025-10-28  1:15   ` Steven Rostedt
2025-10-28  0:45 ` [PATCH v2 03/50] new helper: simple_remove_by_name() Al Viro
2025-10-28  0:45 ` [PATCH v2 04/50] new helper: simple_done_creating() Al Viro
2025-10-28  0:45 ` [PATCH v2 05/50] introduce a flag for explicitly marking persistently pinned dentries Al Viro
2025-10-28  0:45 ` [PATCH v2 06/50] primitives for maintaining persisitency Al Viro
2025-10-28 12:38   ` James Bottomley
2025-10-29  5:10     ` Al Viro
2025-10-29 15:25       ` James Bottomley
2025-10-28  0:45 ` [PATCH v2 07/50] convert simple_{link,unlink,rmdir,rename,fill_super}() to new primitives Al Viro
2025-10-29 14:02   ` [External] : " Mark Tinguely
2025-10-29 17:55     ` Al Viro
2025-10-28  0:45 ` Al Viro [this message]
2025-10-28  0:45 ` [PATCH v2 09/50] procfs: make /self and /thread_self dentries persistent Al Viro
2025-10-28  0:45 ` [PATCH v2 10/50] configfs, securityfs: kill_litter_super() not needed Al Viro
2025-10-28 23:58   ` Paul Moore
2025-10-29  6:18   ` Andreas Hindborg
2025-10-28  0:45 ` [PATCH v2 11/50] convert xenfs Al Viro
2025-10-28  0:45 ` [PATCH v2 12/50] convert smackfs Al Viro
2025-10-28  0:45 ` [PATCH v2 13/50] convert hugetlbfs Al Viro
2025-10-28  0:45 ` [PATCH v2 14/50] convert mqueue Al Viro
2025-10-28  0:45 ` [PATCH v2 15/50] convert bpf Al Viro
2025-10-28  0:45 ` [PATCH v2 16/50] convert dlmfs Al Viro
2025-10-28  0:45 ` [PATCH v2 17/50] convert fuse_ctl Al Viro
2025-10-28  0:45 ` [PATCH v2 18/50] convert pstore Al Viro
2025-11-04  1:43   ` Kees Cook
2025-10-28  0:45 ` [PATCH v2 19/50] convert tracefs Al Viro
2025-10-28 15:37   ` Steven Rostedt
2025-10-28  0:45 ` [PATCH v2 20/50] convert debugfs Al Viro
2025-10-28  0:45 ` [PATCH v2 21/50] debugfs: remove duplicate checks in callers of start_creating() Al Viro
2025-10-28  0:45 ` [PATCH v2 22/50] convert efivarfs Al Viro
2025-10-28 12:53   ` James Bottomley
2025-10-28 17:45     ` Al Viro
2025-10-28 21:08       ` Al Viro
2025-10-28 21:34         ` Ard Biesheuvel
2025-10-29 18:08           ` Al Viro
2025-10-29 18:26             ` Ard Biesheuvel
2025-10-29 18:57           ` James Bottomley
2025-10-29 19:37             ` Al Viro
2025-10-29 19:48               ` James Bottomley
2025-10-30 13:35               ` Ard Biesheuvel
2025-11-05 11:47                 ` Christian Brauner
2025-11-05 13:09                   ` James Bottomley
2025-11-05 13:16                     ` Christian Brauner
2025-11-05 13:33                       ` James Bottomley
2025-11-05 13:46                         ` Christian Brauner
2025-11-05 14:01                           ` James Bottomley
2025-11-05 15:23                             ` Christian Brauner
2025-11-05 13:43                       ` Christian Brauner
2025-11-09 20:40                         ` Al Viro
2025-11-11 10:56                           ` Christian Brauner
2025-11-19 21:15                         ` [REGRESSION] " Chris Bainbridge
2025-11-25  9:00                           ` Christian Brauner
2025-11-05 14:34                   ` Ard Biesheuvel
2025-10-28  0:45 ` [PATCH v2 23/50] convert spufs Al Viro
2025-10-28  1:15   ` bot+bpf-ci
2025-10-28  1:33     ` Al Viro
2025-10-28  0:45 ` [PATCH v2 24/50] convert ibmasmfs Al Viro
2025-10-28  0:45 ` [PATCH v2 25/50] ibmasmfs: get rid of ibmasmfs_dir_ops Al Viro
2025-10-28  0:45 ` [PATCH v2 26/50] convert devpts Al Viro
2025-10-28  0:45 ` [PATCH v2 27/50] binderfs: use simple_start_creating() Al Viro
2025-10-28  0:45 ` [PATCH v2 28/50] binderfs_binder_ctl_create(): kill a bogus check Al Viro
2025-10-28  0:45 ` [PATCH v2 29/50] convert binderfs Al Viro
2025-10-28  0:45 ` [PATCH v2 30/50] autofs_{rmdir,unlink}: dentry->d_fsdata->dentry == dentry there Al Viro
2025-10-28  0:45 ` [PATCH v2 31/50] convert autofs Al Viro
2025-10-28  1:55   ` Al Viro
2025-10-28  5:32     ` Linus Torvalds
2025-10-28  0:45 ` [PATCH v2 32/50] convert binfmt_misc Al Viro
2025-10-28  0:45 ` [PATCH v2 33/50] selinuxfs: don't stash the dentry of /policy_capabilities Al Viro
2025-10-29  0:08   ` Paul Moore
2025-10-29 15:19   ` Stephen Smalley
2025-10-28  0:45 ` [PATCH v2 34/50] selinuxfs: new helper for attaching files to tree Al Viro
2025-10-28 23:51   ` Paul Moore
2025-10-29 15:22   ` Stephen Smalley
2025-10-28  0:45 ` [PATCH v2 35/50] convert selinuxfs Al Viro
2025-10-29  0:02   ` Paul Moore
2025-10-29  3:24     ` Al Viro
2025-10-29 14:49       ` Paul Moore
2025-10-29 15:06   ` Stephen Smalley
2025-10-28  0:45 ` [PATCH v2 36/50] functionfs: switch to simple_remove_by_name() Al Viro
2025-10-28  8:47   ` Greg KH
2025-10-28  0:45 ` [PATCH v2 37/50] convert functionfs Al Viro
2025-10-28  0:45 ` [PATCH v2 38/50] gadgetfs: switch to simple_remove_by_name() Al Viro
2025-10-28  0:45 ` [PATCH v2 39/50] convert gadgetfs Al Viro
2025-10-28  0:45 ` [PATCH v2 40/50] hypfs: don't pin dentries twice Al Viro
2025-10-28  0:46 ` [PATCH v2 41/50] hypfs: switch hypfs_create_str() to returning int Al Viro
2025-10-28  0:46 ` [PATCH v2 42/50] hypfs: swich hypfs_create_u64() " Al Viro
2025-10-28  0:46 ` [PATCH v2 43/50] convert hypfs Al Viro
2025-10-28  0:46 ` [PATCH v2 44/50] convert rpc_pipefs Al Viro
2025-10-28  0:46 ` [PATCH v2 45/50] convert nfsctl Al Viro
2025-10-28  0:46 ` [PATCH v2 46/50] convert rust_binderfs Al Viro
2025-10-28  0:46 ` [PATCH v2 47/50] get rid of kill_litter_super() Al Viro
2025-10-28  0:46 ` [PATCH v2 48/50] convert securityfs Al Viro
2025-10-29  0:10   ` Paul Moore
2025-10-28  0:46 ` [PATCH v2 49/50] kill securityfs_recursive_remove() Al Viro
2025-10-29  0:04   ` Paul Moore
2025-10-28  0:46 ` [PATCH v2 50/50] d_make_discardable(): warn if given a non-persistent dentry Al Viro
2025-10-28  0:59 ` [PATCH v2 00/50] tree-in-dcache stuff Al Viro
2025-10-28  5:33 ` Linus Torvalds

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=20251028004614.393374-9-viro@zeniv.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=a.hindborg@kernel.org \
    --cc=borntraeger@linux.ibm.com \
    --cc=bpf@vger.kernel.org \
    --cc=brauner@kernel.org \
    --cc=casey@schaufler-ca.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jack@suse.cz \
    --cc=john.johansen@canonical.com \
    --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=neil@brown.name \
    --cc=ocfs2-devel@lists.linux.dev \
    --cc=paul@paul-moore.com \
    --cc=raven@themaw.net \
    --cc=rostedt@goodmis.org \
    --cc=selinux@vger.kernel.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