[patch 19/22] pollfs: pollable aio



Submit, retrieve, or poll aio requests for completion through a
file descriptor. User supplies a aio_context_t that is used to
fetch a reference to the kioctx. Once the file descriptor is
closed, the reference is decremented.

Signed-off-by: Davi E. M. Arnaut <davi@xxxxxxxxxxxxx>

---
fs/pollfs/Makefile | 1
fs/pollfs/aio.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++
init/Kconfig | 7 +++
3 files changed, 111 insertions(+)

Index: linux-2.6/fs/pollfs/Makefile
===================================================================
--- linux-2.6.orig/fs/pollfs/Makefile
+++ linux-2.6/fs/pollfs/Makefile
@@ -4,3 +4,4 @@ pollfs-y := file.o
pollfs-$(CONFIG_POLLFS_SIGNAL) += signal.o
pollfs-$(CONFIG_POLLFS_TIMER) += timer.o
pollfs-$(CONFIG_POLLFS_FUTEX) += futex.o
+pollfs-$(CONFIG_POLLFS_AIO) += aio.o
Index: linux-2.6/fs/pollfs/aio.c
===================================================================
--- /dev/null
+++ linux-2.6/fs/pollfs/aio.c
@@ -0,0 +1,103 @@
+/*
+ * pollable aio
+ *
+ * Copyright (C) 2007 Davi E. M. Arnaut
+ *
+ * Licensed under the GNU GPL. See the file COPYING for details.
+ */
+
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/err.h>
+#include <linux/wait.h>
+#include <linux/poll.h>
+#include <linux/pollfs_fs.h>
+#include <linux/aio.h>
+#include <linux/syscalls.h>
+
+struct pfs_aio {
+ struct kioctx *ioctx;
+ struct pfs_file file;
+};
+
+static ssize_t read(struct pfs_aio *evs, struct io_event __user *uioevt)
+{
+ int ret;
+
+ ret = sys_io_getevents(evs->ioctx->user_id, 0, 1, uioevt, NULL);
+
+ if (!ret)
+ ret = -EAGAIN;
+ else if (ret > 0)
+ ret = 0;
+
+ return ret;
+}
+
+static ssize_t write(struct pfs_aio *evs, const struct iocb __user *uiocb)
+{
+ struct iocb iocb;
+
+ if (copy_from_user(&iocb, uiocb, sizeof(iocb)))
+ return -EFAULT;
+
+ return io_submit_one(evs->ioctx, uiocb, &iocb);
+}
+
+static int poll(struct pfs_aio *evs)
+{
+ int ret;
+
+ ret = aio_ring_empty(evs->ioctx) ? 0 : POLLIN;
+
+ return ret;
+}
+
+static int release(struct pfs_aio *evs)
+{
+ put_ioctx(evs->ioctx);
+
+ kfree(evs);
+
+ return 0;
+}
+
+static const struct pfs_operations aio_ops = {
+ .read = PFS_READ(read, struct pfs_aio, struct io_event),
+ .write = PFS_WRITE(write, struct pfs_aio, struct iocb),
+ .poll = PFS_POLL(poll, struct pfs_aio),
+ .release = PFS_RELEASE(release, struct pfs_aio),
+ .rsize = sizeof(struct io_event),
+ .wsize = sizeof(struct iocb),
+};
+
+asmlinkage long sys_plaio(aio_context_t ctx)
+{
+ long error;
+ struct pfs_aio *evs;
+ struct kioctx *ioctx = lookup_ioctx(ctx);
+
+ if (!ioctx)
+ return -EINVAL;
+
+ evs = kzalloc(sizeof(*evs), GFP_KERNEL);
+ if (!evs) {
+ put_ioctx(ioctx);
+ return -ENOMEM;
+ }
+
+ evs->ioctx = ioctx;
+
+ evs->file.data = evs;
+ evs->file.fops = &aio_ops;
+ evs->file.wait = &ioctx->wait;
+
+ error = pfs_open(&evs->file);
+
+ if (error < 0)
+ release(evs);
+
+ return error;
+}
Index: linux-2.6/init/Kconfig
===================================================================
--- linux-2.6.orig/init/Kconfig
+++ linux-2.6/init/Kconfig
@@ -490,6 +490,13 @@ config POLLFS_FUTEX
help
Pollable futex support

+config POLLFS_AIO
+ bool "Enable pollfs aio" if EMBEDDED
+ default y
+ depends on POLLFS
+ help
+ Pollable aio support
+
config SHMEM
bool "Use full shmem filesystem" if EMBEDDED
default y

--
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • [patch 10/12] pollfs: pollable aio
    ... Submit, retrieve, or poll aio requests for completion through a ... file descriptor. ... config SHMEM ...
    (Linux-Kernel)
  • Re: Can a file be deleted even if it is in use.
    ... file, a program uses a 'file descriptor' (small, positive ... ultimatively resolves to the i-node of the file. ... The file reference count in the i-node is used to track the ... If that is still larger than zero afterwards, ...
    (comp.unix.programmer)
  • Re: a question about socket-syscall, thinks
    ... - References can be owned by file descriptor arrays (struct filedesc). ... fallocinitialized the file descriptor reference count to 1 to reflect ... descriptor array for the process, however (i.e., the reference count drops ...
    (freebsd-net)
  • Re: Re: Proposal: a revoke() system call
    ... to the file descriptor you want to revoke, ... socket in a blocking I/O call from another thread -- you first have to call shutdown, ... This has caused problems for Java in the past, but I'm not sure that it's really a bug given that it's not unreasonable behavior not rejected by the spec :-). ... The problem with that is that it creates a lot more contention on the socket locks when the reference count is dropped, not to mention more locking operations. ...
    (freebsd-arch)
  • Re: close() of active socket does not work on FreeBSD 6
    ... Whatever may be implemented to solve this issue will require a fairly serious re-working of how we implement file descriptor reference counting in the kernel. ... Do you propose similar "cancellation" of other system calls blocked on the file descriptor, including select, etc? ... Typically these system calls interact with the underlying object associated with the file descriptor, not the file descriptor itself, and often, they act directly on the object and release the file descriptor before performing their operation. ...
    (freebsd-arch)