From nobody Tue Feb 10 13:01:37 2026 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522321914075405.54921840503243; Thu, 29 Mar 2018 04:11:54 -0700 (PDT) Received: from localhost ([::1]:41662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1VTE-0002vu-QT for importer@patchew.org; Thu, 29 Mar 2018 07:11:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1VR5-0001V4-Va for qemu-devel@nongnu.org; Thu, 29 Mar 2018 07:09:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1VR4-00037l-V0 for qemu-devel@nongnu.org; Thu, 29 Mar 2018 07:09:39 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57638 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 1f1VQy-000359-GZ; Thu, 29 Mar 2018 07:09:32 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 94CEA4070212; Thu, 29 Mar 2018 11:09:31 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-85.pek2.redhat.com [10.72.12.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60FC42026DFD; Thu, 29 Mar 2018 11:09:28 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 29 Mar 2018 19:09:07 +0800 Message-Id: <20180329110914.20888-2-famz@redhat.com> In-Reply-To: <20180329110914.20888-1-famz@redhat.com> References: <20180329110914.20888-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 29 Mar 2018 11:09:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 29 Mar 2018 11:09:31 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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] [RFC PATCH 1/8] block: Introduce bdrv_co_map_range API 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, Max Reitz , Stefan Hajnoczi , pbonzini@redhat.com 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" A little similar to bdrv_co_block_status but with the capability to do allocation depending on the BDRV_REQ_ALLOCATE flag, this API is the building block needed by copy offloading to work for format drivers. The idea is the format drivers return "where" to copy from/to in its underlying "file", then the block layer will drill down until it reaches a protocol layer that can do offloaded copying. Signed-off-by: Fam Zheng --- block/io.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/block/block.h | 8 +++++++- include/block/block_int.h | 21 +++++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/block/io.c b/block/io.c index bd9a19a9c4..1b4cfcacb1 100644 --- a/block/io.c +++ b/block/io.c @@ -2826,3 +2826,47 @@ void bdrv_unregister_buf(BlockDriverState *bs, void = *host) bdrv_unregister_buf(child->bs, host); } } + +int coroutine_fn bdrv_co_map_range(BdrvChild *child, int64_t offset, + int64_t bytes, int64_t *pnum, int64_t *= map, + BlockDriverState **file, + int flags) +{ + BlockDriverState *bs =3D child->bs; + + if (bs->encrypted) { + return -ENOTSUP; + } + while (bs && bs->drv && bs->drv->bdrv_co_map_range) { + int64_t cur_pnum, cur_map; + BlockDriverState *cur_file =3D NULL; + int r =3D bs->drv->bdrv_co_map_range(bs, offset, bytes, + &cur_pnum, &cur_map, &cur_file, + flags); + if (r < 0) { + return r; + } + offset =3D cur_map; + bytes =3D cur_pnum; + if (pnum) { + *pnum =3D cur_pnum; + } + if (map) { + *map =3D cur_map; + } + if (!(r & BDRV_BLOCK_OFFSET_VALID)) { + return -ENOTSUP; + } + if (file) { + *file =3D cur_file; + } + if (!cur_file) { + return -ENOTSUP; + } + if (cur_file =3D=3D bs) { + return r; + } + bs =3D cur_file; + } + return -ENOTSUP; +} diff --git a/include/block/block.h b/include/block/block.h index cdec3639a3..21d3e9db32 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -53,9 +53,10 @@ typedef enum { BDRV_REQ_NO_SERIALISING =3D 0x8, BDRV_REQ_FUA =3D 0x10, BDRV_REQ_WRITE_COMPRESSED =3D 0x20, + BDRV_REQ_ALLOCATE =3D 0x40, =20 /* Mask of valid flags */ - BDRV_REQ_MASK =3D 0x3f, + BDRV_REQ_MASK =3D 0x7f, } BdrvRequestFlags; =20 typedef struct BlockSizes { @@ -604,4 +605,9 @@ bool bdrv_can_store_new_dirty_bitmap(BlockDriverState *= bs, const char *name, */ void bdrv_register_buf(BlockDriverState *bs, void *host, size_t size); void bdrv_unregister_buf(BlockDriverState *bs, void *host); + +int bdrv_co_map_range(BdrvChild *child, int64_t offset, + int64_t bytes, int64_t *pnum, int64_t *map, + BlockDriverState **file, + int flags); #endif diff --git a/include/block/block_int.h b/include/block/block_int.h index c4dd1d4bb8..3f3f6f3efd 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -475,6 +475,27 @@ struct BlockDriver { */ void (*bdrv_register_buf)(BlockDriverState *bs, void *host, size_t siz= e); void (*bdrv_unregister_buf)(BlockDriverState *bs, void *host); + + /** + * Get or create offset mappings for a virtual range. + * + * @offset: the offset of the beginning of the range. + * @bytes: the maximum bytes of the range to map. + * @pnum: at return, this will point to the number of bytes in the ret= urned + * mapping status + * @map: at return, this will point to the offset which the range maps= to + * @file: at return, this will point to the file where the data is map= ped. + * If it is set to bs, it means the mapping is terminal and the result= can + * be used for read/write and copy_range; if it is NULL, it means the = range + * doesn't map to a file, or no I/O to any file is necessary; otherwis= e, it + * means the query should be passed down to an underlying format/proto= col. + * @flags: flags for the request. BDRV_REQ_ALLOCATE means the range + * should be allocated if necessary. + */ + int (*bdrv_co_map_range)(BlockDriverState *bs, int64_t offset, + int64_t bytes, int64_t *pnum, int64_t *map, + BlockDriverState **file, + int flags); QLIST_ENTRY(BlockDriver) list; }; =20 --=20 2.14.3