reorganize do_make_slave()
Make sure that clone_mnt() never returns a mount with MNT_SHARED in flags, but without a valid ->mnt_group_id. That allows to demystify do_make_slave() quite a bit, among other things. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
066715d3fd
commit
5235d448c4
|
@ -1030,6 +1030,8 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root,
|
||||||
if (IS_MNT_SLAVE(old))
|
if (IS_MNT_SLAVE(old))
|
||||||
list_add(&mnt->mnt_slave, &old->mnt_slave);
|
list_add(&mnt->mnt_slave, &old->mnt_slave);
|
||||||
mnt->mnt_master = old->mnt_master;
|
mnt->mnt_master = old->mnt_master;
|
||||||
|
} else {
|
||||||
|
CLEAR_MNT_SHARED(mnt);
|
||||||
}
|
}
|
||||||
if (flag & CL_MAKE_SHARED)
|
if (flag & CL_MAKE_SHARED)
|
||||||
set_mnt_shared(mnt);
|
set_mnt_shared(mnt);
|
||||||
|
|
62
fs/pnode.c
62
fs/pnode.c
|
@ -67,39 +67,15 @@ int get_dominating_id(struct mount *mnt, const struct path *root)
|
||||||
|
|
||||||
static int do_make_slave(struct mount *mnt)
|
static int do_make_slave(struct mount *mnt)
|
||||||
{
|
{
|
||||||
struct mount *peer_mnt = mnt, *master = mnt->mnt_master;
|
struct mount *master, *slave_mnt;
|
||||||
struct mount *slave_mnt;
|
|
||||||
|
|
||||||
/*
|
if (list_empty(&mnt->mnt_share)) {
|
||||||
* slave 'mnt' to a peer mount that has the
|
if (IS_MNT_SHARED(mnt)) {
|
||||||
* same root dentry. If none is available then
|
|
||||||
* slave it to anything that is available.
|
|
||||||
*/
|
|
||||||
while ((peer_mnt = next_peer(peer_mnt)) != mnt &&
|
|
||||||
peer_mnt->mnt.mnt_root != mnt->mnt.mnt_root) ;
|
|
||||||
|
|
||||||
if (peer_mnt == mnt) {
|
|
||||||
peer_mnt = next_peer(mnt);
|
|
||||||
if (peer_mnt == mnt)
|
|
||||||
peer_mnt = NULL;
|
|
||||||
}
|
|
||||||
if (mnt->mnt_group_id && IS_MNT_SHARED(mnt) &&
|
|
||||||
list_empty(&mnt->mnt_share))
|
|
||||||
mnt_release_group_id(mnt);
|
mnt_release_group_id(mnt);
|
||||||
|
CLEAR_MNT_SHARED(mnt);
|
||||||
list_del_init(&mnt->mnt_share);
|
}
|
||||||
mnt->mnt_group_id = 0;
|
master = mnt->mnt_master;
|
||||||
|
if (!master) {
|
||||||
if (peer_mnt)
|
|
||||||
master = peer_mnt;
|
|
||||||
|
|
||||||
if (master) {
|
|
||||||
list_for_each_entry(slave_mnt, &mnt->mnt_slave_list, mnt_slave)
|
|
||||||
slave_mnt->mnt_master = master;
|
|
||||||
list_move(&mnt->mnt_slave, &master->mnt_slave_list);
|
|
||||||
list_splice(&mnt->mnt_slave_list, master->mnt_slave_list.prev);
|
|
||||||
INIT_LIST_HEAD(&mnt->mnt_slave_list);
|
|
||||||
} else {
|
|
||||||
struct list_head *p = &mnt->mnt_slave_list;
|
struct list_head *p = &mnt->mnt_slave_list;
|
||||||
while (!list_empty(p)) {
|
while (!list_empty(p)) {
|
||||||
slave_mnt = list_first_entry(p,
|
slave_mnt = list_first_entry(p,
|
||||||
|
@ -107,9 +83,31 @@ static int do_make_slave(struct mount *mnt)
|
||||||
list_del_init(&slave_mnt->mnt_slave);
|
list_del_init(&slave_mnt->mnt_slave);
|
||||||
slave_mnt->mnt_master = NULL;
|
slave_mnt->mnt_master = NULL;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
mnt->mnt_master = master;
|
} else {
|
||||||
|
struct mount *m;
|
||||||
|
/*
|
||||||
|
* slave 'mnt' to a peer mount that has the
|
||||||
|
* same root dentry. If none is available then
|
||||||
|
* slave it to anything that is available.
|
||||||
|
*/
|
||||||
|
for (m = master = next_peer(mnt); m != mnt; m = next_peer(m)) {
|
||||||
|
if (m->mnt.mnt_root == mnt->mnt.mnt_root) {
|
||||||
|
master = m;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list_del_init(&mnt->mnt_share);
|
||||||
|
mnt->mnt_group_id = 0;
|
||||||
CLEAR_MNT_SHARED(mnt);
|
CLEAR_MNT_SHARED(mnt);
|
||||||
|
}
|
||||||
|
list_for_each_entry(slave_mnt, &mnt->mnt_slave_list, mnt_slave)
|
||||||
|
slave_mnt->mnt_master = master;
|
||||||
|
list_move(&mnt->mnt_slave, &master->mnt_slave_list);
|
||||||
|
list_splice(&mnt->mnt_slave_list, master->mnt_slave_list.prev);
|
||||||
|
INIT_LIST_HEAD(&mnt->mnt_slave_list);
|
||||||
|
mnt->mnt_master = master;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue