Skip to content

Commit 266eb3f

Browse files
gkurzMiklos Szeredi
authored andcommitted
fuse: Call vfs_get_tree() for submounts
We recently fixed an infinite loop by setting the SB_BORN flag on submounts along with the write barrier needed by super_cache_count(). This is the job of vfs_get_tree() and FUSE shouldn't have to care about the barrier at all. Split out some code from fuse_dentry_automount() to the dedicated fuse_get_tree_submount() handler for submounts and call vfs_get_tree(). Signed-off-by: Greg Kurz <groug@kaod.org> Reviewed-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent fe0a7bd commit 266eb3f

2 files changed

Lines changed: 41 additions & 48 deletions

File tree

fs/fuse/dir.c

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,8 @@ static int fuse_dentry_delete(const struct dentry *dentry)
309309
static struct vfsmount *fuse_dentry_automount(struct path *path)
310310
{
311311
struct fs_context *fsc;
312-
struct fuse_mount *parent_fm = get_fuse_mount_super(path->mnt->mnt_sb);
313-
struct fuse_conn *fc = parent_fm->fc;
314-
struct fuse_mount *fm;
315312
struct vfsmount *mnt;
316313
struct fuse_inode *mp_fi = get_fuse_inode(d_inode(path->dentry));
317-
struct super_block *sb;
318314
int err;
319315

320316
fsc = fs_context_for_submount(path->mnt->mnt_sb->s_type, path->dentry);
@@ -323,48 +319,15 @@ static struct vfsmount *fuse_dentry_automount(struct path *path)
323319
goto out;
324320
}
325321

326-
err = -ENOMEM;
327-
fm = kzalloc(sizeof(struct fuse_mount), GFP_KERNEL);
328-
if (!fm)
329-
goto out_put_fsc;
322+
/* Pass the FUSE inode of the mount for fuse_get_tree_submount() */
323+
fsc->fs_private = mp_fi;
330324

331-
fsc->s_fs_info = fm;
332-
sb = sget_fc(fsc, NULL, set_anon_super_fc);
333-
if (IS_ERR(sb)) {
334-
err = PTR_ERR(sb);
335-
kfree(fm);
325+
err = vfs_get_tree(fsc);
326+
if (err)
336327
goto out_put_fsc;
337-
}
338-
fm->fc = fuse_conn_get(fc);
339-
340-
/* Initialize superblock, making @mp_fi its root */
341-
err = fuse_fill_super_submount(sb, mp_fi);
342-
if (err) {
343-
fuse_conn_put(fc);
344-
kfree(fm);
345-
sb->s_fs_info = NULL;
346-
goto out_put_sb;
347-
}
348-
349-
down_write(&fc->killsb);
350-
list_add_tail(&fm->fc_entry, &fc->mounts);
351-
up_write(&fc->killsb);
352-
353-
sb->s_flags |= SB_ACTIVE;
354-
fsc->root = dget(sb->s_root);
355-
356-
/*
357-
* FIXME: setting SB_BORN requires a write barrier for
358-
* super_cache_count(). We should actually come
359-
* up with a proper ->get_tree() implementation
360-
* for submounts and call vfs_get_tree() to take
361-
* care of the write barrier.
362-
*/
363-
smp_wmb();
364-
sb->s_flags |= SB_BORN;
365328

366329
/* We are done configuring the superblock, so unlock it */
367-
up_write(&sb->s_umount);
330+
up_write(&fsc->root->d_sb->s_umount);
368331

369332
/* Create the submount */
370333
mnt = vfs_create_mount(fsc);
@@ -376,12 +339,6 @@ static struct vfsmount *fuse_dentry_automount(struct path *path)
376339
put_fs_context(fsc);
377340
return mnt;
378341

379-
out_put_sb:
380-
/*
381-
* Only jump here when fsc->root is NULL and sb is still locked
382-
* (otherwise put_fs_context() will put the superblock)
383-
*/
384-
deactivate_locked_super(sb);
385342
out_put_fsc:
386343
put_fs_context(fsc);
387344
out:

fs/fuse/inode.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,8 +1353,44 @@ int fuse_fill_super_submount(struct super_block *sb,
13531353
return 0;
13541354
}
13551355

1356+
/* Filesystem context private data holds the FUSE inode of the mount point */
13561357
static int fuse_get_tree_submount(struct fs_context *fsc)
13571358
{
1359+
struct fuse_mount *fm;
1360+
struct fuse_inode *mp_fi = fsc->fs_private;
1361+
struct fuse_conn *fc = get_fuse_conn(&mp_fi->inode);
1362+
struct super_block *sb;
1363+
int err;
1364+
1365+
fm = kzalloc(sizeof(struct fuse_mount), GFP_KERNEL);
1366+
if (!fm)
1367+
return -ENOMEM;
1368+
1369+
fsc->s_fs_info = fm;
1370+
sb = sget_fc(fsc, NULL, set_anon_super_fc);
1371+
if (IS_ERR(sb)) {
1372+
kfree(fm);
1373+
return PTR_ERR(sb);
1374+
}
1375+
fm->fc = fuse_conn_get(fc);
1376+
1377+
/* Initialize superblock, making @mp_fi its root */
1378+
err = fuse_fill_super_submount(sb, mp_fi);
1379+
if (err) {
1380+
fuse_conn_put(fc);
1381+
kfree(fm);
1382+
sb->s_fs_info = NULL;
1383+
deactivate_locked_super(sb);
1384+
return err;
1385+
}
1386+
1387+
down_write(&fc->killsb);
1388+
list_add_tail(&fm->fc_entry, &fc->mounts);
1389+
up_write(&fc->killsb);
1390+
1391+
sb->s_flags |= SB_ACTIVE;
1392+
fsc->root = dget(sb->s_root);
1393+
13581394
return 0;
13591395
}
13601396

0 commit comments

Comments
 (0)