From nobody Wed May 22 02:30:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578482638; cv=none; d=zohomail.com; s=zohoarc; b=XhzEUugSvcAX1ogemPGadKVUgn/RmZar4R9VZ6eVM8GNrCMQtJlAaKv/j7knHoMK74G6svmnYA1KdU/rmsVszq1gafHlMMcB4BvU1Js9SL0TO1pbsWYtCh/HqiHax+MbfCdhpkAPSQWABzSQLwGClUmbgofjRJllNBs4oNEJ5tQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578482638; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=asjGjJ+5UzsC27I8IX7Zxas5kupKb/Y//VGwbMRwWOo=; b=j0Z2A6uG9IASh2+2f/FDlsJfGJ3Bsax5O12rPpxuOFEZYzeFTdNEm63gNtOhBtLaRrFyN19BMazruf3WdOfmtmEWe4gEc2Wb6K75s23q4xdMvWEB3ZnEvl1d7K/KuygL+/Jtc6eQ1OwxgKCt1Zeowk5YQVsL60wh+mxTQSJ+i1k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157848263803636.23943727737344; Wed, 8 Jan 2020 03:23:58 -0800 (PST) Received: from localhost ([::1]:42166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ip9RM-0005Yy-IX for importer@patchew.org; Wed, 08 Jan 2020 06:23:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49678) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ip9Q3-0003tP-Ip for qemu-devel@nongnu.org; Wed, 08 Jan 2020 06:22:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ip9Q0-0004Vt-Ne for qemu-devel@nongnu.org; Wed, 08 Jan 2020 06:22:34 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:32492 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ip9Q0-0004VH-CY for qemu-devel@nongnu.org; Wed, 08 Jan 2020 06:22:32 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-291-MSkLTDWaMc6WM1Mn1ajo6A-1; Wed, 08 Jan 2020 06:22:30 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7FB03801E77; Wed, 8 Jan 2020 11:22:29 +0000 (UTC) Received: from localhost (ovpn-116-249.ams2.redhat.com [10.36.116.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9769960CD3; Wed, 8 Jan 2020 11:22:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578482551; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=asjGjJ+5UzsC27I8IX7Zxas5kupKb/Y//VGwbMRwWOo=; b=UuiyKT2QIin9F/hNsa6IsclDCbBUpOCRoW0ABfRPKZXW8x5VKyFkjy70rYt0SSjivy+nGW 2Ggcj4PSNQki4M4BLYp6gaNLbXiIpv2uP0fLKBuMVkhBzEko/4rp9pBeeW1Tz0S39Ym+oi uFP8DRF+NthF4qiAf81xZukVBp/PZfc= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 1/4] luks: extract block_crypto_calculate_payload_offset() Date: Wed, 8 Jan 2020 11:22:17 +0000 Message-Id: <20200108112220.499180-2-stefanha@redhat.com> In-Reply-To: <20200108112220.499180-1-stefanha@redhat.com> References: <20200108112220.499180-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: MSkLTDWaMc6WM1Mn1ajo6A-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefan Hajnoczi , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The qcow2 .bdrv_measure() code calculates the crypto payload offset. This logic really belongs in block/crypto.c where it can be reused by other image formats. The "luks" block driver will need this same logic in order to implement .bdrv_measure(), so extract the block_crypto_calculate_payload_offset() function now. Signed-off-by: Stefan Hajnoczi --- block/crypto.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ block/crypto.h | 5 ++++ block/qcow2.c | 59 ++++------------------------------------------ 3 files changed, 73 insertions(+), 55 deletions(-) diff --git a/block/crypto.c b/block/crypto.c index 24823835c1..ed32202fa2 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -185,6 +185,70 @@ block_crypto_create_opts_init(QDict *opts, Error **err= p) } =20 =20 +static ssize_t block_crypto_headerlen_hdr_init_func(QCryptoBlock *block, + size_t headerlen, void *opaque, Error **errp) +{ + size_t *headerlenp =3D opaque; + + /* Stash away the payload size */ + *headerlenp =3D headerlen; + return 0; +} + + +static ssize_t block_crypto_headerlen_hdr_write_func(QCryptoBlock *block, + size_t offset, const uint8_t *buf, size_t buflen, + void *opaque, Error **errp) +{ + /* Discard the bytes, we're not actually writing to an image */ + return buflen; +} + + +/* Determine the number of bytes for the crypto header */ +bool block_crypto_calculate_payload_offset(QemuOpts *opts, + const char *optprefix, + size_t *len, + Error **errp) +{ + QDict *cryptoopts_qdict; + QCryptoBlockCreateOptions *cryptoopts; + QCryptoBlock *crypto; + + /* Extract options into a qdict */ + if (optprefix) { + QDict *opts_qdict =3D qemu_opts_to_qdict(opts, NULL); + + qdict_extract_subqdict(opts_qdict, &cryptoopts_qdict, optprefix); + qobject_unref(opts_qdict); + } else { + cryptoopts_qdict =3D qemu_opts_to_qdict(opts, NULL); + } + + /* Build QCryptoBlockCreateOptions object from qdict */ + qdict_put_str(cryptoopts_qdict, "format", "luks"); + + cryptoopts =3D block_crypto_create_opts_init(cryptoopts_qdict, errp); + qobject_unref(cryptoopts_qdict); + if (!cryptoopts) { + return false; + } + + /* Fake LUKS creation in order to determine the payload size */ + crypto =3D qcrypto_block_create(cryptoopts, optprefix, + block_crypto_headerlen_hdr_init_func, + block_crypto_headerlen_hdr_write_func, + len, errp); + qapi_free_QCryptoBlockCreateOptions(cryptoopts); + if (!crypto) { + return false; + } + + qcrypto_block_free(crypto); + return true; +} + + static int block_crypto_open_generic(QCryptoBlockFormat format, QemuOptsList *opts_spec, BlockDriverState *bs, diff --git a/block/crypto.h b/block/crypto.h index b935695e79..5a39bee71b 100644 --- a/block/crypto.h +++ b/block/crypto.h @@ -94,4 +94,9 @@ block_crypto_create_opts_init(QDict *opts, Error **errp); QCryptoBlockOpenOptions * block_crypto_open_opts_init(QDict *opts, Error **errp); =20 +bool block_crypto_calculate_payload_offset(QemuOpts *opts, + const char *optprefix, + size_t *len, + Error **errp); + #endif /* BLOCK_CRYPTO_H */ diff --git a/block/qcow2.c b/block/qcow2.c index 7fbaac8457..cbdcc8695f 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4561,60 +4561,6 @@ static coroutine_fn int qcow2_co_flush_to_os(BlockDr= iverState *bs) return ret; } =20 -static ssize_t qcow2_measure_crypto_hdr_init_func(QCryptoBlock *block, - size_t headerlen, void *opaque, Error **errp) -{ - size_t *headerlenp =3D opaque; - - /* Stash away the payload size */ - *headerlenp =3D headerlen; - return 0; -} - -static ssize_t qcow2_measure_crypto_hdr_write_func(QCryptoBlock *block, - size_t offset, const uint8_t *buf, size_t buflen, - void *opaque, Error **errp) -{ - /* Discard the bytes, we're not actually writing to an image */ - return buflen; -} - -/* Determine the number of bytes for the LUKS payload */ -static bool qcow2_measure_luks_headerlen(QemuOpts *opts, size_t *len, - Error **errp) -{ - QDict *opts_qdict; - QDict *cryptoopts_qdict; - QCryptoBlockCreateOptions *cryptoopts; - QCryptoBlock *crypto; - - /* Extract "encrypt." options into a qdict */ - opts_qdict =3D qemu_opts_to_qdict(opts, NULL); - qdict_extract_subqdict(opts_qdict, &cryptoopts_qdict, "encrypt."); - qobject_unref(opts_qdict); - - /* Build QCryptoBlockCreateOptions object from qdict */ - qdict_put_str(cryptoopts_qdict, "format", "luks"); - cryptoopts =3D block_crypto_create_opts_init(cryptoopts_qdict, errp); - qobject_unref(cryptoopts_qdict); - if (!cryptoopts) { - return false; - } - - /* Fake LUKS creation in order to determine the payload size */ - crypto =3D qcrypto_block_create(cryptoopts, "encrypt.", - qcow2_measure_crypto_hdr_init_func, - qcow2_measure_crypto_hdr_write_func, - len, errp); - qapi_free_QCryptoBlockCreateOptions(cryptoopts); - if (!crypto) { - return false; - } - - qcrypto_block_free(crypto); - return true; -} - static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *i= n_bs, Error **errp) { @@ -4667,7 +4613,10 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opt= s, BlockDriverState *in_bs, if (has_luks) { size_t headerlen; =20 - if (!qcow2_measure_luks_headerlen(opts, &headerlen, &local_err)) { + if (!block_crypto_calculate_payload_offset(opts, + "encrypt.", + &headerlen, + &local_err)) { goto err; } =20 --=20 2.24.1 From nobody Wed May 22 02:30:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578482641; cv=none; d=zohomail.com; s=zohoarc; b=Jw15LDL3uK2sgk9PH1HoJJU9/W6uQj3BeXzpm/L/CkOXBdgbZ+UuaXSicuysaLmb4tuaiMIahA0K4uwfWgJs1VBjkMgyYLMPcugbYvK4I0nAI/q+noh2Hxa108TQ8ff1JkM2zinuEstJCBslXWBweU84pePGfvwwwPioRmic360= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578482641; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Tf7eP6Hlno3E/cmbBYUVQX7SDxz/E3HxyT8pTZXeJF8=; b=YowgA3lmpQ4gRaOM8YgimKJh7mqDvC1aVi5K7gHFrFDK24CAKGVkDRevyObXGJc/Q/u9LHwOyFbBMCYl40wFxrccU0MEkgodC1Z79drHfQKkkrKZIFcGlhRiRweinnbl2KzoSeAJ392RYzphCncnVHa9Tr9yY5MpQxBr0BQc3p4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1578482641317746.0042441056999; Wed, 8 Jan 2020 03:24:01 -0800 (PST) Received: from localhost ([::1]:42168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ip9RQ-0005dy-2i for importer@patchew.org; Wed, 08 Jan 2020 06:24:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49731) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ip9Q6-0003wq-Dg for qemu-devel@nongnu.org; Wed, 08 Jan 2020 06:22:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ip9Q5-0004ZD-BE for qemu-devel@nongnu.org; Wed, 08 Jan 2020 06:22:38 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:34017 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ip9Q5-0004Yb-7U for qemu-devel@nongnu.org; Wed, 08 Jan 2020 06:22:37 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-324-nXH0xA89OK2-Gxbnmrc6YQ-1; Wed, 08 Jan 2020 06:22:35 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 99D73801E7A; Wed, 8 Jan 2020 11:22:34 +0000 (UTC) Received: from localhost (ovpn-116-249.ams2.redhat.com [10.36.116.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id E076F3A2; Wed, 8 Jan 2020 11:22:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578482556; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Tf7eP6Hlno3E/cmbBYUVQX7SDxz/E3HxyT8pTZXeJF8=; b=SNCa0sXkIKH/+8aJoVfhzfPqmE5uA0k1/Z/W2kCn/6GagznIEElc6jlR3BXpi+K8zPSkBS js5LBuTc3tCnvTXnSY+Kk5y4/z6OUU72+rbSPEdl8wKXzn3ew9Bm4Vxccq2XBRUmy8UjBR q6WSclaronnlFmct93V2BA9dTWIkoqk= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 2/4] luks: implement .bdrv_measure() Date: Wed, 8 Jan 2020 11:22:18 +0000 Message-Id: <20200108112220.499180-3-stefanha@redhat.com> In-Reply-To: <20200108112220.499180-1-stefanha@redhat.com> References: <20200108112220.499180-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: nXH0xA89OK2-Gxbnmrc6YQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefan Hajnoczi , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add qemu-img measure support in the "luks" block driver. Signed-off-by: Stefan Hajnoczi --- block/crypto.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/block/crypto.c b/block/crypto.c index ed32202fa2..94a24210ab 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -548,6 +548,87 @@ static int64_t block_crypto_getlength(BlockDriverState= *bs) } =20 =20 +static BlockMeasureInfo *block_crypto_measure(QemuOpts *opts, + BlockDriverState *in_bs, + Error **errp) +{ + Error *local_err =3D NULL; + BlockMeasureInfo *info; + uint64_t required =3D 0; /* bytes that contribute to required size */ + uint64_t virtual_size; /* disk size as seen by guest */ + uint64_t luks_payload_size; + char *optstr; + PreallocMode prealloc; + + optstr =3D qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); + prealloc =3D qapi_enum_parse(&PreallocMode_lookup, optstr, + PREALLOC_MODE_OFF, &local_err); + g_free(optstr); + if (local_err) { + goto err; + } + + virtual_size =3D qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); + + if (!block_crypto_calculate_payload_offset(opts, NULL, &luks_payload_s= ize, + &local_err)) { + goto err; + } + + if (in_bs) { + int64_t ssize; + int64_t offset; + int64_t pnum =3D 0; + + ssize =3D bdrv_getlength(in_bs); + if (ssize < 0) { + error_setg_errno(&local_err, -ssize, + "Unable to get image virtual_size"); + goto err; + } + + virtual_size =3D ssize; + + for (offset =3D 0; offset < ssize; offset +=3D pnum) { + int ret; + + ret =3D bdrv_block_status_above(in_bs, NULL, offset, + ssize - offset, &pnum, NULL, + NULL); + if (ret < 0) { + error_setg_errno(&local_err, -ret, + "Unable to get block status"); + goto err; + } + + if (ret & BDRV_BLOCK_ZERO) { + /* Skip zero regions */ + } else if ((ret & (BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED)) = =3D=3D + (BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED)) { + /* Count clusters we've seen */ + required +=3D pnum; + } + } + } + + /* Take into account preallocation. Nothing special is needed for + * PREALLOC_MODE_METADATA since metadata is always counted. + */ + if (prealloc =3D=3D PREALLOC_MODE_FULL || prealloc =3D=3D PREALLOC_MOD= E_FALLOC) { + required =3D virtual_size; + } + + info =3D g_new(BlockMeasureInfo, 1); + info->fully_allocated =3D luks_payload_size + virtual_size; + info->required =3D luks_payload_size + required; + return info; + +err: + error_propagate(errp, local_err); + return NULL; +} + + static int block_crypto_probe_luks(const uint8_t *buf, int buf_size, const char *filename) { @@ -734,6 +815,7 @@ static BlockDriver bdrv_crypto_luks =3D { .bdrv_co_preadv =3D block_crypto_co_preadv, .bdrv_co_pwritev =3D block_crypto_co_pwritev, .bdrv_getlength =3D block_crypto_getlength, + .bdrv_measure =3D block_crypto_measure, .bdrv_get_info =3D block_crypto_get_info_luks, .bdrv_get_specific_info =3D block_crypto_get_specific_info_luks, =20 --=20 2.24.1 From nobody Wed May 22 02:30:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578482765; cv=none; d=zohomail.com; s=zohoarc; b=ZkWylvmkhsFaU46P+zA4KmTVYf7vaKZ0YGsPY7+lSc8XOUxbsLBJC9ir9RZbJ0B78fuNWoh87jcD1fhztq4pNRZU1OOEnuhcDYWH1yRz9+KiM2PTaGnqFcJmj11yZecOZFms6YKfRElLACy9+5KiJEVYj1DxSowgrzMhlXhLmjE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578482765; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pP+UUPL3KtjmGguKCUXvjDL7hdspl0SO6dUXr7IRjH8=; b=T2VY+iKrtWiAWlv0SKFAtP/SFKCyhpsaLLwzCHrVsY4Xw/ij52AePydY18qvk953ollPiBY/NRg4vI/2UUq5rq+iTzOEvquB8r/w+OWhkR3+G+9FcJ28v2FSwcGOqJxdj9Nm8vAlTS+kOuxgZApNTkbMGxkoTLFTlpU6XeMtTWQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1578482765070108.13021835083191; Wed, 8 Jan 2020 03:26:05 -0800 (PST) Received: from localhost ([::1]:42202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ip9TO-0007y0-TZ for importer@patchew.org; Wed, 08 Jan 2020 06:26:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49779) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ip9QA-00043w-L4 for qemu-devel@nongnu.org; Wed, 08 Jan 2020 06:22:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ip9Q9-0004bv-IZ for qemu-devel@nongnu.org; Wed, 08 Jan 2020 06:22:42 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:58972 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ip9Q9-0004bc-ER for qemu-devel@nongnu.org; Wed, 08 Jan 2020 06:22:41 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-409-ON9N0zpAORGcXPepnQtHKg-1; Wed, 08 Jan 2020 06:22:39 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E5214184B1E1; Wed, 8 Jan 2020 11:22:38 +0000 (UTC) Received: from localhost (ovpn-116-249.ams2.redhat.com [10.36.116.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09E297BA22; Wed, 8 Jan 2020 11:22:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578482561; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pP+UUPL3KtjmGguKCUXvjDL7hdspl0SO6dUXr7IRjH8=; b=WgiayaqOlR2/mUHao/JKs6OULuXl7Me3VKJfHkqoxyxxrJ5w1aUfu98fy6btOn+e72xMW3 iRCTstZIXqbomiO1SJZNgNNEHk+Y7cCvO+XDPAO0EWSKKUhwT7RxG/LCnA/lSCXxmbjvtl J6caOOesR1zpNbpncTC0BSITR94fzrM= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 3/4] qemu-img: allow qemu-img measure --object without a filename Date: Wed, 8 Jan 2020 11:22:19 +0000 Message-Id: <20200108112220.499180-4-stefanha@redhat.com> In-Reply-To: <20200108112220.499180-1-stefanha@redhat.com> References: <20200108112220.499180-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: ON9N0zpAORGcXPepnQtHKg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefan Hajnoczi , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" In most qemu-img sub-commands the --object option only makes sense when there is a filename. qemu-img measure is an exception because objects may be referenced from the image creation options instead of an existing image file. Allow --object without a filename. Signed-off-by: Stefan Hajnoczi --- qemu-img.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 6233b8ca56..4f3e58f13b 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4903,10 +4903,8 @@ static int img_measure(int argc, char **argv) filename =3D argv[optind]; } =20 - if (!filename && - (object_opts || image_opts || fmt || snapshot_name || sn_opts)) { - error_report("--object, --image-opts, -f, and -l " - "require a filename argument."); + if (!filename && (image_opts || fmt || snapshot_name || sn_opts)) { + error_report("--image-opts, -f, and -l require a filename argument= ."); goto out; } if (filename && img_size !=3D UINT64_MAX) { --=20 2.24.1 From nobody Wed May 22 02:30:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578482791; cv=none; d=zohomail.com; s=zohoarc; b=DfDwHzw7yUp6doI/vgAOa4MxGWkN0TQGDqfxwinRWi9+VB0b9EUnQx3UOjebqVZslIK21snse5+nILjKqsEUkCCghI/wjuVrlqHT8frdDY7yefEA6/A6sUKLCaqQsEC0B/6rbiLHZL1HysqUTlUDZArRbKvBzkLkfetY8E5PiRk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578482791; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mgOxQ5uyZJfjGUoehj3MJnX8mFael+qy0RPkOBV6Evw=; b=cK4AJuwcxkVaynKAO0iYxO210l7QMyTj7RXmrVSBkSXJarQo1ocX2nGZbjDg6aI4cmSY/M6c974Xpp+S+oB629s/xzSpju3IEeAOrblJd/dR+c/4gTv1ByvidOFb8gYkJ9MZmn/le6XAtPUrMnUg9HXS5FxTLLIt3gxosIDS+UI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1578482791897499.93298771272123; Wed, 8 Jan 2020 03:26:31 -0800 (PST) Received: from localhost ([::1]:42216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ip9Tq-00009B-2h for importer@patchew.org; Wed, 08 Jan 2020 06:26:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49840) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ip9QG-0004Db-EZ for qemu-devel@nongnu.org; Wed, 08 Jan 2020 06:22:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ip9QE-0004ek-SS for qemu-devel@nongnu.org; Wed, 08 Jan 2020 06:22:48 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:51937 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ip9QD-0004e3-OF for qemu-devel@nongnu.org; Wed, 08 Jan 2020 06:22:46 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-284-9uWu5wa6NUCV4PN8IDKu1Q-1; Wed, 08 Jan 2020 06:22:44 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 390ABDB23; Wed, 8 Jan 2020 11:22:43 +0000 (UTC) Received: from localhost (ovpn-116-249.ams2.redhat.com [10.36.116.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5348B10018FF; Wed, 8 Jan 2020 11:22:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578482565; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mgOxQ5uyZJfjGUoehj3MJnX8mFael+qy0RPkOBV6Evw=; b=gHW5+QLRncxS9jwPZZtWV3xzYmkzIsZ77YzhiljavR12+mgJC/KZdoMVHfwmSWrLs4HyKM meaEaFEyJPditHeyeFjYZSUkgCDIzKaAkQbpKRKAE0SXBw6evF16vgwqRY82zwPD+TKNjd rx8jwUy0uMr6A0GGx4hPidNrAo1xJyg= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 4/4] iotests: add 282 luks qemu-img measure test Date: Wed, 8 Jan 2020 11:22:20 +0000 Message-Id: <20200108112220.499180-5-stefanha@redhat.com> In-Reply-To: <20200108112220.499180-1-stefanha@redhat.com> References: <20200108112220.499180-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: 9uWu5wa6NUCV4PN8IDKu1Q-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefan Hajnoczi , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This test exercises the block/crypto.c "luks" block driver .bdrv_measure() code. Signed-off-by: Stefan Hajnoczi --- tests/qemu-iotests/282 | 93 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/282.out | 30 ++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 124 insertions(+) create mode 100755 tests/qemu-iotests/282 create mode 100644 tests/qemu-iotests/282.out diff --git a/tests/qemu-iotests/282 b/tests/qemu-iotests/282 new file mode 100755 index 0000000000..6c62065aef --- /dev/null +++ b/tests/qemu-iotests/282 @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +# +# qemu-img measure tests for LUKS images +# +# Copyright (C) 2020 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dstefanha@redhat.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img + rm -f "$TEST_IMG.converted" +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter +. ./common.pattern + +_supported_fmt luks +_supported_proto file +_supported_os Linux + +SECRET=3Dsecret,id=3Dsec0,data=3Dpassphrase + +echo "=3D=3D measure 1G image file =3D=3D" +echo + +$QEMU_IMG measure --object "$SECRET" \ + -O "$IMGFMT" \ + -o key-secret=3Dsec0,iter-time=3D10 \ + --size 1G + +echo +echo "=3D=3D create 1G image file (size should be no greater than measured= ) =3D=3D" +echo + +_make_test_img 1G +stat -c "image file size in bytes: %s" "$TEST_IMG_FILE" + +echo +echo "=3D=3D modified 1G image file (size should be no greater than measur= ed) =3D=3D" +echo + +$QEMU_IO --object "$SECRET" --image-opts "$TEST_IMG" -c "write -P 0x51 0x1= 0000 0x400" | _filter_qemu_io | _filter_testdir +stat -c "image file size in bytes: %s" "$TEST_IMG_FILE" + +echo +echo "=3D=3D measure preallocation=3Dfalloc 1G image file =3D=3D" +echo + +$QEMU_IMG measure --object "$SECRET" \ + -O "$IMGFMT" \ + -o key-secret=3Dsec0,iter-time=3D10,preallocation=3Dfalloc \ + --size 1G + +echo +echo "=3D=3D measure with input image file =3D=3D" +echo + +IMGFMT=3Draw IMGKEYSECRET=3D IMGOPTS=3D _make_test_img 1G | _filter_imgfmt +QEMU_IO_OPTIONS=3D IMGOPTSSYNTAX=3D $QEMU_IO -f raw -c "write -P 0x51 0x10= 000 0x400" "$TEST_IMG_FILE" | _filter_qemu_io | _filter_testdir +$QEMU_IMG measure --object "$SECRET" \ + -O "$IMGFMT" \ + -o key-secret=3Dsec0,iter-time=3D10 \ + -f raw \ + "$TEST_IMG_FILE" + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/282.out b/tests/qemu-iotests/282.out new file mode 100644 index 0000000000..8f4737aef7 --- /dev/null +++ b/tests/qemu-iotests/282.out @@ -0,0 +1,30 @@ +QA output created by 282 +=3D=3D measure 1G image file =3D=3D + +required size: 2068480 +fully allocated size: 1075810304 + +=3D=3D create 1G image file (size should be no greater than measured) =3D= =3D + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824 +image file size in bytes: 1075810304 + +=3D=3D modified 1G image file (size should be no greater than measured) = =3D=3D + +wrote 1024/1024 bytes at offset 65536 +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +image file size in bytes: 1075810304 + +=3D=3D measure preallocation=3Dfalloc 1G image file =3D=3D + +required size: 1075810304 +fully allocated size: 1075810304 + +=3D=3D measure with input image file =3D=3D + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824 +wrote 1024/1024 bytes at offset 65536 +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +required size: 2076672 +fully allocated size: 1075810304 +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index cb2b789e44..d114e2c971 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -288,3 +288,4 @@ 277 rw quick 279 rw backing quick 280 rw migration quick +282 quick --=20 2.24.1