diff --git a/criu/cr-restore.c b/criu/cr-restore.c index 9db73ff7a..da21a4dc0 100644 --- a/criu/cr-restore.c +++ b/criu/cr-restore.c @@ -180,6 +180,8 @@ static struct collect_image_info *cinfos[] = { &ext_file_cinfo, &timerfd_cinfo, &file_locks_cinfo, + &pipe_data_cinfo, + &fifo_data_cinfo, &sk_queues_cinfo, }; @@ -241,11 +243,6 @@ static int root_prepare_shared(void) return -1; } - if (collect_pipes()) - return -1; - if (collect_fifo()) - return -1; - if (tty_verify_active_pairs()) return -1; diff --git a/criu/fifo.c b/criu/fifo.c index 9da5a27a4..68f55b4e5 100644 --- a/criu/fifo.c +++ b/criu/fifo.c @@ -162,7 +162,14 @@ struct collect_image_info fifo_cinfo = { .collect = collect_one_fifo, }; -int collect_fifo(void) +static int collect_fifo_data(void *obj, ProtobufCMessage *msg, struct cr_img *img) { - return collect_pipe_data(CR_FD_FIFO_DATA, pd_hash_fifo); + return do_collect_pipe_data(obj, msg, img, pd_hash_fifo); } + +struct collect_image_info fifo_data_cinfo = { + .fd_type = CR_FD_FIFO_DATA, + .pb_type = PB_PIPE_DATA, + .priv_size = sizeof(struct pipe_data_rst), + .collect = collect_fifo_data, +}; diff --git a/criu/include/fifo.h b/criu/include/fifo.h index 776265450..9560a7ba6 100644 --- a/criu/include/fifo.h +++ b/criu/include/fifo.h @@ -6,6 +6,6 @@ struct cr_imgset; extern const struct fdtype_ops fifo_dump_ops; extern struct collect_image_info fifo_cinfo; -extern int collect_fifo(void); +extern struct collect_image_info fifo_data_cinfo; #endif /* __CR_FIFO_H__ */ diff --git a/criu/include/pipes.h b/criu/include/pipes.h index 2cdb7a90d..98e1c0eb1 100644 --- a/criu/include/pipes.h +++ b/criu/include/pipes.h @@ -5,7 +5,7 @@ #include "images/pipe.pb-c.h" extern struct collect_image_info pipe_cinfo; -extern int collect_pipes(void); +extern struct collect_image_info pipe_data_cinfo; extern const struct fdtype_ops pipe_dump_ops; static inline u32 pipe_id(const struct fd_parms *p) @@ -33,7 +33,8 @@ struct pipe_data_rst { #define PIPE_DATA_HASH_SIZE (1 << PIPE_DATA_HASH_BITS) #define PIPE_DATA_HASH_MASK (PIPE_DATA_HASH_SIZE - 1) -extern int collect_pipe_data(int img_type, struct pipe_data_rst **hash); +extern int do_collect_pipe_data(struct pipe_data_rst *, + ProtobufCMessage *, struct cr_img *, struct pipe_data_rst **hash); extern int restore_pipe_data(int img_type, int pfd, u32 id, struct pipe_data_rst **hash); /* diff --git a/criu/pipes.c b/criu/pipes.c index 2f08c5655..1c395431a 100644 --- a/criu/pipes.c +++ b/criu/pipes.c @@ -53,44 +53,22 @@ static int pipe_data_read(struct cr_img *img, struct pipe_data_rst *r) return read_img_buf(img, r->data, bytes); } -int collect_pipe_data(int img_type, struct pipe_data_rst **hash) +int do_collect_pipe_data(struct pipe_data_rst *r, ProtobufCMessage *msg, + struct cr_img *img, struct pipe_data_rst **hash) { - int ret; - struct cr_img *img; - struct pipe_data_rst *r = NULL; + int aux; - img = open_image(img_type, O_RSTR); - if (!img) - return -1; + r->pde = pb_msg(msg, PipeDataEntry); + aux = pipe_data_read(img, r); + if (aux < 0) + return aux; - while (1) { - ret = -1; - r = xmalloc(sizeof(*r)); - if (!r) - break; - - ret = pb_read_one_eof(img, &r->pde, PB_PIPE_DATA); - if (ret <= 0) - break; - - ret = pipe_data_read(img, r); - if (ret < 0) - break; - - ret = r->pde->pipe_id & PIPE_DATA_HASH_MASK; - r->next = hash[ret]; - hash[ret] = r; - - pr_info("Collected pipe data for %#x (chain %u)\n", - r->pde->pipe_id, ret); - } - - if (r && r->pde) - pipe_data_entry__free_unpacked(r->pde, NULL); - xfree(r); - - close_image(img); - return ret; + aux = r->pde->pipe_id & PIPE_DATA_HASH_MASK; + r->next = hash[aux]; + hash[aux] = r; + pr_info("Collected pipe data for %#x (chain %u)\n", + r->pde->pipe_id, aux); + return 0; } /* Choose who will restore a pipe. */ @@ -412,11 +390,18 @@ struct collect_image_info pipe_cinfo = { .collect = collect_one_pipe, }; -int collect_pipes(void) +static int collect_pipe_data(void *obj, ProtobufCMessage *msg, struct cr_img *img) { - return collect_pipe_data(CR_FD_PIPES_DATA, pd_hash_pipes); + return do_collect_pipe_data(obj, msg, img, pd_hash_pipes); } +struct collect_image_info pipe_data_cinfo = { + .fd_type = CR_FD_PIPES_DATA, + .pb_type = PB_PIPE_DATA, + .priv_size = sizeof(struct pipe_data_rst), + .collect = collect_pipe_data, +}; + int dump_one_pipe_data(struct pipe_data_dump *pd, int lfd, const struct fd_parms *p) { struct cr_img *img;