]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
convert ramfs and tmpfs
authorAl Viro <viro@zeniv.linux.org.uk>
Mon, 26 Feb 2024 06:25:24 +0000 (01:25 -0500)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 16 Nov 2025 06:35:02 +0000 (01:35 -0500)
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
fs/ramfs/inode.c
init/do_mounts.c
mm/shmem.c

index 9d4e46ad8352257a6a65d85526ebdbf9bf2d4b19..a63b0ff0c432dbbd2313491ecb9514ef958ac428 100644 (file)
@@ -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 */
index 41f9995da7cab0d11395cb40a98fb4936d52597f..505d10a0cb366537c459785fdba03fa52e8ecec6 100644 (file)
@@ -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 = {
index 6af29da8889ebf675b98cef92ad80923adec79f9..810878fb55b6101a0f94fb18416e5b125afbfb8e 100644 (file)
@@ -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)
index b9081b817d28f3db1fbdd90ed3f04b6904d6ff18..a38f7151981321b670b3783ae3004d63a36d7ea7 100644 (file)
@@ -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,
 };