From 60e6d38868b9b68045c262c65558ddf543479f58 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 21 Aug 2013 03:52:18 +0400 Subject: [PATCH] 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: Pavel Emelyanov --- cr-restore.c | 55 ++++++++++++++++++++++---------------------- eventfd.c | 5 ---- eventpoll.c | 11 --------- fifo.c | 8 +------ files-reg.c | 11 --------- fsnotify.c | 15 ------------ include/eventfd.h | 2 +- include/eventpoll.h | 3 ++- include/fifo.h | 1 + include/files-reg.h | 4 +++- include/fsnotify.h | 5 +++- include/namespaces.h | 2 +- include/pipes.h | 1 + include/signalfd.h | 2 +- include/sk-packet.h | 2 +- include/sockets.h | 3 ++- include/tty.h | 3 ++- namespaces.c | 5 ---- pipes.c | 8 +------ signalfd.c | 5 ---- sk-netlink.c | 5 ---- sk-packet.c | 5 ---- sk-unix.c | 10 +------- tty.c | 13 ----------- 24 files changed, 50 insertions(+), 134 deletions(-) diff --git a/cr-restore.c b/cr-restore.c index b5707539c..4162caa24 100644 --- a/cr-restore.c +++ b/cr-restore.c @@ -110,9 +110,30 @@ static int crtools_prepare_shared(void) return 0; } +static struct collect_image_info *cinfos[] = { + ®_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) { diff --git a/eventfd.c b/eventfd.c index 7098368e2..181495026 100644 --- a/eventfd.c +++ b/eventfd.c @@ -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); -} diff --git a/eventpoll.c b/eventpoll.c index 54710128d..c510f4fc4 100644 --- a/eventpoll.c +++ b/eventpoll.c @@ -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; -} diff --git a/fifo.c b/fifo.c index d3d6a6e0c..530a6d0cf 100644 --- a/fifo.c +++ b/fifo.c @@ -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); } diff --git a/files-reg.c b/files-reg.c index dd7a4438d..b58b63b20 100644 --- a/files-reg.c +++ b/files-reg.c @@ -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(®_file_cinfo); - if (!ret) - ret = collect_image(&remap_cinfo); - - return ret; -} diff --git a/fsnotify.c b/fsnotify.c index 4e28ba0ca..8d1fd3847 100644 --- a/fsnotify.c +++ b/fsnotify.c @@ -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; -} diff --git a/include/eventfd.h b/include/eventfd.h index 8ab8aae64..f4014eb90 100644 --- a/include/eventfd.h +++ b/include/eventfd.h @@ -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__ */ diff --git a/include/eventpoll.h b/include/eventpoll.h index 5bcbf578d..913db606a 100644 --- a/include/eventpoll.h +++ b/include/eventpoll.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); diff --git a/include/fifo.h b/include/fifo.h index 22a102850..182434628 100644 --- a/include/fifo.h +++ b/include/fifo.h @@ -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__ */ diff --git a/include/files-reg.h b/include/files-reg.h index f26cf94ea..a93064113 100644 --- a/include/files-reg.h +++ b/include/files-reg.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__ */ diff --git a/include/fsnotify.h b/include/fsnotify.h index 351be62b8..7fd247b80 100644 --- a/include/fsnotify.h +++ b/include/fsnotify.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); diff --git a/include/namespaces.h b/include/namespaces.h index 034d9c53f..3a1962bc5 100644 --- a/include/namespaces.h +++ b/include/namespaces.h @@ -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); diff --git a/include/pipes.h b/include/pipes.h index 8d960f7f7..a52857a09 100644 --- a/include/pipes.h +++ b/include/pipes.h @@ -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; diff --git a/include/signalfd.h b/include/signalfd.h index 9008ef607..e33d891e9 100644 --- a/include/signalfd.h +++ b/include/signalfd.h @@ -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__ */ diff --git a/include/sk-packet.h b/include/sk-packet.h index 1440cc81b..a6c449284 100644 --- a/include/sk-packet.h +++ b/include/sk-packet.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); diff --git a/include/sockets.h b/include/sockets.h index 215a6f488..3dd727377 100644 --- a/include/sockets.h +++ b/include/sockets.h @@ -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); diff --git a/include/tty.h b/include/tty.h index a1e27a246..43a737c97 100644 --- a/include/tty.h +++ b/include/tty.h @@ -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); diff --git a/namespaces.c b/namespaces.c index 5f50b003a..21767ef2a 100644 --- a/namespaces.c +++ b/namespaces.c @@ -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; diff --git a/pipes.c b/pipes.c index 8db276d02..21fd355b6 100644 --- a/pipes.c +++ b/pipes.c @@ -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) diff --git a/signalfd.c b/signalfd.c index fc515022d..432b41452 100644 --- a/signalfd.c +++ b/signalfd.c @@ -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); -} diff --git a/sk-netlink.c b/sk-netlink.c index c1175561e..a4748f27d 100644 --- a/sk-netlink.c +++ b/sk-netlink.c @@ -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); -} diff --git a/sk-packet.c b/sk-packet.c index 37faf1d6b..ff84d1c84 100644 --- a/sk-packet.c +++ b/sk-packet.c @@ -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); -} diff --git a/sk-unix.c b/sk-unix.c index dd03f81dc..8fe04d50e 100644 --- a/sk-unix.c +++ b/sk-unix.c @@ -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) diff --git a/tty.c b/tty.c index bc188b4f2..ca2de57be 100644 --- a/tty.c +++ b/tty.c @@ -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) {