Commit d020ebb3 authored by Pavel Emelyanov's avatar Pavel Emelyanov

files: Compact the code by removing per-file dump helpers

Since *all* of them just call do_dump_gen_file with proper ops,
just call one directly. Compacts the code.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 42f77676
......@@ -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;
......
......@@ -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;
......
......@@ -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)
......
......@@ -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, &regfile_ops, fdinfo);
}
static int open_path(struct file_desc *d,
int(*open_cb)(struct reg_file_info *, void *), void *arg)
{
......
......@@ -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 = &regfile_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, &regfile_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);
......
......@@ -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,
......
......@@ -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);
......
......@@ -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);
......
......@@ -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__ */
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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)
{
......
......@@ -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);
......
......@@ -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);
......
......@@ -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 *);
......
......@@ -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);
......
......@@ -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;
......
......@@ -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);
}
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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)
{
......
......@@ -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)
......
......@@ -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)
......
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