[CRIU] [PATCH 1/2] pass "bool for_dump" argument down to collect_mntinfo() and parse_mountinfo()

Oleg Nesterov oleg at redhat.com
Tue Mar 31 09:24:14 PDT 2015


Preparation.

1. Add the new "bool for_dump" arg to collect/parse_mntinfo().

2. Introduce "struct collect_mntns_arg" to pass the additional
   "bool for_dump" field to collect_mntinfo() and change it to
   pass this boolean to collect_mntinfo()->parse_mountinfo() path.

3. Change other callers of collect_mntinfo() to pass "false".
---
 cr-check.c           |    2 +-
 include/mount.h      |    2 +-
 include/proc_parse.h |    2 +-
 mount.c              |   32 +++++++++++++++++++++-----------
 proc_parse.c         |    2 +-
 5 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/cr-check.c b/cr-check.c
index badfefc..3518773 100644
--- a/cr-check.c
+++ b/cr-check.c
@@ -692,7 +692,7 @@ int cr_check(void)
 
 	ns.id = root_item->ids->mnt_ns_id;
 
-	mntinfo = collect_mntinfo(&ns);
+	mntinfo = collect_mntinfo(&ns, false);
 	if (mntinfo == NULL)
 		return -1;
 
diff --git a/include/mount.h b/include/mount.h
index a582d25..d2152ff 100644
--- a/include/mount.h
+++ b/include/mount.h
@@ -16,7 +16,7 @@ extern struct fstype *find_fstype_by_name(char *fst);
 extern int add_fstype_auto(const char *names);
 
 struct cr_imgset;
-extern struct mount_info * collect_mntinfo(struct ns_id *ns);
+extern struct mount_info * collect_mntinfo(struct ns_id *ns, bool for_dump);
 extern int prepare_mnt_ns(void);
 
 extern int pivot_root(const char *new_root, const char *put_old);
diff --git a/include/proc_parse.h b/include/proc_parse.h
index 792cf06..4c9ec4e 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -153,7 +153,7 @@ extern void mnt_entry_free(struct mount_info *mi);
 
 struct vm_area_list;
 
-extern struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid);
+extern struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid, bool for_dump);
 extern int parse_pid_stat(pid_t pid, struct proc_pid_stat *s);
 extern int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list);
 extern int parse_self_maps_lite(struct vm_area_list *vms);
diff --git a/mount.c b/mount.c
index 99df27a..42ffd7a 100644
--- a/mount.c
+++ b/mount.c
@@ -1246,11 +1246,11 @@ static void free_mntinfo(struct mount_info *pms)
 	}
 }
 
-struct mount_info *collect_mntinfo(struct ns_id *ns)
+struct mount_info *collect_mntinfo(struct ns_id *ns, bool for_dump)
 {
 	struct mount_info *pm;
 
-	ns->mnt.mntinfo_list = pm = parse_mountinfo(ns->pid, ns);
+	ns->mnt.mntinfo_list = pm = parse_mountinfo(ns->pid, ns, for_dump);
 	if (!pm) {
 		pr_err("Can't parse %d's mountinfo\n", ns->pid);
 		return NULL;
@@ -1871,7 +1871,7 @@ static int rst_collect_local_mntns(void)
 	if (!nsid)
 		return -1;
 
-	mntinfo = collect_mntinfo(nsid);
+	mntinfo = collect_mntinfo(nsid, false);
 	if (!mntinfo)
 		return -1;
 
@@ -2212,7 +2212,7 @@ int prepare_mnt_ns(void)
 
 	pr_info("Restoring mount namespace\n");
 
-	old = collect_mntinfo(&ns);
+	old = collect_mntinfo(&ns, false);
 	if (old == NULL)
 		return -1;
 
@@ -2386,16 +2386,22 @@ int mntns_get_root_by_mnt_id(int mnt_id)
 	return mntns_get_root_fd(mntns);
 }
 
-static int collect_mntns(struct ns_id *ns, void *oarg)
+struct collect_mntns_arg {
+	bool need_to_validate;
+	bool for_dump;
+};
+
+static int collect_mntns(struct ns_id *ns, void *__arg)
 {
+	struct collect_mntns_arg *arg = __arg;
 	struct mount_info *pms;
 
-	pms = collect_mntinfo(ns);
+	pms = collect_mntinfo(ns, arg->for_dump);
 	if (!pms)
 		return -1;
 
-	if (ns->pid != getpid())
-		*(int *)oarg = 1;
+	if (arg->for_dump && ns->pid != getpid())
+		arg->need_to_validate = true;
 
 	mntinfo_add_list(pms);
 	return 0;
@@ -2403,13 +2409,17 @@ static int collect_mntns(struct ns_id *ns, void *oarg)
 
 int collect_mnt_namespaces(bool for_dump)
 {
-	int need_to_validate = 0, ret;
+	struct collect_mntns_arg arg;
+	int ret;
+
+	arg.for_dump = for_dump;
+	arg.need_to_validate = false;
 
-	ret = walk_namespaces(&mnt_ns_desc, collect_mntns, &need_to_validate);
+	ret = walk_namespaces(&mnt_ns_desc, collect_mntns, &arg);
 	if (ret)
 		goto err;
 
-	if (for_dump && need_to_validate) {
+	if (arg.need_to_validate) {
 		ret = -1;
 
 		if (collect_shared(mntinfo))
diff --git a/proc_parse.c b/proc_parse.c
index 1a46ffd..d361fff 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -975,7 +975,7 @@ err:
 	goto ret;
 }
 
-struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid)
+struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid, bool for_dump)
 {
 	struct mount_info *list = NULL;
 	FILE *f;
-- 
1.5.5.1



More information about the CRIU mailing list