Skip to content

Commit 5d132cf

Browse files
author
Al Viro
committed
setup_mnt(): primitive for connecting a mount to filesystem
Take the identical logics in vfs_create_mount() and clone_mnt() into a new helper that takes an empty struct mount and attaches it to given dentry (sub)tree. Should be called once in the lifetime of every mount, prior to making it visible in any data structures. After that point ->mnt_root and ->mnt_sb never change; ->mnt_root is a counting reference to dentry and ->mnt_sb - an active reference to superblock. Mount remains associated with that dentry tree all the way until the call of cleanup_mnt(), when the refcount eventually drops to zero. Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 7f954a6 commit 5d132cf

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

fs/namespace.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,21 @@ static void commit_tree(struct mount *mnt)
11961196
touch_mnt_namespace(n);
11971197
}
11981198

1199+
static void setup_mnt(struct mount *m, struct dentry *root)
1200+
{
1201+
struct super_block *s = root->d_sb;
1202+
1203+
atomic_inc(&s->s_active);
1204+
m->mnt.mnt_sb = s;
1205+
m->mnt.mnt_root = dget(root);
1206+
m->mnt_mountpoint = m->mnt.mnt_root;
1207+
m->mnt_parent = m;
1208+
1209+
lock_mount_hash();
1210+
list_add_tail(&m->mnt_instance, &s->s_mounts);
1211+
unlock_mount_hash();
1212+
}
1213+
11991214
/**
12001215
* vfs_create_mount - Create a mount for a configured superblock
12011216
* @fc: The configuration context with the superblock attached
@@ -1219,15 +1234,8 @@ struct vfsmount *vfs_create_mount(struct fs_context *fc)
12191234
if (fc->sb_flags & SB_KERNMOUNT)
12201235
mnt->mnt.mnt_flags = MNT_INTERNAL;
12211236

1222-
atomic_inc(&fc->root->d_sb->s_active);
1223-
mnt->mnt.mnt_sb = fc->root->d_sb;
1224-
mnt->mnt.mnt_root = dget(fc->root);
1225-
mnt->mnt_mountpoint = mnt->mnt.mnt_root;
1226-
mnt->mnt_parent = mnt;
1237+
setup_mnt(mnt, fc->root);
12271238

1228-
lock_mount_hash();
1229-
list_add_tail(&mnt->mnt_instance, &mnt->mnt.mnt_sb->s_mounts);
1230-
unlock_mount_hash();
12311239
return &mnt->mnt;
12321240
}
12331241
EXPORT_SYMBOL(vfs_create_mount);
@@ -1285,7 +1293,6 @@ EXPORT_SYMBOL_GPL(vfs_kern_mount);
12851293
static struct mount *clone_mnt(struct mount *old, struct dentry *root,
12861294
int flag)
12871295
{
1288-
struct super_block *sb = old->mnt.mnt_sb;
12891296
struct mount *mnt;
12901297
int err;
12911298

@@ -1310,16 +1317,9 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root,
13101317
if (mnt->mnt_group_id)
13111318
set_mnt_shared(mnt);
13121319

1313-
atomic_inc(&sb->s_active);
13141320
mnt->mnt.mnt_idmap = mnt_idmap_get(mnt_idmap(&old->mnt));
13151321

1316-
mnt->mnt.mnt_sb = sb;
1317-
mnt->mnt.mnt_root = dget(root);
1318-
mnt->mnt_mountpoint = mnt->mnt.mnt_root;
1319-
mnt->mnt_parent = mnt;
1320-
lock_mount_hash();
1321-
list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
1322-
unlock_mount_hash();
1322+
setup_mnt(mnt, root);
13231323

13241324
if (flag & CL_PRIVATE) // we are done with it
13251325
return mnt;

0 commit comments

Comments
 (0)