[08/18] fdinfo: Extract FdinfoEntry from dump_one_file

Submitted by Pavel Emelyanov on July 10, 2017, 9:39 a.m.

Details

Message ID b60af1fe-be11-e2ac-f5e0-a193d3656f7a@virtuozzo.com
State Accepted
Series "Support descriptors sent over unix sockets"
Headers show

Commit Message

Pavel Emelyanov July 10, 2017, 9:39 a.m.
To support SCMs we'll need to receive them into criu task
(see the SCM patch for details), then dump the received
file as if it was in the dumpee. Then the info about received
descriptor will be written into packet entry.

For this we'll need to perform all the regular file dumping
 code BUT not write the FdinfoEntry into image, so shuffle
the code for that.

The gist of the patch is in two changes -- one in the
do_dump_gen_file(), the other in dump_task_files_seized().
The rest is just tossing the arguments of the functions
relevant to that change.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/files-ext.c       |  4 ++--
 criu/files.c           | 57 +++++++++++++++++++++++++-------------------------
 criu/include/files.h   |  4 ++--
 criu/include/sockets.h |  3 ++-
 criu/sockets.c         |  4 ++--
 5 files changed, 36 insertions(+), 36 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/files-ext.c b/criu/files-ext.c
index af9c268..a6247d6 100644
--- a/criu/files-ext.c
+++ b/criu/files-ext.c
@@ -84,11 +84,11 @@  struct collect_image_info ext_file_cinfo = {
 };
 
 int dump_unsupp_fd(struct fd_parms *p, int lfd,
-			  struct cr_img *img, char *more, char *info)
+		char *more, char *info, FdinfoEntry *e)
 {
 	int ret;
 
-	ret = do_dump_gen_file(p, lfd, &ext_dump_ops, img);
+	ret = do_dump_gen_file(p, lfd, &ext_dump_ops, e);
 	if (ret == 0)
 		return 0;
 	if (ret == -ENOTSUP)
diff --git a/criu/files.c b/criu/files.c
index 36bb9e6..affdac0 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -290,27 +290,20 @@  static u32 make_gen_id(const struct fd_parms *p)
 }
 
 int do_dump_gen_file(struct fd_parms *p, int lfd,
-		const struct fdtype_ops *ops, struct cr_img *img)
+		const struct fdtype_ops *ops, FdinfoEntry *e)
 {
-	FdinfoEntry e = FDINFO_ENTRY__INIT;
 	int ret = -1;
 
-	e.type	= ops->type;
-	e.id	= make_gen_id(p);
-	e.fd	= p->fd;
-	e.flags = p->fd_flags;
+	e->type	= ops->type;
+	e->id	= make_gen_id(p);
+	e->fd	= p->fd;
+	e->flags = p->fd_flags;
 
-	ret = fd_id_generate(p->pid, &e, p);
+	ret = fd_id_generate(p->pid, e, p);
 	if (ret == 1) /* new ID generated */
-		ret = ops->dump(lfd, e.id, p);
+		ret = ops->dump(lfd, e->id, p);
 
-	if (ret < 0)
-		return ret;
-
-	pr_info("fdinfo: type: %#2x flags: %#o/%#o pos: %#8"PRIx64" fd: %d\n",
-		ops->type, p->flags, (int)p->fd_flags, p->pos, p->fd);
-
-	return pb_write_one(img, &e, PB_FDINFO);
+	return ret;
 }
 
 int fill_fdlink(int lfd, const struct fd_parms *p, struct fd_link *link)
@@ -419,7 +412,7 @@  static const struct fdtype_ops *get_mem_dev_ops(struct fd_parms *p, int minor)
 	return ops;
 }
 
-static int dump_chrdev(struct fd_parms *p, int lfd, struct cr_img *img)
+static int dump_chrdev(struct fd_parms *p, int lfd, FdinfoEntry *e)
 {
 	int maj = major(p->stat.st_rdev);
 	const struct fdtype_ops *ops;
@@ -447,15 +440,15 @@  static int dump_chrdev(struct fd_parms *p, int lfd, struct cr_img *img)
 		}
 
 		sprintf(more, "%d:%d", maj, minor(p->stat.st_rdev));
-		return dump_unsupp_fd(p, lfd, img, "chr", more);
+		return dump_unsupp_fd(p, lfd, "chr", more, e);
 	}
 	}
 
