From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46043) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMTId-00062l-1Y for qemu-devel@nongnu.org; Tue, 26 Aug 2014 22:49:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XMTIW-0005Xc-ME for qemu-devel@nongnu.org; Tue, 26 Aug 2014 22:49:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58553) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMTIW-0005Wp-EG for qemu-devel@nongnu.org; Tue, 26 Aug 2014 22:49:20 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7R2nJPF007933 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 26 Aug 2014 22:49:19 -0400 From: Fam Zheng Date: Wed, 27 Aug 2014 10:49:14 +0800 Message-Id: <1409107756-5967-7-git-send-email-famz@redhat.com> In-Reply-To: <1409107756-5967-1-git-send-email-famz@redhat.com> References: <1409107756-5967-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v3 6/8] dma: Implement .cancel_async List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Stefan Hajnoczi Just forward the request to bdrv_aio_cancel_async. Use a flag to fix the ret value in completion code. Also check memory address before calling dma_memory_unmap. Signed-off-by: Fam Zheng --- dma-helpers.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/dma-helpers.c b/dma-helpers.c index 499b52b..f9c1a79 100644 --- a/dma-helpers.c +++ b/dma-helpers.c @@ -74,6 +74,7 @@ typedef struct { uint64_t sector_num; DMADirection dir; bool in_cancel; + bool cancelled; int sg_cur_index; dma_addr_t sg_cur_byte; QEMUIOVector iov; @@ -105,6 +106,9 @@ static void dma_bdrv_unmap(DMAAIOCB *dbs) int i; for (i = 0; i < dbs->iov.niov; ++i) { + if (!(dbs->iov.iov[i].iov_base && dbs->iov.iov[i].iov_len)) { + break; + } dma_memory_unmap(dbs->sg->as, dbs->iov.iov[i].iov_base, dbs->iov.iov[i].iov_len, dbs->dir, dbs->iov.iov[i].iov_len); @@ -141,6 +145,9 @@ static void dma_bdrv_cb(void *opaque, int ret) trace_dma_bdrv_cb(dbs, ret); + if (dbs->cancelled) { + ret = -ECANCELED; + } dbs->acb = NULL; dbs->sector_num += dbs->iov.size / 512; @@ -185,6 +192,7 @@ static void dma_aio_cancel(BlockDriverAIOCB *acb) trace_dma_aio_cancel(dbs); + dbs->cancelled = true; if (dbs->acb) { BlockDriverAIOCB *acb = dbs->acb; dbs->acb = NULL; @@ -196,9 +204,24 @@ static void dma_aio_cancel(BlockDriverAIOCB *acb) dma_complete(dbs, 0); } +static void dma_aio_cancel_async(BlockDriverAIOCB *acb) +{ + DMAAIOCB *dbs = container_of(acb, DMAAIOCB, common); + + trace_dma_aio_cancel(dbs); + + dbs->cancelled = true; + if (dbs->acb) { + acb = dbs->acb; + bdrv_aio_cancel_async(acb); + } +} + + static const AIOCBInfo dma_aiocb_info = { .aiocb_size = sizeof(DMAAIOCB), .cancel = dma_aio_cancel, + .cancel_async = dma_aio_cancel_async, }; BlockDriverAIOCB *dma_bdrv_io( @@ -218,6 +241,7 @@ BlockDriverAIOCB *dma_bdrv_io( dbs->sg_cur_byte = 0; dbs->dir = dir; dbs->in_cancel = false; + dbs->cancelled = false; dbs->io_func = io_func; dbs->bh = NULL; qemu_iovec_init(&dbs->iov, sg->nsg); -- 2.1.0