Skip to content

Commit 39f7c4d

Browse files
Miklos SzerediAl Viro
Miklos Szeredi
authored and
Al Viro
committed
vfs: keep list of mounts for each superblock
Keep track of vfsmounts belonging to a superblock. List is protected by vfsmount_lock. Signed-off-by: Miklos Szeredi <[email protected]> Tested-by: Toshiyuki Okajima <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 34c80b1 commit 39f7c4d

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

fs/mount.h

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct mount {
2929
#endif
3030
struct list_head mnt_mounts; /* list of children, anchored here */
3131
struct list_head mnt_child; /* and going through their mnt_child */
32+
struct list_head mnt_instance; /* mount instance on sb->s_mounts */
3233
const char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */
3334
struct list_head mnt_list;
3435
struct list_head mnt_expire; /* link in fs-specific expiry list */

fs/namespace.c

+7
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,9 @@ vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void
671671
mnt->mnt.mnt_sb = root->d_sb;
672672
mnt->mnt_mountpoint = mnt->mnt.mnt_root;
673673
mnt->mnt_parent = mnt;
674+
br_write_lock(vfsmount_lock);
675+
list_add_tail(&mnt->mnt_instance, &root->d_sb->s_mounts);
676+
br_write_unlock(vfsmount_lock);
674677
return &mnt->mnt;
675678
}
676679
EXPORT_SYMBOL_GPL(vfs_kern_mount);
@@ -699,6 +702,9 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root,
699702
mnt->mnt.mnt_root = dget(root);
700703
mnt->mnt_mountpoint = mnt->mnt.mnt_root;
701704
mnt->mnt_parent = mnt;
705+
br_write_lock(vfsmount_lock);
706+
list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
707+
br_write_unlock(vfsmount_lock);
702708

703709
if (flag & CL_SLAVE) {
704710
list_add(&mnt->mnt_slave, &old->mnt_slave_list);
@@ -781,6 +787,7 @@ static void mntput_no_expire(struct mount *mnt)
781787
acct_auto_close_mnt(&mnt->mnt);
782788
goto put_again;
783789
}
790+
list_del(&mnt->mnt_instance);
784791
br_write_unlock(vfsmount_lock);
785792
mntfree(mnt);
786793
}

fs/super.c

+2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ static struct super_block *alloc_super(struct file_system_type *type)
142142
INIT_LIST_HEAD(&s->s_dentry_lru);
143143
INIT_LIST_HEAD(&s->s_inode_lru);
144144
spin_lock_init(&s->s_inode_lru_lock);
145+
INIT_LIST_HEAD(&s->s_mounts);
145146
init_rwsem(&s->s_umount);
146147
mutex_init(&s->s_lock);
147148
lockdep_set_class(&s->s_umount, &type->s_umount_key);
@@ -200,6 +201,7 @@ static inline void destroy_super(struct super_block *s)
200201
free_percpu(s->s_files);
201202
#endif
202203
security_sb_free(s);
204+
WARN_ON(!list_empty(&s->s_mounts));
203205
kfree(s->s_subtype);
204206
kfree(s->s_options);
205207
kfree(s);

include/linux/fs.h

+1
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,7 @@ struct super_block {
14281428
#else
14291429
struct list_head s_files;
14301430
#endif
1431+
struct list_head s_mounts; /* list of mounts; _not_ for fs use */
14311432
/* s_dentry_lru, s_nr_dentry_unused protected by dcache.c lru locks */
14321433
struct list_head s_dentry_lru; /* unused dentry lru */
14331434
int s_nr_dentry_unused; /* # of dentry on lru */

0 commit comments

Comments
 (0)