-	return do_dump_gen_file(p, lfd, ops, img);
+	return do_dump_gen_file(p, lfd, ops, e);
 }
 
 static int dump_one_file(struct pid *pid, int fd, int lfd, struct fd_opts *opts,
-		       struct cr_img *img, struct parasite_ctl *ctl)
+		struct parasite_ctl *ctl, FdinfoEntry *e)
 {
 	struct fd_parms p = FD_PARMS_INIT;
 	const struct fdtype_ops *ops;
@@ -472,10 +465,10 @@  static int dump_one_file(struct pid *pid, int fd, int lfd, struct fd_opts *opts,
 	p.fd_ctl = ctl; /* Some dump_opts require this to talk to parasite */
 
 	if (S_ISSOCK(p.stat.st_mode))
-		return dump_socket(&p, lfd, img);
+		return dump_socket(&p, lfd, e);
 
 	if (S_ISCHR(p.stat.st_mode))
-		return dump_chrdev(&p, lfd, img);
+		return dump_chrdev(&p, lfd, e);
 
 	if (p.fs_type == ANON_INODE_FS_MAGIC) {
 		char link[32];
@@ -496,9 +489,9 @@  static int dump_one_file(struct pid *pid, int fd, int lfd, struct fd_opts *opts,
 		else if (is_timerfd_link(link))
 			ops = &timerfd_dump_ops;
 		else
-			return dump_unsupp_fd(&p, lfd, img, "anon", link);
+			return dump_unsupp_fd(&p, lfd, "anon", link, e);
 
-		return do_dump_gen_file(&p, lfd, ops, img);
+		return do_dump_gen_file(&p, lfd, ops, e);
 	}
 
 	if (S_ISREG(p.stat.st_mode) || S_ISDIR(p.stat.st_mode)) {
@@ -507,12 +500,12 @@  static int dump_one_file(struct pid *pid, int fd, int lfd, struct fd_opts *opts,
 
 		p.link = &link;
 		if (link.name[1] == '/')
-			return do_dump_gen_file(&p, lfd, &regfile_dump_ops, img);
+			return do_dump_gen_file(&p, lfd, &regfile_dump_ops, e);
 
 		if (check_ns_proc(&link))
-			return do_dump_gen_file(&p, lfd, &nsfile_dump_ops, img);
+			return do_dump_gen_file(&p, lfd, &nsfile_dump_ops, e);
 
-		return dump_unsupp_fd(&p, lfd, img, "reg", link.name + 1);
+		return dump_unsupp_fd(&p, lfd, "reg", link.name + 1, e);
 	}
 
 	if (S_ISFIFO(p.stat.st_mode)) {
@@ -521,7 +514,7 @@  static int dump_one_file(struct pid *pid, int fd, int lfd, struct fd_opts *opts,
 		else
 			ops = &fifo_dump_ops;
 
-		return do_dump_gen_file(&p, lfd, ops, img);
+		return do_dump_gen_file(&p, lfd, ops, e);
 	}
 
 	/*
@@ -532,7 +525,7 @@  static int dump_one_file(struct pid *pid, int fd, int lfd, struct fd_opts *opts,
 	if (fill_fdlink(lfd, &p, &link))
 		memzero(&link, sizeof(link));
 
-	return dump_unsupp_fd(&p, lfd, img, "unknown", link.name + 1);
+	return dump_unsupp_fd(&p, lfd, "unknown", link.name + 1, e);
 }
 
 int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item,
@@ -571,11 +564,17 @@  int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item,
 			goto err;
 
 		for (i = 0; i < nr_fds; i++) {
+			FdinfoEntry e = FDINFO_ENTRY__INIT;
+
 			ret = dump_one_file(item->pid, dfds->fds[i + off],
-						lfds[i], opts + i, img, ctl);
+						lfds[i], opts + i, ctl, &e);
 			close(lfds[i]);
 			if (ret)
 				break;
+
+			ret = pb_write_one(img, &e, PB_FDINFO);
+			if (ret)
+				break;
 		}
 	}
 
diff --git a/criu/include/files.h b/criu/include/files.h
index 22d5bc8..a96b744 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -133,7 +133,7 @@  struct cr_img;
 
 extern int do_dump_gen_file(struct fd_parms *p, int lfd,
 			    const struct fdtype_ops *ops,
-			    struct cr_img *);
+			    FdinfoEntry *e);
 struct parasite_drain_fd;
 int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item,
 		struct parasite_drain_fd *dfds);
@@ -174,7 +174,7 @@  extern int shared_fdt_prepare(struct pstree_item *item);
 
 extern struct collect_image_info ext_file_cinfo;
 extern int dump_unsupp_fd(struct fd_parms *p, int lfd,
-			  struct cr_img *, char *more, char *info);
+		char *more, char *info, FdinfoEntry *);
 
 extern int inherit_fd_parse(char *optarg);
 extern int inherit_fd_add(int fd, char *key);
diff --git a/criu/include/sockets.h b/criu/include/sockets.h
index 9881d5b..3fa8017 100644
--- a/criu/include/sockets.h
+++ b/criu/include/sockets.h
@@ -5,6 +5,7 @@ 
 #include <sys/socket.h>
 
 #include "images/sk-opts.pb-c.h"
+#include "images/fdinfo.pb-c.h"
 
 struct fdinfo_list_entry;
 struct sk_opts_entry;
@@ -22,7 +23,7 @@  struct socket_desc {
 	int			already_dumped;
 };
 
-extern int dump_socket(struct fd_parms *p, int lfd, struct cr_img *);
+extern int dump_socket(struct fd_parms *p, int lfd, FdinfoEntry *);
 extern int dump_socket_opts(int sk, SkOptsEntry *soe);
 extern int restore_socket_opts(int sk, SkOptsEntry *soe);
 extern void release_skopts(SkOptsEntry *);
diff --git a/criu/sockets.c b/criu/sockets.c
index 9b0c4df..852663e 100644
--- a/criu/sockets.c
+++ b/criu/sockets.c
@@ -557,7 +557,7 @@  void release_skopts(SkOptsEntry *soe)
 	xfree(soe->so_bound_dev);
 }
 
-int dump_socket(struct fd_parms *p, int lfd, struct cr_img *img)
+int dump_socket(struct fd_parms *p, int lfd, FdinfoEntry *e)
 {
 	int family;
 	const struct fdtype_ops *ops;
@@ -586,7 +586,7 @@  int dump_socket(struct fd_parms *p, int lfd, struct cr_img *img)
 		return -1;
 	}
 
-	return do_dump_gen_file(p, lfd, ops, img);
+	return do_dump_gen_file(p, lfd, ops, e);
 }
 
 static int inet_receive_one(struct nlmsghdr *h, struct ns_id *ns, void *arg)