Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755120Ab2HNOGo (ORCPT ); Tue, 14 Aug 2012 10:06:44 -0400 Received: from mail-lpp01m010-f46.google.com ([209.85.215.46]:57578 "EHLO mail-lpp01m010-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751663Ab2HNOG1 (ORCPT ); Tue, 14 Aug 2012 10:06:27 -0400 Message-Id: <20120814140620.191720208@openvz.org> User-Agent: quilt/0.48-1 Date: Tue, 14 Aug 2012 18:03:47 +0400 From: Cyrill Gorcunov To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Al Viro , Alexey Dobriyan , Andrew Morton , Pavel Emelyanov , James Bottomley , Matthew Helsley , Cyrill Gorcunov , Al Viro Subject: [patch 5/8] fs, epoll: Add procfs fdinfo helper v2 References: <20120814140342.354405844@openvz.org> Content-Disposition: inline; filename=seq-fdinfo-eventpoll-5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3279 Lines: 122 This allow us to print out eventpoll target file descriptor, events and data, the /proc/pid/fdinfo/fd consists of | pos: 0 | flags: 02 | tfd: 5 events: 1d data: ffffffffffffffff This feature is CONFIG_CHECKPOINT_RESTORE only. v2: - don't walk over all rb nodes on seq-next, try to continue from pervious position Signed-off-by: Cyrill Gorcunov CC: Al Viro CC: Alexey Dobriyan CC: Andrew Morton CC: Pavel Emelyanov CC: James Bottomley CC: Matthew Helsley --- fs/eventpoll.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) Index: linux-2.6.git/fs/eventpoll.c =================================================================== --- linux-2.6.git.orig/fs/eventpoll.c +++ linux-2.6.git/fs/eventpoll.c @@ -38,6 +38,8 @@ #include #include #include +#include +#include /* * LOCKING: @@ -1897,6 +1899,69 @@ SYSCALL_DEFINE6(epoll_pwait, int, epfd, return error; } +#if defined(CONFIG_PROC_FS) && defined(CONFIG_CHECKPOINT_RESTORE) + +static void *seq_start(struct seq_file *m, loff_t *pos) +{ + struct proc_fdinfo_extra *extra = m->private; + struct eventpoll *ep = extra->f_file->private_data; + struct rb_node *rbp; + loff_t num = *pos; + + mutex_lock(&ep->mtx); + for (rbp = rb_first(&ep->rbr); rbp; rbp = rb_next(rbp)) { + if (num-- == 0) + return rbp; + } + + return NULL; +} + +static void seq_stop(struct seq_file *m, void *v) +{ + struct proc_fdinfo_extra *extra = m->private; + struct eventpoll *ep = extra->f_file->private_data; + mutex_unlock(&ep->mtx); +} + +static void *seq_next(struct seq_file *m, void *p, loff_t *pos) +{ + struct rb_node *rbp = p; + ++*pos; + return (void *)rb_next(rbp); +} + +static int seq_show(struct seq_file *m, void *v) +{ + struct rb_node *rbp = v; + struct epitem *epi = rb_entry(rbp, struct epitem, rbn); + + return seq_printf(m, "tfd: %8d events: %8x data: %16llx\n", + epi->ffd.fd, epi->event.events, + (long long)epi->event.data); +} + +static const struct seq_operations ep_fdinfo_ops = { + .start = seq_start, + .next = seq_next, + .stop = seq_stop, + .show = seq_show, +}; + +static struct proc_fdinfo_driver ep_fdinfo = { + .name = "eventpoll", + .ops = &ep_fdinfo_ops, + .probe = is_file_epoll, +}; + +static int __init ep_register_fdinfo_driver(void) +{ + return proc_register_fdinfo_driver(&ep_fdinfo); +} +#else +static void ep_register_fdinfo_driver(void) { } +#endif /* CONFIG_PROC_FS && CONFIG_CHECKPOINT_RESTORE */ + static int __init eventpoll_init(void) { struct sysinfo si; @@ -1929,6 +1994,8 @@ static int __init eventpoll_init(void) pwq_cache = kmem_cache_create("eventpoll_pwq", sizeof(struct eppoll_entry), 0, SLAB_PANIC, NULL); + ep_register_fdinfo_driver(); + return 0; } fs_initcall(eventpoll_init); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/