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

mount: separate collect_mnt_ns from dump_mnt_ns

We are going to support nested mntns, so the global mntinfo_tree
variable are useless and information about tree should be connected
to a proper namespace.

But when we don't dump mntns, we need to collect mounts for the current
mntns.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 9625ebe5
...@@ -1662,6 +1662,9 @@ int cr_pre_dump_tasks(pid_t pid) ...@@ -1662,6 +1662,9 @@ int cr_pre_dump_tasks(pid_t pid)
if (mntns_collect_root(root_item->pid.real) < 0) if (mntns_collect_root(root_item->pid.real) < 0)
goto err; goto err;
if (collect_mnt_namespaces() < 0)
goto err;
for_each_pstree_item(item) for_each_pstree_item(item)
if (pre_dump_one_task(item, &ctls)) if (pre_dump_one_task(item, &ctls))
goto err; goto err;
...@@ -1772,6 +1775,9 @@ int cr_dump_tasks(pid_t pid) ...@@ -1772,6 +1775,9 @@ int cr_dump_tasks(pid_t pid)
if (mntns_collect_root(root_item->pid.real) < 0) if (mntns_collect_root(root_item->pid.real) < 0)
goto err; goto err;
if (dump_mnt_namespaces() < 0)
goto err;
if (collect_sockets(pid)) if (collect_sockets(pid))
goto err; goto err;
...@@ -1779,9 +1785,6 @@ int cr_dump_tasks(pid_t pid) ...@@ -1779,9 +1785,6 @@ int cr_dump_tasks(pid_t pid)
if (!glob_fdset) if (!glob_fdset)
goto err; goto err;
if (dump_mnt_namespaces() < 0)
goto err;
for_each_pstree_item(item) { for_each_pstree_item(item) {
if (dump_one_task(item)) if (dump_one_task(item))
goto err; goto err;
......
...@@ -11,6 +11,7 @@ extern struct fstype *find_fstype_by_name(char *fst); ...@@ -11,6 +11,7 @@ extern struct fstype *find_fstype_by_name(char *fst);
struct cr_fdset; struct cr_fdset;
struct ns_id; struct ns_id;
extern struct mount_info * collect_mntinfo(struct ns_id *ns);
extern int dump_mnt_ns(struct ns_id *ns); extern int dump_mnt_ns(struct ns_id *ns);
extern int prepare_mnt_ns(int pid); extern int prepare_mnt_ns(int pid);
......
...@@ -40,6 +40,7 @@ extern unsigned long root_ns_mask; ...@@ -40,6 +40,7 @@ extern unsigned long root_ns_mask;
extern const struct fdtype_ops nsfile_dump_ops; extern const struct fdtype_ops nsfile_dump_ops;
extern struct collect_image_info nsfile_cinfo; extern struct collect_image_info nsfile_cinfo;
extern int collect_mnt_namespaces(void);
extern int dump_mnt_namespaces(void); extern int dump_mnt_namespaces(void);
extern int dump_namespaces(struct pstree_item *item, unsigned int ns_flags); extern int dump_namespaces(struct pstree_item *item, unsigned int ns_flags);
extern int prepare_namespace(struct pstree_item *item, unsigned long clone_flags); extern int prepare_namespace(struct pstree_item *item, unsigned long clone_flags);
......
...@@ -827,44 +827,60 @@ static int dump_one_mountpoint(struct mount_info *pm, int fd) ...@@ -827,44 +827,60 @@ static int dump_one_mountpoint(struct mount_info *pm, int fd)
return 0; return 0;
} }
int dump_mnt_ns(struct ns_id *ns) struct mount_info *collect_mntinfo(struct ns_id *ns)
{ {
struct mount_info *pm; struct mount_info *pm, *p;
int img_fd, ret = -1;
int ns_pid = ns->pid;
int ns_id = ns->id;
img_fd = open_image(CR_FD_MNTS, O_DUMP, ns_id);
if (img_fd < 0)
return -1;
if (mntns_collect_root(ns_pid) < 0) if (mntns_collect_root(ns->pid) < 0)
goto err; return NULL;
pm = parse_mountinfo(ns_pid); pm = parse_mountinfo(ns->pid);
if (!pm) { if (!pm) {
pr_err("Can't parse %d's mountinfo\n", ns_pid); pr_err("Can't parse %d's mountinfo\n", ns->pid);
goto err; return NULL;
} }
ns->mnt.mntinfo_tree = mnt_build_tree(pm); ns->mnt.mntinfo_tree = mnt_build_tree(pm);
if (ns->mnt.mntinfo_tree == NULL) if (ns->mnt.mntinfo_tree == NULL)
goto err; goto err;
if (validate_mounts(pm, true)) return pm;
err:
while (pm) {
p = pm;
pm = pm->next;
xfree(p);
}
ns->mnt.mntinfo_tree = NULL;
return NULL;
}
int dump_mnt_ns(struct ns_id *ns)
{
struct mount_info *pm, *pms;
int img_fd = -1, ret = -1;
int ns_id = ns->id;
pms = collect_mntinfo(ns);
if (pms == NULL)
goto err;
if (validate_mounts(pms, true))
goto err; goto err;
pr_info("Dumping mountpoints\n"); pr_info("Dumping mountpoints\n");
do { img_fd = open_image(CR_FD_MNTS, O_DUMP, ns_id);
struct mount_info *n = pm->next; if (img_fd < 0)
goto err;
for (pm = pms; pm; pm = pm->next)
if (dump_one_mountpoint(pm, img_fd)) if (dump_one_mountpoint(pm, img_fd))
goto err; goto err;
pm = n;
} while (pm);
ret = 0; ret = 0;
err: err:
close(img_fd); close(img_fd);
...@@ -1777,6 +1793,36 @@ set_root: ...@@ -1777,6 +1793,36 @@ set_root:
return ret; return ret;
} }
int collect_mnt_namespaces(void)
{
struct mount_info *pm;
struct ns_id *ns;
int ret = -1;
for (ns = ns_ids; ns; ns = ns->next) {
if (ns->pid == getpid()) {
if (!(root_ns_mask & CLONE_NEWNS)) {
if (collect_mntinfo(ns) == NULL)
return -1;
}
/* Skip current namespaces, which are in the list too */
continue;
}
if (!(ns->nd->cflag & CLONE_NEWNS))
continue;
pr_info("Dump MNT namespace (mountpoints) %d via %d\n",
ns->id, ns->pid);
pm = collect_mntinfo(ns);
if (pm == NULL)
goto err;
}
ret = 0;
err:
return ret;
}
int dump_mnt_namespaces(void) int dump_mnt_namespaces(void)
{ {
struct ns_id *ns; struct ns_id *ns;
...@@ -1784,8 +1830,12 @@ int dump_mnt_namespaces(void) ...@@ -1784,8 +1830,12 @@ int dump_mnt_namespaces(void)
for (ns = ns_ids; ns; ns = ns->next) { for (ns = ns_ids; ns; ns = ns->next) {
/* Skip current namespaces, which are in the list too */ /* Skip current namespaces, which are in the list too */
if (ns->pid == getpid()) if (ns->pid == getpid()) {
if (!(root_ns_mask & CLONE_NEWNS))
if (collect_mntinfo(ns) == NULL)
return -1;
continue; continue;
}
if (!(ns->nd->cflag & CLONE_NEWNS)) if (!(ns->nd->cflag & CLONE_NEWNS))
continue; continue;
......
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