diff --git a/criu/files-ext.c b/criu/files-ext.c index af9c2681a..a6247d673 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 d5f15fe2b..cf926d02e 100644 --- a/criu/files.c +++ b/criu/files.c @@ -278,27 +278,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) @@ -407,7 +400,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) { struct fd_link *link_old = p->link; int maj = major(p->stat.st_rdev); @@ -436,19 +429,19 @@ static int dump_chrdev(struct fd_parms *p, int lfd, struct cr_img *img) } sprintf(more, "%d:%d", maj, minor(p->stat.st_rdev)); - err = dump_unsupp_fd(p, lfd, img, "chr", more); + err = dump_unsupp_fd(p, lfd, "chr", more, e); p->link = link_old; return err; } } - err = do_dump_gen_file(p, lfd, ops, img); + err = do_dump_gen_file(p, lfd, ops, e); p->link = link_old; return err; } 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; @@ -465,10 +458,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]; @@ -489,9 +482,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)) { @@ -500,12 +493,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, ®file_dump_ops, img); + return do_dump_gen_file(&p, lfd, ®file_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)) { @@ -514,7 +507,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); } /* @@ -525,7 +518,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, @@ -564,11 +557,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 7c8e0153b..2b067623e 100644 --- a/criu/include/files.h +++ b/criu/include/files.h @@ -135,7 +135,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); @@ -175,7 +175,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 798c3b890..c93177f7f 100644 --- a/criu/include/sockets.h +++ b/criu/include/sockets.h @@ -5,6 +5,7 @@ #include #include "images/sk-opts.pb-c.h" +#include "images/fdinfo.pb-c.h" struct fdinfo_list_entry; struct sk_opts_entry; @@ -21,7 +22,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 a783be87a..c2a5cd130 100644 --- a/criu/sockets.c +++ b/criu/sockets.c @@ -552,7 +552,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; @@ -581,7 +581,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, void *arg)