[CRIU] [PATCH 14/28] rst: old shared files exchange routines removed

Kinsbursky Stanislav skinsbursky at openvz.org
Thu Mar 22 13:59:05 EDT 2012


From: Stanislav Kinsbursky <skinsbursky at openvz.org>

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
 cr-restore.c    |    3 -
 files.c         |  245 -------------------------------------------------------
 include/files.h |    1 
 3 files changed, 0 insertions(+), 249 deletions(-)
-------------- next part --------------
diff --git a/cr-restore.c b/cr-restore.c
index 7d0fa04..95ca897 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -460,9 +460,6 @@ static int prepare_shared(int ps_fd)
 	if (ret < 0)
 		return ret;
 
-	if (prepare_shared_fdinfo())
-		return -1;
-
 	while (1) {
 		struct pstree_entry e;
 
diff --git a/files.c b/files.c
index 2b4872e..6bdc518 100644
--- a/files.c
+++ b/files.c
@@ -21,44 +21,8 @@
 #include "lock.h"
 #include "file-ids.h"
 
-static struct fdinfo_desc *fdinfo_descs;
-static int nr_fdinfo_descs;
-
-static struct fdinfo_list_entry *fdinfo_list;
-static int nr_fdinfo_list;
-
 static struct fmap_fd *fmap_fds;
 
-int prepare_shared_fdinfo(void)
-{
-	fdinfo_descs = xmalloc_shm(4096);
-	if (fdinfo_descs == NULL) {
-		pr_perror("Can't alloc fdinfo_descs");
-		return -1;
-	}
-
-	fdinfo_list = xmalloc_shm(4096);
-	if (fdinfo_list == NULL) {
-		pr_perror("Can't alloc fdinfo_list");
-		return -1;
-	}
-	return 0;
-}
-
-static struct fdinfo_desc *find_fd(u64 id)
-{
-	struct fdinfo_desc *fi;
-	int i;
-
-	for (i = 0; i < nr_fdinfo_descs; i++) {
-		fi = fdinfo_descs + i;
-		if (fi->id == id)
-			return fi;
-	}
-
-	return NULL;
-}
-
 struct file_recipient {
 	struct list_head	list;
 	int			pid;
@@ -108,63 +72,6 @@ static int collect_fd_pid(int pid, struct fd_entry *fde)
 	return 0;
 }
 
-static int collect_fd(int pid, struct fdinfo_entry *e)
-{
-	int i;
-	struct fdinfo_list_entry *le = &fdinfo_list[nr_fdinfo_list];
-	struct fdinfo_desc *desc;
-
-	pr_info("Collect fdinfo pid=%d fd=%ld id=%16lx\n",
-		pid, e->addr, e->fde.id);
-
-	nr_fdinfo_list++;
-	if ((nr_fdinfo_list) * sizeof(struct fdinfo_list_entry) >= 4096) {
-		pr_err("OOM storing fdinfo_list_entries\n");
-		return -1;
-	}
-
-	le->pid = pid;
-	le->fd = e->addr;
-	le->real_pid = 0;
-
-	for (i = 0; i < nr_fdinfo_descs; i++) {
-		desc = &fdinfo_descs[i];
-
-		if (desc->id != e->fde.id)
-			continue;
-
-		fdinfo_descs[i].users++;
-		list_add(&le->list, &desc->list);
-
-		if (fdinfo_descs[i].pid < pid)
-			return 0;
-
-		desc->pid = pid;
-		desc->addr = e->addr;
-
-		return 0;
-	}
-
-	if ((nr_fdinfo_descs + 1) * sizeof(struct fdinfo_desc) >= 4096) {
-		pr_err("OOM storing fdinfo descriptions\n");
-		return -1;
-	}
-
-	desc = &fdinfo_descs[nr_fdinfo_descs];
-	memzero(desc, sizeof(*desc));
-
-	desc->id	= e->fde.id;
-	desc->addr	= e->fde.fd;
-	desc->pid	= pid;
-	desc->users	= 1;
-	INIT_LIST_HEAD(&desc->list);
-
-	list_add(&le->list, &desc->list);
-	nr_fdinfo_descs++;
-
-	return 0;
-}
-
 static struct file_recipient *get_fd_recipient(struct file_info *fi,
 					       int pid, int fd)
 {
@@ -337,66 +244,6 @@ static int receive_shared_fd(int pid, struct file_info *fi, struct fd_entry *fde
 	return reopen_fd_as(fde->fd, real_fd);
 }
 
-struct fdinfo_list_entry *find_fdinfo_list_entry(int pid, int fd, struct fdinfo_desc *fi)
-{
-	struct fdinfo_list_entry *fle;
-	int found = 0;
-
-	list_for_each_entry(fle, &fi->list, list) {
-		if (fle->fd == fd && fle->pid == pid) {
-			found = 1;
-			break;
-		}
-	}
-
-	BUG_ON(found == 0);
-	return fle;
-}
-
-static int open_transport_fd(int pid, struct fdinfo_entry *fe,
-				struct fdinfo_desc *fi)
-{
-	struct fdinfo_list_entry *fle;
-	struct sockaddr_un saddr;
-	int sock;
-	int ret, sun_len;
-
-	if (fi->pid == pid)
-		return 0;
-
-	saddr.sun_family = AF_UNIX;
-	snprintf(saddr.sun_path, UNIX_PATH_MAX,
-			"X/crtools-fd-%d-%ld", getpid(), fe->addr);
-
-	sun_len = SUN_LEN(&saddr);
-	*saddr.sun_path = '\0';
-
-	pr_info("\t%d: Create transport fd for %lx type %d namelen %d users %d\n", pid,
-			(unsigned long)fe->addr, fe->fde.type, fe->len, fi->users);
-
-	fle = find_fdinfo_list_entry(pid, fe->addr, fi);
-
-	sock = socket(PF_UNIX, SOCK_DGRAM, 0);
-	if (sock < 0) {
-		pr_perror("Can't create socket");
-		return -1;
-	}
-	ret = bind(sock, &saddr, sun_len);
-	if (ret < 0) {
-		pr_perror("Can't bind unix socket %s", saddr.sun_path + 1);
-		return -1;
-	}
-
-	ret = reopen_fd_as((int)fe->addr, sock);
-	if (ret < 0)
-		return -1;
-
-	pr_info("Wake up fdinfo pid=%d fd=%d\n", fle->pid, fle->fd);
-	cr_wait_set(&fle->real_pid, getpid());
-
-	return 0;
-}
-
 static int open_transport(int pid, int fd, struct file_info *fi)
 {
 	struct file_recipient *recipient;
@@ -530,98 +377,6 @@ static int open_fd_transport(int pid, struct file_info *fi, struct fd_entry *fde
 	return open_transport(pid, fde->fd, fi);
 }
 
-static int open_fd(int pid, struct fdinfo_entry *fe,
-				struct fdinfo_desc *fi, int fdinfo_fd)
-{
-	int tmp;
-	int serv, sock;
-	struct sockaddr_un saddr;
-	struct fdinfo_list_entry *fle;
-
-	if ((fi->pid != pid) || (fe->addr != fi->addr))
-		return 0;
-
-	tmp = open_fe_fd(fe, fdinfo_fd);
-	if (tmp < 0)
-		return -1;
-
-	if (reopen_fd_as((int)fe->addr, tmp))
-		return -1;
-
-	if (fi->users == 1)
-		goto out;
-
-	sock = socket(PF_UNIX, SOCK_DGRAM, 0);
-	if (sock < 0) {
-		pr_perror("Can't create socket");
-		return -1;
-	}
-
-	cr_wait_set(&fi->real_pid, getpid());
-
-	pr_info("\t%d: Create fd for %lx type %d namelen %d users %d\n", pid,
-			(unsigned long)fe->addr, fe->fde.type, fe->len, fi->users);
-
-	list_for_each_entry(fle, &fi->list, list) {
-		int len;
-
-		fi->users--;
-
-		if (pid == fle->pid)
-			continue;
-
-		pr_info("Wait fdinfo pid=%d fd=%d\n", fle->pid, fle->fd);
-		cr_wait_while(&fle->real_pid, 0);
-
-		pr_info("Send fd %d to %s\n", (int)fe->addr, saddr.sun_path + 1);
-
-		saddr.sun_family = AF_UNIX;
-		snprintf(saddr.sun_path, UNIX_PATH_MAX,
-				"X/crtools-fd-%d-%d", fle->real_pid, fle->fd);
-		len = SUN_LEN(&saddr);
-		*saddr.sun_path = '\0';
-
-		if (send_fd(sock, &saddr, len, fe->addr) < 0) {
-			pr_perror("Can't send file descriptor");
-			return -1;
-		}
-	}
-
-	BUG_ON(fi->users);
-	close(sock);
-out:
-	return 0;
-}
-
-static int receive_fd(int pid, struct fdinfo_entry *fe, struct fdinfo_desc *fi)
-{
-	int tmp;
-
-	if (fi->pid == pid) {
-		if (fi->addr != fe->addr) {
-			tmp = dup2(fi->addr, fe->addr);
-			if (tmp < 0) {
-				pr_perror("Can't duplicate fd %ld %ld",
-						fi->addr, fe->addr);
-				return -1;
-			}
-		}
-		return 0;
-	}
-
-	pr_info("\t%d: Receive fd for %lx type %d namelen %d users %d\n", pid,
-			(unsigned long)fe->addr, fe->fde.type, fe->len, fi->users);
-
-	tmp = recv_fd(fe->addr);
-	if (tmp < 0) {
-		pr_err("Can't get fd %d\n", tmp);
-		return -1;
-	}
-	close(fe->addr);
-
-	return reopen_fd_as((int)fe->addr, tmp);
-}
-
 static int open_fmap(int pid, struct fdinfo_entry *fe, int fd)
 {
 	struct fmap_fd *new;
diff --git a/include/files.h b/include/files.h
index 1d560ad..9d4e297 100644
--- a/include/files.h
+++ b/include/files.h
@@ -40,7 +40,6 @@ struct fdinfo_list_entry {
 extern int prepare_fds(int pid);
 extern int prepare_fd_pid(int pid);
 extern int prepare_files(void);
-extern int prepare_shared_fdinfo(void);
 extern int get_filemap_fd(int pid, struct vma_entry *vma_entry);
 
 #endif /* FILES_H_ */


More information about the CRIU mailing list