From nobody Wed Nov 27 22:42:30 2024 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 1534868609793108.48974642384474; Tue, 21 Aug 2018 09:23:29 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 0D3183164990; Tue, 21 Aug 2018 16:23:27 +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 55FA260CD6; Tue, 21 Aug 2018 16:23:26 +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 7C07C18005D0; Tue, 21 Aug 2018 16:23:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7LGNO2V010130 for ; Tue, 21 Aug 2018 12:23:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 38E4C74E1A; Tue, 21 Aug 2018 16:23:24 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-58.phx2.redhat.com [10.3.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6A5A6FDD5 for ; Tue, 21 Aug 2018 16:23:23 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 21 Aug 2018 12:23:16 -0400 Message-Id: <20180821162317.31638-3-jferlan@redhat.com> In-Reply-To: <20180821162317.31638-1-jferlan@redhat.com> References: <20180821162317.31638-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/3] storage: Allow for inputvol to have any format for encryption 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 21 Aug 2018 16:23:27 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Commit 39cef12a9 altered/fixed the inputvol processing to create a multistep process when using an inputvol to create an encrypted output volume; however, it unnecessarily assumed/restricted the inputvol to be of 'raw' format only. Modify the processing code to allow the inputvol format to be checked and used in order to create the encrypted volume. Signed-off-by: John Ferlan --- src/storage/storage_util.c | 15 +++++++++++-- .../luks-convert-qcow2.argv | 9 ++++++++ tests/storagevolxml2argvtest.c | 4 ++++ tests/storagevolxml2xmlin/vol-file-qcow2.xml | 21 +++++++++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 tests/storagevolxml2argvdata/luks-convert-qcow2.argv create mode 100644 tests/storagevolxml2xmlin/vol-file-qcow2.xml diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index b32e3ccf7d..cc49a5b9f7 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -699,6 +699,7 @@ storagePloopResize(virStorageVolDefPtr vol, struct _virStorageBackendQemuImgInfo { int format; const char *type; + const char *inputType; const char *path; unsigned long long size_arg; unsigned long long allocation; @@ -1021,6 +1022,15 @@ virStorageBackendCreateQemuImgSetInfo(virStoragePool= ObjPtr pool, return -1; } =20 + if (inputvol && + !(info->inputType =3D + virStorageFileFormatTypeToString(inputvol->target.format))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unknown inputvol storage vol type %d"), + inputvol->target.format); + return -1; + } + if (info->preallocate && info->format !=3D VIR_STORAGE_FILE_QCOW2) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("metadata preallocation only available with qcow2= ")); @@ -1080,6 +1090,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePo= olObjPtr pool, struct _virStorageBackendQemuImgInfo info =3D { .format =3D vol->target.format, .type =3D NULL, + .inputType =3D NULL, .path =3D vol->target.path, .allocation =3D vol->target.allocation, .encryption =3D !!vol->target.encryption, @@ -1152,8 +1163,8 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePo= olObjPtr pool, virCommandAddArgFormat(cmd, "%lluK", info.size_arg); } else { /* source */ - virCommandAddArgFormat(cmd, "driver=3Draw,file.filename=3D%s", - info.inputPath); + virCommandAddArgFormat(cmd, "driver=3D%s,file.filename=3D%s", + info.inputType, info.inputPath); =20 /* dest */ virCommandAddArgFormat(cmd, "driver=3D%s,file.filename=3D%s,key-se= cret=3D%s", diff --git a/tests/storagevolxml2argvdata/luks-convert-qcow2.argv b/tests/s= toragevolxml2argvdata/luks-convert-qcow2.argv new file mode 100644 index 0000000000..9124f5f27c --- /dev/null +++ b/tests/storagevolxml2argvdata/luks-convert-qcow2.argv @@ -0,0 +1,9 @@ +qemu-img create -f luks \ +--object secret,id=3DOtherDemo.img_encrypt0,file=3D/path/to/secretFile \ +-o key-secret=3DOtherDemo.img_encrypt0 \ +/var/lib/libvirt/images/OtherDemo.img 5242880K +qemu-img convert --image-opts -n --target-image-opts \ +--object secret,id=3DOtherDemo.img_encrypt0,file=3D/path/to/secretFile \ +driver=3Dqcow2,file.filename=3D/var/lib/libvirt/images/sparse-qcow2.img \ +driver=3Dluks,file.filename=3D/var/lib/libvirt/images/OtherDemo.img,\ +key-secret=3DOtherDemo.img_encrypt0 diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c index b795f83aee..6a9a080dd1 100644 --- a/tests/storagevolxml2argvtest.c +++ b/tests/storagevolxml2argvtest.c @@ -284,6 +284,10 @@ mymain(void) "pool-dir", "vol-file", "luks-convert", 0); =20 + DO_TEST("pool-dir", "vol-luks-convert", + "pool-dir", "vol-file-qcow2", + "luks-convert-qcow2", 0); + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 diff --git a/tests/storagevolxml2xmlin/vol-file-qcow2.xml b/tests/storagevo= lxml2xmlin/vol-file-qcow2.xml new file mode 100644 index 0000000000..025e7e0239 --- /dev/null +++ b/tests/storagevolxml2xmlin/vol-file-qcow2.xml @@ -0,0 +1,21 @@ + + sparse-qcow2.img + + 1 + 0 + + /var/lib/libvirt/images/sparse-qcow2.img + + + 0 + 0744 + 0 + + + + 1341933637.273190990 + 1341930622.047245868 + 1341930622.047245868 + + + --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list