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 */
287290void 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
306306static 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
347347static 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 );
0 commit comments