2012-05-17 16:26:27

by Cyrill Gorcunov

[permalink] [raw]
Subject: [rfc 3/4] fs, eventfd: Add procfs fdinfo helper

This allow us to print out raw counter value.
So the /proc/pid/fdinfo/fd look like

| pos: 0
| flags: 04002
| eventfd-count: 5a

Signed-off-by: Cyrill Gorcunov <[email protected]>
---
fs/eventfd.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)

Index: linux-2.6.git/fs/eventfd.c
===================================================================
--- linux-2.6.git.orig/fs/eventfd.c
+++ linux-2.6.git/fs/eventfd.c
@@ -19,6 +19,8 @@
#include <linux/export.h>
#include <linux/kref.h>
#include <linux/eventfd.h>
+#include <linux/proc_fs.h>
+#include <linux/seq_file.h>

struct eventfd_ctx {
struct kref kref;
@@ -437,3 +439,58 @@ SYSCALL_DEFINE1(eventfd, unsigned int, c
return sys_eventfd2(count, 0);
}

+#ifdef CONFIG_PROC_FS
+
+static void *seq_start(struct seq_file *m, loff_t *pos)
+{
+ struct proc_fdinfo_extra *extra = m->private;
+ return *pos == 1 ? extra->fd_file : NULL;
+}
+
+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;
+ return ++*pos == 1 ? extra->fd_file : NULL;
+}
+
+static int seq_show(struct seq_file *m, void *v)
+{
+ struct eventfd_ctx *ctx = ((struct file *)v)->private_data;
+
+ spin_lock_irq(&ctx->wqh.lock);
+ seq_printf(m, "eventfd-count: %16llx\n",
+ (unsigned long long)ctx->count);
+ spin_unlock_irq(&ctx->wqh.lock);
+
+ return 0;
+}
+
+static const struct seq_operations eventfd_fdinfo_ops = {
+ .start = seq_start,
+ .next = seq_next,
+ .stop = seq_stop,
+ .show = seq_show,
+};
+
+static int eventfd_fdinfo_probe(struct file *file)
+{
+ return file->f_op == &eventfd_fops;
+}
+
+static struct proc_fdinfo_helper eventfd_fdinfo_helper = {
+ .name = "evetfd",
+ .ops = &eventfd_fdinfo_ops,
+ .probe = eventfd_fdinfo_probe,
+};
+
+static int __init eventfd_init(void)
+{
+ return proc_register_fdinfo_helper(&eventfd_fdinfo_helper);
+}
+fs_initcall(eventfd_init);
+
+#endif /* CONFIG_PROC_FS */


2012-05-17 16:35:08

by Pavel Emelyanov

[permalink] [raw]
Subject: Re: [rfc 3/4] fs, eventfd: Add procfs fdinfo helper

> +static void *seq_start(struct seq_file *m, loff_t *pos)
> +{
> + struct proc_fdinfo_extra *extra = m->private;
> + return *pos == 1 ? extra->fd_file : NULL;
> +}
> +
> +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;
> + return ++*pos == 1 ? extra->fd_file : NULL;
> +}
> +

<snip>

> +static const struct seq_operations eventfd_fdinfo_ops = {
> + .start = seq_start,
> + .next = seq_next,
> + .stop = seq_stop,
> + .show = seq_show,

I think, you can use the single_ part of the seq files engine.

> +};

Thanks,
Pavel

2012-05-17 17:43:32

by Cyrill Gorcunov

[permalink] [raw]
Subject: Re: [rfc 3/4] fs, eventfd: Add procfs fdinfo helper

On Thu, May 17, 2012 at 08:34:59PM +0400, Pavel Emelyanov wrote:
> <snip>
>
> > +static const struct seq_operations eventfd_fdinfo_ops = {
> > + .start = seq_start,
> > + .next = seq_next,
> > + .stop = seq_stop,
> > + .show = seq_show,
>
> I think, you can use the single_ part of the seq files engine.

single_stop only, since for other cases this seq methods should
provide data iif pos is 1.

Cyrill