From nobody Wed May 1 09:22:48 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=1582284409; cv=none; d=zohomail.com; s=zohoarc; b=TmhErHzP918pNk3JtQesLzbO99Tc0JpdOl7zwl2IrPyXZuR1CLcz5HZv/64YpwQOn1N7oSvbh7eTq5Rnwmi6EFm4iUb3EBcZxSR7P4e+89pTNk4ypa2RcqESIF31CxvMF2Up+0Iz/PXEmcHrVPDdCIHhQlvg+FYWtjRx0zOlf8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582284409; 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=3hXWaOiZX5Jn9vlkfiXbwuhVruwtqf74Ea79U+XOKwo=; b=MBK9GepXRLbQvo+SMx9nWv/10dXqlLFxhdyJQVAcpb3m+9skxdFTvDJz/1BDPwQLZl5uZNfJzJtAt5DrOQTH0Ih6aBCBEIXjG3Q4qIcJxRJsMV+fndYHXwUfbErOoqsfncVUQxnk/5JcjcAt3xQb7Nyas49ovqyK2Ff221SF+8Q= 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 1582284409692365.7897496096606; Fri, 21 Feb 2020 03:26:49 -0800 (PST) Received: from localhost ([::1]:55550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j56SG-0007n7-Ij for importer@patchew.org; Fri, 21 Feb 2020 06:26:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35658) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j56R8-0005yd-SD for qemu-devel@nongnu.org; Fri, 21 Feb 2020 06:25:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j56R7-0001nE-Bu for qemu-devel@nongnu.org; Fri, 21 Feb 2020 06:25:38 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:59849 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 1j56R7-0001mB-7k for qemu-devel@nongnu.org; Fri, 21 Feb 2020 06:25: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-195-CGT7bfy3OiyDFVeKLMsamA-1; Fri, 21 Feb 2020 06:25:33 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 451BF92506; Fri, 21 Feb 2020 11:25:32 +0000 (UTC) Received: from localhost (ovpn-117-223.ams2.redhat.com [10.36.117.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 260BD6E3EE; Fri, 21 Feb 2020 11:25:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582284336; 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=3hXWaOiZX5Jn9vlkfiXbwuhVruwtqf74Ea79U+XOKwo=; b=C7raVuXvE9kucwhBSm791o29uhm1vK/My9ty5bQlusMeqM2rK+OA/DLkrIbJO3HbvOK/Io dpEDYOwBfkFMHLmFQMSdrjID3Sjka355JYvDYEL/Pz1Mis+O9qvf/Q+q3UEC+2pyrKBRvs /zmeYsIrB+BZ0C8THEJLVT3+vzz0fEg= X-MC-Unique: CGT7bfy3OiyDFVeKLMsamA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 1/4] luks: extract qcrypto_block_calculate_payload_offset() Date: Fri, 21 Feb 2020 11:25:19 +0000 Message-Id: <20200221112522.1497712-2-stefanha@redhat.com> In-Reply-To: <20200221112522.1497712-1-stefanha@redhat.com> References: <20200221112522.1497712-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , 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 crypto/block.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 qcrypto_block_calculate_payload_offset() function now. Signed-off-by: Stefan Hajnoczi Reviewed-by: Max Reitz --- block/qcow2.c | 74 +++++++++++------------------------------- crypto/block.c | 36 ++++++++++++++++++++ include/crypto/block.h | 22 +++++++++++++ 3 files changed, 77 insertions(+), 55 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 8dcee5efec..59df7ec0ce 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4601,60 +4601,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) { @@ -4705,9 +4651,27 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opt= s, BlockDriverState *in_bs, g_free(optstr); =20 if (has_luks) { + g_autoptr(QCryptoBlockCreateOptions) create_opts =3D NULL; + QDict *opts_qdict; + QDict *cryptoopts; size_t headerlen; =20 - if (!qcow2_measure_luks_headerlen(opts, &headerlen, &local_err)) { + opts_qdict =3D qemu_opts_to_qdict(opts, NULL); + qdict_extract_subqdict(opts_qdict, &cryptoopts, "encrypt."); + qobject_unref(opts_qdict); + + qdict_put_str(cryptoopts, "format", "luks"); + + create_opts =3D block_crypto_create_opts_init(cryptoopts, errp); + qobject_unref(cryptoopts); + if (!create_opts) { + goto err; + } + + if (!qcrypto_block_calculate_payload_offset(create_opts, + "encrypt.", + &headerlen, + &local_err)) { goto err; } =20 diff --git a/crypto/block.c b/crypto/block.c index 325752871c..6f42b32f1e 100644 --- a/crypto/block.c +++ b/crypto/block.c @@ -115,6 +115,42 @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateO= ptions *options, } =20 =20 +static ssize_t qcrypto_block_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 qcrypto_block_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; +} + + +bool +qcrypto_block_calculate_payload_offset(QCryptoBlockCreateOptions *create_o= pts, + const char *optprefix, + size_t *len, + Error **errp) +{ + /* Fake LUKS creation in order to determine the payload size */ + g_autoptr(QCryptoBlock) crypto =3D + qcrypto_block_create(create_opts, optprefix, + qcrypto_block_headerlen_hdr_init_func, + qcrypto_block_headerlen_hdr_write_func, + len, errp); + return crypto !=3D NULL; +} + + QCryptoBlockInfo *qcrypto_block_get_info(QCryptoBlock *block, Error **errp) { diff --git a/include/crypto/block.h b/include/crypto/block.h index d49d2c2da9..c77ccaf9c0 100644 --- a/include/crypto/block.h +++ b/include/crypto/block.h @@ -145,6 +145,26 @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateO= ptions *options, Error **errp); =20 =20 +/** + * qcrypto_block_calculate_payload_offset: + * @create_opts: the encryption options + * @optprefix: name prefix for options + * @len: output for number of header bytes before payload + * @errp: pointer to a NULL-initialized error object + * + * Calculate the number of header bytes before the payload in an encrypted + * storage volume. The header is an area before the payload that is reser= ved + * for encryption metadata. + * + * Returns: true on success, false on error + */ +bool +qcrypto_block_calculate_payload_offset(QCryptoBlockCreateOptions *create_o= pts, + const char *optprefix, + size_t *len, + Error **errp); + + /** * qcrypto_block_get_info: * @block: the block encryption object @@ -269,5 +289,7 @@ uint64_t qcrypto_block_get_sector_size(QCryptoBlock *bl= ock); void qcrypto_block_free(QCryptoBlock *block); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoBlock, qcrypto_block_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoBlockCreateOptions, + qapi_free_QCryptoBlockCreateOptions) =20 #endif /* QCRYPTO_BLOCK_H */ --=20 2.24.1 From nobody Wed May 1 09:22:48 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=1582284413; cv=none; d=zohomail.com; s=zohoarc; b=Qcz7/o3ruXJ4bdu+IRgq/xfF1HslrR2CxEZQ+hcQswcLLR54o+fRR31UktKTMOKVdf0Cx6/s0RYbjTZj8g6kqDVIE1KoSDu0NktNWgwOqtaSmP23Wtbdh9Al2nf9THr7xUpX0D266v78dHfsPy8cx7dFZz2kVmMDX2aRJBrKUzM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582284413; 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=DOjkhYK9Ev6VFF4mYEv8pPngwL00LgAB6vpzU/9FSFM=; b=YBVFwF+Sq0vhcBBHlu7dbwC6xDtY2NCF898C0WJSPKB7ER8BqH8wDk8oNNebYOGZyec6+Xo2eVToVVT18+XyhpqfrmwfkL7k3ADhCFXvXSMzzNokClVAkJ+uqzV81GPyifAh2VpzIqk/u71yW0NqcRjjlsdtGASrBnqlupzBDJc= 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 1582284413290759.724095040473; Fri, 21 Feb 2020 03:26:53 -0800 (PST) Received: from localhost ([::1]:55552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j56SK-0007vX-Bh for importer@patchew.org; Fri, 21 Feb 2020 06:26:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35717) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j56RC-00066l-Vl for qemu-devel@nongnu.org; Fri, 21 Feb 2020 06:25:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j56RB-0001sh-Qm for qemu-devel@nongnu.org; Fri, 21 Feb 2020 06:25:42 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:38029 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 1j56RB-0001sQ-Mv for qemu-devel@nongnu.org; Fri, 21 Feb 2020 06:25: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-456-yfjwDKyCNUy9G5svmQiNEQ-1; Fri, 21 Feb 2020 06:25:37 -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 8DFED1005513; Fri, 21 Feb 2020 11:25:36 +0000 (UTC) Received: from localhost (ovpn-117-223.ams2.redhat.com [10.36.117.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7E4390F69; Fri, 21 Feb 2020 11:25:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582284341; 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=DOjkhYK9Ev6VFF4mYEv8pPngwL00LgAB6vpzU/9FSFM=; b=D9O+m0NO4hJWpLwJ8fdCV+yXoYiibPQGBa5G++TxNfY4Zi9mXGohTvSRl7qkuTqku3sLVr +6Vm9zKaDGLa9KZRkQafSwgvgmPVbhRmNBGyc4W85ROMyQUXHjvwTNjLV03LogpwZcq0I6 y+kAZxPEC/SAYlEtVsUroxU/M5Kd20A= X-MC-Unique: yfjwDKyCNUy9G5svmQiNEQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 2/4] luks: implement .bdrv_measure() Date: Fri, 21 Feb 2020 11:25:20 +0000 Message-Id: <20200221112522.1497712-3-stefanha@redhat.com> In-Reply-To: <20200221112522.1497712-1-stefanha@redhat.com> References: <20200221112522.1497712-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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 , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , 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 Reviewed-by: Max Reitz --- block/crypto.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/block/crypto.c b/block/crypto.c index 24823835c1..23e9c74d6f 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -484,6 +484,67 @@ static int64_t block_crypto_getlength(BlockDriverState= *bs) } =20 =20 +static BlockMeasureInfo *block_crypto_measure(QemuOpts *opts, + BlockDriverState *in_bs, + Error **errp) +{ + g_autoptr(QCryptoBlockCreateOptions) create_opts =3D NULL; + Error *local_err =3D NULL; + BlockMeasureInfo *info; + uint64_t size; + size_t luks_payload_size; + QDict *cryptoopts; + + /* + * Preallocation mode doesn't affect size requirements but we must con= sume + * the option. + */ + g_free(qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC)); + + size =3D qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); + + if (in_bs) { + int64_t ssize =3D bdrv_getlength(in_bs); + + if (ssize < 0) { + error_setg_errno(&local_err, -ssize, + "Unable to get image virtual_size"); + goto err; + } + + size =3D ssize; + } + + cryptoopts =3D qemu_opts_to_qdict_filtered(opts, NULL, + &block_crypto_create_opts_luks, true); + qdict_put_str(cryptoopts, "format", "luks"); + create_opts =3D block_crypto_create_opts_init(cryptoopts, &local_err); + qobject_unref(cryptoopts); + if (!create_opts) { + goto err; + } + + if (!qcrypto_block_calculate_payload_offset(create_opts, NULL, + &luks_payload_size, + &local_err)) { + goto err; + } + + /* + * Unallocated blocks are still encrypted so allocation status makes no + * difference to the file size. + */ + info =3D g_new(BlockMeasureInfo, 1); + info->fully_allocated =3D luks_payload_size + size; + info->required =3D luks_payload_size + size; + 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) { @@ -670,6 +731,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 1 09:22:48 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=1582284429; cv=none; d=zohomail.com; s=zohoarc; b=k00w/J5/3QY0WFZ28K5TuYFk8m/uChJ38xMAdDFS3F7QbVQvwiNbHfy1jx/Q1ZZ9fKaJ8xXq1V2KirFnuJtE1/xr/nPOxeHAl+nXY2sB/CcPXTB5Dfko1sJN3pKVHLUuPNGGjB92664V7hzxNU1wgJmBs+Pw0ToZiGtE1zn2q6U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582284429; 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=7JxLX3G2fQYdmYBZqXd/PlErIkcNdVDptn8OF0OsJVU=; b=GVuo39fIvbzQlIRfojKysaxxBFVn8qabR2MfTKZqJmlfajpkgJeVg73EBeW3VKyqCIuh9dFFrRJE9juv1GjyvQzDCBFpkR7OtlkqJW5rkJZNybTUUr8z+nfeB3/NGQz/z19EKq/zCb1Y+DENo3Gva277JUKWCVDVmWF8+wQCv4A= 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 1582284429144872.3938767450195; Fri, 21 Feb 2020 03:27:09 -0800 (PST) Received: from localhost ([::1]:55554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j56SZ-0000Ct-VZ for importer@patchew.org; Fri, 21 Feb 2020 06:27:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35773) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j56RJ-0006Ol-SO for qemu-devel@nongnu.org; Fri, 21 Feb 2020 06:25:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j56RI-0001vC-DR for qemu-devel@nongnu.org; Fri, 21 Feb 2020 06:25:49 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:43816 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 1j56RI-0001v1-9P for qemu-devel@nongnu.org; Fri, 21 Feb 2020 06:25:48 -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-384-TUt43Nq1O9uD7bHCO09fbQ-1; Fri, 21 Feb 2020 06:25:42 -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 153E6800D5B; Fri, 21 Feb 2020 11:25:41 +0000 (UTC) Received: from localhost (ovpn-117-223.ams2.redhat.com [10.36.117.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0AFF1001DC2; Fri, 21 Feb 2020 11:25:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582284347; 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=7JxLX3G2fQYdmYBZqXd/PlErIkcNdVDptn8OF0OsJVU=; b=TTPeUDnA0rD9xN8xJvLxfoHWq/P0XAqUUZ/9C26Mm9H6MHuOYIzGfZr4b2y0nc9w6PwIGz 8S6Ju26BbYrHnWuSKawmc7c7u11VLJbLqQQV5gohTa9Yd9YjOY1dS5OmhlQTfpuqjyQwNR lQfokV9RX4V8WXLm+vQLFInJ/aHZbxs= X-MC-Unique: TUt43Nq1O9uD7bHCO09fbQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 3/4] qemu-img: allow qemu-img measure --object without a filename Date: Fri, 21 Feb 2020 11:25:21 +0000 Message-Id: <20200221112522.1497712-4-stefanha@redhat.com> In-Reply-To: <20200221112522.1497712-1-stefanha@redhat.com> References: <20200221112522.1497712-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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 , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , 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 Reviewed-by: Max Reitz --- qemu-img.c | 6 ++---- tests/qemu-iotests/178 | 2 +- tests/qemu-iotests/178.out.qcow2 | 8 ++++---- tests/qemu-iotests/178.out.raw | 8 ++++---- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 2b4562b9d9..0cee7bed8b 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4912,10 +4912,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) { diff --git a/tests/qemu-iotests/178 b/tests/qemu-iotests/178 index 51a70fe669..7cf0e27154 100755 --- a/tests/qemu-iotests/178 +++ b/tests/qemu-iotests/178 @@ -50,7 +50,7 @@ _make_test_img 1G $QEMU_IMG measure # missing arguments $QEMU_IMG measure --size 2G "$TEST_IMG" # only one allowed $QEMU_IMG measure "$TEST_IMG" a # only one filename allowed -$QEMU_IMG measure --object secret,id=3Dsec0,data=3DMTIzNDU2,format=3Dbase6= 4 # missing filename +$QEMU_IMG measure --object secret,id=3Dsec0,data=3DMTIzNDU2,format=3Dbase6= 4 # size or filename needed $QEMU_IMG measure --image-opts # missing filename $QEMU_IMG measure -f qcow2 # missing filename $QEMU_IMG measure -l snap1 # missing filename diff --git a/tests/qemu-iotests/178.out.qcow2 b/tests/qemu-iotests/178.out.= qcow2 index 9e7d8c44df..f59bf4b2fb 100644 --- a/tests/qemu-iotests/178.out.qcow2 +++ b/tests/qemu-iotests/178.out.qcow2 @@ -5,10 +5,10 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D10737= 41824 qemu-img: Either --size N or one filename must be specified. qemu-img: --size N cannot be used together with a filename. qemu-img: At most one filename argument is allowed. -qemu-img: --object, --image-opts, -f, and -l require a filename argument. -qemu-img: --object, --image-opts, -f, and -l require a filename argument. -qemu-img: --object, --image-opts, -f, and -l require a filename argument. -qemu-img: --object, --image-opts, -f, and -l require a filename argument. +qemu-img: Either --size N or one filename must be specified. +qemu-img: --image-opts, -f, and -l require a filename argument. +qemu-img: --image-opts, -f, and -l require a filename argument. +qemu-img: --image-opts, -f, and -l require a filename argument. qemu-img: Invalid option list: , qemu-img: Invalid parameter 'snapshot.foo' qemu-img: Failed in parsing snapshot param 'snapshot.foo' diff --git a/tests/qemu-iotests/178.out.raw b/tests/qemu-iotests/178.out.raw index 6478365905..404ca908d8 100644 --- a/tests/qemu-iotests/178.out.raw +++ b/tests/qemu-iotests/178.out.raw @@ -5,10 +5,10 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D10737= 41824 qemu-img: Either --size N or one filename must be specified. qemu-img: --size N cannot be used together with a filename. qemu-img: At most one filename argument is allowed. -qemu-img: --object, --image-opts, -f, and -l require a filename argument. -qemu-img: --object, --image-opts, -f, and -l require a filename argument. -qemu-img: --object, --image-opts, -f, and -l require a filename argument. -qemu-img: --object, --image-opts, -f, and -l require a filename argument. +qemu-img: Either --size N or one filename must be specified. +qemu-img: --image-opts, -f, and -l require a filename argument. +qemu-img: --image-opts, -f, and -l require a filename argument. +qemu-img: --image-opts, -f, and -l require a filename argument. qemu-img: Invalid option list: , qemu-img: Invalid parameter 'snapshot.foo' qemu-img: Failed in parsing snapshot param 'snapshot.foo' --=20 2.24.1 From nobody Wed May 1 09:22:48 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=1582284504; cv=none; d=zohomail.com; s=zohoarc; b=Vh1woGOAfVOiEWqWg6kbv/jx/kNoKhaIi6sxsJhJhgYIJ9+Xtc7DWAJLSgNGVwVkRhu05NaEGk/W4VWETK5nfEvgtYeQPVf5ihSnOFpYps5IjwQvWXwojZUNRWDeGOCbMWKq1NWmim4KYMCSzW00Z/ovqVZIFDv4rA2B32SDajE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582284504; 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=PbfJzGZfZyPY7f+Bc25X6hdR3DBj5uJbiEJ8wpa/tTQ=; b=GUVkCYYDNXXLvxUHiTGT1fCK+b0mKb9MVpexYVYYwACy1m4/vY98BWQ2baNlv7Vr/RmPQUOlCWwWPy55d3S1dhU/YCaGkStuMdo3mNmN99yH2cI82+cFXZEEc8ju0q2u1g/cu1qf7Um+W/Z3xJblCxNhOiJWpVgASd/gm6E7oPQ= 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 158228450458484.13692305833968; Fri, 21 Feb 2020 03:28:24 -0800 (PST) Received: from localhost ([::1]:55596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j56Tn-0002OB-J3 for importer@patchew.org; Fri, 21 Feb 2020 06:28:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35814) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j56RN-0006Yr-Fb for qemu-devel@nongnu.org; Fri, 21 Feb 2020 06:25:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j56RL-0001xV-Ua for qemu-devel@nongnu.org; Fri, 21 Feb 2020 06:25:53 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:57615 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 1j56RL-0001xF-QO for qemu-devel@nongnu.org; Fri, 21 Feb 2020 06:25:51 -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-55-ipVJy9vpODGRo9RNWtOVqA-1; Fri, 21 Feb 2020 06:25:46 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 907C48017CC; Fri, 21 Feb 2020 11:25:45 +0000 (UTC) Received: from localhost (ovpn-117-223.ams2.redhat.com [10.36.117.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77F655D9C5; Fri, 21 Feb 2020 11:25:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582284351; 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=PbfJzGZfZyPY7f+Bc25X6hdR3DBj5uJbiEJ8wpa/tTQ=; b=U3RhuzSJG9Br5ee4qfWkKtqdbfeDaXb1HziL6eXfBGqFKsz/lWDqk0Q42adwerMQm10jPl pe4VeBNZRohIDXw6Y/dCf9EICv3wJa4mGhmWuTrRXP3eOswuonzN7VnSwrxe2RxygcGykf zknlr+0lKHgA0qAjIRBhOOv2hBsx1fE= X-MC-Unique: ipVJy9vpODGRo9RNWtOVqA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v4 4/4] iotests: add 282 luks qemu-img measure test Date: Fri, 21 Feb 2020 11:25:22 +0000 Message-Id: <20200221112522.1497712-5-stefanha@redhat.com> In-Reply-To: <20200221112522.1497712-1-stefanha@redhat.com> References: <20200221112522.1497712-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , 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 Reviewed-by: Max Reitz --- 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..996cc44a67 --- /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: 1075810304 +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: 1075810304 +fully allocated size: 1075810304 +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 1904223020..6a25efea4d 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -289,4 +289,5 @@ 279 rw backing quick 280 rw migration quick 281 rw quick +282 quick 283 auto quick --=20 2.24.1