[CRIU] [PATCH 2/7] pre-dump: Collect mount info, root and nsmask
Pavel Emelyanov
xemul at parallels.com
Thu Jan 30 02:23:41 PST 2014
Well, we want to pre-dump files (fsnotifies), for that we
will need mountinfo-s and root, and for the latter -- the
current ns mask.
The problem with current ns mask is that its generation is
incorporated into ns IDs generation and dumping. And since
the ids dumping is not performed on pre-dump, let's just
provide a helper for ns-mask generation.
Strictly speaking, the whole ns-mask idea is not great, but
it's to be fixed later.
Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
cr-dump.c | 9 +++++++++
include/namespaces.h | 1 +
namespaces.c | 28 ++++++++++++++++++++++++++++
3 files changed, 38 insertions(+)
diff --git a/cr-dump.c b/cr-dump.c
index af5abd1..c0f29b0 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1620,6 +1620,15 @@ int cr_pre_dump_tasks(pid_t pid)
if (collect_pstree(pid))
goto err;
+ if (gen_predump_ns_mask())
+ goto err;
+
+ if (collect_mount_info(pid))
+ goto err;
+
+ if (mntns_collect_root(root_item->pid.real))
+ goto err;
+
for_each_pstree_item(item)
if (pre_dump_one_task(item, &ctls))
goto err;
diff --git a/include/namespaces.h b/include/namespaces.h
index 163de8e..9fb5c06 100644
--- a/include/namespaces.h
+++ b/include/namespaces.h
@@ -33,5 +33,6 @@ extern int switch_ns(int pid, struct ns_desc *nd, int *rst);
extern int restore_ns(int rst, struct ns_desc *nd);
extern int dump_task_ns_ids(struct pstree_item *);
+extern int gen_predump_ns_mask(void);
#endif /* __CR_NS_H__ */
diff --git a/namespaces.c b/namespaces.c
index 5d7f6a2..37e232c 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -353,6 +353,34 @@ int dump_task_ns_ids(struct pstree_item *item)
return 0;
}
+static int gen_ns_ids(int pid)
+{
+ /* needed for mntns_collect_root */
+ if (!get_ns_id(pid, &mnt_ns_desc))
+ return -1;
+ return 0;
+}
+
+/*
+ * We use ns_mask in various places to check whether
+ * the tasks we dump live in namespaces or not. The
+ * mask generation is tied with dumping inventory and
+ * tasks' images, which is not needed for pre-dump.
+ * This routine generates a mask for pre-dump.
+ */
+int gen_predump_ns_mask(void)
+{
+ BUG_ON(current_ns_mask);
+
+ if (gen_ns_ids(getpid()))
+ return -1;
+ if (gen_ns_ids(root_item->pid.real))
+ return -1;
+
+ pr_info("NS mask generated: %lx\n", current_ns_mask);
+ return 0;
+}
+
static int do_dump_namespaces(struct ns_id *ns)
{
int ret = -1;
--
1.8.4.2
More information about the CRIU
mailing list