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

[Xen-devel] [PATCH 1 of 4] blktap2: Sort out tapdisk IPC init



# HG changeset patch
# User Daniel Stodden <daniel.stodden@xxxxxxxxxx>
# Date 1258172773 28800
# Node ID aa0d1795f1ecfdc7e235b9ada87fb7a71e455f7f
# Parent  aa1ad4c5c931e0c402dc2c8356d1604a156d02f0
blktap2: Sort out tapdisk IPC init.

Move I/O and event callbacks setup out of tapdisk-server, into tapdisk-ipc.

Signed-off-by: Daniel Stodden <daniel.stodden@xxxxxxxxxx>

diff -r aa1ad4c5c931 -r aa0d1795f1ec tools/blktap2/drivers/tapdisk-ipc.c
--- a/tools/blktap2/drivers/tapdisk-ipc.c       Thu Jan 28 23:30:21 2010 -0800
+++ b/tools/blktap2/drivers/tapdisk-ipc.c       Fri Nov 13 20:26:13 2009 -0800
@@ -30,12 +30,86 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#include <fcntl.h>
 
 #include "tapdisk.h"
 #include "tapdisk-ipc.h"
 #include "tapdisk-vbd.h"
 #include "tapdisk-server.h"
 
+static void
+tapdisk_ipc_read_event(event_id_t id, char mode, void *private)
+{
+       td_ipc_t *ipc = private;
+       tapdisk_ipc_read(ipc);
+}
+
+static void
+__tapdisk_ipc_init(td_ipc_t *ipc)
+{
+       ipc->rfd = -1;
+       ipc->wfd = -1;
+       ipc->rfd_event = -1;
+}
+
+int
+tapdisk_ipc_open(td_ipc_t *ipc, const char *read, const char *write)
+{
+       int err;
+
+       memset(ipc, 0, sizeof(td_ipc_t));
+       __tapdisk_ipc_init(ipc);
+
+       if (read) {
+               ipc->rfd = open(read, O_RDWR | O_NONBLOCK);
+               if (ipc->rfd < 0) {
+                       err = -errno;
+                       EPRINTF("FD open failed %s: %d\n", read, err);
+                       goto fail;
+               }
+
+               ipc->rfd_event = 
+                       tapdisk_server_register_event(SCHEDULER_POLL_READ_FD,
+                                                     ipc->rfd, 0,
+                                                     tapdisk_ipc_read_event,
+                                                     ipc);
+               if (ipc->rfd_event < 0) {
+                       err = ipc->rfd_event;
+                       goto fail;
+               }
+       }
+
+       if (write) {
+               ipc->wfd = open(write, O_RDWR | O_NONBLOCK);
+               if (ipc->wfd < 0) {
+                       err = -errno;
+                       EPRINTF("FD open failed %s, %d\n", write, err);
+                       goto fail;
+               }
+       }
+
+       return 0;
+
+fail:
+       tapdisk_ipc_close(ipc);
+       return err;
+}
+
+void
+tapdisk_ipc_close(td_ipc_t *ipc)
+{
+       if (ipc->rfd > 0)
+               close(ipc->rfd);
+
+       if (ipc->wfd > 0)
+               close(ipc->wfd);
+
+       if (ipc->rfd_event >= 0)
+               tapdisk_server_unregister_event(ipc->rfd_event);
+
+       __tapdisk_ipc_init(ipc);
+}
+
 static int
 tapdisk_ipc_write_message(int fd, tapdisk_message_t *message, int timeout)
 {
diff -r aa1ad4c5c931 -r aa0d1795f1ec tools/blktap2/drivers/tapdisk-ipc.h
--- a/tools/blktap2/drivers/tapdisk-ipc.h       Thu Jan 28 23:30:21 2010 -0800
+++ b/tools/blktap2/drivers/tapdisk-ipc.h       Fri Nov 13 20:26:13 2009 -0800
@@ -29,13 +29,17 @@
 #define _TAPDISK_IPC_H_
 
 #include "tapdisk-message.h"
+#include "scheduler.h"
 
 typedef struct td_ipc_handle {
        int                         rfd;
        int                         wfd;
+       event_id_t                  rfd_event;
        td_uuid_t                   uuid;
 } td_ipc_t;
 
+int tapdisk_ipc_open(td_ipc_t *ipc, const char *read, const char *write);
+void tapdisk_ipc_close(td_ipc_t *ipc);
 int tapdisk_ipc_read(td_ipc_t *ipc);
 int tapdisk_ipc_write(td_ipc_t *ipc, int type);
 int tapdisk_ipc_write_error(td_ipc_t *ipc, const char *message);
diff -r aa1ad4c5c931 -r aa0d1795f1ec tools/blktap2/drivers/tapdisk-server.c
--- a/tools/blktap2/drivers/tapdisk-server.c    Thu Jan 28 23:30:21 2010 -0800
+++ b/tools/blktap2/drivers/tapdisk-server.c    Fri Nov 13 20:26:13 2009 -0800
@@ -26,7 +26,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #include <stdio.h>
-#include <fcntl.h>
 #include <errno.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -223,12 +222,6 @@
 }
 
 static void
