[CRIU] [PATCH RFC 03/30] files: Wait transport_fd before sending a fd to peer

Kirill Tkhai ktkhai at virtuozzo.com
Tue Nov 1 07:30:49 PDT 2016


Now it's excess, because we already wait per-fd transport
sockets. But this will be used in next patches.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/files.c          |    2 ++
 criu/include/pstree.h |    7 +++++++
 criu/pstree.c         |    1 +
 3 files changed, 10 insertions(+)

diff --git a/criu/files.c b/criu/files.c
index e869614..97b4e95 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -964,6 +964,7 @@ int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle, int sock)
 
 	pr_info("\t\tWait fdinfo pid=%d fd=%d\n", fle->pid, fle->fe->fd);
 	futex_wait_while(&fle->real_pid, 0);
+	futex_wait_while(&pstree_item_by_virt(fle->pid)->task_st, TSK_ALLOCATED);
 	transport_name_gen(&saddr, &len,
 			futex_get(&fle->real_pid), fle->fe->fd);
 	pr_info("\t\tSend fd %d to %s\n", fd, saddr.sun_path + 1);
@@ -1691,6 +1692,7 @@ static int open_transport_socket(pid_t pid)
 		return -1;
 	}
 	close(sock);
+	futex_set_and_wake(&current->task_st, TFD_INSTALLED);
 
 	return 0;
 }
diff --git a/criu/include/pstree.h b/criu/include/pstree.h
index 5768b64..b3547ca 100644
--- a/criu/include/pstree.h
+++ b/criu/include/pstree.h
@@ -4,6 +4,7 @@
 #include "common/list.h"
 #include "pid.h"
 #include "images/core.pb-c.h"
+#include "lock.h"
 
 /*
  * That's the init process which usually inherit
@@ -24,6 +25,12 @@ struct pstree_item {
 	struct pid		*threads;	/* array of threads */
 	CoreEntry		**core;
 	TaskKobjIdsEntry	*ids;
+	futex_t			task_st;
+};
+
+enum {
+	TSK_ALLOCATED = 0,
+	TFD_INSTALLED = 1 << 0,
 };
 
 struct pstree_item *current;
diff --git a/criu/pstree.c b/criu/pstree.c
index ec1f7ee..ed7e999 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -216,6 +216,7 @@ struct pstree_item *__alloc_pstree_item(bool rst)
 	item->pid.virt = -1;
 	item->pid.real = -1;
 	item->born_sid = -1;
+	futex_init(&item->task_st);
 
 	return item;
 }



More information about the CRIU mailing list