From patchwork Thu Mar 29 11:09:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 10314947 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9552B60353 for ; Thu, 29 Mar 2018 11:11:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90CFF20134 for ; Thu, 29 Mar 2018 11:11:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8502126AE3; Thu, 29 Mar 2018 11:11:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 0FF5920134 for ; Thu, 29 Mar 2018 11:11:18 +0000 (UTC) Received: from localhost ([::1]:41662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1VSg-0002vu-3F for patchwork-qemu-devel@patchwork.kernel.org; Thu, 29 Mar 2018 07:11:18 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 = 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 = NULL; + int r = bs->drv->bdrv_co_map_range(bs, offset, bytes, + &cur_pnum, &cur_map, &cur_file, + flags); + if (r < 0) { + return r; + } + offset = cur_map; + bytes = cur_pnum; + if (pnum) { + *pnum = cur_pnum; + } + if (map) { + *map = cur_map; + } + if (!(r & BDRV_BLOCK_OFFSET_VALID)) { + return -ENOTSUP; + } + if (file) { + *file = cur_file; + } + if (!cur_file) { + return -ENOTSUP; + } + if (cur_file == bs) { + return r; + } + bs = 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 = 0x8, BDRV_REQ_FUA = 0x10, BDRV_REQ_WRITE_COMPRESSED = 0x20, + BDRV_REQ_ALLOCATE = 0x40, /* Mask of valid flags */ - BDRV_REQ_MASK = 0x3f, + BDRV_REQ_MASK = 0x7f, } BdrvRequestFlags; 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 size); 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 returned + * 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 mapped. + * 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; otherwise, it + * means the query should be passed down to an underlying format/protocol. + * @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; };