debuggers.hg

changeset 20916:f2ef85551a09

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.

Signed-off-by: Daniel Stodden <daniel.stodden@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jan 29 08:54:22 2010 +0000 (2010-01-29)
parents 07f33d124053
children 218026df8d5f
files tools/blktap2/drivers/io-optimize.c tools/blktap2/drivers/qcow2raw.c tools/blktap2/drivers/tapdisk-queue.c tools/blktap2/drivers/tapdisk-queue.h tools/blktap2/drivers/tapdisk-server.c tools/blktap2/drivers/tapdisk-server.h
line diff
     1.1 --- a/tools/blktap2/drivers/io-optimize.c	Fri Jan 29 08:53:52 2010 +0000
     1.2 +++ b/tools/blktap2/drivers/io-optimize.c	Fri Jan 29 08:54:22 2010 +0000
     1.3 @@ -51,9 +51,16 @@ void
     1.4  opio_free(struct opioctx *ctx)
     1.5  {
     1.6  	free(ctx->opios);
     1.7 +	ctx->opios = NULL;
     1.8 +
     1.9  	free(ctx->free_opios);
    1.10 +	ctx->free_opios = NULL;
    1.11 +
    1.12  	free(ctx->iocb_queue);
    1.13 +	ctx->iocb_queue = NULL;
    1.14 +
    1.15  	free(ctx->event_queue);
    1.16 +	ctx->event_queue = NULL;
    1.17  }
    1.18  
    1.19  int
     2.1 --- a/tools/blktap2/drivers/qcow2raw.c	Fri Jan 29 08:53:52 2010 +0000
     2.2 +++ b/tools/blktap2/drivers/qcow2raw.c	Fri Jan 29 08:54:22 2010 +0000
     2.3 @@ -101,12 +101,6 @@ static void print_bytes(void *ptr, int l
     2.4      return;
     2.5  }
     2.6  
     2.7 -void
     2.8 -queue_event(event_id_t id, char mode, void *private)
     2.9 -{
    2.10 -  tapdisk_complete_tiocbs(&server.aio_queue);
    2.11 -}
    2.12 -
    2.13  static void debug_output(uint64_t progress, uint64_t size)
    2.14  {
    2.15          //Output progress every PROGRESS_QUANT 
     3.1 --- a/tools/blktap2/drivers/tapdisk-queue.c	Fri Jan 29 08:53:52 2010 +0000
     3.2 +++ b/tools/blktap2/drivers/tapdisk-queue.c	Fri Jan 29 08:54:22 2010 +0000
     3.3 @@ -35,6 +35,7 @@
     3.4  #include "tapdisk-log.h"
     3.5  #include "tapdisk-queue.h"
     3.6  #include "tapdisk-filter.h"
     3.7 +#include "tapdisk-server.h"
     3.8  #include "atomicio.h"
     3.9  
    3.10  #define WARN(_f, _a...) tlog_write(TLOG_WARN, _f, ##_a)
    3.11 @@ -46,7 +47,7 @@
    3.12   * so that we can concurrently poll on synchronous and async descriptors.
    3.13   * This is signalled by passing 1 as the io context to io_setup.
    3.14   */
    3.15 -#define REQUEST_ASYNC_FD 1
    3.16 +#define REQUEST_ASYNC_FD ((io_context_t)1)
    3.17  
    3.18  static inline void
    3.19  queue_tiocb(struct tqueue *queue, struct tiocb *tiocb)
    3.20 @@ -220,6 +221,8 @@ io_synchronous_rw(struct tqueue *queue)
    3.21  	return split;
    3.22  }
    3.23  
    3.24 +static void tapdisk_tiocb_event(event_id_t id, char mode, void *private);
    3.25 +
    3.26  int
    3.27  tapdisk_init_queue(struct tqueue *queue, int size,
    3.28  		   int sync, struct tfilter *filter)
    3.29 @@ -232,18 +235,18 @@ tapdisk_init_queue(struct tqueue *queue,
    3.30  	queue->sync   = sync;
    3.31  	queue->filter = filter;
    3.32  
    3.33 -	if (sync) {
    3.34 -		/* set up a pipe so we can return
    3.35 -		 * a poll fd that won't fire. */
    3.36 -		if (pipe(queue->dummy_pipe))
    3.37 -			return -errno;
    3.38 -		queue->poll_fd = queue->dummy_pipe[0];
    3.39 -	} else {
    3.40 -		queue->aio_ctx = (io_context_t)REQUEST_ASYNC_FD;
    3.41 +	queue->event   = -1;
    3.42 +	queue->aio_ctx = NULL;
    3.43 +
    3.44 +	if (!size)
    3.45 +		return 0;
    3.46 +
    3.47 +	if (!sync) {
    3.48 +		queue->aio_ctx = REQUEST_ASYNC_FD;
    3.49  		queue->poll_fd = io_setup(size, &queue->aio_ctx);
    3.50 -
    3.51 -		if (queue->poll_fd < 0) {
    3.52 -			if (queue->poll_fd == -EAGAIN)
    3.53 +		err = queue->poll_fd;
    3.54 +		if (err < 0) {
    3.55 +			if (err == -EAGAIN)
    3.56  				DPRINTF("Couldn't setup AIO context.  If you "
    3.57  					"are trying to concurrently use a "
    3.58  					"large number of blktap-based disks, "
    3.59 @@ -256,8 +259,19 @@ tapdisk_init_queue(struct tqueue *queue,
    3.60  					"support.  This is probably because "
    3.61  					"your kernel does not have the "
    3.62  					"aio-poll patch applied.\n");
    3.63 -			return queue->poll_fd;
    3.64 +			queue->aio_ctx = NULL;
    3.65 +			goto fail;
    3.66  		}
    3.67 +
    3.68 +		queue->event =
    3.69 +			tapdisk_server_register_event(SCHEDULER_POLL_READ_FD,
    3.70 +						      queue->poll_fd, 0,
    3.71 +						      tapdisk_tiocb_event,
    3.72 +						      queue);
    3.73 +		err = queue->event;
    3.74 +		if (err < 0)
    3.75 +			goto fail;
    3.76 +
    3.77  	}
    3.78  
    3.79  	err               = -ENOMEM;
    3.80 @@ -280,14 +294,22 @@ tapdisk_init_queue(struct tqueue *queue,
    3.81  void
    3.82  tapdisk_free_queue(struct tqueue *queue)
    3.83  {
    3.84 -	if (queue->sync) {
    3.85 -		close(queue->dummy_pipe[0]);
    3.86 -		close(queue->dummy_pipe[1]);
    3.87 -	} else
    3.88 +	if (queue->event >= 0) {
    3.89 +		tapdisk_server_unregister_event(queue->event);
    3.90 +		queue->event = -1;
    3.91 +	}
    3.92 +
    3.93 +	if (queue->aio_ctx) {
    3.94  		io_destroy(queue->aio_ctx);
    3.95 +		queue->aio_ctx = NULL;
    3.96 +	}
    3.97  
    3.98  	free(queue->iocbs);
    3.99 +	queue->iocbs = NULL;
   3.100 +
   3.101  	free(queue->aio_events);
   3.102 +	queue->aio_events = NULL;
   3.103 +
   3.104  	opio_free(&queue->opioctx);
   3.105  }
   3.106  
   3.107 @@ -390,7 +412,7 @@ tapdisk_submit_all_tiocbs(struct tqueue 
   3.108  	return submitted;
   3.109  }
   3.110  
   3.111 -int
   3.112 +static void
   3.113  tapdisk_complete_tiocbs(struct tqueue *queue)
   3.114  {
   3.115  	int i, ret, split;
   3.116 @@ -415,8 +437,13 @@ tapdisk_complete_tiocbs(struct tqueue *q
   3.117  	}
   3.118  
   3.119  	queue_deferred_tiocbs(queue);
   3.120 +}
   3.121  
   3.122 -	return split;
   3.123 +static void
   3.124 +tapdisk_tiocb_event(event_id_t id, char mode, void *private)
   3.125 +{
   3.126 +	struct tqueue *queue = private;
   3.127 +	tapdisk_complete_tiocbs(queue);
   3.128  }
   3.129  
   3.130  /*
     4.1 --- a/tools/blktap2/drivers/tapdisk-queue.h	Fri Jan 29 08:53:52 2010 +0000
     4.2 +++ b/tools/blktap2/drivers/tapdisk-queue.h	Fri Jan 29 08:54:22 2010 +0000
     4.3 @@ -32,6 +32,7 @@
     4.4  #include <libaio.h>
     4.5  
     4.6  #include "io-optimize.h"
     4.7 +#include "scheduler.h"
     4.8  
     4.9  struct tiocb;
    4.10  struct tfilter;
    4.11 @@ -57,9 +58,9 @@ struct tqueue {
    4.12  	int                   sync;
    4.13  
    4.14  	int                   poll_fd;
    4.15 +	event_id_t	      event;
    4.16  	io_context_t          aio_ctx;
    4.17  	struct opioctx        opioctx;
    4.18 -	int                   dummy_pipe[2];
    4.19  
    4.20  	int                   queued;
    4.21  	struct iocb         **iocbs;
    4.22 @@ -104,7 +105,6 @@ void tapdisk_debug_queue(struct tqueue *
    4.23  void tapdisk_queue_tiocb(struct tqueue *, struct tiocb *);
    4.24  int tapdisk_submit_tiocbs(struct tqueue *);
    4.25  int tapdisk_submit_all_tiocbs(struct tqueue *);
    4.26 -int tapdisk_complete_tiocbs(struct tqueue *);
    4.27  int tapdisk_cancel_tiocbs(struct tqueue *);
    4.28  int tapdisk_cancel_all_tiocbs(struct tqueue *);
    4.29  void tapdisk_prep_tiocb(struct tiocb *, int, int, char *, size_t,
     5.1 --- a/tools/blktap2/drivers/tapdisk-server.c	Fri Jan 29 08:53:52 2010 +0000
     5.2 +++ b/tools/blktap2/drivers/tapdisk-server.c	Fri Jan 29 08:54:22 2010 +0000
     5.3 @@ -221,19 +221,6 @@ tapdisk_server_send_error(const char *me
     5.4  		tapdisk_ipc_write_error(&vbd->ipc, message);
     5.5  }
     5.6  
     5.7 -static void
     5.8 -tapdisk_server_aio_queue_event(event_id_t id, char mode, void *private)
     5.9 -{
    5.10 -	tapdisk_complete_tiocbs(&server.aio_queue);
    5.11 -}
    5.12 -
    5.13 -static void
    5.14 -tapdisk_server_free_aio_queue(void)
    5.15 -{
    5.16 -	tapdisk_server_unregister_event(server.aio_queue_event_id);
    5.17 -	tapdisk_free_queue(&server.aio_queue);
    5.18 -}
    5.19 -
    5.20  static int
    5.21  tapdisk_server_init_ipc(const char *read, const char *write)
    5.22  {
    5.23 @@ -247,34 +234,21 @@ tapdisk_server_close_ipc(void)
    5.24  }
    5.25  
    5.26  static int
    5.27 -tapdisk_server_initialize_aio_queue(void)
    5.28 +tapdisk_server_init_aio(void)
    5.29  {
    5.30 -	int err;
    5.31 -	event_id_t id;
    5.32 -
    5.33 -	err = tapdisk_init_queue(&server.aio_queue,
    5.34 -				 TAPDISK_TIOCBS, 0, NULL);
    5.35 -	if (err)
    5.36 -		return err;
    5.37 +	return tapdisk_init_queue(&server.aio_queue, TAPDISK_TIOCBS, 0, NULL);
    5.38 +}
    5.39  
    5.40 -	id = tapdisk_server_register_event(SCHEDULER_POLL_READ_FD,
    5.41 -					   server.aio_queue.poll_fd, 0,
    5.42 -					   tapdisk_server_aio_queue_event,
    5.43 -					   NULL);
    5.44 -	if (id < 0) {
    5.45 -		tapdisk_free_queue(&server.aio_queue);
    5.46 -		return id;
    5.47 -	}
    5.48 -
    5.49 -	server.aio_queue_event_id = id;
    5.50 -
    5.51 -	return 0;
    5.52 +static void
    5.53 +tapdisk_server_close_aio(void)
    5.54 +{
    5.55 +	tapdisk_free_queue(&server.aio_queue);
    5.56  }
    5.57  
    5.58  static void
    5.59  tapdisk_server_close(void)
    5.60  {
    5.61 -	tapdisk_server_free_aio_queue();
    5.62 +	tapdisk_server_close_aio();
    5.63  	tapdisk_server_close_ipc();
    5.64  }
    5.65  
    5.66 @@ -341,7 +315,7 @@ tapdisk_server_initialize(const char *re
    5.67  	if (err)
    5.68  		goto fail;
    5.69  
    5.70 -	err = tapdisk_server_initialize_aio_queue();
    5.71 +	err = tapdisk_server_init_aio();
    5.72  	if (err)
    5.73  		goto fail;
    5.74  
     6.1 --- a/tools/blktap2/drivers/tapdisk-server.h	Fri Jan 29 08:53:52 2010 +0000
     6.2 +++ b/tools/blktap2/drivers/tapdisk-server.h	Fri Jan 29 08:54:22 2010 +0000
     6.3 @@ -58,7 +58,6 @@ typedef struct tapdisk_server {
     6.4  	struct list_head             vbds;
     6.5  	scheduler_t                  scheduler;
     6.6  	struct tqueue                aio_queue;
     6.7 -	event_id_t                   aio_queue_event_id;
     6.8  } tapdisk_server_t;
     6.9  
    6.10  #endif