From nobody Tue Apr 30 14:45:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528438019336501.0319885207716; Thu, 7 Jun 2018 23:06:59 -0700 (PDT) Received: from localhost ([::1]:33291 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRAY3-0001BS-5u for importer@patchew.org; Fri, 08 Jun 2018 02:06:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRAW6-0008UI-5E for qemu-devel@nongnu.org; Fri, 08 Jun 2018 02:04:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRAW2-0008GK-Vo for qemu-devel@nongnu.org; Fri, 08 Jun 2018 02:04:54 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57152 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fRAVy-0008EK-Im; Fri, 08 Jun 2018 02:04:46 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2822140200A0; Fri, 8 Jun 2018 06:04:46 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-108.pek2.redhat.com [10.72.12.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id A250F1C5B9; Fri, 8 Jun 2018 06:04:41 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 8 Jun 2018 14:04:12 +0800 Message-Id: <20180608060417.10170-2-famz@redhat.com> In-Reply-To: <20180608060417.10170-1-famz@redhat.com> References: <20180608060417.10170-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 08 Jun 2018 06:04:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 08 Jun 2018 06:04:46 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 1/6] file-posix: Fix EINTR handling 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: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Jeff Cody , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" EINTR should be checked against errno, not ret. While fixing the bug, collecting the branches with a switch block. Signed-off-by: Fam Zheng --- block/file-posix.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 513d371bb1..c6dae38f94 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1473,20 +1473,20 @@ static ssize_t handle_aiocb_copy_range(RawPosixAIOD= ata *aiocb) ssize_t ret =3D copy_file_range(aiocb->aio_fildes, &in_off, aiocb->aio_fd2, &out_off, bytes, 0); - if (ret =3D=3D -EINTR) { - continue; - } - if (ret < 0) { - if (errno =3D=3D ENOSYS) { + if (ret <=3D 0) { + switch (errno) { + case 0: + /* No progress (e.g. when beyond EOF), let the caller fall= back + * to buffer I/O. */ + /* fall through */ + case ENOSYS: return -ENOTSUP; - } else { + case EINTR: + continue; + default: return -errno; } } - if (!ret) { - /* No progress (e.g. when beyond EOF), fall back to buffer I/O= . */ - return -ENOTSUP; - } bytes -=3D ret; } return 0; --=20 2.17.0 From nobody Tue Apr 30 14:45:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528438149740346.6747593850754; Thu, 7 Jun 2018 23:09:09 -0700 (PDT) Received: from localhost ([::1]:33301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRAa5-0002jC-H8 for importer@patchew.org; Fri, 08 Jun 2018 02:09:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRAW8-0008WV-SD for qemu-devel@nongnu.org; Fri, 08 Jun 2018 02:04:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRAW7-0008IS-N3 for qemu-devel@nongnu.org; Fri, 08 Jun 2018 02:04:56 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37780 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fRAW4-0008Gx-Co; Fri, 08 Jun 2018 02:04:52 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F201A805A531; Fri, 8 Jun 2018 06:04:51 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-108.pek2.redhat.com [10.72.12.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3AE6C1C5BA; Fri, 8 Jun 2018 06:04:46 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 8 Jun 2018 14:04:13 +0800 Message-Id: <20180608060417.10170-3-famz@redhat.com> In-Reply-To: <20180608060417.10170-1-famz@redhat.com> References: <20180608060417.10170-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 08 Jun 2018 06:04:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 08 Jun 2018 06:04:52 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 2/6] block: Check if block drivers can do copy offloading 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: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Jeff Cody , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This avoids the wasteful cluster allocation in qcow2 before actually trying an unsupported copy range call, for example. Signed-off-by: Fam Zheng --- block.c | 12 ++++++++++++ block/file-posix.c | 9 +++++++++ block/io.c | 3 +++ block/iscsi.c | 8 ++++++++ block/qcow2.c | 11 +++++++++++ block/raw-format.c | 6 ++++++ include/block/block_int.h | 4 ++++ 7 files changed, 53 insertions(+) diff --git a/block.c b/block.c index 501b64c819..28aa8d8a65 100644 --- a/block.c +++ b/block.c @@ -5320,3 +5320,15 @@ bool bdrv_can_store_new_dirty_bitmap(BlockDriverStat= e *bs, const char *name, =20 return drv->bdrv_can_store_new_dirty_bitmap(bs, name, granularity, err= p); } + +bool bdrv_can_copy_range(BdrvChild *src, BdrvChild *dst) +{ + BlockDriverState *bs; + + if (!src || !src->bs) { + return false; + } + bs =3D src->bs; + return bs && bs->drv && bs->drv->bdrv_can_copy_range && + bs->drv->bdrv_can_copy_range(bs, dst); +} diff --git a/block/file-posix.c b/block/file-posix.c index c6dae38f94..41c491c65b 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2539,6 +2539,13 @@ static int coroutine_fn raw_co_copy_range_to(BlockDr= iverState *bs, NULL, bytes, QEMU_AIO_COPY_RANGE); } =20 +static bool raw_can_copy_range(BlockDriverState *bs, + BdrvChild *dst) +{ + return dst->bs && dst->bs->drv && + dst->bs->drv->bdrv_can_copy_range =3D=3D raw_can_copy_range; +} + BlockDriver bdrv_file =3D { .format_name =3D "file", .protocol_name =3D "file", @@ -2564,6 +2571,7 @@ BlockDriver bdrv_file =3D { .bdrv_aio_pdiscard =3D raw_aio_pdiscard, .bdrv_co_copy_range_from =3D raw_co_copy_range_from, .bdrv_co_copy_range_to =3D raw_co_copy_range_to, + .bdrv_can_copy_range =3D raw_can_copy_range, .bdrv_refresh_limits =3D raw_refresh_limits, .bdrv_io_plug =3D raw_aio_plug, .bdrv_io_unplug =3D raw_aio_unplug, @@ -3044,6 +3052,7 @@ static BlockDriver bdrv_host_device =3D { .bdrv_aio_pdiscard =3D hdev_aio_pdiscard, .bdrv_co_copy_range_from =3D raw_co_copy_range_from, .bdrv_co_copy_range_to =3D raw_co_copy_range_to, + .bdrv_can_copy_range =3D raw_can_copy_range, .bdrv_refresh_limits =3D raw_refresh_limits, .bdrv_io_plug =3D raw_aio_plug, .bdrv_io_unplug =3D raw_aio_unplug, diff --git a/block/io.c b/block/io.c index b7beaeeb9f..d8039793c2 100644 --- a/block/io.c +++ b/block/io.c @@ -2913,6 +2913,9 @@ int coroutine_fn bdrv_co_copy_range(BdrvChild *src, u= int64_t src_offset, BlockDriverState *dst_bs =3D dst->bs; int ret; =20 + if (!bdrv_can_copy_range(src, dst)) { + return -ENOTSUP; + } bdrv_inc_in_flight(src_bs); bdrv_inc_in_flight(dst_bs); tracked_request_begin(&src_req, src_bs, src_offset, diff --git a/block/iscsi.c b/block/iscsi.c index c2fbd8a8aa..6c465ebd46 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2420,6 +2420,12 @@ out_unlock: return r; } =20 +static bool iscsi_can_copy_range(BlockDriverState *bs, BdrvChild *dst) +{ + return dst->bs && dst->bs->drv && + dst->bs->drv->bdrv_can_copy_range =3D=3D iscsi_can_copy_range; +} + static QemuOptsList iscsi_create_opts =3D { .name =3D "iscsi-create-opts", .head =3D QTAILQ_HEAD_INITIALIZER(iscsi_create_opts.head), @@ -2456,6 +2462,7 @@ static BlockDriver bdrv_iscsi =3D { .bdrv_co_pdiscard =3D iscsi_co_pdiscard, .bdrv_co_copy_range_from =3D iscsi_co_copy_range_from, .bdrv_co_copy_range_to =3D iscsi_co_copy_range_to, + .bdrv_can_copy_range =3D iscsi_can_copy_range, .bdrv_co_pwrite_zeroes =3D iscsi_co_pwrite_zeroes, .bdrv_co_readv =3D iscsi_co_readv, .bdrv_co_writev =3D iscsi_co_writev, @@ -2493,6 +2500,7 @@ static BlockDriver bdrv_iser =3D { .bdrv_co_pdiscard =3D iscsi_co_pdiscard, .bdrv_co_copy_range_from =3D iscsi_co_copy_range_from, .bdrv_co_copy_range_to =3D iscsi_co_copy_range_to, + .bdrv_can_copy_range =3D iscsi_can_copy_range, .bdrv_co_pwrite_zeroes =3D iscsi_co_pwrite_zeroes, .bdrv_co_readv =3D iscsi_co_readv, .bdrv_co_writev =3D iscsi_co_writev, diff --git a/block/qcow2.c b/block/qcow2.c index 549fee9b69..1326410d1c 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3440,6 +3440,16 @@ fail: return ret; } =20 +static bool qcow2_can_copy_range(BlockDriverState *bs, BdrvChild *dst) +{ + bool r =3D bdrv_can_copy_range(bs->file, dst); + + if (bs->backing) { + r =3D r && bdrv_can_copy_range(bs->backing, dst); + } + return r; +} + static int qcow2_truncate(BlockDriverState *bs, int64_t offset, PreallocMode prealloc, Error **errp) { @@ -4690,6 +4700,7 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_co_pdiscard =3D qcow2_co_pdiscard, .bdrv_co_copy_range_from =3D qcow2_co_copy_range_from, .bdrv_co_copy_range_to =3D qcow2_co_copy_range_to, + .bdrv_can_copy_range =3D qcow2_can_copy_range, .bdrv_truncate =3D qcow2_truncate, .bdrv_co_pwritev_compressed =3D qcow2_co_pwritev_compressed, .bdrv_make_empty =3D qcow2_make_empty, diff --git a/block/raw-format.c b/block/raw-format.c index f2e468df6f..707b25fc77 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -527,6 +527,11 @@ static int coroutine_fn raw_co_copy_range_to(BlockDriv= erState *bs, flags); } =20 +static bool raw_can_copy_range(BlockDriverState *bs, BdrvChild *dst) +{ + return bdrv_can_copy_range(bs->file, dst); +} + BlockDriver bdrv_raw =3D { .format_name =3D "raw", .instance_size =3D sizeof(BDRVRawState), @@ -545,6 +550,7 @@ BlockDriver bdrv_raw =3D { .bdrv_co_block_status =3D &raw_co_block_status, .bdrv_co_copy_range_from =3D &raw_co_copy_range_from, .bdrv_co_copy_range_to =3D &raw_co_copy_range_to, + .bdrv_can_copy_range =3D &raw_can_copy_range, .bdrv_truncate =3D &raw_truncate, .bdrv_getlength =3D &raw_getlength, .has_variable_length =3D true, diff --git a/include/block/block_int.h b/include/block/block_int.h index 888b7f7bff..2c51cd420f 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -235,6 +235,9 @@ struct BlockDriver { uint64_t bytes, BdrvRequestFlags flags); =20 + bool (*bdrv_can_copy_range)(BlockDriverState *bs, + BdrvChild *dst); + /* * Building block for bdrv_block_status[_above] and * bdrv_is_allocated[_above]. The driver should answer only @@ -1139,5 +1142,6 @@ int coroutine_fn bdrv_co_copy_range_from(BdrvChild *s= rc, uint64_t src_offset, int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src, uint64_t src_offset, BdrvChild *dst, uint64_t dst_offset, uint64_t bytes, BdrvRequestFlags fl= ags); +bool bdrv_can_copy_range(BdrvChild *src, BdrvChild *dst); =20 #endif /* BLOCK_INT_H */ --=20 2.17.0 From nobody Tue Apr 30 14:45:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528438174007692.9674605633727; Thu, 7 Jun 2018 23:09:34 -0700 (PDT) Received: from localhost ([::1]:33302 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRAab-000346-6S for importer@patchew.org; Fri, 08 Jun 2018 02:09:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42026) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRAWN-0000Ii-It for qemu-devel@nongnu.org; Fri, 08 Jun 2018 02:05:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRAWL-0008Pu-Ld for qemu-devel@nongnu.org; Fri, 08 Jun 2018 02:05:11 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40230 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fRAWF-0008Lb-Vl; Fri, 08 Jun 2018 02:05:04 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8ACE4401EF04; Fri, 8 Jun 2018 06:05:03 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-108.pek2.redhat.com [10.72.12.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD4BF1C5B9; Fri, 8 Jun 2018 06:04:52 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 8 Jun 2018 14:04:14 +0800 Message-Id: <20180608060417.10170-4-famz@redhat.com> In-Reply-To: <20180608060417.10170-1-famz@redhat.com> References: <20180608060417.10170-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 08 Jun 2018 06:05:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 08 Jun 2018 06:05:03 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 3/6] block-backend: Refactor AIO emulation 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: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Jeff Cody , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" BlkRwCo fields are multi-purposed. @offset is sometimes used to pass the 'req' number for blk_ioctl and blk_aio_ioctl; @iobuf is sometimes the pointer for QEMUIOVector @qiov sometimes the ioctl @buf. This is not as clean as it can be. As the coming copy range emulation wants to add more differentiation in parameters, refactor a bit. Move the per-request fields to a union and create one struct for each type. While at it also move the bytes parameter from BlkAioEmAIOCB to BlkRwCo. Signed-off-by: Fam Zheng --- block/block-backend.c | 211 +++++++++++++++++++++++++++--------------- 1 file changed, 134 insertions(+), 77 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index d55c328736..e20a204bee 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1192,62 +1192,79 @@ int coroutine_fn blk_co_pwritev(BlockBackend *blk, = int64_t offset, =20 typedef struct BlkRwCo { BlockBackend *blk; - int64_t offset; - void *iobuf; int ret; - BdrvRequestFlags flags; + + union { + struct { + int64_t offset; + int bytes; + QEMUIOVector *qiov; + BdrvRequestFlags flags; + } prwv; + + struct { + int64_t offset; + int bytes; + void *buf; + BdrvRequestFlags flags; + } prw; + + struct { + unsigned long int req; + void *buf; + } ioctl; + }; + } BlkRwCo; =20 static void blk_read_entry(void *opaque) { BlkRwCo *rwco =3D opaque; - QEMUIOVector *qiov =3D rwco->iobuf; + QEMUIOVector qiov; + struct iovec iov; =20 - rwco->ret =3D blk_co_preadv(rwco->blk, rwco->offset, qiov->size, - qiov, rwco->flags); + iov =3D (struct iovec) { + .iov_base =3D rwco->prw.buf, + .iov_len =3D rwco->prw.bytes, + }; + qemu_iovec_init_external(&qiov, &iov, 1); + + rwco->ret =3D blk_co_preadv(rwco->blk, rwco->prw.offset, rwco->prw.byt= es, + &qiov, rwco->prw.flags); } =20 static void blk_write_entry(void *opaque) { BlkRwCo *rwco =3D opaque; - QEMUIOVector *qiov =3D rwco->iobuf; - - rwco->ret =3D blk_co_pwritev(rwco->blk, rwco->offset, qiov->size, - qiov, rwco->flags); -} - -static int blk_prw(BlockBackend *blk, int64_t offset, uint8_t *buf, - int64_t bytes, CoroutineEntry co_entry, - BdrvRequestFlags flags) -{ QEMUIOVector qiov; struct iovec iov; - BlkRwCo rwco; =20 iov =3D (struct iovec) { - .iov_base =3D buf, - .iov_len =3D bytes, + .iov_base =3D rwco->prw.buf, + .iov_len =3D rwco->prw.bytes, }; qemu_iovec_init_external(&qiov, &iov, 1); =20 - rwco =3D (BlkRwCo) { - .blk =3D blk, - .offset =3D offset, - .iobuf =3D &qiov, - .flags =3D flags, - .ret =3D NOT_DONE, - }; + rwco->ret =3D blk_co_pwritev(rwco->blk, rwco->prw.offset, rwco->prw.by= tes, + &qiov, rwco->prw.flags); +} =20 +static int blk_prw(BlockBackend *blk, BlkRwCo *rwco, + CoroutineEntry co_entry) +{ + + rwco->blk =3D blk; + rwco->ret =3D NOT_DONE; if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ - co_entry(&rwco); + co_entry(rwco); } else { - Coroutine *co =3D qemu_coroutine_create(co_entry, &rwco); + Coroutine *co =3D qemu_coroutine_create(co_entry, rwco); bdrv_coroutine_enter(blk_bs(blk), co); - BDRV_POLL_WHILE(blk_bs(blk), rwco.ret =3D=3D NOT_DONE); + BDRV_POLL_WHILE(blk_bs(blk), rwco->ret =3D=3D NOT_DONE); } =20 - return rwco.ret; + return rwco->ret; } =20 int blk_pread_unthrottled(BlockBackend *blk, int64_t offset, uint8_t *buf, @@ -1269,8 +1286,12 @@ int blk_pread_unthrottled(BlockBackend *blk, int64_t= offset, uint8_t *buf, int blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, int bytes, BdrvRequestFlags flags) { - return blk_prw(blk, offset, NULL, bytes, blk_write_entry, - flags | BDRV_REQ_ZERO_WRITE); + BlkRwCo rwco =3D (BlkRwCo) { + .prwv.offset =3D offset, + .prwv.bytes =3D bytes, + .prwv.flags =3D flags | BDRV_REQ_ZERO_WRITE, + }; + return blk_prw(blk, &rwco, blk_write_entry); } =20 int blk_make_zero(BlockBackend *blk, BdrvRequestFlags flags) @@ -1316,7 +1337,6 @@ BlockAIOCB *blk_abort_aio_request(BlockBackend *blk, typedef struct BlkAioEmAIOCB { BlockAIOCB common; BlkRwCo rwco; - int bytes; bool has_returned; } BlkAioEmAIOCB; =20 @@ -1340,9 +1360,8 @@ static void blk_aio_complete_bh(void *opaque) blk_aio_complete(acb); } =20 -static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, int64_t offset, int byt= es, - void *iobuf, CoroutineEntry co_entry, - BdrvRequestFlags flags, +static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, const BlkRwCo *rwco, + CoroutineEntry co_entry, BlockCompletionFunc *cb, void *opaque) { BlkAioEmAIOCB *acb; @@ -1350,14 +1369,9 @@ static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, i= nt64_t offset, int bytes, =20 blk_inc_in_flight(blk); acb =3D blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, opaque); - acb->rwco =3D (BlkRwCo) { - .blk =3D blk, - .offset =3D offset, - .iobuf =3D iobuf, - .flags =3D flags, - .ret =3D NOT_DONE, - }; - acb->bytes =3D bytes; + acb->rwco =3D *rwco; + acb->rwco.blk =3D blk; + acb->rwco.ret =3D NOT_DONE; acb->has_returned =3D false; =20 co =3D qemu_coroutine_create(co_entry, acb); @@ -1376,11 +1390,11 @@ static void blk_aio_read_entry(void *opaque) { BlkAioEmAIOCB *acb =3D opaque; BlkRwCo *rwco =3D &acb->rwco; - QEMUIOVector *qiov =3D rwco->iobuf; + QEMUIOVector *qiov =3D rwco->prwv.qiov; =20 - assert(qiov->size =3D=3D acb->bytes); - rwco->ret =3D blk_co_preadv(rwco->blk, rwco->offset, acb->bytes, - qiov, rwco->flags); + assert(qiov->size =3D=3D rwco->prwv.bytes); + rwco->ret =3D blk_co_preadv(rwco->blk, rwco->prwv.offset, rwco->prwv.b= ytes, + qiov, rwco->prwv.flags); blk_aio_complete(acb); } =20 @@ -1388,11 +1402,11 @@ static void blk_aio_write_entry(void *opaque) { BlkAioEmAIOCB *acb =3D opaque; BlkRwCo *rwco =3D &acb->rwco; - QEMUIOVector *qiov =3D rwco->iobuf; + QEMUIOVector *qiov =3D rwco->prwv.qiov; =20 - assert(!qiov || qiov->size =3D=3D acb->bytes); - rwco->ret =3D blk_co_pwritev(rwco->blk, rwco->offset, acb->bytes, - qiov, rwco->flags); + assert(!qiov || qiov->size =3D=3D rwco->prwv.bytes); + rwco->ret =3D blk_co_pwritev(rwco->blk, rwco->prwv.offset, rwco->prwv.= bytes, + qiov, rwco->prwv.flags); blk_aio_complete(acb); } =20 @@ -1400,13 +1414,22 @@ BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk= , int64_t offset, int count, BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque) { - return blk_aio_prwv(blk, offset, count, NULL, blk_aio_write_entry, - flags | BDRV_REQ_ZERO_WRITE, cb, opaque); + BlkRwCo rwco =3D (BlkRwCo) { + .prwv.offset =3D offset, + .prwv.bytes =3D count, + .prwv.flags =3D flags | BDRV_REQ_ZERO_WRITE, + }; + return blk_aio_prwv(blk, &rwco, blk_aio_write_entry, cb, opaque); } =20 int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int count) { - int ret =3D blk_prw(blk, offset, buf, count, blk_read_entry, 0); + BlkRwCo rwco =3D (BlkRwCo) { + .prw.offset =3D offset, + .prw.bytes =3D count, + .prw.buf =3D buf, + }; + int ret =3D blk_prw(blk, &rwco, blk_read_entry); if (ret < 0) { return ret; } @@ -1416,8 +1439,13 @@ int blk_pread(BlockBackend *blk, int64_t offset, voi= d *buf, int count) int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int cou= nt, BdrvRequestFlags flags) { - int ret =3D blk_prw(blk, offset, (void *) buf, count, blk_write_entry, - flags); + BlkRwCo rwco =3D (BlkRwCo) { + .prw.offset =3D offset, + .prw.bytes =3D count, + .prw.buf =3D (void *)buf, + .prw.flags =3D flags, + }; + int ret =3D blk_prw(blk, &rwco, blk_write_entry); if (ret < 0) { return ret; } @@ -1455,16 +1483,26 @@ BlockAIOCB *blk_aio_preadv(BlockBackend *blk, int64= _t offset, QEMUIOVector *qiov, BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque) { - return blk_aio_prwv(blk, offset, qiov->size, qiov, - blk_aio_read_entry, flags, cb, opaque); + BlkRwCo rwco =3D (BlkRwCo) { + .prwv.offset =3D offset, + .prwv.bytes =3D qiov->size, + .prwv.flags =3D flags, + .prwv.qiov =3D qiov, + }; + return blk_aio_prwv(blk, &rwco, blk_aio_read_entry, cb, opaque); } =20 BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset, QEMUIOVector *qiov, BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque) { - return blk_aio_prwv(blk, offset, qiov->size, qiov, - blk_aio_write_entry, flags, cb, opaque); + BlkRwCo rwco =3D (BlkRwCo) { + .prwv.offset =3D offset, + .prwv.bytes =3D qiov->size, + .prwv.flags =3D flags, + .prwv.qiov =3D qiov, + }; + return blk_aio_prwv(blk, &rwco, blk_aio_write_entry, cb, opaque); } =20 static void blk_aio_flush_entry(void *opaque) @@ -1479,7 +1517,8 @@ static void blk_aio_flush_entry(void *opaque) BlockAIOCB *blk_aio_flush(BlockBackend *blk, BlockCompletionFunc *cb, void *opaque) { - return blk_aio_prwv(blk, 0, 0, NULL, blk_aio_flush_entry, 0, cb, opaqu= e); + BlkRwCo rwco =3D { }; + return blk_aio_prwv(blk, &rwco, blk_aio_flush_entry, cb, opaque); } =20 static void blk_aio_pdiscard_entry(void *opaque) @@ -1487,7 +1526,7 @@ static void blk_aio_pdiscard_entry(void *opaque) BlkAioEmAIOCB *acb =3D opaque; BlkRwCo *rwco =3D &acb->rwco; =20 - rwco->ret =3D blk_co_pdiscard(rwco->blk, rwco->offset, acb->bytes); + rwco->ret =3D blk_co_pdiscard(rwco->blk, rwco->prwv.offset, rwco->prwv= .bytes); blk_aio_complete(acb); } =20 @@ -1495,8 +1534,11 @@ BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int bytes, BlockCompletionFunc *cb, void *opaque) { - return blk_aio_prwv(blk, offset, bytes, NULL, blk_aio_pdiscard_entry, = 0, - cb, opaque); + BlkRwCo rwco =3D (BlkRwCo) { + .prwv.offset =3D offset, + .prwv.bytes =3D bytes, + }; + return blk_aio_prwv(blk, &rwco, blk_aio_pdiscard_entry, cb, opaque); } =20 void blk_aio_cancel(BlockAIOCB *acb) @@ -1521,15 +1563,17 @@ int blk_co_ioctl(BlockBackend *blk, unsigned long i= nt req, void *buf) static void blk_ioctl_entry(void *opaque) { BlkRwCo *rwco =3D opaque; - QEMUIOVector *qiov =3D rwco->iobuf; =20 - rwco->ret =3D blk_co_ioctl(rwco->blk, rwco->offset, - qiov->iov[0].iov_base); + rwco->ret =3D blk_co_ioctl(rwco->blk, rwco->ioctl.req, rwco->ioctl.buf= ); } =20 int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf) { - return blk_prw(blk, req, buf, 0, blk_ioctl_entry, 0); + BlkRwCo rwco =3D (BlkRwCo) { + .ioctl.req =3D req, + .ioctl.buf =3D buf, + }; + return blk_prw(blk, &rwco, blk_ioctl_entry); } =20 static void blk_aio_ioctl_entry(void *opaque) @@ -1537,7 +1581,7 @@ static void blk_aio_ioctl_entry(void *opaque) BlkAioEmAIOCB *acb =3D opaque; BlkRwCo *rwco =3D &acb->rwco; =20 - rwco->ret =3D blk_co_ioctl(rwco->blk, rwco->offset, rwco->iobuf); + rwco->ret =3D blk_co_ioctl(rwco->blk, rwco->ioctl.req, rwco->ioctl.buf= ); =20 blk_aio_complete(acb); } @@ -1545,7 +1589,11 @@ static void blk_aio_ioctl_entry(void *opaque) BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *= buf, BlockCompletionFunc *cb, void *opaque) { - return blk_aio_prwv(blk, req, 0, buf, blk_aio_ioctl_entry, 0, cb, opaq= ue); + BlkRwCo rwco =3D (BlkRwCo) { + .ioctl.req =3D req, + .ioctl.buf =3D buf, + }; + return blk_aio_prwv(blk, &rwco, blk_aio_ioctl_entry, cb, opaque); } =20 int blk_co_pdiscard(BlockBackend *blk, int64_t offset, int bytes) @@ -1575,7 +1623,8 @@ static void blk_flush_entry(void *opaque) =20 int blk_flush(BlockBackend *blk) { - return blk_prw(blk, 0, NULL, 0, blk_flush_entry, 0); + BlkRwCo rwco =3D { }; + return blk_prw(blk, &rwco, blk_flush_entry); } =20 void blk_drain(BlockBackend *blk) @@ -1985,8 +2034,13 @@ int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *= blk, int64_t offset, int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, const void *b= uf, int count) { - return blk_prw(blk, offset, (void *) buf, count, blk_write_entry, - BDRV_REQ_WRITE_COMPRESSED); + BlkRwCo rwco =3D (BlkRwCo) { + .prw.offset =3D offset, + .prw.buf =3D (void *)buf, + .prw.bytes =3D count, + .prw.flags =3D BDRV_REQ_WRITE_COMPRESSED, + }; + return blk_prw(blk, &rwco, blk_write_entry); } =20 int blk_truncate(BlockBackend *blk, int64_t offset, PreallocMode prealloc, @@ -2003,14 +2057,17 @@ int blk_truncate(BlockBackend *blk, int64_t offset,= PreallocMode prealloc, static void blk_pdiscard_entry(void *opaque) { BlkRwCo *rwco =3D opaque; - QEMUIOVector *qiov =3D rwco->iobuf; =20 - rwco->ret =3D blk_co_pdiscard(rwco->blk, rwco->offset, qiov->size); + rwco->ret =3D blk_co_pdiscard(rwco->blk, rwco->prw.offset, rwco->prw.b= ytes); } =20 int blk_pdiscard(BlockBackend *blk, int64_t offset, int bytes) { - return blk_prw(blk, offset, NULL, bytes, blk_pdiscard_entry, 0); + BlkRwCo rwco =3D (BlkRwCo) { + .prw.offset =3D offset, + .prw.bytes =3D bytes, + }; + return blk_prw(blk, &rwco, blk_pdiscard_entry); } =20 int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf, --=20 2.17.0 From nobody Tue Apr 30 14:45:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528438284071694.6700276944171; Thu, 7 Jun 2018 23:11:24 -0700 (PDT) Received: from localhost ([::1]:33318 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRAcN-0005MU-8q for importer@patchew.org; Fri, 08 Jun 2018 02:11:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42028) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRAWN-0000Ix-Lh for qemu-devel@nongnu.org; Fri, 08 Jun 2018 02:05:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRAWM-0008Ru-Q6 for qemu-devel@nongnu.org; Fri, 08 Jun 2018 02:05:11 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40232 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fRAWK-0008Ok-IU; Fri, 08 Jun 2018 02:05:08 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2A9BE401EF04; Fri, 8 Jun 2018 06:05:08 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-108.pek2.redhat.com [10.72.12.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5749C1C65D; Fri, 8 Jun 2018 06:05:03 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 8 Jun 2018 14:04:15 +0800 Message-Id: <20180608060417.10170-5-famz@redhat.com> In-Reply-To: <20180608060417.10170-1-famz@redhat.com> References: <20180608060417.10170-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 08 Jun 2018 06:05:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 08 Jun 2018 06:05:08 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 4/6] block-backend: Add blk_aio_copy_range 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: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Jeff Cody , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Fam Zheng --- block/block-backend.c | 36 ++++++++++++++++++++++++++++++++++ include/sysemu/block-backend.h | 4 ++++ 2 files changed, 40 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index e20a204bee..36d928e13d 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1213,6 +1213,14 @@ typedef struct BlkRwCo { unsigned long int req; void *buf; } ioctl; + + struct { + BlockBackend *dst_blk; + int64_t src_off; + int64_t dst_off; + int bytes; + BdrvRequestFlags flags; + } copy_range; }; =20 } BlkRwCo; @@ -1505,6 +1513,34 @@ BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64= _t offset, return blk_aio_prwv(blk, &rwco, blk_aio_write_entry, cb, opaque); } =20 +static void blk_aio_copy_range_entry(void *opaque) +{ + BlkAioEmAIOCB *acb =3D opaque; + BlkRwCo *rwco =3D &acb->rwco; + + rwco->ret =3D blk_co_copy_range(rwco->blk, rwco->copy_range.src_off, + rwco->copy_range.dst_blk, + rwco->copy_range.dst_off, + rwco->copy_range.bytes, + rwco->copy_range.flags); + blk_aio_complete(acb); +} + +BlockAIOCB *blk_aio_copy_range(BlockBackend *src, int64_t src_offset, + BlockBackend *dst, int64_t dst_offset, + uint64_t bytes, BdrvRequestFlags flags, + BlockCompletionFunc *cb, void *opaque) +{ + BlkRwCo rwco =3D (BlkRwCo) { + .copy_range.src_off =3D src_offset, + .copy_range.dst_blk =3D dst, + .copy_range.dst_off =3D dst_offset, + .copy_range.bytes =3D bytes, + .copy_range.flags =3D flags, + }; + return blk_aio_prwv(src, &rwco, blk_aio_copy_range_entry, cb, opaque); +} + static void blk_aio_flush_entry(void *opaque) { BlkAioEmAIOCB *acb =3D opaque; diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 8d03d493c2..ea121eac3f 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -147,6 +147,10 @@ BlockAIOCB *blk_aio_flush(BlockBackend *blk, BlockCompletionFunc *cb, void *opaque); BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int bytes, BlockCompletionFunc *cb, void *opaque); +BlockAIOCB *blk_aio_copy_range(BlockBackend *src, int64_t src_offset, + BlockBackend *dst, int64_t dst_offset, + uint64_t bytes, BdrvRequestFlags flags, + BlockCompletionFunc *cb, void *opaque); void blk_aio_cancel(BlockAIOCB *acb); void blk_aio_cancel_async(BlockAIOCB *acb); int blk_co_ioctl(BlockBackend *blk, unsigned long int req, void *buf); --=20 2.17.0 From nobody Tue Apr 30 14:45:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528438032417438.2581544510077; Thu, 7 Jun 2018 23:07:12 -0700 (PDT) Received: from localhost ([::1]:33292 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRAYJ-0001PP-IM for importer@patchew.org; Fri, 08 Jun 2018 02:07:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42065) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRAWU-0000Sr-EL for qemu-devel@nongnu.org; Fri, 08 Jun 2018 02:05:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRAWT-0008Vq-FN for qemu-devel@nongnu.org; Fri, 08 Jun 2018 02:05:18 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37786 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fRAWO-0008U9-VH; Fri, 08 Jun 2018 02:05:13 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 909A78151D42; Fri, 8 Jun 2018 06:05:12 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-108.pek2.redhat.com [10.72.12.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA6B71C641; Fri, 8 Jun 2018 06:05:08 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 8 Jun 2018 14:04:16 +0800 Message-Id: <20180608060417.10170-6-famz@redhat.com> In-Reply-To: <20180608060417.10170-1-famz@redhat.com> References: <20180608060417.10170-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 08 Jun 2018 06:05:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 08 Jun 2018 06:05:12 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 5/6] block: Add backing passthrough implementations for copy_range 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: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Jeff Cody , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Similar to bdrv_co_block_status_from_backing we add the two passthrough callbacks for copy_range. This will be used by the block driver filters so that they can support copy offloading. Signed-off-by: Fam Zheng --- block/io.c | 24 ++++++++++++++++++++++++ include/block/block_int.h | 22 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/block/io.c b/block/io.c index d8039793c2..d1559c9cd5 100644 --- a/block/io.c +++ b/block/io.c @@ -1900,6 +1900,30 @@ int coroutine_fn bdrv_co_block_status_from_backing(B= lockDriverState *bs, return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID; } =20 +int coroutine_fn bdrv_co_copy_range_from_backing(BlockDriverState *bs, + BdrvChild *src, uint64_t = src_offset, + BdrvChild *dst, uint64_t = dst_offset, + uint64_t bytes, BdrvReque= stFlags flags) +{ + if (!src->bs) { + return -ENOMEDIUM; + } + return bdrv_co_copy_range_from(src->bs->backing, src_offset, dst, + dst_offset, bytes, flags); +} + +int coroutine_fn bdrv_co_copy_range_to_backing(BlockDriverState *bs, + BdrvChild *src, uint64_t sr= c_offset, + BdrvChild *dst, uint64_t ds= t_offset, + uint64_t bytes, BdrvRequest= Flags flags) +{ + if (!dst->bs) { + return -ENOMEDIUM; + } + return bdrv_co_copy_range_to(src, src_offset, dst->bs->backing, + dst_offset, bytes, flags); +} + /* * Returns the allocation status of the specified sectors. * Drivers not implementing the functionality are assumed to not support diff --git a/include/block/block_int.h b/include/block/block_int.h index 2c51cd420f..b488d74c1b 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1118,6 +1118,28 @@ int coroutine_fn bdrv_co_block_status_from_backing(B= lockDriverState *bs, int64_t *pnum, int64_t *map, BlockDriverState **file= ); + +/* + * Default implementation for drivers to pass bdrv_co_copy_range_from() to + * their backing file. + */ +int coroutine_fn bdrv_co_copy_range_from_backing(BlockDriverState *bs, + BdrvChild *src, uint64_t = src_offset, + BdrvChild *dst, uint64_t = dst_offset, + uint64_t bytes, + BdrvRequestFlags flags); + + +/* + * Default implementation for drivers to pass bdrv_co_copy_range_to() to t= heir + * backing file. + */ +int coroutine_fn bdrv_co_copy_range_to_backing(BlockDriverState *bs, + BdrvChild *src, uint64_t sr= c_offset, + BdrvChild *dst, uint64_t ds= t_offset, + uint64_t bytes, + BdrvRequestFlags flags); + const char *bdrv_get_parent_name(const BlockDriverState *bs); void blk_dev_change_media_cb(BlockBackend *blk, bool load, Error **errp); bool blk_dev_has_removable_media(BlockBackend *blk); --=20 2.17.0 From nobody Tue Apr 30 14:45:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528438179173281.6702997226773; Thu, 7 Jun 2018 23:09:39 -0700 (PDT) Received: from localhost ([::1]:33303 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRAag-0003B5-A7 for importer@patchew.org; Fri, 08 Jun 2018 02:09:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRAWg-0000Zd-L4 for qemu-devel@nongnu.org; Fri, 08 Jun 2018 02:05:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRAWf-00009o-1w for qemu-devel@nongnu.org; Fri, 08 Jun 2018 02:05:30 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40236 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fRAWZ-00007G-Rs; Fri, 08 Jun 2018 02:05:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6C91A401EF04; Fri, 8 Jun 2018 06:05:23 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-108.pek2.redhat.com [10.72.12.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5972A1C5BA; Fri, 8 Jun 2018 06:05:12 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 8 Jun 2018 14:04:17 +0800 Message-Id: <20180608060417.10170-7-famz@redhat.com> In-Reply-To: <20180608060417.10170-1-famz@redhat.com> References: <20180608060417.10170-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 08 Jun 2018 06:05:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 08 Jun 2018 06:05:23 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 6/6] mirror: Use copy offloading 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: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Jeff Cody , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This makes the mirror job to try offloaded copy. If it fails, error action will not be taken yet, instead the failed cluster and all the subsequent ones will fall back to bounce buffer. Signed-off-by: Fam Zheng --- block/mirror.c | 71 +++++++++++++++++++++++++++++++++++++++++++++- block/trace-events | 1 + 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/block/mirror.c b/block/mirror.c index 435268bbbf..a90b64550c 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -71,6 +71,8 @@ typedef struct MirrorBlockJob { int target_cluster_size; int max_iov; bool initial_zeroing_ongoing; + + bool use_copy_range; } MirrorBlockJob; =20 typedef struct MirrorOp { @@ -293,6 +295,69 @@ static uint64_t mirror_do_read(MirrorBlockJob *s, int6= 4_t offset, return ret; } =20 +static void mirror_copy_range_complete(void *opaque, int ret) +{ + MirrorOp *op =3D opaque; + MirrorBlockJob *s =3D op->s; + + aio_context_acquire(blk_get_aio_context(s->common.blk)); + trace_mirror_copy_range_complete(s, ret, op->offset, op->bytes); + if (!ret) { + mirror_iteration_done(op, ret); + } else { + uint64_t bytes; + + s->use_copy_range =3D false; + s->in_flight--; + s->bytes_in_flight -=3D op->bytes; + bytes =3D mirror_do_read(s, op->offset, op->bytes); + /* No alignment adjusting in mirror_do_read since we've already do= ne + * that in mirror_do_copy(). */ + assert(bytes =3D=3D op->bytes); + g_free(op); + } + aio_context_release(blk_get_aio_context(s->common.blk)); +} + +static uint64_t mirror_do_copy(MirrorBlockJob *s, int64_t offset, + uint64_t bytes) +{ + uint64_t ret; + MirrorOp *op; + + if (!s->use_copy_range || offset < BLOCK_PROBE_BUF_SIZE) { + return mirror_do_read(s, offset, bytes); + } + + assert(bytes); + assert(bytes < BDRV_REQUEST_MAX_BYTES); + ret =3D bytes; + + if (s->cow_bitmap) { + ret +=3D mirror_cow_align(s, &offset, &bytes); + } + /* The offset is granularity-aligned because: + * 1) Caller passes in aligned values; + * 2) mirror_cow_align is used only when target cluster is larger. */ + assert(QEMU_IS_ALIGNED(offset, s->granularity)); + /* The range is sector-aligned, since bdrv_getlength() rounds up. */ + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); + + op =3D g_new0(MirrorOp, 1); + op->s =3D s; + op->offset =3D offset; + op->bytes =3D bytes; + + /* Copy the dirty cluster. */ + s->in_flight++; + s->bytes_in_flight +=3D bytes; + trace_mirror_one_iteration(s, offset, bytes); + + blk_aio_copy_range(s->common.blk, offset, s->target, offset, + bytes, 0, mirror_copy_range_complete, op); + return ret; +} + static void mirror_do_zero_or_discard(MirrorBlockJob *s, int64_t offset, uint64_t bytes, @@ -429,7 +494,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) io_bytes =3D mirror_clip_bytes(s, offset, io_bytes); switch (mirror_method) { case MIRROR_METHOD_COPY: - io_bytes =3D io_bytes_acct =3D mirror_do_read(s, offset, io_by= tes); + io_bytes =3D io_bytes_acct =3D mirror_do_copy(s, offset, io_by= tes); break; case MIRROR_METHOD_ZERO: case MIRROR_METHOD_DISCARD: @@ -1090,6 +1155,8 @@ static BlockDriver bdrv_mirror_top =3D { .bdrv_co_pdiscard =3D bdrv_mirror_top_pdiscard, .bdrv_co_flush =3D bdrv_mirror_top_flush, .bdrv_co_block_status =3D bdrv_co_block_status_from_backing, + .bdrv_co_copy_range_from =3D bdrv_co_copy_range_from_backing, + .bdrv_co_copy_range_to =3D bdrv_co_copy_range_to_backing, .bdrv_refresh_filename =3D bdrv_mirror_top_refresh_filename, .bdrv_close =3D bdrv_mirror_top_close, .bdrv_child_perm =3D bdrv_mirror_top_child_perm, @@ -1177,6 +1244,8 @@ static void mirror_start_job(const char *job_id, Bloc= kDriverState *bs, s->source =3D bs; s->mirror_top_bs =3D mirror_top_bs; =20 + s->use_copy_range =3D true; + /* No resize for the target either; while the mirror is still running,= a * consistent read isn't necessarily possible. We could possibly allow * writes and graph modifications, though it would likely defeat the diff --git a/block/trace-events b/block/trace-events index 2d59b53fd3..2958003e33 100644 --- a/block/trace-events +++ b/block/trace-events @@ -34,6 +34,7 @@ mirror_one_iteration(void *s, int64_t offset, uint64_t by= tes) "s %p offset %" PR mirror_iteration_done(void *s, int64_t offset, uint64_t bytes, int ret) "s= %p offset %" PRId64 " bytes %" PRIu64 " ret %d" mirror_yield(void *s, int64_t cnt, int buf_free_count, int in_flight) "s %= p dirty count %"PRId64" free buffers %d in_flight %d" mirror_yield_in_flight(void *s, int64_t offset, int in_flight) "s %p offse= t %" PRId64 " in_flight %d" +mirror_copy_range_complete(void *s, int ret, int64_t offset, uint64_t byte= s) "s %p ret %d offset %" PRId64 " bytes %" PRIu64 =20 # block/backup.c backup_do_cow_enter(void *job, int64_t start, int64_t offset, uint64_t byt= es) "job %p start %" PRId64 " offset %" PRId64 " bytes %" PRIu64 --=20 2.17.0