The patch titled
     signal/timer/event: KAIO eventfd support example
has been added to the -mm tree.  Its filename is
     signal-timer-event-fds-v9-kaio-eventfd-support-example.patch

*** Remember to use Documentation/SubmitChecklist when testing your code ***

See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find
out what to do about this

------------------------------------------------------
Subject: signal/timer/event: KAIO eventfd support example
From: Davide Libenzi <[email protected]>

This is an example about how to add eventfd support to the current KAIO code,
in order to enable KAIO to post readiness events to a pollable fd (hence
compatible with POSIX select/poll).  The KAIO code simply signals the eventfd
fd when events are ready, and this triggers a POLLIN in the fd.  This patch
uses a reserved for future use member of the struct iocb to pass an eventfd
file descriptor, that KAIO will use to post events every time a request
completes.  At that point, an aio_getevents() will return the completed result
to a struct io_event.  I made a quick test program to verify the patch, and it
runs fine here:

http://www.xmailserver.org/eventfd-aio-test.c

The test program uses poll(2), but it'd, of course, work with select and epoll
too.

This can allow to schedule both block I/O and other poll-able devices
requests, and wait for results using select/poll/epoll.  In a typical
scenario, an application would submit KAIO request using aio_submit(), and
will also use epoll_ctl() on the whole other class of devices (that with the
addition of signals, timers and user events, now it's pretty much complete),
and then would:

        epoll_wait(...);
        for_each_event {
                if (curr_event_is_kaiofd) {
                        aio_getevents();
                        dispatch_aio_events();
                } else {
                        dispatch_epoll_event();
                }
        }

Signed-off-by: Davide Libenzi <[email protected]>
Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
---

 fs/aio.c                |   25 +++++++++++++++++++++++++
 include/linux/aio.h     |    6 ++++++
 include/linux/aio_abi.h |    6 +++++-
 3 files changed, 36 insertions(+), 1 deletion(-)

diff -puN fs/aio.c~signal-timer-event-fds-v9-kaio-eventfd-support-example 
fs/aio.c
--- a/fs/aio.c~signal-timer-event-fds-v9-kaio-eventfd-support-example
+++ a/fs/aio.c
@@ -30,6 +30,7 @@
 #include <linux/highmem.h>
 #include <linux/workqueue.h>
 #include <linux/security.h>
+#include <linux/eventfd.h>
 
 #include <asm/kmap_types.h>
 #include <asm/uaccess.h>
@@ -419,6 +420,7 @@ static struct kiocb fastcall *__aio_get_
        req->private = NULL;
        req->ki_iovec = NULL;
        INIT_LIST_HEAD(&req->ki_run_list);
+       req->ki_eventfd = ERR_PTR(-EINVAL);
 
        /* Check if the completion queue has enough free space to
         * accept an event from this io.
@@ -460,6 +462,8 @@ static inline void really_put_req(struct
 {
        assert_spin_locked(&ctx->ctx_lock);
 
+       if (!IS_ERR(req->ki_eventfd))
+               fput(req->ki_eventfd);
        if (req->ki_dtor)
                req->ki_dtor(req);
        if (req->ki_iovec != &req->ki_inline_vec)
@@ -944,6 +948,14 @@ int fastcall aio_complete(struct kiocb *
                return 1;
        }
 
+       /*
+        * Check if the user asked us to deliver the result through an
+        * eventfd. The eventfd_signal() function is safe to be called
+        * from IRQ context.
+        */
+       if (!IS_ERR(iocb->ki_eventfd))
+               eventfd_signal(iocb->ki_eventfd, 1);
+
        info = &ctx->ring_info;
 
        /* add a completion event to the ring buffer.
@@ -1553,6 +1565,19 @@ int fastcall io_submit_one(struct kioctx
                fput(file);
                return -EAGAIN;
        }
+       if (iocb->aio_resfd != 0) {
+               /*
+                * If the aio_resfd field of the iocb is not zero, get an
+                * instance of the file* now. The file descriptor must be
+                * an eventfd() fd, and will be signaled for each completed
+                * event using the eventfd_signal() function.
+                */
+               req->ki_eventfd = eventfd_fget((int) iocb->aio_resfd);
+               if (IS_ERR(req->ki_eventfd)) {
+                       ret = PTR_ERR(req->ki_eventfd);
+                       goto out_put_req;
+               }
+       }
 
        req->ki_filp = file;
        ret = put_user(req->ki_key, &user_iocb->aio_key);
diff -puN 
include/linux/aio.h~signal-timer-event-fds-v9-kaio-eventfd-support-example 
include/linux/aio.h
--- a/include/linux/aio.h~signal-timer-event-fds-v9-kaio-eventfd-support-example
+++ a/include/linux/aio.h
@@ -119,6 +119,12 @@ struct kiocb {
 
        struct list_head        ki_list;        /* the aio core uses this
                                                 * for cancellation */
+
+       /*
+        * If the aio_resfd field of the userspace iocb is not zero,
+        * this is the underlying file* to deliver event to.
+        */
+       struct file             *ki_eventfd;
 };
 
 #define is_sync_kiocb(iocb)    ((iocb)->ki_key == KIOCB_SYNC_KEY)
diff -puN 
include/linux/aio_abi.h~signal-timer-event-fds-v9-kaio-eventfd-support-example 
include/linux/aio_abi.h
--- 
a/include/linux/aio_abi.h~signal-timer-event-fds-v9-kaio-eventfd-support-example
+++ a/include/linux/aio_abi.h
@@ -84,7 +84,11 @@ struct iocb {
 
        /* extra parameters */
        __u64   aio_reserved2;  /* TODO: use this for a (struct sigevent *) */
-       __u64   aio_reserved3;
+       __u32   aio_reserved3;
+       /*
+        * If different from 0, this is an eventfd to deliver AIO results to
+        */
+       __u32   aio_resfd;
 }; /* 64 bytes */
 
 #undef IFBIG
_

Patches currently in -mm which might be from [email protected] are

origin.patch
epoll-optimizations-and-cleanups.patch
epoll-optimizations-and-cleanups-tidy.patch
signal-timer-event-fds-v9-anonymous-inode-source.patch
signal-timer-event-fds-v9-signalfd-core.patch
signal-timer-event-fds-v9-signalfd-wire-up-i386-arch.patch
signal-timer-event-fds-v9-signalfd-wire-up-x86_64-arch.patch
signal-timer-event-fds-v9-signalfd-compat-code.patch
signal-timer-event-fds-v9-timerfd-core.patch
signal-timer-event-fds-v9-timerfd-wire-up-i386-arch.patch
signal-timer-event-fds-v9-timerfd-wire-up-x86_64-arch.patch
signal-timer-event-fds-v9-timerfd-compat-code.patch
signal-timer-event-fds-v9-eventfd-core.patch
signal-timer-event-fds-v9-eventfd-wire-up-i386-arch.patch
signal-timer-event-fds-v9-eventfd-wire-up-x86_64-arch.patch
signal-timer-event-fds-v9-kaio-eventfd-support-example.patch

-
To unsubscribe from this list: send the line "unsubscribe mm-commits" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to