From patchwork Wed May 11 11:41:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9068101 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 64CBA9F1C3 for ; Wed, 11 May 2016 11:42:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 902C5201B9 for ; Wed, 11 May 2016 11:42:06 +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 A5D2F20145 for ; Wed, 11 May 2016 11:42:05 +0000 (UTC) Received: from localhost ([::1]:51748 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0SWi-000266-P6 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 May 2016 07:42:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0SWD-0001R5-4N for qemu-devel@nongnu.org; Wed, 11 May 2016 07:41:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b0SW4-0001HK-06 for qemu-devel@nongnu.org; Wed, 11 May 2016 07:41:32 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33527) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0SW3-0001HG-N6 for qemu-devel@nongnu.org; Wed, 11 May 2016 07:41:23 -0400 Received: by mail-wm0-x242.google.com with SMTP id r12so8888920wme.0 for ; Wed, 11 May 2016 04:41:23 -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=zZBHTRzPyZIyt7VJrNz3noaqoxZiGmtvD27c/Y5WUUY=; b=qdRGvSFIsJylDXyKO1tuYq9pjNNC7r9z7RAQkMuGNO7oQT7HbXNWvwXiKSVqAV2XVK dQBscJg7VzlLEGv0UeKbCdBYAiUR4oQEUwW19UtHcigB6fWFsMGBI9a8VbKAve8Oljvl BuEsvavCXFriZ386zI5WzFUwrruIefjxoP7sc2OUdGhqs/87GItnfpy392O577bWN3x4 t6Y7NMQd5S5gYZTxslz/3sRUeroEAlBORZPuRA8zqjUtfODWC2nuZaJR+pkbjhrb1qgv hHc+pSbqXKpG+vCEpG7ph6pMmoDB70JrZWSdnSCOLRwROEHR4rDx4TLVvaV9KG24bjjY vOdw== 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=zZBHTRzPyZIyt7VJrNz3noaqoxZiGmtvD27c/Y5WUUY=; b=DXTyeDe8HP4QTx/3PNuVKIb+NJVu9lZXEunbbmLf26Q1bve/hD6N93RhLh7Ecjdy0P IO97FkPyw7WjRH4KTAj+Wgakqx31i6n1tNnKfEC/GxV+4qg29n8vMnAOaPyOgePn6hDG /vXN+Nalv9rvSDlfnheJz8mvpFuY0bA4OK5yW6ibfl4TT3BU85yafrNzEhT/y3OQF8k0 /9Q3eGKfNUVjYoI+jrI5kgixfHZZnZ207gg1BGHnu87oO8BbuUlDKPPrFESnfnH6jt+B a5DLip4x5pvZ1Vufn86HfZQ5qMdJlCdcViYfwH9RSvU2Gn5ylViqEOjZqX4GVo65QexW octg== X-Gm-Message-State: AOPr4FUPHPJ4fnFdMj67DvGtCUb3ehpF9lr1Lm57DUhR9KIibZY4TDvv7AJz3cW415NUag== X-Received: by 10.28.238.72 with SMTP id m69mr22214277wmh.4.1462966883132; Wed, 11 May 2016 04:41:23 -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.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 May 2016 04:41:22 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 11 May 2016 13:41:12 +0200 Message-Id: <1462966873-30473-4-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::242 Subject: [Qemu-devel] [PATCH 3/4] scsi-disk: introduce dma_readv and dma_writev 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 These are replacements for blk_aio_readv and blk_aio_writev that allow customization of the data path. They reuse the DMA helpers' DMAIOFunc callback type, so that the same function can be used in either the QEMUSGList or the bounce-buffered case. This customization will be needed in the next patch to do zero-copy SG_IO on scsi-block. Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-disk.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 45b604f..3ecfc46 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -55,7 +55,21 @@ do { printf("scsi-disk: " fmt , ## __VA_ARGS__); } while (0) #define TYPE_SCSI_DISK_BASE "scsi-disk-base" +#define SCSI_DISK_BASE(obj) \ + OBJECT_CHECK(SCSIDiskState, (obj), TYPE_SCSI_DISK_BASE) +#define SCSI_DISK_BASE_CLASS(klass) \ + OBJECT_CLASS_CHECK(SCSIDiskClass, (klass), TYPE_SCSI_DISK_BASE) +#define SCSI_DISK_BASE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(SCSIDiskClass, (obj), TYPE_SCSI_DISK_BASE) + typedef struct SCSIDiskState SCSIDiskState; +typedef struct SCSIDiskClass SCSIDiskClass; + +typedef struct SCSIDiskClass { + SCSIDeviceClass parent_class; + DMAIOFunc *dma_readv; + DMAIOFunc *dma_writev; +} SCSIDiskClass; typedef struct SCSIDiskReq { SCSIRequest req; @@ -318,6 +332,7 @@ done: static void scsi_do_read(SCSIDiskReq *r, int ret) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); + SCSIDiskClass *sdc = (SCSIDiskClass *) object_get_class(OBJECT(s)); uint32_t n; assert (r->req.aiocb == NULL); @@ -339,14 +354,16 @@ static void scsi_do_read(SCSIDiskReq *r, int ret) if (r->req.sg) { dma_acct_start(s->qdev.conf.blk, &r->acct, r->req.sg, BLOCK_ACCT_READ); r->req.resid -= r->req.sg->size; - r->req.aiocb = dma_blk_read(s->qdev.conf.blk, r->req.sg, r->sector, - scsi_dma_complete, r); + r->req.aiocb = dma_blk_io(blk_get_aio_context(s->qdev.conf.blk), + r->req.sg, r->sector, + sdc->dma_readv, r, scsi_dma_complete, r, + DMA_DIRECTION_FROM_DEVICE); } else { n = scsi_init_iovec(r, SCSI_DMA_BUF_SIZE); block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, n * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ); - r->req.aiocb = blk_aio_readv(s->qdev.conf.blk, r->sector, &r->qiov, n, - scsi_read_complete, r); + r->req.aiocb = sdc->dma_readv(r->sector, &r->qiov, n, + scsi_read_complete, r, r); } done: @@ -506,6 +523,7 @@ static void scsi_write_data(SCSIRequest *req) { SCSIDiskReq *r = DO_UPCAST(SCSIDiskReq, req, req); SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); + SCSIDiskClass *sdc = (SCSIDiskClass *) object_get_class(OBJECT(s)); uint32_t n; /* No data transfer may already be in progress */ @@ -543,14 +561,16 @@ static void scsi_write_data(SCSIRequest *req) if (r->req.sg) { dma_acct_start(s->qdev.conf.blk, &r->acct, r->req.sg, BLOCK_ACCT_WRITE); r->req.resid -= r->req.sg->size; - r->req.aiocb = dma_blk_write(s->qdev.conf.blk, r->req.sg, r->sector, - scsi_dma_complete, r); + r->req.aiocb = dma_blk_io(blk_get_aio_context(s->qdev.conf.blk), + r->req.sg, r->sector, + sdc->dma_writev, r, scsi_dma_complete, r, + DMA_DIRECTION_TO_DEVICE); } else { n = r->qiov.size / 512; block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, n * BDRV_SECTOR_SIZE, BLOCK_ACCT_WRITE); - r->req.aiocb = blk_aio_writev(s->qdev.conf.blk, r->sector, &r->qiov, n, - scsi_write_complete, r); + r->req.aiocb = sdc->dma_writev(r->sector, &r->qiov, n, + scsi_write_complete, r, r); } } @@ -2657,12 +2677,39 @@ static int scsi_block_parse_cdb(SCSIDevice *d, SCSICommand *cmd, #endif +static +BlockAIOCB *scsi_dma_readv(int64_t sector_num, + QEMUIOVector *iov, int nb_sectors, + BlockCompletionFunc *cb, void *cb_opaque, + void *opaque) +{ + SCSIDiskReq *r = opaque; + SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); + return blk_aio_readv(s->qdev.conf.blk, sector_num, iov, nb_sectors, + cb, cb_opaque); +} + +static +BlockAIOCB *scsi_dma_writev(int64_t sector_num, + QEMUIOVector *iov, int nb_sectors, + BlockCompletionFunc *cb, void *cb_opaque, + void *opaque) +{ + SCSIDiskReq *r = opaque; + SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); + return blk_aio_writev(s->qdev.conf.blk, sector_num, iov, nb_sectors, + cb, cb_opaque); +} + static void scsi_disk_base_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); + SCSIDiskClass *sdc = SCSI_DISK_BASE_CLASS(klass); dc->fw_name = "disk"; dc->reset = scsi_disk_reset; + sdc->dma_readv = scsi_dma_readv; + sdc->dma_writev = scsi_dma_writev; } static const TypeInfo scsi_disk_base_info = { @@ -2670,6 +2717,7 @@ static const TypeInfo scsi_disk_base_info = { .parent = TYPE_SCSI_DEVICE, .class_init = scsi_disk_base_class_initfn, .instance_size = sizeof(SCSIDiskState), + .class_size = sizeof(SCSIDiskClass), }; #define DEFINE_SCSI_DISK_PROPERTIES() \