[CRIU] [PATCH 1/6] unix: Run peer resolving via post_cb engine

Pavel Emelyanov xemul at virtuozzo.com
Thu Mar 24 06:00:12 PDT 2016


With autofs patches we've merged a small engine that allows
to queue random routine for post-prepare execution. Re-use
this for unix sockets' interconneting routine.

Also this is a tiny optimization -- when we don't have unix
sockets to interconnect we don't make extra list walk.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/cr-restore.c      |  4 ----
 criu/include/sockets.h |  1 -
 criu/sk-unix.c         | 12 +++++++++++-
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 8abbfbc..467ad07 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -277,10 +277,6 @@ static int root_prepare_shared(void)
 	if (ret)
 		goto err;
 
-	ret = resolve_unix_peers();
-	if (ret)
-		goto err;
-
 	ret = prepare_restorer_blob();
 	if (ret)
 		goto err;
diff --git a/criu/include/sockets.h b/criu/include/sockets.h
index df25179..b566fae 100644
--- a/criu/include/sockets.h
+++ b/criu/include/sockets.h
@@ -40,7 +40,6 @@ extern int collect_inet_sockets(void);
 extern struct collect_image_info unix_sk_cinfo;
 extern int collect_unix_sockets(void);
 extern int fix_external_unix_sockets(void);
-extern int resolve_unix_peers(void);
 
 extern struct collect_image_info netlink_sk_cinfo;
 
diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index a0a848e..9279337 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -28,6 +28,7 @@
 #include "plugin.h"
 #include "namespaces.h"
 #include "pstree.h"
+#include "crtools.h"
 
 #include "protobuf.h"
 #include "images/sk-unix.pb-c.h"
@@ -1281,13 +1282,22 @@ static void unlink_stale(struct unix_sk_info *ui)
 	revert_unix_sk_cwd(&cwd_fd);
 }
 
+static int resolve_unix_peers(void *unused);
+
 static int collect_one_unixsk(void *o, ProtobufCMessage *base)
 {
 	struct unix_sk_info *ui = o;
+	static bool post_queued = false;
 
 	ui->ue = pb_msg(base, UnixSkEntry);
 	ui->name_dir = (void *)ui->ue->name_dir;
 
+	if (ui->ue->peer && !post_queued) {
+		post_queued = true;
+		if (add_post_prepare_cb(resolve_unix_peers, NULL))
+			return -1;
+	}
+
 	if (ui->ue->name.len) {
 		if (ui->ue->name.len > UNIX_PATH_MAX) {
 			pr_err("Bad unix name len %d\n", (int)ui->ue->name.len);
@@ -1325,7 +1335,7 @@ int collect_unix_sockets(void)
 	return read_sk_queues();
 }
 
-int resolve_unix_peers(void)
+static int resolve_unix_peers(void *unused)
 {
 	struct unix_sk_info *ui, *peer;
 	struct fdinfo_list_entry *fle, *fle_peer;
-- 
2.5.0



More information about the CRIU mailing list