Skip to content

Commit

Permalink
collect: Shorten common images collecting code
Browse files Browse the repository at this point in the history
Now we have a set of cinfo-s, it's possible to collect all
this stuff in a plan for-loop.

Signed-off-by: Pavel Emelyanov <[email protected]>
  • Loading branch information
xemul committed Aug 20, 2013
1 parent 64e7d24 commit 60e6d38
Show file tree
Hide file tree
Showing 24 changed files with 50 additions and 134 deletions.
55 changes: 28 additions & 27 deletions cr-restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions eventfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
11 changes: 0 additions & 11 deletions eventpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
8 changes: 1 addition & 7 deletions fifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
11 changes: 0 additions & 11 deletions files-reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
15 changes: 0 additions & 15 deletions fsnotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion include/eventfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */
3 changes: 2 additions & 1 deletion include/eventpoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions include/fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */
4 changes: 3 additions & 1 deletion include/files-reg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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__ */
5 changes: 4 additions & 1 deletion include/fsnotify.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/namespaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions include/pipes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/signalfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */
2 changes: 1 addition & 1 deletion include/sk-packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion include/sockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion include/tty.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 0 additions & 5 deletions namespaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 1 addition & 7 deletions pipes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions signalfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
5 changes: 0 additions & 5 deletions sk-netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
5 changes: 0 additions & 5 deletions sk-packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
10 changes: 1 addition & 9 deletions sk-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 0 additions & 13 deletions tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 60e6d38

Please sign in to comment.