From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=56082 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PZzQP-00012z-2y for qemu-devel@nongnu.org; Tue, 04 Jan 2011 00:27:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PZzQN-0004X9-VP for qemu-devel@nongnu.org; Tue, 04 Jan 2011 00:27:12 -0500 Received: from e28smtp08.in.ibm.com ([122.248.162.8]:56326) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PZzQN-0004Wy-9J for qemu-devel@nongnu.org; Tue, 04 Jan 2011 00:27:11 -0500 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by e28smtp08.in.ibm.com (8.14.4/8.13.1) with ESMTP id p044gDW4031142 for ; Tue, 4 Jan 2011 10:12:13 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p045R9F34059238 for ; Tue, 4 Jan 2011 10:57:09 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p045R8X9015914 for ; Tue, 4 Jan 2011 10:57:09 +0530 From: Arun R Bharadwaj Date: Tue, 04 Jan 2011 10:57:08 +0530 Message-ID: <20110104052708.15887.7563.stgit@localhost6.localdomain6> In-Reply-To: <20110104052627.15887.43436.stgit@localhost6.localdomain6> References: <20110104052627.15887.43436.stgit@localhost6.localdomain6> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH 01/13] Add aiocb_mutex and aiocb_completion. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, stefanha@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com This patch adds the aiocb_mutex to protect aiocb. This patch also removes the infinite loop present in paio_cancel. Since there can only be one cancellation at a time, we need to introduce a condition variable. For this, we need a global aiocb_completion condition variable. This patch also adds the Makefile entry to compile qemu-thread.c when CONFIG_POSIX is set, instead of the unused CONFIG_THREAD. Signed-off-by: Arun R Bharadwaj --- Makefile.objs | 2 +- posix-aio-compat.c | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Makefile.objs b/Makefile.objs index cd5a24b..3b7ec27 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -9,6 +9,7 @@ qobject-obj-y += qerror.o block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o block-obj-y += nbd.o block.o aio.o aes.o osdep.o qemu-config.o +block-obj-$(CONFIG_POSIX) += qemu-thread.o block-obj-$(CONFIG_POSIX) += posix-aio-compat.o block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o @@ -124,7 +125,6 @@ endif common-obj-y += $(addprefix ui/, $(ui-obj-y)) common-obj-y += iov.o acl.o -common-obj-$(CONFIG_THREAD) += qemu-thread.o common-obj-y += notify.o event_notifier.o common-obj-y += qemu-timer.o diff --git a/posix-aio-compat.c b/posix-aio-compat.c index 7b862b5..ae5e20e 100644 --- a/posix-aio-compat.c +++ b/posix-aio-compat.c @@ -27,9 +27,12 @@ #include "qemu-common.h" #include "trace.h" #include "block_int.h" +#include "qemu-thread.h" #include "block/raw-posix-aio.h" +static QemuMutex aiocb_mutex; +static QemuCond aiocb_completion; struct qemu_paiocb { BlockDriverAIOCB common; @@ -351,10 +354,14 @@ static void *aio_thread(void *unused) } mutex_lock(&lock); - aiocb->ret = ret; idle_threads++; mutex_unlock(&lock); + qemu_mutex_lock(&aiocb_mutex); + aiocb->ret = ret; + qemu_cond_broadcast(&aiocb_completion); + qemu_mutex_unlock(&aiocb_mutex); + if (kill(pid, aiocb->ev_signo)) die("kill failed"); } @@ -383,8 +390,11 @@ static void spawn_thread(void) static void qemu_paio_submit(struct qemu_paiocb *aiocb) { + qemu_mutex_lock(&aiocb_mutex); aiocb->ret = -EINPROGRESS; aiocb->active = 0; + qemu_mutex_unlock(&aiocb_mutex); + mutex_lock(&lock); if (idle_threads == 0 && cur_threads < max_threads) spawn_thread(); @@ -397,9 +407,9 @@ static ssize_t qemu_paio_return(struct qemu_paiocb *aiocb) { ssize_t ret; - mutex_lock(&lock); + qemu_mutex_lock(&aiocb_mutex); ret = aiocb->ret; - mutex_unlock(&lock); + qemu_mutex_unlock(&aiocb_mutex); return ret; } @@ -545,13 +555,19 @@ static void paio_cancel(BlockDriverAIOCB *blockacb) } mutex_unlock(&lock); - if (active) { - /* fail safe: if the aio could not be canceled, we wait for - it */ - while (qemu_paio_error(acb) == EINPROGRESS) - ; + qemu_mutex_lock(&aiocb_mutex); + if (!active) { + acb->ret = -ECANCELED; + } else { + while (acb->ret == -EINPROGRESS) { + /* + * fail safe: if the aio could not be canceled, + * we wait for it + */ + qemu_cond_wait(&aiocb_completion, &aiocb_mutex); + } } - + qemu_mutex_unlock(&aiocb_mutex); paio_remove(acb); } @@ -623,6 +639,9 @@ int paio_init(void) if (posix_aio_state) return 0; + qemu_mutex_init(&aiocb_mutex); + qemu_cond_init(&aiocb_completion); + s = qemu_malloc(sizeof(PosixAioState)); sigfillset(&act.sa_mask);