-tapdisk_server_read_ipc_message(event_id_t id, char mode, void *private)
-{
-       tapdisk_ipc_read(&server.ipc);
-}
-
-static void
 tapdisk_server_aio_queue_event(event_id_t id, char mode, void *private)
 {
        tapdisk_complete_tiocbs(&server.aio_queue);
@@ -242,6 +235,18 @@
 }
 
 static int
+tapdisk_server_init_ipc(const char *read, const char *write)
+{
+       return tapdisk_ipc_open(&server.ipc, read, write);
+}
+
+static void
+tapdisk_server_close_ipc(void)
+{
+       tapdisk_ipc_close(&server.ipc);
+}
+
+static int
 tapdisk_server_initialize_aio_queue(void)
 {
        int err;
@@ -270,15 +275,7 @@
 tapdisk_server_close(void)
 {
        tapdisk_server_free_aio_queue();
-
-       if (server.control_event)
-               scheduler_unregister_event(&server.scheduler, 
server.control_event);
-
-       if (server.ipc.rfd != -1)
-               close(server.ipc.rfd);
-
-       if (server.ipc.wfd != -1)
-               close(server.ipc.wfd);
+       tapdisk_server_close_ipc();
 }
 
 static void
@@ -334,63 +331,26 @@
 tapdisk_server_initialize(const char *read, const char *write)
 {
        int err;
-       event_id_t event_id;
 
-       event_id = 0;
        memset(&server, 0, sizeof(tapdisk_server_t));
-       server.ipc.rfd = server.ipc.wfd = -1;
-
        INIT_LIST_HEAD(&server.vbds);
 
-       if (read) {
-               server.ipc.rfd = open(read, O_RDWR | O_NONBLOCK);
-               if (server.ipc.rfd < 0) {
-                       err = -errno;
-                       EPRINTF("FD open failed %s: %d\n", read, err);
-                       goto fail;
-               }
-       }
-
-       if (write) {
-               server.ipc.wfd = open(write, O_RDWR | O_NONBLOCK);
-               if (server.ipc.wfd < 0) {
-                       err = -errno;
-                       EPRINTF("FD open failed %s, %d\n", write, err);
-                       goto fail;
-               }
-       }
-
        scheduler_initialize(&server.scheduler);
 
-       if (read) {
-               event_id = scheduler_register_event(&server.scheduler,
-                                                   SCHEDULER_POLL_READ_FD,
-                                                   server.ipc.rfd, 0,
-                                                   
tapdisk_server_read_ipc_message,
-                                                   NULL);
-               if (event_id < 0) {
-                       err = event_id;
-                       goto fail;
-               }
-       }
+       err = tapdisk_server_init_ipc(read, write);
+       if (err)
+               goto fail;
 
        err = tapdisk_server_initialize_aio_queue();
        if (err)
                goto fail;
 
-       server.control_event = event_id;
        server.run = 1;
 
        return 0;
 
 fail:
-       if (server.ipc.rfd > 0)
-               close(server.ipc.rfd);
-       if (server.ipc.wfd > 0)
-               close(server.ipc.wfd);
-       if (event_id > 0)
-               scheduler_unregister_event(&server.scheduler,
-                                          server.control_event);
+       tapdisk_server_close_ipc();
        return err;
 }
 
diff -r aa1ad4c5c931 -r aa0d1795f1ec tools/blktap2/drivers/tapdisk-server.h
--- a/tools/blktap2/drivers/tapdisk-server.h    Thu Jan 28 23:30:21 2010 -0800
+++ b/tools/blktap2/drivers/tapdisk-server.h    Fri Nov 13 20:26:13 2009 -0800
@@ -57,7 +57,6 @@
        td_ipc_t                     ipc;
        struct list_head             vbds;
        scheduler_t                  scheduler;
-       event_id_t                   control_event;
        struct tqueue                aio_queue;
        event_id_t                   aio_queue_event_id;
 } tapdisk_server_t;
_______________________________________________
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®.