[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] blktap2: Sort out tapdisk IPC init.
# HG changeset patch # User Keir Fraser <keir.fraser@xxxxxxxxxx> # Date 1264755232 0 # Node ID 07f33d1240539effbbb7c1cff55aacff25dfcc50 # Parent 2bc69db28153e8da148cda58b1a6c5ddd23ca8b2 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> --- tools/blktap2/drivers/tapdisk-ipc.c | 74 ++++++++++++++++++++++++++++++++ tools/blktap2/drivers/tapdisk-ipc.h | 4 + tools/blktap2/drivers/tapdisk-server.c | 76 +++++++-------------------------- tools/blktap2/drivers/tapdisk-server.h | 1 4 files changed, 96 insertions(+), 59 deletions(-) diff -r 2bc69db28153 -r 07f33d124053 tools/blktap2/drivers/tapdisk-ipc.c --- a/tools/blktap2/drivers/tapdisk-ipc.c Fri Jan 29 07:14:32 2010 +0000 +++ b/tools/blktap2/drivers/tapdisk-ipc.c Fri Jan 29 08:53:52 2010 +0000 @@ -30,11 +30,85 @@ #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 2bc69db28153 -r 07f33d124053 tools/blktap2/drivers/tapdisk-ipc.h --- a/tools/blktap2/drivers/tapdisk-ipc.h Fri Jan 29 07:14:32 2010 +0000 +++ b/tools/blktap2/drivers/tapdisk-ipc.h Fri Jan 29 08:53:52 2010 +0000 @@ -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 2bc69db28153 -r 07f33d124053 tools/blktap2/drivers/tapdisk-server.c --- a/tools/blktap2/drivers/tapdisk-server.c Fri Jan 29 07:14:32 2010 +0000 +++ b/tools/blktap2/drivers/tapdisk-server.c Fri Jan 29 08:53:52 2010 +0000 @@ -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 @@ tapdisk_server_send_error(const char *me } 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); @@ -239,6 +232,18 @@ 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) +{ + return tapdisk_ipc_open(&server.ipc, read, write); +} + +static void +tapdisk_server_close_ipc(void) +{ + tapdisk_ipc_close(&server.ipc); } static int @@ -270,15 +275,7 @@ tapdisk_server_close(void) 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 *re 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 2bc69db28153 -r 07f33d124053 tools/blktap2/drivers/tapdisk-server.h --- a/tools/blktap2/drivers/tapdisk-server.h Fri Jan 29 07:14:32 2010 +0000 +++ b/tools/blktap2/drivers/tapdisk-server.h Fri Jan 29 08:53:52 2010 +0000 @@ -57,7 +57,6 @@ typedef struct tapdisk_server { 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-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |