[CRIU] [PATCH 24/39] mount: separate collect_mnt_ns from dump_mnt_ns
Andrey Vagin
avagin at openvz.org
Mon Apr 21 07:23:34 PDT 2014
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: Andrey Vagin <avagin at openvz.org>
---
cr-dump.c | 9 +++--
include/mount.h | 1 +
include/namespaces.h | 1 +
mount.c | 92 ++++++++++++++++++++++++++++++++++++++++------------
4 files changed, 79 insertions(+), 24 deletions(-)
diff --git a/cr-dump.c b/cr-dump.c
index d135ff4..1087e56 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1662,6 +1662,9 @@ int cr_pre_dump_tasks(pid_t pid)
if (mntns_collect_root(root_item->pid.real) < 0)
goto err;
+ if (collect_mnt_namespaces() < 0)
+ goto err;
+
for_each_pstree_item(item)
if (pre_dump_one_task(item, &ctls))
goto err;
@@ -1772,6 +1775,9 @@ int cr_dump_tasks(pid_t pid)
if (mntns_collect_root(root_item->pid.real) < 0)
goto err;
+ if (dump_mnt_namespaces() < 0)
+ goto err;
+
if (collect_sockets(pid))
goto err;
@@ -1779,9 +1785,6 @@ int cr_dump_tasks(pid_t pid)
if (!glob_fdset)
goto err;
- if (dump_mnt_namespaces() < 0)
- goto err;
-
for_each_pstree_item(item) {
if (dump_one_task(item))
goto err;
diff --git a/include/mount.h b/include/mount.h
index 1d51910..1361c61 100644
--- a/include/mount.h
+++ b/include/mount.h
@@ -11,6 +11,7 @@ extern struct fstype *find_fstype_by_name(char *fst);
struct cr_fdset;
struct ns_id;
+extern struct mount_info * collect_mntinfo(struct ns_id *ns);
extern int dump_mnt_ns(struct ns_id *ns);
extern int prepare_mnt_ns(int pid);
diff --git a/include/namespaces.h b/include/namespaces.h
index 55cf37a..41d073e 100644
--- a/include/namespaces.h
+++ b/include/namespaces.h
@@ -40,6 +40,7 @@ extern unsigned long root_ns_mask;
extern const struct fdtype_ops nsfile_dump_ops;
extern struct collect_image_info nsfile_cinfo;
+extern int collect_mnt_namespaces(void);
extern int dump_mnt_namespaces(void);
extern int dump_namespaces(struct pstree_item *item, unsigned int ns_flags);
extern int prepare_namespace(struct pstree_item *item, unsigned long clone_flags);
diff --git a/mount.c b/mount.c
index 21350de..867dd50 100644
--- a/mount.c
+++ b/mount.c
@@ -827,44 +827,60 @@ static int dump_one_mountpoint(struct mount_info *pm, int fd)
return 0;
}
-int dump_mnt_ns(struct ns_id *ns)
+struct mount_info *collect_mntinfo(struct ns_id *ns)
{
- struct mount_info *pm;
- 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;
+ struct mount_info *pm, *p;
- if (mntns_collect_root(ns_pid) < 0)
- goto err;
+ if (mntns_collect_root(ns->pid) < 0)
+ return NULL;
- pm = parse_mountinfo(ns_pid);
+ pm = parse_mountinfo(ns->pid);
if (!pm) {
- pr_err("Can't parse %d's mountinfo\n", ns_pid);
- goto err;
+ pr_err("Can't parse %d's mountinfo\n", ns->pid);
+ return NULL;
}
ns->mnt.mntinfo_tree = mnt_build_tree(pm);
if (ns->mnt.mntinfo_tree == NULL)
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;
pr_info("Dumping mountpoints\n");
- do {
- struct mount_info *n = pm->next;
+ img_fd = open_image(CR_FD_MNTS, O_DUMP, ns_id);
+ if (img_fd < 0)
+ goto err;
+ for (pm = pms; pm; pm = pm->next)
if (dump_one_mountpoint(pm, img_fd))
goto err;
- pm = n;
- } while (pm);
-
ret = 0;
err:
close(img_fd);
@@ -1777,6 +1793,36 @@ set_root:
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)
{
struct ns_id *ns;
@@ -1784,8 +1830,12 @@ int dump_mnt_namespaces(void)
for (ns = ns_ids; ns; ns = ns->next) {
/* 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;
+ }
if (!(ns->nd->cflag & CLONE_NEWNS))
continue;
--
1.8.5.3
More information about the CRIU
mailing list