[CRIU] [PATCH 1/5] introduce find_ext_ns_id()

Oleg Nesterov oleg at redhat.com
Tue Apr 14 09:54:03 PDT 2015


Preparation. Extract the "search the criu's mount info" code from
resolve_external_mounts() into the new simple helper, find_ext_ns_id().

Also change resolve_external_mounts() to check ext_ns == NULL rather
than !opts.autodetect_ext_mounts. Cosmetic.

Signed-off-by: Oleg Nesterov <oleg at redhat.com>
---
 mount.c |   34 +++++++++++++++++++++-------------
 1 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/mount.c b/mount.c
index f3ebd1d..9891c53 100644
--- a/mount.c
+++ b/mount.c
@@ -692,21 +692,29 @@ static struct mount_info *find_best_external_match(struct mount_info *list, stru
 	return candidate;
 }
 
-static int resolve_external_mounts(struct mount_info *info)
+static struct ns_id *find_ext_ns_id(void)
 {
-	struct mount_info *m;
-	struct ns_id *ns = NULL, *iter;
+	int pid = getpid();
+	struct ns_id *ns;
 
-	for (iter = ns_ids; iter->next; iter = iter->next) {
-		if (iter->pid == getpid() && iter->nd == &mnt_ns_desc) {
-			ns = iter;
-			break;
+	for (ns = ns_ids; ns->next; ns = ns->next)
+		if (ns->pid == pid && ns->nd == &mnt_ns_desc) {
+			return ns;
 		}
-	}
 
-	if (!ns) {
-		pr_err("Failed to find criu pid's mount ns!");
-		return -1;
+	pr_err("Failed to find criu pid's mount ns!");
+	return NULL;
+}
+
+static int resolve_external_mounts(struct mount_info *info)
+{
+	struct ns_id *ext_ns = NULL;
+	struct mount_info *m;
+
+	if (opts.autodetect_ext_mounts) {
+		ext_ns = find_ext_ns_id();
+		if (!ext_ns)
+			return -1;
 	}
 
 	for (m = info; m; m = m->next) {
@@ -721,13 +729,13 @@ static int resolve_external_mounts(struct mount_info *info)
 		ret = try_resolve_ext_mount(m);
 		if (ret < 0 && ret != -ENOTSUP) {
 			return -1;
-		} else if (ret == -ENOTSUP && !opts.autodetect_ext_mounts) {
+		} else if (ret == -ENOTSUP && !ext_ns) {
 			continue;
 		} else if (ret == 0) {
 			continue;
 		}
 
-		match = find_best_external_match(ns->mnt.mntinfo_list, m);
+		match = find_best_external_match(ext_ns->mnt.mntinfo_list, m);
 		if (!match)
 			continue;
 
-- 
1.5.5.1



More information about the CRIU mailing list