diff --git a/eventfd.c b/eventfd.c index 0f6c2f9bc..9e85ec3ef 100644 --- a/eventfd.c +++ b/eventfd.c @@ -80,16 +80,11 @@ static int dump_one_eventfd(int lfd, u32 id, const struct fd_parms *p) return parse_fdinfo(lfd, FD_TYPES__EVENTFD, dump_eventfd_entry, &da); } -static const struct fdtype_ops eventfd_ops = { +const struct fdtype_ops eventfd_dump_ops = { .type = FD_TYPES__EVENTFD, .dump = dump_one_eventfd, }; -int dump_eventfd(struct fd_parms *p, int lfd, const int fdinfo) -{ - return do_dump_gen_file(p, lfd, &eventfd_ops, fdinfo); -} - static int eventfd_open(struct file_desc *d) { struct eventfd_file_info *info; diff --git a/eventpoll.c b/eventpoll.c index cb00e360e..03840cecd 100644 --- a/eventpoll.c +++ b/eventpoll.c @@ -92,16 +92,11 @@ static int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p) return parse_fdinfo(lfd, FD_TYPES__EVENTPOLL, dump_eventpoll_entry, &id); } -static const struct fdtype_ops eventpoll_ops = { +const struct fdtype_ops eventpoll_dump_ops = { .type = FD_TYPES__EVENTPOLL, .dump = dump_one_eventpoll, }; -int dump_eventpoll(struct fd_parms *p, int lfd, const int fdinfo) -{ - return do_dump_gen_file(p, lfd, &eventpoll_ops, fdinfo); -} - static int eventpoll_open(struct file_desc *d) { struct eventpoll_file_info *info; diff --git a/fifo.c b/fifo.c index 15693e387..41bea017f 100644 --- a/fifo.c +++ b/fifo.c @@ -63,16 +63,11 @@ static int dump_one_fifo(int lfd, u32 id, const struct fd_parms *p) return dump_one_pipe_data(&pd_fifo, lfd, p); } -static const struct fdtype_ops fifo_ops = { +const struct fdtype_ops fifo_dump_ops = { .type = FD_TYPES__FIFO, .dump = dump_one_fifo, }; -int dump_fifo(struct fd_parms *p, int lfd, const int fdinfo) -{ - return do_dump_gen_file(p, lfd, &fifo_ops, fdinfo); -} - static struct pipe_data_rst *pd_hash_fifo[PIPE_DATA_HASH_SIZE]; static int do_open_fifo(struct reg_file_info *rfi, void *arg) diff --git a/files-reg.c b/files-reg.c index 5f3c2710b..9acd81557 100644 --- a/files-reg.c +++ b/files-reg.c @@ -471,17 +471,11 @@ int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p) return pb_write_one(rfd, &rfe, PB_REG_FILES); } -static const struct fdtype_ops regfile_ops = { +const struct fdtype_ops regfile_dump_ops = { .type = FD_TYPES__REG, .dump = dump_one_reg_file, }; -int dump_reg_file(struct fd_parms *p, int lfd, - const int fdinfo) -{ - return do_dump_gen_file(p, lfd, ®file_ops, fdinfo); -} - static int open_path(struct file_desc *d, int(*open_cb)(struct reg_file_info *, void *), void *arg) { diff --git a/files.c b/files.c index 3abf39060..ef9990e44 100644 --- a/files.c +++ b/files.c @@ -207,17 +207,22 @@ static int dump_unsupp_fd(const struct fd_parms *p) static int dump_chrdev(struct fd_parms *p, int lfd, const int fdinfo) { int maj = major(p->stat.st_rdev); + const struct fdtype_ops *ops; switch (maj) { case MEM_MAJOR: - return dump_reg_file(p, lfd, fdinfo); + ops = ®file_dump_ops; + break; case TTYAUX_MAJOR: case UNIX98_PTY_MASTER_MAJOR ... (UNIX98_PTY_MASTER_MAJOR + UNIX98_PTY_MAJOR_COUNT - 1): case UNIX98_PTY_SLAVE_MAJOR: - return dump_tty(p, lfd, fdinfo); + ops = &tty_dump_ops; + break; + default: + return dump_unsupp_fd(p); } - return dump_unsupp_fd(p); + return do_dump_gen_file(p, lfd, ops, fdinfo); } #ifndef PIPEFS_MAGIC @@ -229,6 +234,7 @@ static int dump_one_file(struct parasite_ctl *ctl, int fd, int lfd, struct fd_op { struct fd_parms p = FD_PARMS_INIT; struct statfs statfs; + const struct fdtype_ops *ops; if (fill_fd_params(ctl, fd, lfd, opts, &p) < 0) { pr_perror("Can't get stat on %d", fd); @@ -248,17 +254,19 @@ static int dump_one_file(struct parasite_ctl *ctl, int fd, int lfd, struct fd_op if (is_anon_inode(&statfs)) { if (is_eventfd_link(lfd)) - return dump_eventfd(&p, lfd, fdinfo); + ops = &eventfd_dump_ops; else if (is_eventpoll_link(lfd)) - return dump_eventpoll(&p, lfd, fdinfo); + ops = &eventpoll_dump_ops; else if (is_inotify_link(lfd)) - return dump_inotify(&p, lfd, fdinfo); + ops = &inotify_dump_ops; else if (is_fanotify_link(lfd)) - return dump_fanotify(&p, lfd, fdinfo); + ops = &fanotify_dump_ops; else if (is_signalfd_link(lfd)) - return dump_signalfd(&p, lfd, fdinfo); + ops = &signalfd_dump_ops; else return dump_unsupp_fd(&p); + + return do_dump_gen_file(&p, lfd, ops, fdinfo); } if (S_ISREG(p.stat.st_mode) || S_ISDIR(p.stat.st_mode)) { @@ -269,19 +277,21 @@ static int dump_one_file(struct parasite_ctl *ctl, int fd, int lfd, struct fd_op p.link = &link; if (link.name[1] == '/') - return dump_reg_file(&p, lfd, fdinfo); + return do_dump_gen_file(&p, lfd, ®file_dump_ops, fdinfo); if (check_ns_proc(&link)) - return dump_ns_file(&p, lfd, fdinfo); + return do_dump_gen_file(&p, lfd, &nsfile_dump_ops, fdinfo); return dump_unsupp_fd(&p); } if (S_ISFIFO(p.stat.st_mode)) { if (statfs.f_type == PIPEFS_MAGIC) - return dump_pipe(&p, lfd, fdinfo); + ops = &pipe_dump_ops; else - return dump_fifo(&p, lfd, fdinfo); + ops = &fifo_dump_ops; + + return do_dump_gen_file(&p, lfd, ops, fdinfo); } return dump_unsupp_fd(&p); diff --git a/fsnotify.c b/fsnotify.c index 191a99bbe..24d334061 100644 --- a/fsnotify.c +++ b/fsnotify.c @@ -125,16 +125,11 @@ static int dump_one_inotify(int lfd, u32 id, const struct fd_parms *p) return parse_fdinfo(lfd, FD_TYPES__INOTIFY, dump_inotify_entry, &id); } -static const struct fdtype_ops inotify_ops = { +const struct fdtype_ops inotify_dump_ops = { .type = FD_TYPES__INOTIFY, .dump = dump_one_inotify, }; -int dump_inotify(struct fd_parms *p, int lfd, const int fdinfo) -{ - return do_dump_gen_file(p, lfd, &inotify_ops, fdinfo); -} - static int dump_fanotify_entry(union fdinfo_entries *e, void *arg) { struct fsnotify_params *fsn_params = arg; @@ -195,16 +190,11 @@ static int dump_one_fanotify(int lfd, u32 id, const struct fd_parms *p) return pb_write_one(fdset_fd(glob_fdset, CR_FD_FANOTIFY), &fe, PB_FANOTIFY); } -static const struct fdtype_ops fanotify_ops = { +const struct fdtype_ops fanotify_dump_ops = { .type = FD_TYPES__FANOTIFY, .dump = dump_one_fanotify, }; -int dump_fanotify(struct fd_parms *p, int lfd, const int fdinfo) -{ - return do_dump_gen_file(p, lfd, &fanotify_ops, fdinfo); -} - static char *get_mark_path(const char *who, struct file_remap *remap, FhEntry *f_handle, unsigned long i_ino, unsigned int s_dev, char *buf, size_t size, diff --git a/include/eventfd.h b/include/eventfd.h index 5fe26db84..8ab8aae64 100644 --- a/include/eventfd.h +++ b/include/eventfd.h @@ -10,7 +10,7 @@ #include "crtools.h" extern int is_eventfd_link(int lfd); -extern int dump_eventfd(struct fd_parms *p, int lfd, const int fdinfo); +extern const struct fdtype_ops eventfd_dump_ops; extern int collect_eventfd(void); extern void show_eventfds(int fd); diff --git a/include/eventpoll.h b/include/eventpoll.h index 68220890e..5bcbf578d 100644 --- a/include/eventpoll.h +++ b/include/eventpoll.h @@ -10,7 +10,7 @@ #include "crtools.h" extern int is_eventpoll_link(int lfd); -extern int dump_eventpoll(struct fd_parms *p, int lfd, const int fdinfo); +extern const struct fdtype_ops eventpoll_dump_ops; extern int collect_eventpoll(void); extern void show_eventpoll(int fd); extern void show_eventpoll_tfd(int fd); diff --git a/include/fifo.h b/include/fifo.h index dc5aecf99..22a102850 100644 --- a/include/fifo.h +++ b/include/fifo.h @@ -4,7 +4,7 @@ struct fd_parms; struct cr_fdset; -extern int dump_fifo(struct fd_parms *p, int lfd, const int fdinfo); +extern const struct fdtype_ops fifo_dump_ops; extern int collect_fifo(void); #endif /* __CR_FIFO_H__ */ diff --git a/include/files-reg.h b/include/files-reg.h index e870d8633..f26cf94ea 100644 --- a/include/files-reg.h +++ b/include/files-reg.h @@ -30,7 +30,7 @@ extern int collect_reg_files(void); extern int prepare_shared_reg_files(void); -extern int dump_reg_file(struct fd_parms *p, int lfd, const int fdinfo); +extern const struct fdtype_ops regfile_dump_ops; 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); diff --git a/include/fsnotify.h b/include/fsnotify.h index 424176723..351be62b8 100644 --- a/include/fsnotify.h +++ b/include/fsnotify.h @@ -17,8 +17,8 @@ struct fsnotify_params { extern int is_inotify_link(int lfd); extern int is_fanotify_link(int lfd); -extern int dump_inotify(struct fd_parms *p, int lfd, const int fdinfo); -extern int dump_fanotify(struct fd_parms *p, int lfd, const int fdinfo); +extern const struct fdtype_ops inotify_dump_ops; +extern const struct fdtype_ops fanotify_dump_ops; extern int collect_inotify(void); extern void show_inotify_wd(int fd); extern void show_inotify(int fd); diff --git a/include/namespaces.h b/include/namespaces.h index 573b02276..034d9c53f 100644 --- a/include/namespaces.h +++ b/include/namespaces.h @@ -24,7 +24,7 @@ extern struct ns_desc pid_ns_desc; extern struct ns_desc user_ns_desc; extern unsigned long current_ns_mask; -extern int dump_ns_file(struct fd_parms *p, int lfd, const int fdinfo); +extern const struct fdtype_ops nsfile_dump_ops; extern int collect_ns_files(void); int dump_namespaces(struct pid *pid, unsigned int ns_flags); diff --git a/include/pipes.h b/include/pipes.h index 02ef80e79..8d960f7f7 100644 --- a/include/pipes.h +++ b/include/pipes.h @@ -5,8 +5,7 @@ extern int collect_pipes(void); extern void mark_pipe_master(void); -int dump_pipe(struct fd_parms *p, int lfd, - const int fdinfo); +extern const struct fdtype_ops pipe_dump_ops; static inline u32 pipe_id(const struct fd_parms *p) { diff --git a/include/signalfd.h b/include/signalfd.h index ac1c09bec..9008ef607 100644 --- a/include/signalfd.h +++ b/include/signalfd.h @@ -4,7 +4,7 @@ struct cr_fdset; struct fd_parms; extern int is_signalfd_link(int lfd); -extern int dump_signalfd(struct fd_parms *p, int lfd, const int fdinfo); +extern const struct fdtype_ops signalfd_dump_ops; extern void show_signalfd(int fd); extern int collect_signalfd(void); diff --git a/include/sk-packet.h b/include/sk-packet.h index b78517a07..1440cc81b 100644 --- a/include/sk-packet.h +++ b/include/sk-packet.h @@ -9,7 +9,6 @@ struct cr_fdset; struct fd_parms; struct vma_area; -int dump_one_packet_sk(struct fd_parms *p, int lfd, const int fdinfo); int collect_packet_sockets(void); void show_packetsk(int fd); diff --git a/include/sockets.h b/include/sockets.h index 078b10674..215a6f488 100644 --- a/include/sockets.h +++ b/include/sockets.h @@ -54,10 +54,11 @@ extern char *skstate2s(u32 state); extern struct socket_desc *lookup_socket(int ino, int family, int proto); -extern int dump_one_inet(struct fd_parms *p, int lfd, const int fdinfo); -extern int dump_one_inet6(struct fd_parms *p, int lfd, const int fdinfo); -extern int dump_one_unix(struct fd_parms *p, int lfd, const int fdinfo); -extern int dump_one_netlink(struct fd_parms *p, int lfd, const int fdinfo); +extern const struct fdtype_ops unix_dump_ops; +extern const struct fdtype_ops inet_dump_ops; +extern const struct fdtype_ops inet6_dump_ops; +extern const struct fdtype_ops netlink_dump_ops; +extern const struct fdtype_ops packet_dump_ops; extern int inet_collect_one(struct nlmsghdr *h, int family, int type); extern int unix_receive_one(struct nlmsghdr *h, void *); diff --git a/include/tty.h b/include/tty.h index 0d8834f9f..a1e27a246 100644 --- a/include/tty.h +++ b/include/tty.h @@ -13,7 +13,7 @@ #endif #define PTS_FMT "/dev/pts/%d" -extern int dump_tty(struct fd_parms *p, int lfd, const int fdinfo); +extern const struct fdtype_ops tty_dump_ops; extern int dump_verify_tty_sids(void); extern int collect_tty(void); extern int prepare_shared_tty(void); diff --git a/namespaces.c b/namespaces.c index 7b99e5c34..f9cc3cbc2 100644 --- a/namespaces.c +++ b/namespaces.c @@ -212,16 +212,11 @@ int dump_one_ns_file(int lfd, u32 id, const struct fd_parms *p) return pb_write_one(fd, &nfe, PB_NS_FILES); } -static const struct fdtype_ops nsfile_ops = { +const struct fdtype_ops nsfile_dump_ops = { .type = FD_TYPES__NS, .dump = dump_one_ns_file, }; -int dump_ns_file(struct fd_parms *p, int lfd, const int fdinfo) -{ - return do_dump_gen_file(p, lfd, &nsfile_ops, fdinfo); -} - struct ns_file_info { struct file_desc d; NsFileEntry *nfe; diff --git a/pipes.c b/pipes.c index b69fa61ec..c0328c2fd 100644 --- a/pipes.c +++ b/pipes.c @@ -507,12 +507,7 @@ static int dump_one_pipe(int lfd, u32 id, const struct fd_parms *p) return dump_one_pipe_data(&pd_pipes, lfd, p); } -static const struct fdtype_ops pipe_ops = { +const struct fdtype_ops pipe_dump_ops = { .type = FD_TYPES__PIPE, .dump = dump_one_pipe, }; - -int dump_pipe(struct fd_parms *p, int lfd, const int fdinfo) -{ - return do_dump_gen_file(p, lfd, &pipe_ops, fdinfo); -} diff --git a/signalfd.c b/signalfd.c index 6716f5b50..1a26caafa 100644 --- a/signalfd.c +++ b/signalfd.c @@ -60,16 +60,11 @@ static int dump_one_signalfd(int lfd, u32 id, const struct fd_parms *p) return parse_fdinfo(lfd, FD_TYPES__SIGNALFD, dump_signalfd_entry, &da); } -static const struct fdtype_ops signalfd_ops = { +const struct fdtype_ops signalfd_dump_ops = { .type = FD_TYPES__SIGNALFD, .dump = dump_one_signalfd, }; -int dump_signalfd(struct fd_parms *p, int lfd, const int fdinfo) -{ - return do_dump_gen_file(p, lfd, &signalfd_ops, fdinfo); -} - static void sigset_fill(sigset_t *to, unsigned long long from) { int sig; diff --git a/sk-inet.c b/sk-inet.c index 01c87743d..f3989283b 100644 --- a/sk-inet.c +++ b/sk-inet.c @@ -316,31 +316,21 @@ static int dump_one_inet_fd(int lfd, u32 id, const struct fd_parms *p) return do_dump_one_inet_fd(lfd, id, p, PF_INET); } -static const struct fdtype_ops inet_dump_ops = { +const struct fdtype_ops inet_dump_ops = { .type = FD_TYPES__INETSK, .dump = dump_one_inet_fd, }; -int dump_one_inet(struct fd_parms *p, int lfd, const int fdinfo) -{ - return do_dump_gen_file(p, lfd, &inet_dump_ops, fdinfo); -} - static int dump_one_inet6_fd(int lfd, u32 id, const struct fd_parms *p) { return do_dump_one_inet_fd(lfd, id, p, PF_INET6); } -static const struct fdtype_ops inet6_dump_ops = { +const struct fdtype_ops inet6_dump_ops = { .type = FD_TYPES__INETSK, .dump = dump_one_inet6_fd, }; -int dump_one_inet6(struct fd_parms *p, int lfd, const int fdinfo) -{ - return do_dump_gen_file(p, lfd, &inet6_dump_ops, fdinfo); -} - int inet_collect_one(struct nlmsghdr *h, int family, int type) { struct inet_sk_desc *d; diff --git a/sk-netlink.c b/sk-netlink.c index 1b1e111a1..6cb49a5ad 100644 --- a/sk-netlink.c +++ b/sk-netlink.c @@ -154,16 +154,11 @@ err: return -1; } -static const struct fdtype_ops netlink_dump_ops = { +const struct fdtype_ops netlink_dump_ops = { .type = FD_TYPES__NETLINKSK, .dump = dump_one_netlink_fd, }; -int dump_one_netlink(struct fd_parms *p, int lfd, const int fdinfo) -{ - return do_dump_gen_file(p, lfd, &netlink_dump_ops, fdinfo); -} - struct netlink_sock_info { NetlinkSkEntry *nse; struct file_desc d; diff --git a/sk-packet.c b/sk-packet.c index 28897187a..ef4479f79 100644 --- a/sk-packet.c +++ b/sk-packet.c @@ -205,16 +205,11 @@ out: return ret; } -static const struct fdtype_ops packet_dump_ops = { +const struct fdtype_ops packet_dump_ops = { .type = FD_TYPES__PACKETSK, .dump = dump_one_packet_fd, }; -int dump_one_packet_sk(struct fd_parms *p, int lfd, const int fdinfo) -{ - return do_dump_gen_file(p, lfd, &packet_dump_ops, fdinfo); -} - int dump_socket_map(struct vma_area *vma) { struct packet_sock_desc *sd; diff --git a/sk-unix.c b/sk-unix.c index cadba5dd6..abc68b003 100644 --- a/sk-unix.c +++ b/sk-unix.c @@ -251,16 +251,11 @@ err: return -1; } -static const struct fdtype_ops unix_dump_ops = { +const struct fdtype_ops unix_dump_ops = { .type = FD_TYPES__UNIXSK, .dump = dump_one_unix_fd, }; -int dump_one_unix(struct fd_parms *p, int lfd, const int fdinfo) -{ - return do_dump_gen_file(p, lfd, &unix_dump_ops, fdinfo); -} - static int unix_collect_one(const struct unix_diag_msg *m, struct rtattr **tb) { diff --git a/sockets.c b/sockets.c index c2346ee47..44c8b42cf 100644 --- a/sockets.c +++ b/sockets.c @@ -441,27 +441,33 @@ void release_skopts(SkOptsEntry *soe) int dump_socket(struct fd_parms *p, int lfd, const int fdinfo) { int family; + const struct fdtype_ops *ops; if (dump_opt(lfd, SOL_SOCKET, SO_DOMAIN, &family)) return -1; switch (family) { case AF_UNIX: - return dump_one_unix(p, lfd, fdinfo); + ops = &unix_dump_ops; + break; case AF_INET: - return dump_one_inet(p, lfd, fdinfo); + ops = &inet_dump_ops; + break; case AF_INET6: - return dump_one_inet6(p, lfd, fdinfo); + ops = &inet6_dump_ops; + break; case AF_PACKET: - return dump_one_packet_sk(p, lfd, fdinfo); + ops = &packet_dump_ops; + break; case AF_NETLINK: - return dump_one_netlink(p, lfd, fdinfo); + ops = &netlink_dump_ops; + break; default: pr_err("BUG! Unknown socket collected (family %d)\n", family); - break; + return -1; } - return -1; + return do_dump_gen_file(p, lfd, ops, fdinfo); } static int inet_receive_one(struct nlmsghdr *h, void *arg) diff --git a/tty.c b/tty.c index ac954aabb..6631cb6aa 100644 --- a/tty.c +++ b/tty.c @@ -1196,16 +1196,11 @@ static int dump_one_pty(int lfd, u32 id, const struct fd_parms *p) return ret; } -static const struct fdtype_ops tty_ops = { +const struct fdtype_ops tty_dump_ops = { .type = FD_TYPES__TTY, .dump = dump_one_pty, }; -int dump_tty(struct fd_parms *p, int lfd, const int fdinfo) -{ - return do_dump_gen_file(p, lfd, &tty_ops, fdinfo); -} - int tty_prep_fds(void) { if (!opts.shell_job)