[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 13 of 21] blktap3/drivers: Introduce queuing and queue management for I/O requests
This patch copies I/O request queue functionality from blktap2, with changes coming from blktap2.5. Signed-off-by: Thanos Makatos <thanos.makatos@xxxxxxxxxx> diff --git a/tools/blktap2/drivers/tapdisk-queue.c b/tools/blktap3/drivers/tapdisk-queue.c copy from tools/blktap2/drivers/tapdisk-queue.c copy to tools/blktap3/drivers/tapdisk-queue.c --- a/tools/blktap2/drivers/tapdisk-queue.c +++ b/tools/blktap3/drivers/tapdisk-queue.c @@ -1,5 +1,7 @@ /* - * Copyright (c) 2008, XenSource Inc. + * Copyright (c) 2007, XenSource Inc. + * Copyright (c) 2010, Citrix Systems, Inc. + * * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -55,8 +57,7 @@ */ #define REQUEST_ASYNC_FD ((io_context_t)1) -static inline void -queue_tiocb(struct tqueue *queue, struct tiocb *tiocb) +static inline void queue_tiocb(struct tqueue *queue, struct tiocb *tiocb) { struct iocb *iocb = &tiocb->iocb; @@ -69,14 +70,12 @@ queue_tiocb(struct tqueue *queue, struct queue->iocbs[queue->queued++] = iocb; } -static inline int -deferred_tiocbs(struct tqueue *queue) +static inline int deferred_tiocbs(struct tqueue *queue) { return (queue->deferred.head != NULL); } -static inline void -defer_tiocb(struct tqueue *queue, struct tiocb *tiocb) +static inline void defer_tiocb(struct tqueue *queue, struct tiocb *tiocb) { struct tlist *list = &queue->deferred; @@ -89,8 +88,7 @@ defer_tiocb(struct tqueue *queue, struct queue->deferrals++; } -static inline void -queue_deferred_tiocb(struct tqueue *queue) +static inline void queue_deferred_tiocb(struct tqueue *queue) { struct tlist *list = &queue->deferred; @@ -106,8 +104,7 @@ queue_deferred_tiocb(struct tqueue *queu } } -static inline void -queue_deferred_tiocbs(struct tqueue *queue) +static inline void queue_deferred_tiocbs(struct tqueue *queue) { while (!tapdisk_queue_full(queue) && deferred_tiocbs(queue)) queue_deferred_tiocb(queue); @@ -116,8 +113,8 @@ queue_deferred_tiocbs(struct tqueue *que /* * td_complete may queue more tiocbs */ -static void -complete_tiocb(struct tqueue *queue, struct tiocb *tiocb, unsigned long res) +static void complete_tiocb(struct tqueue *queue __attribute__((unused)), + struct tiocb *tiocb, unsigned long res) { int err; struct iocb *iocb = &tiocb->iocb; @@ -132,8 +129,7 @@ complete_tiocb(struct tqueue *queue, str tiocb->cb(tiocb->arg, tiocb, err); } -static int -cancel_tiocbs(struct tqueue *queue, int err) +static int cancel_tiocbs(struct tqueue *queue, int err) { int queued; struct tiocb *tiocb; @@ -160,8 +156,7 @@ cancel_tiocbs(struct tqueue *queue, int static int fail_tiocbs(struct tqueue *queue, int succeeded, int total, int err) { - ERR(err, "io_submit error: %d of %d failed", - total - succeeded, total); + ERR(err, "io_submit error: %d of %d failed", total - succeeded, total); /* take any non-submitted, merged iocbs * off of the queue, split them, and fail them */ @@ -179,8 +174,7 @@ struct rwio { struct io_event *aio_events; }; -static void -tapdisk_rwio_destroy(struct tqueue *queue) +static void tapdisk_rwio_destroy(struct tqueue *queue) { struct rwio *rwio = queue->tio_data; @@ -190,11 +184,9 @@ tapdisk_rwio_destroy(struct tqueue *queu } } -static int -tapdisk_rwio_setup(struct tqueue *queue, int size) +static int tapdisk_rwio_setup(struct tqueue *queue, int size) { struct rwio *rwio = queue->tio_data; - int err; rwio->aio_events = calloc(size, sizeof(struct io_event)); if (!rwio->aio_events) @@ -203,8 +195,7 @@ tapdisk_rwio_setup(struct tqueue *queue, return 0; } -static inline ssize_t -tapdisk_rwio_rw(const struct iocb *iocb) +static inline ssize_t tapdisk_rwio_rw(const struct iocb *iocb) { int fd = iocb->aio_fildes; char *buf = iocb->u.c.buf; @@ -213,7 +204,7 @@ tapdisk_rwio_rw(const struct iocb *iocb) ssize_t (*func)(int, void *, size_t) = (iocb->aio_lio_opcode == IO_CMD_PWRITE ? vwrite : read); - if (lseek(fd, off, SEEK_SET) == (off_t)-1) + if (lseek64(fd, off, SEEK_SET) == (off64_t) - 1) return -errno; if (atomicio(func, fd, buf, size) != size) @@ -222,8 +213,7 @@ tapdisk_rwio_rw(const struct iocb *iocb) return size; } -static int -tapdisk_rwio_submit(struct tqueue *queue) +static int tapdisk_rwio_submit(struct tqueue *queue) { struct rwio *rwio = queue->tio_data; int i, merged, split; @@ -263,8 +253,8 @@ tapdisk_rwio_submit(struct tqueue *queue static const struct tio td_tio_rwio = { .name = "rwio", .data_size = 0, - .tio_setup = NULL, - .tio_destroy = NULL, + .tio_setup = tapdisk_rwio_setup, + .tio_destroy = tapdisk_rwio_destroy, .tio_submit = tapdisk_rwio_submit }; @@ -284,18 +274,12 @@ struct lio { #define LIO_FLAG_EVENTFD (1<<0) -static int -tapdisk_lio_check_resfd(void) +static int tapdisk_lio_check_resfd(void) { -#if defined(__linux__) return tapdisk_linux_version() >= KERNEL_VERSION(2, 6, 22); -#else - return 1; -#endif } -static void -tapdisk_lio_destroy_aio(struct tqueue *queue) +static void tapdisk_lio_destroy_aio(struct tqueue *queue) { struct lio *lio = queue->tio_data; @@ -310,8 +294,7 @@ tapdisk_lio_destroy_aio(struct tqueue *q } } -static int -__lio_setup_aio_poll(struct tqueue *queue, int qlen) +static int __lio_setup_aio_poll(struct tqueue *queue, int qlen) { struct lio *lio = queue->tio_data; int err, fd; @@ -341,8 +324,7 @@ fail: return err; } -static int -__lio_setup_aio_eventfd(struct tqueue *queue, int qlen) +static int __lio_setup_aio_eventfd(struct tqueue *queue, int qlen) { struct lio *lio = queue->tio_data; int err; @@ -362,8 +344,7 @@ static int return 0; } -static int -tapdisk_lio_setup_aio(struct tqueue *queue, int qlen) +static int tapdisk_lio_setup_aio(struct tqueue *queue, int qlen) { struct lio *lio = queue->tio_data; int err; @@ -396,8 +377,7 @@ fail_rsv: } -static void -tapdisk_lio_destroy(struct tqueue *queue) +static void tapdisk_lio_destroy(struct tqueue *queue) { struct lio *lio = queue->tio_data; @@ -428,18 +408,20 @@ tapdisk_lio_set_eventfd(struct tqueue *q __io_set_eventfd(iocbs[i], lio->event_fd); } -static void -tapdisk_lio_ack_event(struct tqueue *queue) +static void tapdisk_lio_ack_event(struct tqueue *queue) { struct lio *lio = queue->tio_data; uint64_t val; - if (lio->flags & LIO_FLAG_EVENTFD) - read_exact(lio->event_fd, &val, sizeof(val)); + if (lio->flags & LIO_FLAG_EVENTFD) { + int gcc = read(lio->event_fd, &val, sizeof(val)); + if (gcc) { + }; + } } -static void -tapdisk_lio_event(event_id_t id, char mode, void *private) +static void tapdisk_lio_event(event_id_t id __attribute__((unused)), + char mode __attribute__((unused)), void *private) { struct tqueue *queue = private; struct lio *lio; @@ -470,11 +452,9 @@ tapdisk_lio_event(event_id_t id, char mo queue_deferred_tiocbs(queue); } -static int -tapdisk_lio_setup(struct tqueue *queue, int qlen) +static int tapdisk_lio_setup(struct tqueue *queue, int qlen) { struct lio *lio = queue->tio_data; - size_t sz; int err; lio->event_id = -1; @@ -486,8 +466,7 @@ tapdisk_lio_setup(struct tqueue *queue, lio->event_id = tapdisk_server_register_event(SCHEDULER_POLL_READ_FD, lio->event_fd, 0, - tapdisk_lio_event, - queue); + tapdisk_lio_event, queue); err = lio->event_id; if (err < 0) goto fail; @@ -505,8 +484,7 @@ fail: return err; } -static int -tapdisk_lio_submit(struct tqueue *queue) +static int tapdisk_lio_submit(struct tqueue *queue) { struct lio *lio = queue->tio_data; int merged, submitted, err = 0; @@ -547,8 +525,7 @@ static const struct tio td_tio_lio = { .tio_submit = tapdisk_lio_submit, }; -static void -tapdisk_queue_free_io(struct tqueue *queue) +static void tapdisk_queue_free_io(struct tqueue *queue) { if (queue->tio) { if (queue->tio->tio_destroy) @@ -562,8 +539,7 @@ tapdisk_queue_free_io(struct tqueue *que } } -static int -tapdisk_queue_init_io(struct tqueue *queue, int drv) +static int tapdisk_queue_init_io(struct tqueue *queue, int drv) { const struct tio *tio; int err; @@ -608,7 +584,7 @@ int tapdisk_init_queue(struct tqueue *queue, int size, int drv, struct tfilter *filter) { - int i, err; + int err; memset(queue, 0, sizeof(struct tqueue)); @@ -639,8 +615,7 @@ tapdisk_init_queue(struct tqueue *queue, return err; } -void -tapdisk_free_queue(struct tqueue *queue) +void tapdisk_free_queue(struct tqueue *queue) { tapdisk_queue_free_io(queue); @@ -650,16 +625,16 @@ tapdisk_free_queue(struct tqueue *queue) opio_free(&queue->opioctx); } -void -tapdisk_debug_queue(struct tqueue *queue) +void tapdisk_debug_queue(struct tqueue *queue) { struct tiocb *tiocb = queue->deferred.head; WARN("TAPDISK QUEUE:\n"); WARN("size: %d, tio: %s, queued: %d, iocbs_pending: %d, " - "tiocbs_pending: %d, tiocbs_deferred: %d, deferrals: %"PRIx64"\n", - queue->size, queue->tio->name, queue->queued, queue->iocbs_pending, - queue->tiocbs_pending, queue->tiocbs_deferred, queue->deferrals); + "tiocbs_pending: %d, tiocbs_deferred: %d, deferrals: %" PRIx64 + "\n", queue->size, queue->tio->name, queue->queued, + queue->iocbs_pending, queue->tiocbs_pending, + queue->tiocbs_deferred, queue->deferrals); if (tiocb) { WARN("deferred:\n"); @@ -667,15 +642,15 @@ tapdisk_debug_queue(struct tqueue *queue struct iocb *io = &tiocb->iocb; WARN("%s of %lu bytes at %lld\n", (io->aio_lio_opcode == IO_CMD_PWRITE ? - "write" : "read"), - io->u.c.nbytes, io->u.c.offset); + "write" : "read"), io->u.c.nbytes, io->u.c.offset); } } } void -tapdisk_prep_tiocb(struct tiocb *tiocb, int fd, int rw, char *buf, size_t size, - long long offset, td_queue_callback_t cb, void *arg) +tapdisk_prep_tiocb(struct tiocb *tiocb, int fd, int rw, char *buf, + size_t size, long long offset, td_queue_callback_t cb, + void *arg) { struct iocb *iocb = &tiocb->iocb; @@ -690,8 +665,7 @@ tapdisk_prep_tiocb(struct tiocb *tiocb, tiocb->next = NULL; } -void -tapdisk_queue_tiocb(struct tqueue *queue, struct tiocb *tiocb) +void tapdisk_queue_tiocb(struct tqueue *queue, struct tiocb *tiocb) { if (!tapdisk_queue_full(queue)) queue_tiocb(queue, tiocb); @@ -703,14 +677,12 @@ tapdisk_queue_tiocb(struct tqueue *queue /* * fail_tiocbs may queue more tiocbs */ -int -tapdisk_submit_tiocbs(struct tqueue *queue) +int tapdisk_submit_tiocbs(struct tqueue *queue) { return queue->tio->tio_submit(queue); } -int -tapdisk_submit_all_tiocbs(struct tqueue *queue) +int tapdisk_submit_all_tiocbs(struct tqueue *queue) { int submitted = 0; @@ -724,14 +696,12 @@ tapdisk_submit_all_tiocbs(struct tqueue /* * cancel_tiocbs may queue more tiocbs */ -int -tapdisk_cancel_tiocbs(struct tqueue *queue) +int tapdisk_cancel_tiocbs(struct tqueue *queue) { return cancel_tiocbs(queue, -EIO); } -int -tapdisk_cancel_all_tiocbs(struct tqueue *queue) +int tapdisk_cancel_all_tiocbs(struct tqueue *queue) { int cancelled = 0; _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |