From nobody Sun Feb 8 07:22:11 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609935979; cv=none; d=zohomail.com; s=zohoarc; b=MZSN2i4alXlLRlnVl1VAFF2bWoN7uV2VgjNLCjG29JoU7B3I3OTUWMABFq4J5f/tIrzJVIRuQyyt+nq46mlHXZUwTYGyjvxSxjAbSciJg/KKFqqk5IZEuj4oysNXiO7g32yfxv66/qsWSN1ePfUrq6zNgXWe/QKQ8VoIZTYtg54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609935979; h=Content-Type:Content-Transfer-Encoding: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=ERVDhMyZPIAJ5N2raUD62mK40+tbvj98vbWWfKGTT+w=; b=mpedU+Q8wup42MaYPg7ZmZpbFRZ9+Ylob2JU0Eur+rupIVnTJqumN1ghmylbdGcDXHC8cA7v7SXCAPqFIP8lfJgIkwyRiAGsqLsQAsN39Zqp45Gdy2Cr/LCWyaY0nfGVXFViBh3sww1axUgCM6Q+df2zMKdjLW/zgqnyj+O5XLk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609935979624534.9175661032364; Wed, 6 Jan 2021 04:26:19 -0800 (PST) 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-80-p3kWxWsQNFG5Tfw-lHInfw-1; Wed, 06 Jan 2021 07:26:15 -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 78DC98144E1; Wed, 6 Jan 2021 12:26:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D23419C66; Wed, 6 Jan 2021 12:26:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D628B1809CA1; Wed, 6 Jan 2021 12:26:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 106CQ7lt019025 for ; Wed, 6 Jan 2021 07:26:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7415E60BE5; Wed, 6 Jan 2021 12:26:07 +0000 (UTC) Received: from antique-work.lan (unknown [10.40.194.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id E51DF60BE2 for ; Wed, 6 Jan 2021 12:26:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609935978; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ERVDhMyZPIAJ5N2raUD62mK40+tbvj98vbWWfKGTT+w=; b=KwcVqrdfJLklaAaXrvyUndjCCDEBACvilcQ477BjrknvXPpth+8t++Jqoc88k+FfU1MCjT Vj5aQWUUZ/S6cjZFulspMOgSdnVUGl09A5Qjim7vuKGB4vaVx1uUFdlbeuCbsxM6ku4AaU szm53dG+QOfSGebcaoodeBxuo0BJGg4= X-MC-Unique: p3kWxWsQNFG5Tfw-lHInfw-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v2 3/9] util: move virQEMUBuildQemuImgKeySecretOpts into storage Date: Wed, 6 Jan 2021 13:25:54 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Function virQEMUBuildQemuImgKeySecretOpts is not used anywhere else so there is no need to have it in util. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/libvirt_private.syms | 1 - src/storage/storage_util.c | 74 ++++++++++++++++++++++++++++++++++++-- src/util/virqemu.c | 69 ----------------------------------- src/util/virqemu.h | 6 ---- 4 files changed, 72 insertions(+), 78 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index f8da4a7648..b8fedc82d5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2954,7 +2954,6 @@ virQEMUBuildCommandLineJSONArrayNumbered; virQEMUBuildDriveCommandlineFromJSON; virQEMUBuildNetdevCommandlineFromJSON; virQEMUBuildObjectCommandlineFromJSON; -virQEMUBuildQemuImgKeySecretOpts; =20 =20 # util/virrandom.h diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 2d46452da5..83b120924b 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -679,6 +679,74 @@ struct _virStorageBackendQemuImgInfo { }; =20 =20 +/** + * storageBackendBuildQemuImgEncriptionOpts: + * @buf: buffer to build the string into + * @encinfo: pointer to encryption info + * @alias: alias to use + * + * Generate the string for id=3D$alias and any encryption options for + * into the buffer. + * + * Important note, a trailing comma (",") is built into the return since + * it's expected other arguments are appended after the id=3D$alias string. + * So either turn something like: + * + * "key-secret=3D$alias," + * + * or + * "key-secret=3D$alias,cipher-alg=3Dtwofish-256,cipher-mode=3Dcbc, + * hash-alg=3Dsha256,ivgen-alg=3Dplain64,igven-hash-alg=3Dsha256," + * + */ +static void +storageBackendBuildQemuImgEncriptionOpts(virBufferPtr buf, + int format, + virStorageEncryptionInfoDefPtr en= cinfo, + const char *alias) +{ + const char *encprefix; + + if (format =3D=3D VIR_STORAGE_FILE_QCOW2) { + virBufferAddLit(buf, "encrypt.format=3Dluks,"); + encprefix =3D "encrypt."; + } else { + encprefix =3D ""; + } + + virBufferAsprintf(buf, "%skey-secret=3D%s,", encprefix, alias); + + if (!encinfo->cipher_name) + return; + + virBufferAsprintf(buf, "%scipher-alg=3D", encprefix); + virQEMUBuildBufferEscapeComma(buf, encinfo->cipher_name); + virBufferAsprintf(buf, "-%u,", encinfo->cipher_size); + if (encinfo->cipher_mode) { + virBufferAsprintf(buf, "%scipher-mode=3D", encprefix); + virQEMUBuildBufferEscapeComma(buf, encinfo->cipher_mode); + virBufferAddLit(buf, ","); + } + if (encinfo->cipher_hash) { + virBufferAsprintf(buf, "%shash-alg=3D", encprefix); + virQEMUBuildBufferEscapeComma(buf, encinfo->cipher_hash); + virBufferAddLit(buf, ","); + } + if (!encinfo->ivgen_name) + return; + + virBufferAsprintf(buf, "%sivgen-alg=3D", encprefix); + virQEMUBuildBufferEscapeComma(buf, encinfo->ivgen_name); + virBufferAddLit(buf, ","); + + if (encinfo->ivgen_hash) { + virBufferAsprintf(buf, "%sivgen-hash-alg=3D", encprefix); + virQEMUBuildBufferEscapeComma(buf, encinfo->ivgen_hash); + virBufferAddLit(buf, ","); + } +} + + static int storageBackendCreateQemuImgOpts(virStorageEncryptionInfoDefPtr encinfo, char **opts, @@ -690,8 +758,10 @@ storageBackendCreateQemuImgOpts(virStorageEncryptionIn= foDefPtr encinfo, virBufferAsprintf(&buf, "backing_fmt=3D%s,", virStorageFileFormatTypeToString(info->backingFo= rmat)); =20 - if (encinfo) - virQEMUBuildQemuImgKeySecretOpts(&buf, info->format, encinfo, info= ->secretAlias); + if (encinfo) { + storageBackendBuildQemuImgEncriptionOpts(&buf, info->format, encin= fo, + info->secretAlias); + } =20 if (info->preallocate) { if (info->size_arg > info->allocation) diff --git a/src/util/virqemu.c b/src/util/virqemu.c index 5405c9eac9..c4b6e8b3db 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -28,7 +28,6 @@ #include "virqemu.h" #include "virstring.h" #include "viralloc.h" -#include "virstoragefile.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 @@ -384,71 +383,3 @@ virQEMUBuildBufferEscapeComma(virBufferPtr buf, const = char *str) { virBufferEscape(buf, ',', ",", "%s", str); } - - -/** - * virQEMUBuildQemuImgKeySecretOpts: - * @buf: buffer to build the string into - * @encinfo: pointer to encryption info - * @alias: alias to use - * - * Generate the string for id=3D$alias and any encryption options for - * into the buffer. - * - * Important note, a trailing comma (",") is built into the return since - * it's expected other arguments are appended after the id=3D$alias string. - * So either turn something like: - * - * "key-secret=3D$alias," - * - * or - * "key-secret=3D$alias,cipher-alg=3Dtwofish-256,cipher-mode=3Dcbc, - * hash-alg=3Dsha256,ivgen-alg=3Dplain64,igven-hash-alg=3Dsha256," - * - */ -void -virQEMUBuildQemuImgKeySecretOpts(virBufferPtr buf, - int format, - virStorageEncryptionInfoDefPtr encinfo, - const char *alias) -{ - const char *encprefix; - - if (format =3D=3D VIR_STORAGE_FILE_QCOW2) { - virBufferAddLit(buf, "encrypt.format=3Dluks,"); - encprefix =3D "encrypt."; - } else { - encprefix =3D ""; - } - - virBufferAsprintf(buf, "%skey-secret=3D%s,", encprefix, alias); - - if (!encinfo->cipher_name) - return; - - virBufferAsprintf(buf, "%scipher-alg=3D", encprefix); - virQEMUBuildBufferEscapeComma(buf, encinfo->cipher_name); - virBufferAsprintf(buf, "-%u,", encinfo->cipher_size); - if (encinfo->cipher_mode) { - virBufferAsprintf(buf, "%scipher-mode=3D", encprefix); - virQEMUBuildBufferEscapeComma(buf, encinfo->cipher_mode); - virBufferAddLit(buf, ","); - } - if (encinfo->cipher_hash) { - virBufferAsprintf(buf, "%shash-alg=3D", encprefix); - virQEMUBuildBufferEscapeComma(buf, encinfo->cipher_hash); - virBufferAddLit(buf, ","); - } - if (!encinfo->ivgen_name) - return; - - virBufferAsprintf(buf, "%sivgen-alg=3D", encprefix); - virQEMUBuildBufferEscapeComma(buf, encinfo->ivgen_name); - virBufferAddLit(buf, ","); - - if (encinfo->ivgen_hash) { - virBufferAsprintf(buf, "%sivgen-hash-alg=3D", encprefix); - virQEMUBuildBufferEscapeComma(buf, encinfo->ivgen_hash); - virBufferAddLit(buf, ","); - } -} diff --git a/src/util/virqemu.h b/src/util/virqemu.h index 2b33968158..b81efc765f 100644 --- a/src/util/virqemu.h +++ b/src/util/virqemu.h @@ -25,7 +25,6 @@ #include "internal.h" #include "virbuffer.h" #include "virjson.h" -#include "virstorageencryption.h" =20 typedef int (*virQEMUBuildCommandLineJSONArrayFormatFunc)(const char *key, virJSONValuePtr = array, @@ -59,8 +58,3 @@ int virQEMUBuildObjectCommandlineFromJSON(virBufferPtr bu= f, char *virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr src); =20 void virQEMUBuildBufferEscapeComma(virBufferPtr buf, const char *str); -void virQEMUBuildQemuImgKeySecretOpts(virBufferPtr buf, - int format, - virStorageEncryptionInfoDefPtr enc, - const char *alias) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4); --=20 2.29.2