]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
new helper: simple_remove_by_name()
authorAl Viro <viro@zeniv.linux.org.uk>
Thu, 18 Sep 2025 02:19:10 +0000 (22:19 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 16 Nov 2025 06:35:01 +0000 (01:35 -0500)
simple_recursive_removal(), but instead of victim dentry it takes
parent + name.

Used to be open-coded in fs/fuse/control.c, but there's no need to expose
the guts of that thing there and there are other potential users, so
let's lift it into libfs...

Acked-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/fuse/control.c
fs/libfs.c
include/linux/fs.h

index 5247df896c5d016dd2dfa589f7967ab1ccbc2faf..3dca752127ff8fd1f7a04883b774a71b73277b63 100644 (file)
@@ -290,18 +290,13 @@ static void remove_one(struct dentry *dentry)
  */
 void fuse_ctl_remove_conn(struct fuse_conn *fc)
 {
-       struct dentry *dentry;
        char name[32];
 
        if (!fuse_control_sb || fc->no_control)
                return;
 
        sprintf(name, "%u", fc->dev);
-       dentry = lookup_noperm_positive_unlocked(&QSTR(name), fuse_control_sb->s_root);
-       if (!IS_ERR(dentry)) {
-               simple_recursive_removal(dentry, remove_one);
-               dput(dentry);   // paired with lookup_noperm_positive_unlocked()
-       }
+       simple_remove_by_name(fuse_control_sb->s_root, name, remove_one);
 }
 
 static int fuse_ctl_fill_super(struct super_block *sb, struct fs_context *fsc)
index ce8c496a6940ac4727e845ac57d8e2645d2ab36f..d029aff41f666a13759f9576fabdf967dffff832 100644 (file)
@@ -655,6 +655,19 @@ void simple_recursive_removal(struct dentry *dentry,
 }
 EXPORT_SYMBOL(simple_recursive_removal);
 
+void simple_remove_by_name(struct dentry *parent, const char *name,
+                           void (*callback)(struct dentry *))
+{
+       struct dentry *dentry;
+
+       dentry = lookup_noperm_positive_unlocked(&QSTR(name), parent);
+       if (!IS_ERR(dentry)) {
+               simple_recursive_removal(dentry, callback);
+               dput(dentry);   // paired with lookup_noperm_positive_unlocked()
+       }
+}
+EXPORT_SYMBOL(simple_remove_by_name);
+
 /* caller holds parent directory with I_MUTEX_PARENT */
 void locked_recursive_removal(struct dentry *dentry,
                               void (*callback)(struct dentry *))
index c895146c1444be36e0a779df55622cc38c9419ff..28bd4e8d38925ca883688710c3babc3feb8fa614 100644 (file)
@@ -3631,6 +3631,8 @@ extern int simple_rename(struct mnt_idmap *, struct inode *,
                         unsigned int);
 extern void simple_recursive_removal(struct dentry *,
                               void (*callback)(struct dentry *));
+extern void simple_remove_by_name(struct dentry *, const char *,
+                              void (*callback)(struct dentry *));
 extern void locked_recursive_removal(struct dentry *,
                               void (*callback)(struct dentry *));
 extern int noop_fsync(struct file *, loff_t, loff_t, int);