[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 2 of 4] blktap2: Sort out tapdisk AIO init



# HG changeset patch
# User Daniel Stodden <daniel.stodden@xxxxxxxxxx>
# Date 1258172774 28800
# Node ID 2439e941318745b333e63493af247b9558ddebc2
# Parent  9da64803841f4d8d8816f6d0218cbc6b672f7903
blktap2: Sort out tapdisk AIO init.

Move event callbacks registration into tapdisk-queue. This should also
obsoletes the dummy pollfd pipe in the synchronous I/O case.

diff -r 9da64803841f -r 2439e9413187 tools/blktap2/drivers/io-optimize.c
--- a/tools/blktap2/drivers/io-optimize.c       Fri Nov 13 20:26:13 2009 -0800
+++ b/tools/blktap2/drivers/io-optimize.c       Fri Nov 13 20:26:14 2009 -0800
@@ -51,9 +51,16 @@
 opio_free(struct opioctx *ctx)
 {
        free(ctx->opios);
+       ctx->opios = NULL;
+
        free(ctx->free_opios);
+       ctx->free_opios = NULL;
+
        free(ctx->iocb_queue);
+       ctx->iocb_queue = NULL;
+
        free(ctx->event_queue);
+       ctx->event_queue = NULL;
 }
 
 int
diff -r 9da64803841f -r 2439e9413187 tools/blktap2/drivers/qcow2raw.c
--- a/tools/blktap2/drivers/qcow2raw.c  Fri Nov 13 20:26:13 2009 -0800
+++ b/tools/blktap2/drivers/qcow2raw.c  Fri Nov 13 20:26:14 2009 -0800
@@ -101,12 +101,6 @@
     return;
 }
 
-void
-queue_event(event_id_t id, char mode, void *private)
-{
-  tapdisk_complete_tiocbs(&server.aio_queue);
-}
-
 static void debug_output(uint64_t progress, uint64_t size)
 {
         //Output progress every PROGRESS_QUANT 
diff -r 9da64803841f -r 2439e9413187 tools/blktap2/drivers/tapdisk-queue.c
--- a/tools/blktap2/drivers/tapdisk-queue.c     Fri Nov 13 20:26:13 2009 -0800
+++ b/tools/blktap2/drivers/tapdisk-queue.c     Fri Nov 13 20:26:14 2009 -0800
@@ -35,6 +35,7 @@
 #include "tapdisk-log.h"
 #include "tapdisk-queue.h"
 #include "tapdisk-filter.h"
+#include "tapdisk-server.h"
 #include "atomicio.h"
 
 #define WARN(_f, _a...) tlog_write(TLOG_WARN, _f, ##_a)
@@ -46,7 +47,7 @@
  * so that we can concurrently poll on synchronous and async descriptors.
  * This is signalled by passing 1 as the io context to io_setup.
  */
-#define REQUEST_ASYNC_FD 1
+#define REQUEST_ASYNC_FD ((io_context_t)1)
 
 static inline void
 queue_tiocb(struct tqueue *queue, struct tiocb *tiocb)
@@ -220,6 +221,8 @@
        return split;
 }
 
+static void tapdisk_tiocb_event(event_id_t id, char mode, void *private);
+
 int
 tapdisk_init_queue(struct tqueue *queue, int size,
                   int sync, struct tfilter *filter)
@@ -232,18 +235,18 @@
        queue->sync   = sync;
        queue->filter = filter;
 
-       if (sync) {
-               /* set up a pipe so we can return
-                * a poll fd that won't fire. */
-               if (pipe(queue->dummy_pipe))
-                       return -errno;
-               queue->poll_fd = queue->dummy_pipe[0];
-       } else {
-               queue->aio_ctx = (io_context_t)REQUEST_ASYNC_FD;
+       queue->event   = -1;
+       queue->aio_ctx = NULL;
+
+       if (!size)
+               return 0;
+
+       if (!sync) {
+               queue->aio_ctx = REQUEST_ASYNC_FD;
                queue->poll_fd = io_setup(size, &queue->aio_ctx);
-
-               if (queue->poll_fd < 0) {
-                       if (queue->poll_fd == -EAGAIN)
+               err = queue->poll_fd;
+               if (err < 0) {
+                       if (err == -EAGAIN)
                                DPRINTF("Couldn't setup AIO context.  If you "
                                        "are trying to concurrently use a "
                                        "large number of blktap-based disks, "
@@ -256,8 +259,19 @@
                                        "support.  This is probably because "
                                        "your kernel does not have the "
                                        "aio-poll patch applied.\n");
-                       return queue->poll_fd;
+                       queue->aio_ctx = NULL;
+                       goto fail;
                }
+
+               queue->event =
+                       tapdisk_server_register_event(SCHEDULER_POLL_READ_FD,
+                                                     queue->poll_fd, 0,
+                                                     tapdisk_tiocb_event,
+                                                     queue);
+               err = queue->event;
+               if (err < 0)
+                       goto fail;
+
        }
 
        err               = -ENOMEM;
@@ -280,14 +294,22 @@
 void
 tapdisk_free_queue(struct tqueue *queue)
 {
-       if (queue->sync) {
-               close(queue->dummy_pipe[0]);
-               close(queue->dummy_pipe[1]);
-       } else
+       if (queue->event >= 0) {
+               tapdisk_server_unregister_event(queue->event);
+               queue->event = -1;
+       }
+
+       if (queue->aio_ctx) {
                io_destroy(queue->aio_ctx);
+               queue->aio_ctx = NULL;
+       }
 
        free(queue->iocbs);
+       queue->iocbs = NULL;
+
        free(queue->aio_events);
+       queue->aio_events = NULL;
+
        opio_free(&queue->opioctx);
 }
 
@@ -390,7 +412,7 @@
        return submitted;
 }
 
-int
+static void
 tapdisk_complete_tiocbs(struct tqueue *queue)
 {
        int i, ret, split;
@@ -415,8 +437,13 @@
        }
 
        queue_deferred_tiocbs(queue);
+}
 
