Commit 4051a911 authored by Al Viro's avatar Al Viro
Browse files

new helper: simple_remove_by_name()



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: default avatarMiklos Szeredi <mszeredi@redhat.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 798a4016
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -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)
+13 −0
Original line number Diff line number Diff line
@@ -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 *))
+2 −0
Original line number Diff line number Diff line
@@ -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);