Commit d00e7c6f authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

mount: link dependent mounts (v3)

All shared mounts from one group are connected to circular list.
All slave are added into the proper master list.

v2: change variable name and fix a bug about adding shared mounts in a
circular list.
v3: handle errors of collect_shared
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent c9501e63
...@@ -116,6 +116,11 @@ struct mount_info { ...@@ -116,6 +116,11 @@ struct mount_info {
struct mount_info *parent; struct mount_info *parent;
struct list_head children; struct list_head children;
struct list_head siblings; struct list_head siblings;
struct list_head mnt_share; /* circular list of shared mounts */
struct list_head mnt_slave_list;/* list of slave mounts */
struct list_head mnt_slave; /* slave list entry */
struct mount_info *mnt_master; /* slave is on master->mnt_slave_list */
}; };
struct proc_posix_timer { struct proc_posix_timer {
......
...@@ -194,6 +194,51 @@ static void mnt_tree_show(struct mount_info *tree, int off) ...@@ -194,6 +194,51 @@ static void mnt_tree_show(struct mount_info *tree, int off)
pr_info("%*s<--\n", off, ""); pr_info("%*s<--\n", off, "");
} }
static int collect_shared(struct mount_info *info)
{
struct mount_info *m, *t;
/*
* If we have a shared mounts, both master
* slave targets are to be present in mount
* list, otherwise we can't be sure if we can
* recreate the scheme later on restore.
*/
for (m = info; m; m = m->next) {
bool need_share, need_master;
need_share = m->shared_id && list_empty(&m->mnt_share);
need_master = m->master_id;
for (t = info; t && (need_share || need_master); t = t->next) {
if (t == m)
continue;
if (need_master && t->shared_id == m->master_id) {
pr_debug("The mount %d is slave for %d\n", m->mnt_id, t->mnt_id);
list_add(&m->mnt_slave, &t->mnt_slave_list);
m->mnt_master = t;
need_master = false;
}
/* Collect all mounts from this group */
if (need_share && t->shared_id == m->shared_id) {
pr_debug("Mount %d is shared with %d group %d\n",
m->mnt_id, t->mnt_id, m->shared_id);
list_add(&t->mnt_share, &m->mnt_share);
}
}
if (need_master) {
pr_err("Mount %d (master_id: %d shared_id: %d) "
"has unreachable sharing\n", m->mnt_id,
m->master_id, m->shared_id);
return -1;
}
}
return 0;
}
static struct mount_info *mnt_build_tree(struct mount_info *list) static struct mount_info *mnt_build_tree(struct mount_info *list)
{ {
struct mount_info *tree; struct mount_info *tree;
...@@ -208,6 +253,8 @@ static struct mount_info *mnt_build_tree(struct mount_info *list) ...@@ -208,6 +253,8 @@ static struct mount_info *mnt_build_tree(struct mount_info *list)
return NULL; return NULL;
mnt_resort_siblings(tree); mnt_resort_siblings(tree);
if (collect_shared(list))
return NULL;
pr_info("Done:\n"); pr_info("Done:\n");
mnt_tree_show(tree, 0); mnt_tree_show(tree, 0);
return tree; return tree;
...@@ -457,36 +504,6 @@ static struct fstype *decode_fstype(u32 fst) ...@@ -457,36 +504,6 @@ static struct fstype *decode_fstype(u32 fst)
return &fstypes[fst]; return &fstypes[fst];
} }
static int validate_shared(struct mount_info *info)
{
struct mount_info *m, *t;
/*
* If we have a shared mounts, both master
* slave targets are to be present in mount
* list, otherwise we can't be sure if we can
* recreate the scheme later on restore.
*/
for (m = info; m; m = m->next) {
if (!m->master_id)
continue;
for (t = info; t; t = t->next) {
if (t->shared_id == m->master_id)
break;
}
if (t)
continue;
pr_err("Mount %d (master_id: %d shared_id: %d) "
"has unreachable sharing\n", m->mnt_id,
m->master_id, m->shared_id);
return -1;
}
return 0;
}
static int dump_one_mountpoint(struct mount_info *pm, int fd) static int dump_one_mountpoint(struct mount_info *pm, int fd)
{ {
MntEntry me = MNT_ENTRY__INIT; MntEntry me = MNT_ENTRY__INIT;
...@@ -533,11 +550,6 @@ int dump_mnt_ns(int ns_pid, struct cr_fdset *fdset) ...@@ -533,11 +550,6 @@ int dump_mnt_ns(int ns_pid, struct cr_fdset *fdset)
if (mnt_build_tree(pm) == NULL) if (mnt_build_tree(pm) == NULL)
return -1; return -1;
if (validate_shared(mntinfo)) {
pr_err("Can't proceed %d's mountinfo\n", ns_pid);
return -1;
}
pr_info("Dumping mountpoints\n"); pr_info("Dumping mountpoints\n");
img_fd = fdset_fd(fdset, CR_FD_MNTS); img_fd = fdset_fd(fdset, CR_FD_MNTS);
...@@ -747,6 +759,9 @@ struct mount_info *mnt_entry_alloc() ...@@ -747,6 +759,9 @@ struct mount_info *mnt_entry_alloc()
if (new) { if (new) {
INIT_LIST_HEAD(&new->children); INIT_LIST_HEAD(&new->children);
INIT_LIST_HEAD(&new->siblings); INIT_LIST_HEAD(&new->siblings);
INIT_LIST_HEAD(&new->mnt_slave_list);
INIT_LIST_HEAD(&new->mnt_share);
new->mnt_master = NULL;
} }
return new; return new;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment