qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [RFC 3/5] nbd: Use aio_set_fd_handler2()


From: Max Reitz
Subject: [Qemu-devel] [RFC 3/5] nbd: Use aio_set_fd_handler2()
Date: Sat, 31 May 2014 20:43:10 +0200

Instead of using the main loop function qemu_set_fd_handler2(), use the
AIO function in the context of the exported BDS.

Signed-off-by: Max Reitz <address@hidden>
---
 nbd.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/nbd.c b/nbd.c
index 0787cba..803b3d7 100644
--- a/nbd.c
+++ b/nbd.c
@@ -18,6 +18,7 @@
 
 #include "block/nbd.h"
 #include "block/block.h"
+#include "block/block_int.h"
 
 #include "block/coroutine.h"
 
@@ -100,6 +101,8 @@ struct NBDExport {
     uint32_t nbdflags;
     QTAILQ_HEAD(, NBDClient) clients;
     QTAILQ_ENTRY(NBDExport) next;
+
+    AioContext *ctx;
 };
 
 static QTAILQ_HEAD(, NBDExport) exports = QTAILQ_HEAD_INITIALIZER(exports);
@@ -744,7 +747,10 @@ void nbd_client_put(NBDClient *client)
          */
         assert(client->closing);
 
-        qemu_set_fd_handler2(client->sock, NULL, NULL, NULL, NULL);
+        if (client->exp) {
+            aio_set_fd_handler2(client->exp->ctx, client->sock,
+                                NULL, NULL, NULL, NULL);
+        }
         close(client->sock);
         client->sock = -1;
         if (client->exp) {
@@ -797,7 +803,7 @@ static void nbd_request_put(NBDRequest *req)
     g_slice_free(NBDRequest, req);
 
     if (client->nb_requests-- == MAX_NBD_REQUESTS) {
-        qemu_notify_event();
+        aio_notify(client->exp->ctx);
     }
     nbd_client_put(client);
 }
@@ -814,6 +820,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t 
dev_offset,
     exp->nbdflags = nbdflags;
     exp->size = size == -1 ? bdrv_getlength(bs) : size;
     exp->close = close;
+    exp->ctx = bdrv_get_aio_context(bs);
     bdrv_ref(bs);
     return exp;
 }
@@ -917,8 +924,8 @@ static ssize_t nbd_co_send_reply(NBDRequest *req, struct 
nbd_reply *reply,
     ssize_t rc, ret;
 
     qemu_co_mutex_lock(&client->send_lock);
-    qemu_set_fd_handler2(csock, nbd_can_read, nbd_read,
-                         nbd_restart_write, client);
+    aio_set_fd_handler2(client->exp->ctx, csock,
+                        nbd_can_read, nbd_read, nbd_restart_write, client);
     client->send_coroutine = qemu_coroutine_self();
 
     if (!len) {
@@ -936,7 +943,8 @@ static ssize_t nbd_co_send_reply(NBDRequest *req, struct 
nbd_reply *reply,
     }
 
     client->send_coroutine = NULL;
-    qemu_set_fd_handler2(csock, nbd_can_read, nbd_read, NULL, client);
+    aio_set_fd_handler2(client->exp->ctx, csock,
+                        nbd_can_read, nbd_read, NULL, client);
     qemu_co_mutex_unlock(&client->send_lock);
     return rc;
 }
@@ -1179,7 +1187,8 @@ NBDClient *nbd_client_new(NBDExport *exp, int csock,
     }
     client->close = close;
     qemu_co_mutex_init(&client->send_lock);
-    qemu_set_fd_handler2(csock, nbd_can_read, nbd_read, NULL, client);
+    aio_set_fd_handler2(client->exp->ctx, csock,
+                        nbd_can_read, nbd_read, NULL, client);
 
     if (exp) {
         QTAILQ_INSERT_TAIL(&exp->clients, client, next);
-- 
1.9.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]