Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964844Ab2EWKlt (ORCPT ); Wed, 23 May 2012 06:41:49 -0400 Received: from mail-bk0-f46.google.com ([209.85.214.46]:39568 "EHLO mail-bk0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758923Ab2EWKkj (ORCPT ); Wed, 23 May 2012 06:40:39 -0400 Message-Id: <20120523104031.079339134@openvz.org> User-Agent: quilt/0.48-1 Date: Wed, 23 May 2012 14:25:46 +0400 From: Cyrill Gorcunov To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Andrew Morton , Pavel Emelyanov , James Bottomley , ebiederm@xmission.com, tj@kernel.org, skinsbursky@openvz.org, Cyrill Gorcunov Subject: [rfc v2 5/7] fs, epoll: Add procfs fdinfo helper References: <20120523102541.382837149@openvz.org> Content-Disposition: inline; filename=seq-fdinfo-eventpoll-4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3489 Lines: 129 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. Signed-off-by: Cyrill Gorcunov CC: Andrew Morton CC: Pavel Emelyanov CC: James Bottomley --- fs/eventpoll.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) Index: linux-2.6.git/fs/eventpoll.c =================================================================== --- linux-2.6.git.orig/fs/eventpoll.c +++ linux-2.6.git/fs/eventpoll.c @@ -37,6 +37,8 @@ #include #include #include +#include +#include /* * LOCKING: @@ -1815,6 +1817,83 @@ SYSCALL_DEFINE6(epoll_pwait, int, epfd, #endif /* HAVE_SET_RESTORE_SIGMASK */ +#if defined(CONFIG_PROC_FS) && defined(CONFIG_CHECKPOINT_RESTORE) + +struct epitem_fdinfo { + struct epoll_event ev; + int fd; +}; + +static struct epitem_fdinfo * +seq_lookup_fdinfo(struct proc_fdinfo_extra *extra, struct eventpoll *ep, loff_t num) +{ + struct epitem_fdinfo *fdinfo = extra->priv; + struct epitem *epi = NULL; + struct rb_node *rbp; + + mutex_lock(&ep->mtx); + for (rbp = rb_first(&ep->rbr); rbp; rbp = rb_next(rbp)) { + if (num-- == 0) { + epi = rb_entry(rbp, struct epitem, rbn); + fdinfo->fd = epi->ffd.fd; + fdinfo->ev = epi->event; + break; + } + } + mutex_unlock(&ep->mtx); + + return epi ? fdinfo : NULL; +} + +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; + + return seq_lookup_fdinfo(extra, ep, *pos); +} + +static void seq_stop(struct seq_file *m, void *v) { } + +static void *seq_next(struct seq_file *m, void *p, loff_t *pos) +{ + struct proc_fdinfo_extra *extra = m->private; + struct eventpoll *ep = extra->f_file->private_data; + ++*pos; + return (void *)seq_lookup_fdinfo(extra, ep, *pos); +} + +static int seq_show(struct seq_file *m, void *v) +{ + struct epitem_fdinfo *fdinfo = v; + seq_printf(m, "tfd: %8d events: %8x data: %16llx\n", + fdinfo->fd, fdinfo->ev.events, + (long long)fdinfo->ev.data); + return 0; +} + +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, + .priv_size = sizeof(struct epitem_fdinfo), +}; + +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; @@ -1847,6 +1926,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/