Skip to content

Commit fcaac5b

Browse files
author
Al Viro
committed
fuse_ctl: use simple_recursive_removal()
easier that way - no need to keep that array of dentry references, etc. Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 7b7a8ca commit fcaac5b

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

fs/fuse/control.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/init.h>
1212
#include <linux/module.h>
1313
#include <linux/fs_context.h>
14+
#include <linux/namei.h>
1415

1516
#define FUSE_CTL_SUPER_MAGIC 0x65735543
1617

@@ -212,7 +213,6 @@ static struct dentry *fuse_ctl_add_dentry(struct dentry *parent,
212213
struct dentry *dentry;
213214
struct inode *inode;
214215

215-
BUG_ON(fc->ctl_ndents >= FUSE_CTL_NUM_DENTRIES);
216216
dentry = d_alloc_name(parent, name);
217217
if (!dentry)
218218
return NULL;
@@ -236,8 +236,6 @@ static struct dentry *fuse_ctl_add_dentry(struct dentry *parent,
236236
inode->i_private = fc;
237237
d_add(dentry, inode);
238238

239-
fc->ctl_dentry[fc->ctl_ndents++] = dentry;
240-
241239
return dentry;
242240
}
243241

@@ -280,27 +278,29 @@ int fuse_ctl_add_conn(struct fuse_conn *fc)
280278
return -ENOMEM;
281279
}
282280

281+
static void remove_one(struct dentry *dentry)
282+
{
283+
d_inode(dentry)->i_private = NULL;
284+
}
285+
283286
/*
284287
* Remove a connection from the control filesystem (if it exists).
285288
* Caller must hold fuse_mutex
286289
*/
287290
void fuse_ctl_remove_conn(struct fuse_conn *fc)
288291
{
289-
int i;
292+
struct dentry *dentry;
293+
char name[32];
290294

291295
if (!fuse_control_sb || fc->no_control)
292296
return;
293297

294-
for (i = fc->ctl_ndents - 1; i >= 0; i--) {
295-
struct dentry *dentry = fc->ctl_dentry[i];
296-
d_inode(dentry)->i_private = NULL;
297-
if (!i) {
298-
/* Get rid of submounts: */
299-
d_invalidate(dentry);
300-
}
301-
dput(dentry);
298+
sprintf(name, "%u", fc->dev);
299+
dentry = lookup_noperm_positive_unlocked(&QSTR(name), fuse_control_sb->s_root);
300+
if (!IS_ERR(dentry)) {
301+
simple_recursive_removal(dentry, remove_one);
302+
dput(dentry); // paired with lookup_noperm_positive_unlocked()
302303
}
303-
drop_nlink(d_inode(fuse_control_sb->s_root));
304304
}
305305

306306
static int fuse_ctl_fill_super(struct super_block *sb, struct fs_context *fsc)
@@ -346,12 +346,8 @@ static int fuse_ctl_init_fs_context(struct fs_context *fsc)
346346

347347
static void fuse_ctl_kill_sb(struct super_block *sb)
348348
{
349-
struct fuse_conn *fc;
350-
351349
mutex_lock(&fuse_mutex);
352350
fuse_control_sb = NULL;
353-
list_for_each_entry(fc, &fuse_conn_list, entry)
354-
fc->ctl_ndents = 0;
355351
mutex_unlock(&fuse_mutex);
356352

357353
kill_litter_super(sb);

fs/fuse/fuse_i.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -913,12 +913,6 @@ struct fuse_conn {
913913
/** Device ID from the root super block */
914914
dev_t dev;
915915

916-
/** Dentries in the control filesystem */
917-
struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
918-
919-
/** number of dentries used in the above array */
920-
int ctl_ndents;
921-
922916
/** Key for lock owner ID scrambling */
923917
u32 scramble_key[4];
924918

0 commit comments

Comments
 (0)