-       return split;
+static void
+tapdisk_tiocb_event(event_id_t id, char mode, void *private)
+{
+       struct tqueue *queue = private;
+       tapdisk_complete_tiocbs(queue);
 }
 
 /*
diff -r 9da64803841f -r 2439e9413187 tools/blktap2/drivers/tapdisk-queue.h
--- a/tools/blktap2/drivers/tapdisk-queue.h     Fri Nov 13 20:26:13 2009 -0800
+++ b/tools/blktap2/drivers/tapdisk-queue.h     Fri Nov 13 20:26:14 2009 -0800
@@ -32,6 +32,7 @@
 #include <libaio.h>
 
 #include "io-optimize.h"
+#include "scheduler.h"
 
 struct tiocb;
 struct tfilter;
@@ -57,9 +58,9 @@
        int                   sync;
 
        int                   poll_fd;
+       event_id_t            event;
        io_context_t          aio_ctx;
        struct opioctx        opioctx;
-       int                   dummy_pipe[2];
 
        int                   queued;
        struct iocb         **iocbs;
@@ -104,7 +105,6 @@
 void tapdisk_queue_tiocb(struct tqueue *, struct tiocb *);
 int tapdisk_submit_tiocbs(struct tqueue *);
 int tapdisk_submit_all_tiocbs(struct tqueue *);
-int tapdisk_complete_tiocbs(struct tqueue *);
 int tapdisk_cancel_tiocbs(struct tqueue *);
 int tapdisk_cancel_all_tiocbs(struct tqueue *);
 void tapdisk_prep_tiocb(struct tiocb *, int, int, char *, size_t,
diff -r 9da64803841f -r 2439e9413187 tools/blktap2/drivers/tapdisk-server.c
--- a/tools/blktap2/drivers/tapdisk-server.c    Fri Nov 13 20:26:13 2009 -0800
+++ b/tools/blktap2/drivers/tapdisk-server.c    Fri Nov 13 20:26:14 2009 -0800
@@ -221,19 +221,6 @@
                tapdisk_ipc_write_error(&vbd->ipc, message);
 }
 
-static void
-tapdisk_server_aio_queue_event(event_id_t id, char mode, void *private)
-{
-       tapdisk_complete_tiocbs(&server.aio_queue);
-}
-
-static void
-tapdisk_server_free_aio_queue(void)
-{
-       tapdisk_server_unregister_event(server.aio_queue_event_id);
-       tapdisk_free_queue(&server.aio_queue);
-}
-
 static int
 tapdisk_server_init_ipc(const char *read, const char *write)
 {
@@ -247,34 +234,21 @@
 }
 
 static int
-tapdisk_server_initialize_aio_queue(void)
+tapdisk_server_init_aio(void)
 {
-       int err;
-       event_id_t id;
+       return tapdisk_init_queue(&server.aio_queue, TAPDISK_TIOCBS, 0, NULL);
+}
 
-       err = tapdisk_init_queue(&server.aio_queue,
-                                TAPDISK_TIOCBS, 0, NULL);
-       if (err)
-               return err;
-
-       id = tapdisk_server_register_event(SCHEDULER_POLL_READ_FD,
-                                          server.aio_queue.poll_fd, 0,
-                                          tapdisk_server_aio_queue_event,
-                                          NULL);
-       if (id < 0) {
-               tapdisk_free_queue(&server.aio_queue);
-               return id;
-       }
-
-       server.aio_queue_event_id = id;
-
-       return 0;
+static void
+tapdisk_server_close_aio(void)
+{
+       tapdisk_free_queue(&server.aio_queue);
 }
 
 static void
 tapdisk_server_close(void)
 {
-       tapdisk_server_free_aio_queue();
+       tapdisk_server_close_aio();
        tapdisk_server_close_ipc();
 }
 
@@ -341,7 +315,7 @@
        if (err)
                goto fail;
 
-       err = tapdisk_server_initialize_aio_queue();
+       err = tapdisk_server_init_aio();
        if (err)
                goto fail;
 
diff -r 9da64803841f -r 2439e9413187 tools/blktap2/drivers/tapdisk-server.h
--- a/tools/blktap2/drivers/tapdisk-server.h    Fri Nov 13 20:26:13 2009 -0800
+++ b/tools/blktap2/drivers/tapdisk-server.h    Fri Nov 13 20:26:14 2009 -0800
@@ -58,7 +58,6 @@
        struct list_head             vbds;
        scheduler_t                  scheduler;
        struct tqueue                aio_queue;
-       event_id_t                   aio_queue_event_id;
 } tapdisk_server_t;
 
 #endif

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.