Commit 362784f0 authored by Pavel Emelyanov's avatar Pavel Emelyanov

pipe/fifo: Collect data via cinfo engine

Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent f674cbd6
...@@ -180,6 +180,8 @@ static struct collect_image_info *cinfos[] = { ...@@ -180,6 +180,8 @@ static struct collect_image_info *cinfos[] = {
&ext_file_cinfo, &ext_file_cinfo,
&timerfd_cinfo, &timerfd_cinfo,
&file_locks_cinfo, &file_locks_cinfo,
&pipe_data_cinfo,
&fifo_data_cinfo,
&sk_queues_cinfo, &sk_queues_cinfo,
}; };
...@@ -241,11 +243,6 @@ static int root_prepare_shared(void) ...@@ -241,11 +243,6 @@ static int root_prepare_shared(void)
return -1; return -1;
} }
if (collect_pipes())
return -1;
if (collect_fifo())
return -1;
if (tty_verify_active_pairs()) if (tty_verify_active_pairs())
return -1; return -1;
......
...@@ -162,7 +162,14 @@ struct collect_image_info fifo_cinfo = { ...@@ -162,7 +162,14 @@ struct collect_image_info fifo_cinfo = {
.collect = collect_one_fifo, .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,
};
...@@ -6,6 +6,6 @@ struct cr_imgset; ...@@ -6,6 +6,6 @@ struct cr_imgset;
extern const struct fdtype_ops fifo_dump_ops; extern const struct fdtype_ops fifo_dump_ops;
extern struct collect_image_info fifo_cinfo; extern struct collect_image_info fifo_cinfo;
extern int collect_fifo(void); extern struct collect_image_info fifo_data_cinfo;
#endif /* __CR_FIFO_H__ */ #endif /* __CR_FIFO_H__ */
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "images/pipe.pb-c.h" #include "images/pipe.pb-c.h"
extern struct collect_image_info pipe_cinfo; 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; extern const struct fdtype_ops pipe_dump_ops;
static inline u32 pipe_id(const struct fd_parms *p) static inline u32 pipe_id(const struct fd_parms *p)
...@@ -33,7 +33,8 @@ struct pipe_data_rst { ...@@ -33,7 +33,8 @@ struct pipe_data_rst {
#define PIPE_DATA_HASH_SIZE (1 << PIPE_DATA_HASH_BITS) #define PIPE_DATA_HASH_SIZE (1 << PIPE_DATA_HASH_BITS)
#define PIPE_DATA_HASH_MASK (PIPE_DATA_HASH_SIZE - 1) #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); extern int restore_pipe_data(int img_type, int pfd, u32 id, struct pipe_data_rst **hash);
/* /*
......
...@@ -53,44 +53,22 @@ static int pipe_data_read(struct cr_img *img, struct pipe_data_rst *r) ...@@ -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); 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; int aux;
struct cr_img *img;
struct pipe_data_rst *r = NULL;
img = open_image(img_type, O_RSTR);
if (!img)
return -1;
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); r->pde = pb_msg(msg, PipeDataEntry);
if (ret < 0) aux = pipe_data_read(img, r);
break; if (aux < 0)
return aux;
ret = r->pde->pipe_id & PIPE_DATA_HASH_MASK;
r->next = hash[ret];
hash[ret] = r;
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", pr_info("Collected pipe data for %#x (chain %u)\n",
r->pde->pipe_id, ret); r->pde->pipe_id, aux);
} return 0;
if (r && r->pde)
pipe_data_entry__free_unpacked(r->pde, NULL);
xfree(r);
close_image(img);
return ret;
} }
/* Choose who will restore a pipe. */ /* Choose who will restore a pipe. */
...@@ -412,11 +390,18 @@ struct collect_image_info pipe_cinfo = { ...@@ -412,11 +390,18 @@ struct collect_image_info pipe_cinfo = {
.collect = collect_one_pipe, .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) int dump_one_pipe_data(struct pipe_data_dump *pd, int lfd, const struct fd_parms *p)
{ {
struct cr_img *img; struct cr_img *img;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment