From 9917c4fe347bdc2cc9d24a2e031b8808420be99c Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 21 Aug 2013 01:06:58 +0400 Subject: [PATCH] rst: Compact file-descs collects a bit Signed-off-by: Pavel Emelyanov --- eventfd.c | 4 +--- eventpoll.c | 4 +--- fifo.c | 5 ++--- files-reg.c | 4 +--- files.c | 4 +++- fsnotify.c | 8 ++------ include/files.h | 2 +- namespaces.c | 5 +---- pipes.c | 4 +--- signalfd.c | 4 +--- sk-inet.c | 3 +-- sk-netlink.c | 4 +--- sk-packet.c | 4 +--- sk-unix.c | 4 +--- tty.c | 4 +--- 15 files changed, 19 insertions(+), 44 deletions(-) diff --git a/eventfd.c b/eventfd.c index 9e85ec3ef..bbb5a5b35 100644 --- a/eventfd.c +++ b/eventfd.c @@ -122,10 +122,8 @@ static int collect_one_efd(void *obj, ProtobufCMessage *msg) struct eventfd_file_info *info = obj; info->efe = pb_msg(msg, EventfdFileEntry); - file_desc_add(&info->d, info->efe->id, &eventfd_desc_ops); pr_info_eventfd("Collected ", info->efe); - - return 0; + return file_desc_add(&info->d, info->efe->id, &eventfd_desc_ops); } int collect_eventfd(void) diff --git a/eventpoll.c b/eventpoll.c index 03840cecd..92a5bcc96 100644 --- a/eventpoll.c +++ b/eventpoll.c @@ -181,10 +181,8 @@ static int collect_one_epoll(void *o, ProtobufCMessage *msg) struct eventpoll_file_info *info = o; info->efe = pb_msg(msg, EventpollFileEntry); - file_desc_add(&info->d, info->efe->id, &desc_ops); pr_info_eventpoll("Collected ", info->efe); - - return 0; + return file_desc_add(&info->d, info->efe->id, &desc_ops); } int collect_eventpoll(void) diff --git a/fifo.c b/fifo.c index 41bea017f..738957274 100644 --- a/fifo.c +++ b/fifo.c @@ -125,8 +125,6 @@ static int collect_one_fifo(void *o, ProtobufCMessage *base) pr_info("Collected fifo entry ID %#x PIPE ID %#x\n", info->fe->id, info->fe->pipe_id); - file_desc_add(&info->d, info->fe->id, &fifo_desc_ops); - /* check who will restore the fifo data */ list_for_each_entry(f, &fifo_head, list) if (f->fe->pipe_id == info->fe->pipe_id) @@ -140,7 +138,8 @@ static int collect_one_fifo(void *o, ProtobufCMessage *base) info->restore_data = false; } - return 0; + return file_desc_add(&info->d, info->fe->id, &fifo_desc_ops); + } int collect_fifo(void) diff --git a/files-reg.c b/files-reg.c index d0de0ebf1..16f64424e 100644 --- a/files-reg.c +++ b/files-reg.c @@ -556,9 +556,7 @@ static int collect_one_regfile(void *o, ProtobufCMessage *base) rfi->remap = NULL; pr_info("Collected [%s] ID %#x\n", rfi->path, rfi->rfe->id); - file_desc_add(&rfi->d, rfi->rfe->id, ®_desc_ops); - - return 0; + return file_desc_add(&rfi->d, rfi->rfe->id, ®_desc_ops); } int prepare_shared_reg_files(void) diff --git a/files.c b/files.c index 814448bfb..3cee3fae5 100644 --- a/files.c +++ b/files.c @@ -53,13 +53,15 @@ int prepare_shared_fdinfo(void) return 0; } -void file_desc_add(struct file_desc *d, u32 id, struct file_desc_ops *ops) +int file_desc_add(struct file_desc *d, u32 id, struct file_desc_ops *ops) { d->id = id; d->ops = ops; INIT_LIST_HEAD(&d->fd_info_head); hlist_add_head(&d->hash, &file_desc_hash[id % FDESC_HASH_SIZE]); + + return 0; /* this is to make tail-calls in collect_one_foo look nice */ } struct file_desc *find_file_desc_raw(int type, u32 id) diff --git a/fsnotify.c b/fsnotify.c index 24d334061..69ce85333 100644 --- a/fsnotify.c +++ b/fsnotify.c @@ -455,10 +455,8 @@ static int collect_one_inotify(void *o, ProtobufCMessage *msg) info->ife = pb_msg(msg, InotifyFileEntry); INIT_LIST_HEAD(&info->marks); list_add(&info->list, &inotify_info_head); - file_desc_add(&info->d, info->ife->id, &inotify_desc_ops); pr_info("Collected id 0x%08x flags 0x%08x\n", info->ife->id, info->ife->flags); - - return 0; + return file_desc_add(&info->d, info->ife->id, &inotify_desc_ops); } static int collect_one_fanotify(void *o, ProtobufCMessage *msg) @@ -468,10 +466,8 @@ static int collect_one_fanotify(void *o, ProtobufCMessage *msg) info->ffe = pb_msg(msg, FanotifyFileEntry); INIT_LIST_HEAD(&info->marks); list_add(&info->list, &fanotify_info_head); - file_desc_add(&info->d, info->ffe->id, &fanotify_desc_ops); pr_info("Collected id 0x%08x flags 0x%08x\n", info->ffe->id, info->ffe->flags); - - return 0; + return file_desc_add(&info->d, info->ffe->id, &fanotify_desc_ops); } static int collect_one_inotify_mark(void *o, ProtobufCMessage *msg) diff --git a/include/files.h b/include/files.h index b1e1a02dd..c92f3ed21 100644 --- a/include/files.h +++ b/include/files.h @@ -117,7 +117,7 @@ struct parasite_drain_fd; int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item, struct parasite_drain_fd *dfds); -extern void file_desc_add(struct file_desc *d, u32 id, struct file_desc_ops *ops); +extern int file_desc_add(struct file_desc *d, u32 id, struct file_desc_ops *ops); extern struct fdinfo_list_entry *file_master(struct file_desc *d); extern struct file_desc *find_file_desc_raw(int type, u32 id); diff --git a/namespaces.c b/namespaces.c index f9cc3cbc2..8088b838e 100644 --- a/namespaces.c +++ b/namespaces.c @@ -293,11 +293,8 @@ static int collect_one_nsfile(void *o, ProtobufCMessage *base) struct ns_file_info *nfi = o; nfi->nfe = pb_msg(base, NsFileEntry); - pr_info("Collected ns file ID %#x NS-ID %#x\n", nfi->nfe->id, nfi->nfe->ns_id); - file_desc_add(&nfi->d, nfi->nfe->id, &ns_desc_ops); - - return 0; + return file_desc_add(&nfi->d, nfi->nfe->id, &ns_desc_ops); } int collect_ns_files(void) diff --git a/pipes.c b/pipes.c index 1110b1282..ecaa1ba32 100644 --- a/pipes.c +++ b/pipes.c @@ -375,8 +375,6 @@ static int collect_one_pipe(void *o, ProtobufCMessage *base) pr_info("Collected pipe entry ID %#x PIPE ID %#x\n", pi->pe->id, pi->pe->pipe_id); - file_desc_add(&pi->d, pi->pe->id, &pipe_desc_ops); - list_for_each_entry(tmp, &pipes, list) if (pi->pe->pipe_id == tmp->pe->pipe_id) break; @@ -387,8 +385,8 @@ static int collect_one_pipe(void *o, ProtobufCMessage *base) list_add(&pi->pipe_list, &tmp->pipe_list); list_add_tail(&pi->list, &pipes); + return file_desc_add(&pi->d, pi->pe->id, &pipe_desc_ops); - return 0; } int collect_pipes(void) diff --git a/signalfd.c b/signalfd.c index 1a26caafa..1b92d05c4 100644 --- a/signalfd.c +++ b/signalfd.c @@ -117,9 +117,7 @@ static int collect_one_sigfd(void *o, ProtobufCMessage *msg) struct signalfd_info *info = o; info->sfe = pb_msg(msg, SignalfdEntry); - file_desc_add(&info->d, info->sfe->id, &signalfd_desc_ops); - - return 0; + return file_desc_add(&info->d, info->sfe->id, &signalfd_desc_ops); } int collect_signalfd(void) diff --git a/sk-inet.c b/sk-inet.c index a540e7bdd..40c7a7f2c 100644 --- a/sk-inet.c +++ b/sk-inet.c @@ -386,7 +386,6 @@ static int collect_one_inetsk(void *o, ProtobufCMessage *base) struct inet_sk_info *ii = o; ii->ie = pb_msg(base, InetSkEntry); - file_desc_add(&ii->d, ii->ie->id, &inet_desc_ops); if (tcp_connection(ii->ie)) tcp_locked_conn_add(ii); @@ -399,7 +398,7 @@ static int collect_one_inetsk(void *o, ProtobufCMessage *base) if (ii->port == NULL) return -1; - return 0; + return file_desc_add(&ii->d, ii->ie->id, &inet_desc_ops); } int collect_inet_sockets(void) diff --git a/sk-netlink.c b/sk-netlink.c index 6cb49a5ad..c6f6f0bdf 100644 --- a/sk-netlink.c +++ b/sk-netlink.c @@ -231,9 +231,7 @@ static int collect_one_netlink_sk(void *o, ProtobufCMessage *base) struct netlink_sock_info *si = o; si->nse = pb_msg(base, NetlinkSkEntry); - file_desc_add(&si->d, si->nse->id, &netlink_sock_desc_ops); - - return 0; + return file_desc_add(&si->d, si->nse->id, &netlink_sock_desc_ops); } int collect_netlink_sockets(void) diff --git a/sk-packet.c b/sk-packet.c index ef4479f79..702e02ab1 100644 --- a/sk-packet.c +++ b/sk-packet.c @@ -496,9 +496,7 @@ static int collect_one_packet_sk(void *o, ProtobufCMessage *base) struct packet_sock_info *si = o; si->pse = pb_msg(base, PacketSockEntry); - file_desc_add(&si->d, si->pse->id, &packet_sock_desc_ops); - - return 0; + return file_desc_add(&si->d, si->pse->id, &packet_sock_desc_ops); } int collect_packet_sockets(void) diff --git a/sk-unix.c b/sk-unix.c index 01050410e..6c2a292a8 100644 --- a/sk-unix.c +++ b/sk-unix.c @@ -822,10 +822,8 @@ static int collect_one_unixsk(void *o, ProtobufCMessage *base) pr_info(" `- Got %#x peer %#x (name %s)\n", ui->ue->ino, ui->ue->peer, ui->name ? (ui->name[0] ? ui->name : &ui->name[1]) : "-"); - file_desc_add(&ui->d, ui->ue->id, &unix_desc_ops); list_add_tail(&ui->list, &unix_sockets); - - return 0; + return file_desc_add(&ui->d, ui->ue->id, &unix_desc_ops); } int collect_unix_sockets(void) diff --git a/tty.c b/tty.c index 014b81729..09c97995b 100644 --- a/tty.c +++ b/tty.c @@ -972,9 +972,7 @@ static int collect_one_tty(void *obj, ProtobufCMessage *msg) pr_info("Collected tty ID %#x\n", info->tfe->id); list_add(&info->list, &all_ttys); - file_desc_add(&info->d, info->tfe->id, &tty_desc_ops); - - return 0; + return file_desc_add(&info->d, info->tfe->id, &tty_desc_ops); } int collect_tty(void)