From 9fc1d6bbebe86f3825f1fd982fef41be8c2e7e09 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Thu, 19 Jul 2012 10:18:37 +0400 Subject: [PATCH] fdinfo: Make fdinfo.type be an enum This types specifies a strict set of what is hidden behind the fd. Thus these numbers should be in the description of the fdinfo message. Plus protobuf makes shure nothing else will be there. Signed-off-by: Pavel Emelyanov --- cr-check.c | 6 +++--- eventfd.c | 6 +++--- eventpoll.c | 6 +++--- fifo.c | 4 ++-- files-reg.c | 8 ++++---- files.c | 2 +- include/image.h | 14 -------------- inotify.c | 6 +++--- pipes.c | 4 ++-- proc_parse.c | 7 ++++--- protobuf/fdinfo.proto | 14 +++++++++++++- sk-inet.c | 4 ++-- sk-unix.c | 4 ++-- 13 files changed, 42 insertions(+), 43 deletions(-) diff --git a/cr-check.c b/cr-check.c index b23cb7b0c..f66524dee 100644 --- a/cr-check.c +++ b/cr-check.c @@ -161,7 +161,7 @@ static int check_fdinfo_eventfd(void) return -1; } - ret = parse_fdinfo(fd, FDINFO_EVENTFD, check_one_fdinfo, &proc_cnt); + ret = parse_fdinfo(fd, FD_TYPES__EVENTFD, check_one_fdinfo, &proc_cnt); close(fd); if (ret) { @@ -209,7 +209,7 @@ static int check_fdinfo_eventpoll(void) return -1; } - ret = parse_fdinfo(efd, FDINFO_EVENTPOLL, check_one_epoll, &proc_fd); + ret = parse_fdinfo(efd, FD_TYPES__EVENTPOLL, check_one_epoll, &proc_fd); close(efd); close(pfd[0]); close(pfd[1]); @@ -251,7 +251,7 @@ static int check_fdinfo_inotify(void) return -1; } - ret = parse_fdinfo(ifd, FDINFO_INOTIFY, check_one_inotify, &proc_wd); + ret = parse_fdinfo(ifd, FD_TYPES__INOTIFY, check_one_inotify, &proc_wd); close(ifd); if (ret < 0) { diff --git a/eventfd.c b/eventfd.c index 999629c80..17be2c517 100644 --- a/eventfd.c +++ b/eventfd.c @@ -74,11 +74,11 @@ static int dump_eventfd_entry(union fdinfo_entries *e, void *arg) static int dump_one_eventfd(int lfd, u32 id, const struct fd_parms *p) { struct eventfd_dump_arg da = { .id = id, .p = p, }; - return parse_fdinfo(lfd, FDINFO_EVENTFD, dump_eventfd_entry, &da); + return parse_fdinfo(lfd, FD_TYPES__EVENTFD, dump_eventfd_entry, &da); } static const struct fdtype_ops eventfd_ops = { - .type = FDINFO_EVENTFD, + .type = FD_TYPES__EVENTFD, .make_gen_id = make_gen_id, .dump = dump_one_eventfd, }; @@ -116,7 +116,7 @@ err_close: } static struct file_desc_ops eventfd_desc_ops = { - .type = FDINFO_EVENTFD, + .type = FD_TYPES__EVENTFD, .open = eventfd_open, }; diff --git a/eventpoll.c b/eventpoll.c index 92bff99d6..714221b37 100644 --- a/eventpoll.c +++ b/eventpoll.c @@ -86,11 +86,11 @@ static int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p) &e, eventpoll_file_entry)) return -1; - return parse_fdinfo(lfd, FDINFO_EVENTPOLL, dump_eventpoll_entry, &id); + return parse_fdinfo(lfd, FD_TYPES__EVENTPOLL, dump_eventpoll_entry, &id); } static const struct fdtype_ops eventpoll_ops = { - .type = FDINFO_EVENTPOLL, + .type = FD_TYPES__EVENTPOLL, .make_gen_id = make_gen_id, .dump = dump_one_eventpoll, }; @@ -144,7 +144,7 @@ err_close: } static struct file_desc_ops desc_ops = { - .type = FDINFO_EVENTPOLL, + .type = FD_TYPES__EVENTPOLL, .open = eventpoll_open, }; diff --git a/fifo.c b/fifo.c index af7100c72..03f10b3fb 100644 --- a/fifo.c +++ b/fifo.c @@ -64,7 +64,7 @@ static int dump_one_fifo(int lfd, u32 id, const struct fd_parms *p) } static const struct fdtype_ops fifo_ops = { - .type = FDINFO_FIFO, + .type = FD_TYPES__FIFO, .make_gen_id = make_gen_id, .dump = dump_one_fifo, }; @@ -119,7 +119,7 @@ static int open_fifo_fd(struct file_desc *d) } static struct file_desc_ops fifo_desc_ops = { - .type = FDINFO_FIFO, + .type = FD_TYPES__FIFO, .open = open_fifo_fd, }; diff --git a/files-reg.c b/files-reg.c index 829608a6f..e6e1c2d22 100644 --- a/files-reg.c +++ b/files-reg.c @@ -160,7 +160,7 @@ static int collect_remaps(void) goto tail; } - fdesc = find_file_desc_raw(FDINFO_REG, rfe->orig_id); + fdesc = find_file_desc_raw(FD_TYPES__REG, rfe->orig_id); if (fdesc == NULL) { pr_err("Remap for non existing file %#x\n", rfe->orig_id); @@ -335,7 +335,7 @@ int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p) } static const struct fdtype_ops regfile_ops = { - .type = FDINFO_REG, + .type = FD_TYPES__REG, .make_gen_id = make_gen_id, .dump = dump_one_reg_file, }; @@ -380,7 +380,7 @@ int open_path_by_id(u32 id, int (*open_cb)(struct reg_file_info *, void *), void { struct file_desc *fd; - fd = find_file_desc_raw(FDINFO_REG, id); + fd = find_file_desc_raw(FD_TYPES__REG, id); if (fd == NULL) { pr_perror("Can't find regfile for %#x\n", id); return -1; @@ -418,7 +418,7 @@ int open_reg_by_id(u32 id) } static struct file_desc_ops reg_desc_ops = { - .type = FDINFO_REG, + .type = FD_TYPES__REG, .open = open_fe_fd, }; diff --git a/files.c b/files.c index 7ec1ab9cf..2270127b8 100644 --- a/files.c +++ b/files.c @@ -186,7 +186,7 @@ static int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info) list_add_tail(&le->desc_list, &l->desc_list); le->desc = fdesc; - if (unlikely(le->fe->type == FDINFO_EVENTPOLL)) + if (unlikely(le->fe->type == FD_TYPES__EVENTPOLL)) list_add_tail(&le->ps_list, &rst_info->eventpoll); else list_add_tail(&le->ps_list, &rst_info->fds); diff --git a/include/image.h b/include/image.h index a2bac69f8..432ac77f5 100644 --- a/include/image.h +++ b/include/image.h @@ -43,20 +43,6 @@ #define INOTIFY_WD_MAGIC 0x54562009 /* Svetlogorsk (Rauschen) */ #define MOUNTPOINTS_MAGIC 0x55563928 /* Petushki */ -enum fd_types { - FDINFO_UND, - FDINFO_REG, - FDINFO_PIPE, - FDINFO_FIFO, - FDINFO_INETSK, - FDINFO_UNIXSK, - FDINFO_EVENTFD, - FDINFO_EVENTPOLL, - FDINFO_INOTIFY, - - FD_INFO_MAX -}; - #define PAGE_IMAGE_SIZE 4096 #define PAGE_RSS 1 #define PAGE_ANON 2 diff --git a/inotify.c b/inotify.c index a5c9c3571..df8c60464 100644 --- a/inotify.c +++ b/inotify.c @@ -92,11 +92,11 @@ static int dump_one_inotify(int lfd, u32 id, const struct fd_parms *p) if (pb_write(fdset_fd(glob_fdset, CR_FD_INOTIFY), &ie, inotify_file_entry)) return -1; - return parse_fdinfo(lfd, FDINFO_INOTIFY, dump_inotify_entry, &id); + return parse_fdinfo(lfd, FD_TYPES__INOTIFY, dump_inotify_entry, &id); } static const struct fdtype_ops inotify_ops = { - .type = FDINFO_INOTIFY, + .type = FD_TYPES__INOTIFY, .make_gen_id = make_gen_id, .dump = dump_one_inotify, }; @@ -195,7 +195,7 @@ static int open_inotify_fd(struct file_desc *d) } static struct file_desc_ops desc_ops = { - .type = FDINFO_INOTIFY, + .type = FD_TYPES__INOTIFY, .open = open_inotify_fd, }; diff --git a/pipes.c b/pipes.c index 918b4a545..587fc4526 100644 --- a/pipes.c +++ b/pipes.c @@ -303,7 +303,7 @@ static int want_transport(FdinfoEntry *fe, struct file_desc *d) } static struct file_desc_ops pipe_desc_ops = { - .type = FDINFO_PIPE, + .type = FD_TYPES__PIPE, .open = open_pipe, .want_transport = want_transport, }; @@ -446,7 +446,7 @@ static int dump_one_pipe(int lfd, u32 id, const struct fd_parms *p) } static const struct fdtype_ops pipe_ops = { - .type = FDINFO_PIPE, + .type = FD_TYPES__PIPE, .make_gen_id = make_gen_id, .dump = dump_one_pipe, }; diff --git a/proc_parse.c b/proc_parse.c index 301579c2a..0d80011a1 100644 --- a/proc_parse.c +++ b/proc_parse.c @@ -16,6 +16,7 @@ #include "proc_parse.h" #include "protobuf.h" +#include "protobuf/fdinfo.pb-c.h" #include @@ -731,7 +732,7 @@ int parse_fdinfo(int fd, int type, if (fdinfo_field(str, "eventfd-count")) { eventfd_file_entry__init(&entry.efd); - if (type != FDINFO_EVENTFD) + if (type != FD_TYPES__EVENTFD) goto parse_err; ret = sscanf(str, "eventfd-count: %lx", &entry.efd.counter); @@ -745,7 +746,7 @@ int parse_fdinfo(int fd, int type, if (fdinfo_field(str, "tfd")) { eventpoll_tfd_entry__init(&entry.epl); - if (type != FDINFO_EVENTPOLL) + if (type != FD_TYPES__EVENTPOLL) goto parse_err; ret = sscanf(str, "tfd: %d events: %x data: %lx", &entry.epl.tfd, &entry.epl.events, &entry.epl.data); @@ -763,7 +764,7 @@ int parse_fdinfo(int fd, int type, inotify_wd_entry__init(&entry.ify); entry.ify.f_handle = &f_handle; - if (type != FDINFO_INOTIFY) + if (type != FD_TYPES__INOTIFY) goto parse_err; ret = sscanf(str, "inotify wd: %8d ino: %16lx sdev: %8x " diff --git a/protobuf/fdinfo.proto b/protobuf/fdinfo.proto index 3b4a57ca4..cedc40062 100644 --- a/protobuf/fdinfo.proto +++ b/protobuf/fdinfo.proto @@ -1,6 +1,18 @@ +enum fd_types { + UND = 0; + REG = 1; + PIPE = 2; + FIFO = 3; + INETSK = 4; + UNIXSK = 5; + EVENTFD = 6; + EVENTPOLL = 7; + INOTIFY = 8; +} + message fdinfo_entry { required uint32 id = 1; required uint32 flags = 2; - required uint32 type = 3; + required fd_types type = 3; required uint32 fd = 4; } diff --git a/sk-inet.c b/sk-inet.c index d2fa4c3cf..fbf85f17d 100644 --- a/sk-inet.c +++ b/sk-inet.c @@ -231,7 +231,7 @@ err: } static const struct fdtype_ops inet_dump_ops = { - .type = FDINFO_INETSK, + .type = FD_TYPES__INETSK, .make_gen_id = make_gen_id, .dump = dump_one_inet_fd, }; @@ -288,7 +288,7 @@ static bool is_bound(struct inet_sk_info *ii) static int open_inet_sk(struct file_desc *d); static struct file_desc_ops inet_desc_ops = { - .type = FDINFO_INETSK, + .type = FD_TYPES__INETSK, .open = open_inet_sk, }; diff --git a/sk-unix.c b/sk-unix.c index e381ed3c5..53f737b2c 100644 --- a/sk-unix.c +++ b/sk-unix.c @@ -220,7 +220,7 @@ err: } static const struct fdtype_ops unix_dump_ops = { - .type = FDINFO_UNIXSK, + .type = FD_TYPES__UNIXSK, .make_gen_id = make_gen_id, .dump = dump_one_unix_fd, }; @@ -709,7 +709,7 @@ static int open_unix_sk(struct file_desc *d) } static struct file_desc_ops unix_desc_ops = { - .type = FDINFO_UNIXSK, + .type = FD_TYPES__UNIXSK, .open = open_unix_sk, .want_transport = unixsk_should_open_transport, };