[CRIU] [PATCH] files: don't create a transport socket for each file

Andrey Vagin avagin at openvz.org
Thu Jul 28 18:49:29 PDT 2016


From: Andrew Vagin <avagin at virtuozzo.com>

This is an unix dgram socket which doesn't have an address and
isn't connected to somewhere, so we can use one socket for all processes.

Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 criu/cr-restore.c        |  5 +++++
 criu/files.c             | 25 +++++++++++++++++++------
 criu/include/files.h     |  2 ++
 criu/include/servicefd.h |  1 +
 4 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 9bd1747..10d5f14 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -272,6 +272,9 @@ static int root_prepare_shared(void)
 		goto err;
 
 	show_saved_files();
+
+	if (open_transport_socket())
+		goto err;
 err:
 	return ret;
 }
@@ -711,6 +714,8 @@ static int restore_one_alive_task(int pid, CoreEntry *core)
 	if (prepare_vmas(current, ta))
 		return -1;
 
+	close_service_fd(TRANSPORT_FD_OFF);
+
 	if (setup_uffd(pid, ta))
 		return -1;
 
diff --git a/criu/files.c b/criu/files.c
index a66a142..a29d317 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -1000,11 +1000,7 @@ static int serve_out_fd(int pid, int fd, struct file_desc *d)
 	int sock, ret;
 	struct fdinfo_list_entry *fle;
 
-	sock = socket(PF_UNIX, SOCK_DGRAM, 0);
-	if (sock < 0) {
-		pr_perror("Can't create socket");
-		return -1;
-	}
+	sock = get_service_fd(TRANSPORT_FD_OFF);
 
 	pr_info("\t\tCreate fd for %d\n", fd);
 
@@ -1022,7 +1018,6 @@ static int serve_out_fd(int pid, int fd, struct file_desc *d)
 
 	ret = 0;
 out:
-	close(sock);
 	return ret;
 }
 
@@ -1672,3 +1667,21 @@ char *external_lookup_by_key(char *key)
 	}
 	return NULL;
 }
+
+int open_transport_socket()
+{
+	int sock;
+
+	sock = socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sock < 0) {
+		pr_perror("Can't create socket");
+		return -1;
+	}
+	if (install_service_fd(TRANSPORT_FD_OFF, sock) < 0) {
+		close(sock);
+		return -1;
+	}
+	close(sock);
+
+	return 0;
+}
diff --git a/criu/include/files.h b/criu/include/files.h
index e0b853d..7513b21 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -201,4 +201,6 @@ extern FdinfoEntry *dup_fdinfo(FdinfoEntry *old, int fd, unsigned flags);
 int dup_fle(struct pstree_item *task, struct fdinfo_list_entry *ple,
 	    int fd, unsigned flags);
 
+extern int open_transport_socket(void);
+
 #endif /* __CR_FILES_H__ */
diff --git a/criu/include/servicefd.h b/criu/include/servicefd.h
index e133752..a35f25a 100644
--- a/criu/include/servicefd.h
+++ b/criu/include/servicefd.h
@@ -19,6 +19,7 @@ enum sfd_type {
 	CGROUP_YARD,
 	USERNSD_SK,	/* Socket for usernsd */
 	NS_FD_OFF,	/* Node's net namespace fd */
+	TRANSPORT_FD_OFF, /* to transfer file descriptors */
 
 	SERVICE_FD_MAX
 };
-- 
2.7.4



More information about the CRIU mailing list