From patchwork Wed May 11 11:41:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9068121 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1F4149F1C3 for ; Wed, 11 May 2016 11:44:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E49D2201B9 for ; Wed, 11 May 2016 11:44:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D955B20145 for ; Wed, 11 May 2016 11:44:16 +0000 (UTC) Received: from localhost ([::1]:51773 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0SYq-00076v-2y for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 May 2016 07:44:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34385) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0SWC-0001P4-0Z for qemu-devel@nongnu.org; Wed, 11 May 2016 07:41:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b0SW2-0001H9-SN for qemu-devel@nongnu.org; Wed, 11 May 2016 07:41:31 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:33924) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0SW2-0001Gz-BA for qemu-devel@nongnu.org; Wed, 11 May 2016 07:41:22 -0400 Received: by mail-wm0-x244.google.com with SMTP id n129so8895358wmn.1 for ; Wed, 11 May 2016 04:41:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=qucL9FUVEgsTAsI2TRUd3DVIOQW3pOYTvV8S1iHia2Y=; b=Eg9kSP+cV/AuEeYLpxYCpmzf6YDb+3zvKQcXWdtyFcfNYGq/XFKz3mlj8NmjlU+eDC gB80HTaLf8JIVUbgtfOEPcWn9xk76kFTq8O/9WVpQTCDQJXD2p09vd0H2WLDF1Gjjh03 fW4MD/2WkCVn4NaS90GENxqreQBl/j21LQlq4u51fGJn0DGxw80Uuot755y4c6QUGKrV tY2gk/3+KH/W5+DhELsWeTa1Dxw4hjmwAwRpsl3jOKoqGYKao98e61Dk1e/bex16vC7j fEfXY6jrzgmVi/xr5Cr/AGDzuefhzT8+oX+XXTw0ln2CZGW1BNdAt9gmFRNbwbtrsuXm BD2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=qucL9FUVEgsTAsI2TRUd3DVIOQW3pOYTvV8S1iHia2Y=; b=Scgwt/BFB6LGzC3jR0CtYyPYFUTK+jgNyIvcCc/QVaRxapJ7fGOx04BQeYDOWkx8GB ieuq4g9wW4P+x8XvT5jCrcCgVQ1tY+7JeEiY0SmUUmgMcrRyGVOe/NEK+6rO1amBRhQS 2nWkInDdjaJ/CYHKWAR2AULNP/CKTNUfmCIHfug5j8QJamM5Q6gGYBf6LcN2BReeyMYx 8MVGSKhj1z7mQ5YwzbbK1WP+yn+c2k40MTIjYufq3a5EDB0/VQqCUeaINiJsgw8no0Ut Cpx+0fqifb+m4+AwQ5aXGEBHohwkVO384KTs1IF8+ruYlkb7RbolZoKdCjDhIaghV+NJ x5nw== X-Gm-Message-State: AOPr4FU8SkhcOLjw+yJ1xLC6lwx3aHcYV3ifxgpgIOmYx4BV2a2qgedBBGUcuRWk/yydXw== X-Received: by 10.28.6.138 with SMTP id 132mr22167000wmg.60.1462966881768; Wed, 11 May 2016 04:41:21 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-252-58.clienti.tiscali.it. [78.12.252.58]) by smtp.gmail.com with ESMTPSA id e8sm8124892wma.2.2016.05.11.04.41.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 May 2016 04:41:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 11 May 2016 13:41:11 +0200 Message-Id: <1462966873-30473-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1462966873-30473-1-git-send-email-pbonzini@redhat.com> References: <1462966873-30473-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PATCH 2/4] dma-helpers: change BlockBackend to opaque value in DMAIOFunc X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, hare@suse.de, vrozenfe@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Callers of dma_blk_io have no way to pass extra data to the DMAIOFunc, because the original callback and opaque are gone by the time DMAIOFunc is called. On the other hand, the BlockBackend is usually derived from those extra data that you could pass to the DMAIOFunc (in the next patch, that would be the SCSIRequest). So change DMAIOFunc's prototype, decoupling it from blk_aio_readv and blk_aio_writev's. The new prototype loses the BlockBackend and gains an extra opaque value which, in the case of dma_blk_readv and dma_blk_writev, is of course used for the BlockBackend. Signed-off-by: Paolo Bonzini --- dma-helpers.c | 51 ++++++++++++++++++++++++++++++++++++++------------- hw/ide/core.c | 12 +++++++----- hw/ide/internal.h | 4 ++-- hw/ide/macio.c | 4 ++-- include/sysemu/dma.h | 11 ++++++----- 5 files changed, 55 insertions(+), 27 deletions(-) diff --git a/dma-helpers.c b/dma-helpers.c index 4ad0bca..000620e 100644 --- a/dma-helpers.c +++ b/dma-helpers.c @@ -70,7 +70,7 @@ void qemu_sglist_destroy(QEMUSGList *qsg) typedef struct { BlockAIOCB common; - BlockBackend *blk; + AioContext *ctx; BlockAIOCB *acb; QEMUSGList *sg; uint64_t sector_num; @@ -80,6 +80,7 @@ typedef struct { QEMUIOVector iov; QEMUBH *bh; DMAIOFunc *io_func; + void *io_func_opaque; } DMAAIOCB; static void dma_blk_cb(void *opaque, int ret); @@ -154,8 +155,7 @@ static void dma_blk_cb(void *opaque, int ret) if (dbs->iov.size == 0) { trace_dma_map_wait(dbs); - dbs->bh = aio_bh_new(blk_get_aio_context(dbs->blk), - reschedule_dma, dbs); + dbs->bh = aio_bh_new(dbs->ctx, reschedule_dma, dbs); cpu_register_map_client(dbs->bh); return; } @@ -164,8 +164,9 @@ static void dma_blk_cb(void *opaque, int ret) qemu_iovec_discard_back(&dbs->iov, dbs->iov.size & ~BDRV_SECTOR_MASK); } - dbs->acb = dbs->io_func(dbs->blk, dbs->sector_num, &dbs->iov, - dbs->iov.size / 512, dma_blk_cb, dbs); + dbs->acb = dbs->io_func(dbs->sector_num, &dbs->iov, + dbs->iov.size / 512, dma_blk_cb, dbs, + dbs->io_func_opaque); assert(dbs->acb); } @@ -191,23 +192,25 @@ static const AIOCBInfo dma_aiocb_info = { .cancel_async = dma_aio_cancel, }; -BlockAIOCB *dma_blk_io( - BlockBackend *blk, QEMUSGList *sg, uint64_t sector_num, - DMAIOFunc *io_func, BlockCompletionFunc *cb, +BlockAIOCB *dma_blk_io(AioContext *ctx, + QEMUSGList *sg, uint64_t sector_num, + DMAIOFunc *io_func, void *io_func_opaque, + BlockCompletionFunc *cb, void *opaque, DMADirection dir) { - DMAAIOCB *dbs = blk_aio_get(&dma_aiocb_info, blk, cb, opaque); + DMAAIOCB *dbs = qemu_aio_get(&dma_aiocb_info, NULL, cb, opaque); - trace_dma_blk_io(dbs, blk, sector_num, (dir == DMA_DIRECTION_TO_DEVICE)); + trace_dma_blk_io(dbs, io_func_opaque, sector_num, (dir == DMA_DIRECTION_TO_DEVICE)); dbs->acb = NULL; - dbs->blk = blk; dbs->sg = sg; + dbs->ctx = ctx; dbs->sector_num = sector_num; dbs->sg_cur_index = 0; dbs->sg_cur_byte = 0; dbs->dir = dir; dbs->io_func = io_func; + dbs->io_func_opaque = io_func_opaque; dbs->bh = NULL; qemu_iovec_init(&dbs->iov, sg->nsg); dma_blk_cb(dbs, 0); @@ -215,19 +218,41 @@ BlockAIOCB *dma_blk_io( } +static +BlockAIOCB *dma_blk_read_io_func(int64_t sector_num, + QEMUIOVector *iov, int nb_sectors, + BlockCompletionFunc *cb, void *cb_opaque, + void *opaque) +{ + BlockBackend *blk = opaque; + return blk_aio_readv(blk, sector_num, iov, nb_sectors, cb, cb_opaque); +} + BlockAIOCB *dma_blk_read(BlockBackend *blk, QEMUSGList *sg, uint64_t sector, void (*cb)(void *opaque, int ret), void *opaque) { - return dma_blk_io(blk, sg, sector, blk_aio_readv, cb, opaque, + return dma_blk_io(blk_get_aio_context(blk), + sg, sector, dma_blk_read_io_func, blk, cb, opaque, DMA_DIRECTION_FROM_DEVICE); } +static +BlockAIOCB *dma_blk_write_io_func(int64_t sector_num, + QEMUIOVector *iov, int nb_sectors, + BlockCompletionFunc *cb, void *cb_opaque, + void *opaque) +{ + BlockBackend *blk = opaque; + return blk_aio_writev(blk, sector_num, iov, nb_sectors, cb, cb_opaque); +} + BlockAIOCB *dma_blk_write(BlockBackend *blk, QEMUSGList *sg, uint64_t sector, void (*cb)(void *opaque, int ret), void *opaque) { - return dma_blk_io(blk, sg, sector, blk_aio_writev, cb, opaque, + return dma_blk_io(blk_get_aio_context(blk), + sg, sector, dma_blk_write_io_func, blk, cb, opaque, DMA_DIRECTION_TO_DEVICE); } diff --git a/hw/ide/core.c b/hw/ide/core.c index 41e6a2d..4057924 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -441,13 +441,14 @@ static void ide_issue_trim_cb(void *opaque, int ret) } } -BlockAIOCB *ide_issue_trim(BlockBackend *blk, +BlockAIOCB *ide_issue_trim( int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, - BlockCompletionFunc *cb, void *opaque) + BlockCompletionFunc *cb, void *cb_opaque, void *opaque) { + BlockBackend *blk = opaque; TrimAIOCB *iocb; - iocb = blk_aio_get(&trim_aiocb_info, blk, cb, opaque); + iocb = blk_aio_get(&trim_aiocb_info, blk, cb, cb_opaque); iocb->blk = blk; iocb->bh = qemu_bh_new(ide_trim_bh_cb, iocb); iocb->ret = 0; @@ -869,8 +870,9 @@ static void ide_dma_cb(void *opaque, int ret) ide_dma_cb, s); break; case IDE_DMA_TRIM: - s->bus->dma->aiocb = dma_blk_io(s->blk, &s->sg, sector_num, - ide_issue_trim, ide_dma_cb, s, + s->bus->dma->aiocb = dma_blk_io(blk_get_aio_context(s->blk), + &s->sg, sector_num, + ide_issue_trim, s->blk, ide_dma_cb, s, DMA_DIRECTION_TO_DEVICE); break; default: diff --git a/hw/ide/internal.h b/hw/ide/internal.h index d2c458f..1a3f3e8 100644 --- a/hw/ide/internal.h +++ b/hw/ide/internal.h @@ -613,9 +613,9 @@ void ide_transfer_start(IDEState *s, uint8_t *buf, int size, EndTransferFunc *end_transfer_func); void ide_transfer_stop(IDEState *s); void ide_set_inactive(IDEState *s, bool more); -BlockAIOCB *ide_issue_trim(BlockBackend *blk, +BlockAIOCB *ide_issue_trim( int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, - BlockCompletionFunc *cb, void *opaque); + BlockCompletionFunc *cb, void *cb_opaque, void *opaque); BlockAIOCB *ide_buffered_readv(IDEState *s, int64_t sector_num, QEMUIOVector *iov, int nb_sectors, BlockCompletionFunc *cb, void *opaque); diff --git a/hw/ide/macio.c b/hw/ide/macio.c index 76256eb..9773923 100644 --- a/hw/ide/macio.c +++ b/hw/ide/macio.c @@ -232,8 +232,8 @@ static void pmac_dma_trim(BlockBackend *blk, s->io_buffer_index += io->len; io->len = 0; - s->bus->dma->aiocb = ide_issue_trim(blk, (offset >> 9), &io->iov, - (bytes >> 9), cb, io); + s->bus->dma->aiocb = ide_issue_trim((offset >> 9), &io->iov, + (bytes >> 9), cb, io, blk); } static void pmac_ide_atapi_transfer_cb(void *opaque, int ret) diff --git a/include/sysemu/dma.h b/include/sysemu/dma.h index b0fbb9b..ddc4afc 100644 --- a/include/sysemu/dma.h +++ b/include/sysemu/dma.h @@ -197,14 +197,15 @@ void qemu_sglist_add(QEMUSGList *qsg, dma_addr_t base, dma_addr_t len); void qemu_sglist_destroy(QEMUSGList *qsg); #endif -typedef BlockAIOCB *DMAIOFunc(BlockBackend *blk, int64_t sector_num, +typedef BlockAIOCB *DMAIOFunc(int64_t sector_num, QEMUIOVector *iov, int nb_sectors, - BlockCompletionFunc *cb, void *opaque); + BlockCompletionFunc *cb, void *cb_opaque, + void *opaque); -BlockAIOCB *dma_blk_io(BlockBackend *blk, +BlockAIOCB *dma_blk_io(AioContext *ctx, QEMUSGList *sg, uint64_t sector_num, - DMAIOFunc *io_func, BlockCompletionFunc *cb, - void *opaque, DMADirection dir); + DMAIOFunc *io_func, void *io_func_opaque, + BlockCompletionFunc *cb, void *opaque, DMADirection dir); BlockAIOCB *dma_blk_read(BlockBackend *blk, QEMUSGList *sg, uint64_t sector, BlockCompletionFunc *cb, void *opaque);