From nobody Wed May 14 05:54:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525783697722106.55044677739568; Tue, 8 May 2018 05:48:17 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 6BD154E90A; Tue, 8 May 2018 12:48:16 +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 4597C5D756; Tue, 8 May 2018 12:48:16 +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 00FD7180BAE6; Tue, 8 May 2018 12:48:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w48CmDlm020488 for ; Tue, 8 May 2018 08:48:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id CBC81272A6; Tue, 8 May 2018 12:48:13 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-94.phx2.redhat.com [10.3.116.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E30016E46 for ; Tue, 8 May 2018 12:48:13 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 8 May 2018 08:47:58 -0400 Message-Id: <20180508124805.2372-6-jferlan@redhat.com> In-Reply-To: <20180508124805.2372-1-jferlan@redhat.com> References: <20180508124805.2372-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/12] storage_util: Generate the qcow secret earlier 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 08 May 2018 12:48:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than having storageBackendCreateQemuImgCheckEncryption perform the virStorageGenerateQcowEncryption, let's just do that earlier during storageBackendCreateQemuImg so that the check helper is just a check helper rather doing something different based on whether the format is qcow[2] or raw based encryption. Signed-off-by: John Ferlan --- src/storage/storage_util.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 37a649d17b..64d4d1d7d2 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -901,10 +901,10 @@ storageBackendCreateQemuImgCheckEncryption(int format, _("too many secrets for qcow encryption")); return -1; } - if (enc->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT || - enc->nsecrets =3D=3D 0) { - if (virStorageGenerateQcowEncryption(vol) < 0) - return -1; + if (enc->nsecrets =3D=3D 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("no secret provided for qcow encryption")); + return -1; } } else if (format =3D=3D VIR_STORAGE_FILE_RAW) { if (enc->format !=3D VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) { @@ -1309,6 +1309,26 @@ storageBackendCreateQemuImgSecretPath(virStoragePool= ObjPtr pool, } =20 =20 +static int +storageBackendGenerateSecretData(virStorageVolDefPtr vol) +{ + virStorageEncryptionPtr enc =3D vol->target.encryption; + + if (!enc) + return 0; + + if ((vol->target.format =3D=3D VIR_STORAGE_FILE_QCOW || + vol->target.format =3D=3D VIR_STORAGE_FILE_QCOW2) && + (enc->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT || + enc->nsecrets =3D=3D 0)) { + if (virStorageGenerateQcowEncryption(vol) < 0) + return -1; + } + + return 0; +} + + static int storageBackendCreateQemuImg(virStoragePoolObjPtr pool, virStorageVolDefPtr vol, @@ -1330,6 +1350,9 @@ storageBackendCreateQemuImg(virStoragePoolObjPtr pool, return -1; } =20 + if (storageBackendGenerateSecretData(vol) < 0) + goto cleanup; + if (vol->target.format =3D=3D VIR_STORAGE_FILE_RAW && vol->target.encryption && vol->target.encryption->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMA= T_LUKS) { --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list