Commit 60e6d388 authored by Pavel Emelyanov's avatar Pavel Emelyanov

collect: Shorten common images collecting code

Now we have a set of cinfo-s, it's possible to collect all
this stuff in a plan for-loop.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 64e7d243
......@@ -110,9 +110,30 @@ static int crtools_prepare_shared(void)
return 0;
}
static struct collect_image_info *cinfos[] = {
&reg_file_cinfo,
&remap_cinfo,
&nsfile_cinfo,
&pipe_cinfo,
&fifo_cinfo,
&unix_sk_cinfo,
&packet_sk_cinfo,
&netlink_sk_cinfo,
&eventfd_cinfo,
&epoll_tfd_cinfo,
&epoll_cinfo,
&signalfd_cinfo,
&inotify_cinfo,
&inotify_mark_cinfo,
&fanotify_cinfo,
&fanotify_mark_cinfo,
&tty_info_cinfo,
&tty_cinfo,
};
static int root_prepare_shared(void)
{
int ret = 0;
int ret = 0, i;
struct pstree_item *pi;
pr_info("Preparing info about shared resources\n");
......@@ -126,40 +147,20 @@ static int root_prepare_shared(void)
if (prepare_shared_reg_files())
return -1;
if (collect_reg_files())
return -1;
if (collect_ns_files())
return -1;
for (i = 0; i < ARRAY_SIZE(cinfos); i++) {
ret = collect_image(cinfos[i]);
if (ret)
return -1;
}
if (collect_pipes())
return -1;
if (collect_fifo())
return -1;
if (collect_unix_sockets())
return -1;
if (collect_packet_sockets())
return -1;
if (collect_netlink_sockets())
return -1;
if (collect_eventfd())
return -1;
if (collect_eventpoll())
return -1;
if (collect_signalfd())
return -1;
if (collect_inotify())
return -1;
if (collect_tty())
if (tty_verify_active_pairs())
return -1;
for_each_pstree_item(pi) {
......
......@@ -132,8 +132,3 @@ struct collect_image_info eventfd_cinfo = {
.priv_size = sizeof(struct eventfd_file_info),
.collect = collect_one_efd,
};
int collect_eventfd(void)
{
return collect_image(&eventfd_cinfo);
}
......@@ -198,14 +198,3 @@ struct collect_image_info epoll_cinfo = {
.priv_size = sizeof(struct eventpoll_file_info),
.collect = collect_one_epoll,
};
int collect_eventpoll(void)
{
int ret;
ret = collect_image(&epoll_tfd_cinfo);
if (!ret)
ret = collect_image(&epoll_cinfo);
return ret;
}
......@@ -151,11 +151,5 @@ struct collect_image_info fifo_cinfo = {
int collect_fifo(void)
{
int ret;
ret = collect_image(&fifo_cinfo);
if (!ret)
ret = collect_pipe_data(CR_FD_FIFO_DATA, pd_hash_fifo);
return ret;
return collect_pipe_data(CR_FD_FIFO_DATA, pd_hash_fifo);
}
......@@ -581,14 +581,3 @@ int prepare_shared_reg_files(void)
mutex_init(ghost_file_mutex);
return 0;
}
int collect_reg_files(void)
{
int ret;
ret = collect_image(&reg_file_cinfo);
if (!ret)
ret = collect_image(&remap_cinfo);
return ret;
}
......@@ -523,18 +523,3 @@ struct collect_image_info fanotify_mark_cinfo = {
.collect = collect_one_fanotify_mark,
.flags = COLLECT_OPTIONAL,
};
int collect_inotify(void)
{
int ret;
ret = collect_image(&inotify_cinfo);
if (!ret)
ret = collect_image(&inotify_mark_cinfo);
if (!ret)
ret = collect_image(&fanotify_cinfo);
if (!ret)
ret = collect_image(&fanotify_mark_cinfo);
return ret;
}
......@@ -11,7 +11,7 @@
extern int is_eventfd_link(int lfd);
extern const struct fdtype_ops eventfd_dump_ops;
extern int collect_eventfd(void);
extern struct collect_image_info eventfd_cinfo;
extern void show_eventfds(int fd);
#endif /* __CR_EVENTFD_H__ */
......@@ -11,7 +11,8 @@
extern int is_eventpoll_link(int lfd);
extern const struct fdtype_ops eventpoll_dump_ops;
extern int collect_eventpoll(void);
extern struct collect_image_info epoll_tfd_cinfo;
extern struct collect_image_info epoll_cinfo;
extern void show_eventpoll(int fd);
extern void show_eventpoll_tfd(int fd);
......
......@@ -5,6 +5,7 @@ struct fd_parms;
struct cr_fdset;
extern const struct fdtype_ops fifo_dump_ops;
extern struct collect_image_info fifo_cinfo;
extern int collect_fifo(void);
#endif /* __CR_FIFO_H__ */
......@@ -26,7 +26,6 @@ struct reg_file_info {
extern int open_reg_by_id(u32 id);
extern int open_path_by_id(u32 id, int (*open_cb)(struct reg_file_info *, void *), void *arg);
extern void clear_ghost_files(void);
extern int collect_reg_files(void);
extern int prepare_shared_reg_files(void);
......@@ -36,4 +35,7 @@ extern int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p);
extern struct file_remap *lookup_ghost_remap(u32 dev, u32 ino);
extern void remap_put(struct file_remap *remap);
extern struct collect_image_info reg_file_cinfo;
extern struct collect_image_info remap_cinfo;
#endif /* __CR_FILES_REG_H__ */
......@@ -19,7 +19,10 @@ extern int is_inotify_link(int lfd);
extern int is_fanotify_link(int lfd);
extern const struct fdtype_ops inotify_dump_ops;
extern const struct fdtype_ops fanotify_dump_ops;
extern int collect_inotify(void);
extern struct collect_image_info inotify_cinfo;
extern struct collect_image_info inotify_mark_cinfo;
extern struct collect_image_info fanotify_cinfo;
extern struct collect_image_info fanotify_mark_cinfo;
extern void show_inotify_wd(int fd);
extern void show_inotify(int fd);
extern void show_fanotify_mark(int fd);
......
......@@ -25,7 +25,7 @@ extern struct ns_desc user_ns_desc;
extern unsigned long current_ns_mask;
extern const struct fdtype_ops nsfile_dump_ops;
extern int collect_ns_files(void);
extern struct collect_image_info nsfile_cinfo;
int dump_namespaces(struct pid *pid, unsigned int ns_flags);
int prepare_namespace(int pid, unsigned long clone_flags);
......
......@@ -3,6 +3,7 @@
#include "protobuf/pipe-data.pb-c.h"
extern struct collect_image_info pipe_cinfo;
extern int collect_pipes(void);
extern void mark_pipe_master(void);
extern const struct fdtype_ops pipe_dump_ops;
......
......@@ -6,6 +6,6 @@ struct fd_parms;
extern int is_signalfd_link(int lfd);
extern const struct fdtype_ops signalfd_dump_ops;
extern void show_signalfd(int fd);
extern int collect_signalfd(void);
extern struct collect_image_info signalfd_cinfo;
#endif /* __CR_SIGNALFD_H__ */
......@@ -9,7 +9,7 @@ struct cr_fdset;
struct fd_parms;
struct vma_area;
int collect_packet_sockets(void);
extern struct collect_image_info packet_sk_cinfo;
void show_packetsk(int fd);
int dump_socket_map(struct vma_area *vma);
......
......@@ -36,11 +36,12 @@ extern bool socket_test_collect_bit(unsigned int family, unsigned int proto);
extern int sk_collect_one(int ino, int family, struct socket_desc *d);
extern int collect_sockets(int pid);
extern int collect_inet_sockets(void);
extern struct collect_image_info unix_sk_cinfo;
extern int collect_unix_sockets(void);
extern int fix_external_unix_sockets(void);
extern int resolve_unix_peers(void);
extern int collect_netlink_sockets(void);
extern struct collect_image_info netlink_sk_cinfo;
extern void show_unixsk(int fd);
extern void show_inetsk(int fd);
......
......@@ -15,7 +15,8 @@
extern const struct fdtype_ops tty_dump_ops;
extern int dump_verify_tty_sids(void);
extern int collect_tty(void);
extern struct collect_image_info tty_info_cinfo;
extern struct collect_image_info tty_cinfo;
extern int prepare_shared_tty(void);
extern int tty_setup_slavery(void);
......
......@@ -305,11 +305,6 @@ struct collect_image_info nsfile_cinfo = {
.flags = COLLECT_OPTIONAL,
};
int collect_ns_files(void)
{
return collect_image(&nsfile_cinfo);
}
int dump_task_ns_ids(struct pstree_item *item)
{
int pid = item->pid.real;
......
......@@ -398,13 +398,7 @@ struct collect_image_info pipe_cinfo = {
int collect_pipes(void)
{
int ret;
ret = collect_image(&pipe_cinfo);
if (!ret)
ret = collect_pipe_data(CR_FD_PIPES_DATA, pd_hash_pipes);
return ret;
return collect_pipe_data(CR_FD_PIPES_DATA, pd_hash_pipes);
}
int dump_one_pipe_data(struct pipe_data_dump *pd, int lfd, const struct fd_parms *p)
......
......@@ -127,8 +127,3 @@ struct collect_image_info signalfd_cinfo = {
.collect = collect_one_sigfd,
.flags = COLLECT_OPTIONAL,
};
int collect_signalfd(void)
{
return collect_image(&signalfd_cinfo);
}
......@@ -241,8 +241,3 @@ struct collect_image_info netlink_sk_cinfo = {
.collect = collect_one_netlink_sk,
.flags = COLLECT_OPTIONAL,
};
int collect_netlink_sockets(void)
{
return collect_image(&netlink_sk_cinfo);
}
......@@ -506,8 +506,3 @@ struct collect_image_info packet_sk_cinfo = {
.collect = collect_one_packet_sk,
.flags = COLLECT_OPTIONAL,
};
int collect_packet_sockets(void)
{
return collect_image(&packet_sk_cinfo);
}
......@@ -836,15 +836,7 @@ struct collect_image_info unix_sk_cinfo = {
int collect_unix_sockets(void)
{
int ret;
pr_info("Reading unix sockets in\n");
ret = collect_image(&unix_sk_cinfo);
if (!ret)
ret = read_sk_queues();
return ret;
return read_sk_queues();
}
int resolve_unix_peers(void)
......
......@@ -991,19 +991,6 @@ struct collect_image_info tty_cinfo = {
.flags = COLLECT_OPTIONAL,
};
int collect_tty(void)
{
int ret;
ret = collect_image(&tty_info_cinfo);
if (!ret)
ret = collect_image(&tty_cinfo);
if (!ret)
ret = tty_verify_active_pairs();
return ret;
}
/* Make sure the ttys we're dumping do belong our process tree */
int dump_verify_tty_sids(void)
{
......
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