From nobody Mon Feb 9 09:52:44 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.zoho.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 1489570244139419.35811427243266; Wed, 15 Mar 2017 02:30:44 -0700 (PDT) Received: from localhost ([::1]:35362 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1co5GU-0000dG-R3 for importer@patchew.org; Wed, 15 Mar 2017 05:30:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49732) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1co5Fg-0000bL-Mq for qemu-devel@nongnu.org; Wed, 15 Mar 2017 05:29:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1co5Ff-0000L4-I2 for qemu-devel@nongnu.org; Wed, 15 Mar 2017 05:29:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38790) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1co5Ff-0000KA-99 for qemu-devel@nongnu.org; Wed, 15 Mar 2017 05:29:51 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 42EB180462; Wed, 15 Mar 2017 09:29:51 +0000 (UTC) Received: from localhost (ovpn-116-16.ams2.redhat.com [10.36.116.16]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2F9TlGs023282; Wed, 15 Mar 2017 05:29:49 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 42EB180462 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=stefanha@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 42EB180462 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Wed, 15 Mar 2017 17:29:33 +0800 Message-Id: <20170315092940.1367-2-stefanha@redhat.com> In-Reply-To: <20170315092940.1367-1-stefanha@redhat.com> References: <20170315092940.1367-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 15 Mar 2017 09:29:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v2 1/8] block: add bdrv_measure() 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 , John Snow , Nir Soffer , Maor Lipchuk , Stefan Hajnoczi , Alberto Garcia 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" bdrv_measure() provides a conservative maximum for the size of a new image. This information is handy if storage needs to be allocated (e.g. a SAN or an LVM volume) ahead of time. Signed-off-by: Stefan Hajnoczi --- qapi/block-core.json | 19 +++++++++++++++++++ include/block/block.h | 4 ++++ include/block/block_int.h | 2 ++ block.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) diff --git a/qapi/block-core.json b/qapi/block-core.json index 786b39e..673569d 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -463,6 +463,25 @@ '*dirty-bitmaps': ['BlockDirtyInfo'] } } =20 ## +# @BlockMeasureInfo: +# +# Image size calculation information. This structure describes the size +# requirements for creating a new image. +# +# @required-bytes: Amount of space required for image creation. This valu= e is +# the host file size including sparse file regions. A ne= w 5 +# GB raw file therefore has a required size of 5 GB, not 0 +# bytes. +# +# @fully-allocated-bytes: Space required once data has been written to all +# sectors +# +# Since: 2.10 +## +{ 'struct': 'BlockMeasureInfo', + 'data': {'required-bytes': 'int', 'fully-allocated-bytes': 'int'} } + +## # @query-block: # # Get a list of BlockInfo for all virtual block devices. diff --git a/include/block/block.h b/include/block/block.h index 5149260..43c789f 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -298,6 +298,10 @@ int bdrv_truncate(BdrvChild *child, int64_t offset); int64_t bdrv_nb_sectors(BlockDriverState *bs); int64_t bdrv_getlength(BlockDriverState *bs); int64_t bdrv_get_allocated_file_size(BlockDriverState *bs); +void bdrv_measure(BlockDriver *drv, QemuOpts *opts, + BlockDriverState *in_bs, + BlockMeasureInfo *info, + Error **errp); void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr); void bdrv_refresh_limits(BlockDriverState *bs, Error **errp); int bdrv_commit(BlockDriverState *bs); diff --git a/include/block/block_int.h b/include/block/block_int.h index 6c699ac..45a7fbe 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -201,6 +201,8 @@ struct BlockDriver { int64_t (*bdrv_getlength)(BlockDriverState *bs); bool has_variable_length; int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs); + void (*bdrv_measure)(QemuOpts *opts, BlockDriverState *in_bs, + BlockMeasureInfo *info, Error **errp); =20 int coroutine_fn (*bdrv_co_pwritev_compressed)(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov); diff --git a/block.c b/block.c index cb57370..532a4d1 100644 --- a/block.c +++ b/block.c @@ -3260,6 +3260,39 @@ int64_t bdrv_get_allocated_file_size(BlockDriverStat= e *bs) return -ENOTSUP; } =20 +/* + * bdrv_measure: + * @drv: Format driver + * @opts: Creation options + * @in_bs: Existing image containing data for new image (may be NULL) + * @info: Result object + * @errp: Error object + * + * Calculate file size required to create a new image. + * + * If @in_bs is given then space for allocated clusters and zero clusters + * from that image are included in the calculation. If @opts contains a + * backing file that is shared by @in_bs then backing clusters are omitted + * from the calculation. + * + * If @in_bs is NULL then the calculation includes no allocated clusters + * unless a preallocation option is given in @opts. + * + * Note that @in_bs may use a different BlockDriver from @drv. + */ +void bdrv_measure(BlockDriver *drv, QemuOpts *opts, + BlockDriverState *in_bs, BlockMeasureInfo *info, + Error **errp) +{ + if (!drv->bdrv_measure) { + error_setg(errp, "Block driver '%s' does not support size measurem= ent", + drv->format_name); + return; + } + + drv->bdrv_measure(opts, in_bs, info, errp); +} + /** * Return number of sectors on success, -errno on error. */ --=20 2.9.3