From nobody Mon Apr 29 11:21:24 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1507317090210110.58478929055491; Fri, 6 Oct 2017 12:11:30 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 5452F7E391; Fri, 6 Oct 2017 19:11:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0DDFE5D9C8; Fri, 6 Oct 2017 19:11:28 +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 274D0410B2; Fri, 6 Oct 2017 19:11:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v96IDcaC030595 for ; Fri, 6 Oct 2017 14:13:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id D53F517CCE; Fri, 6 Oct 2017 18:13:38 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-17.phx2.redhat.com [10.3.116.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EDC360C48 for ; Fri, 6 Oct 2017 18:13:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5452F7E391 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Fri, 6 Oct 2017 14:13:28 -0400 Message-Id: <20171006181332.16531-2-jferlan@redhat.com> In-Reply-To: <20171006181332.16531-1-jferlan@redhat.com> References: <20171006181332.16531-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/5] storage: Alter args to storageBackendResizeQemuImg 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 06 Oct 2017 19:11:28 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than passing just the path, pass the virStorageVolDefPtr as we're going to need it shortly. Also fix the order of code and stack variables in the calling function virStorageBackendVolResizeLocal. Signed-off-by: John Ferlan --- src/storage/storage_util.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index a10e4590f3..50db358dc4 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -2287,7 +2287,7 @@ virStorageBackendVolRefreshLocal(virConnectPtr conn, =20 =20 static int -storageBackendResizeQemuImg(const char *path, +storageBackendResizeQemuImg(virStorageVolDefPtr vol, unsigned long long capacity) { int ret =3D -1; @@ -2306,7 +2306,7 @@ storageBackendResizeQemuImg(const char *path, capacity =3D VIR_ROUND_UP(capacity, 512); =20 cmd =3D virCommandNew(img_tool); - virCommandAddArgList(cmd, "resize", path, NULL); + virCommandAddArgList(cmd, "resize", vol->target.path, NULL); virCommandAddArgFormat(cmd, "%llu", capacity); =20 ret =3D virCommandRun(cmd, NULL); @@ -2328,11 +2328,11 @@ virStorageBackendVolResizeLocal(virConnectPtr conn = ATTRIBUTE_UNUSED, unsigned long long capacity, unsigned int flags) { + bool pre_allocate =3D flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE; + virCheckFlags(VIR_STORAGE_VOL_RESIZE_ALLOCATE | VIR_STORAGE_VOL_RESIZE_SHRINK, -1); =20 - bool pre_allocate =3D flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE; - if (vol->target.format =3D=3D VIR_STORAGE_FILE_RAW) { return virStorageFileResize(vol->target.path, capacity, pre_alloca= te); } else if (vol->target.format =3D=3D VIR_STORAGE_FILE_PLOOP) { @@ -2345,7 +2345,7 @@ virStorageBackendVolResizeLocal(virConnectPtr conn AT= TRIBUTE_UNUSED, return -1; } =20 - return storageBackendResizeQemuImg(vol->target.path, capacity); + return storageBackendResizeQemuImg(vol, capacity); } } =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 11:21:24 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1507314563144183.75389225601896; Fri, 6 Oct 2017 11:29:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E2634C0587EB; Fri, 6 Oct 2017 18:29:21 +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 AA07366D2D; Fri, 6 Oct 2017 18:29:21 +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 6BE7818355C5; Fri, 6 Oct 2017 18:29:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v96IDeMi030601 for ; Fri, 6 Oct 2017 14:13:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 33B8461B69; Fri, 6 Oct 2017 18:13:40 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-17.phx2.redhat.com [10.3.116.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6D0117D79 for ; Fri, 6 Oct 2017 18:13:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E2634C0587EB Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Fri, 6 Oct 2017 14:13:29 -0400 Message-Id: <20171006181332.16531-3-jferlan@redhat.com> In-Reply-To: <20171006181332.16531-1-jferlan@redhat.com> References: <20171006181332.16531-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/5] storage: Add error path for virStorageBackendCreateQemuImgCmdFromVol 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 06 Oct 2017 18:29:22 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than inline the various free's and return NULL, just create an error label. Signed-off-by: John Ferlan --- src/storage/storage_util.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 50db358dc4..561899a3d0 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -1261,19 +1261,13 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnect= Ptr conn, if (info.format =3D=3D VIR_STORAGE_FILE_RAW && vol->target.encryption !=3D NULL && vol->target.encryption->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMA= T_LUKS) { - if (storageBackendCreateQemuImgSecretObject(cmd, vol, &info) < 0) { - VIR_FREE(info.secretAlias); - virCommandFree(cmd); - return NULL; - } + if (storageBackendCreateQemuImgSecretObject(cmd, vol, &info) < 0) + goto error; enc =3D &vol->target.encryption->encinfo; } =20 - if (storageBackendCreateQemuImgSetOptions(cmd, imgformat, enc, info) <= 0) { - VIR_FREE(info.secretAlias); - virCommandFree(cmd); - return NULL; - } + if (storageBackendCreateQemuImgSetOptions(cmd, imgformat, enc, info) <= 0) + goto error; VIR_FREE(info.secretAlias); =20 if (info.inputPath) @@ -1283,6 +1277,11 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectP= tr conn, virCommandAddArgFormat(cmd, "%lluK", info.size_arg); =20 return cmd; + + error: + VIR_FREE(info.secretAlias); + virCommandFree(cmd); + return NULL; } =20 =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 11:21:24 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1507317112925217.4293281427199; Fri, 6 Oct 2017 12:11:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E335A25BA6; Fri, 6 Oct 2017 19:11:51 +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 A221360176; Fri, 6 Oct 2017 19:11:51 +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 58FAA18355C6; Fri, 6 Oct 2017 19:11:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v96IDffG030610 for ; Fri, 6 Oct 2017 14:13:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 13C6F5D9C1; Fri, 6 Oct 2017 18:13:41 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-17.phx2.redhat.com [10.3.116.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFC5D17DA3 for ; Fri, 6 Oct 2017 18:13:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E335A25BA6 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Fri, 6 Oct 2017 14:13:30 -0400 Message-Id: <20171006181332.16531-4-jferlan@redhat.com> In-Reply-To: <20171006181332.16531-1-jferlan@redhat.com> References: <20171006181332.16531-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/5] storage: Alter storageBackendCreateQemuImgSecretObject args 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 06 Oct 2017 19:11:52 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since all that was really needed was a couple of fields and building the object can be more generic, let's alter the args a bit. This will be useful shortly for adding the secret object for a volume resize operation on a luks volume that will need a secret object. Signed-off-by: John Ferlan --- src/storage/storage_util.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 561899a3d0..e6d2747e8d 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -1120,17 +1120,14 @@ storageBackendCreateQemuImgSetOptions(virCommandPtr= cmd, */ static int storageBackendCreateQemuImgSecretObject(virCommandPtr cmd, - virStorageVolDefPtr vol, - struct _virStorageBackendQemuImgIn= fo *info) + const char *secretPath, + const char *secretAlias) { virBuffer buf =3D VIR_BUFFER_INITIALIZER; char *commandStr =3D NULL; =20 - if (virAsprintf(&info->secretAlias, "%s_luks0", vol->name) < 0) - return -1; - - virBufferAsprintf(&buf, "secret,id=3D%s,file=3D", info->secretAlias); - virQEMUBuildBufferEscapeComma(&buf, info->secretPath); + virBufferAsprintf(&buf, "secret,id=3D%s,file=3D", secretAlias); + virQEMUBuildBufferEscapeComma(&buf, secretPath); =20 if (virBufferCheckError(&buf) < 0) { virBufferFreeAndReset(&buf); @@ -1261,7 +1258,10 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectP= tr conn, if (info.format =3D=3D VIR_STORAGE_FILE_RAW && vol->target.encryption !=3D NULL && vol->target.encryption->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMA= T_LUKS) { - if (storageBackendCreateQemuImgSecretObject(cmd, vol, &info) < 0) + if (virAsprintf(&info.secretAlias, "%s_luks0", vol->name) < 0) + goto error; + if (storageBackendCreateQemuImgSecretObject(cmd, info.secretPath, + info.secretAlias) < 0) goto error; enc =3D &vol->target.encryption->encinfo; } --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 11:21:24 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1507317133696309.55086899759715; Fri, 6 Oct 2017 12:12:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 956E38210D; Fri, 6 Oct 2017 19:12:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6E52B679CE; Fri, 6 Oct 2017 19:12:12 +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 3B8C1410B3; Fri, 6 Oct 2017 19:12:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v96IDgB2030620 for ; Fri, 6 Oct 2017 14:13:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1EFB05D9C1; Fri, 6 Oct 2017 18:13:42 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-17.phx2.redhat.com [10.3.116.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC04117CDE for ; Fri, 6 Oct 2017 18:13:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 956E38210D Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Fri, 6 Oct 2017 14:13:31 -0400 Message-Id: <20171006181332.16531-5-jferlan@redhat.com> In-Reply-To: <20171006181332.16531-1-jferlan@redhat.com> References: <20171006181332.16531-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/5] storage: Properly resize a local volume using LUKS 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 06 Oct 2017 19:12:13 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1490279 Turns out the virStorageBackendVolResizeLocal did not differentiate whether the target volume was a LUKS volume or not and just blindly did the ftruncate() on the target volume. Follow the volume creation logic (in general) and create a qemu-img resize command to resize the target volume for LUKS ensuring that the --object secret is provided as well as the '--image-opts' used by the qemu-img resize logic to describe the path and secret ensuring that it's using the luks driver on the volume of course. Signed-off-by: John Ferlan --- src/storage/storage_util.c | 98 ++++++++++++++++++++++++++++++++++++++++++= ---- 1 file changed, 90 insertions(+), 8 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index e6d2747e8d..e485fa5a95 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -1143,6 +1143,37 @@ storageBackendCreateQemuImgSecretObject(virCommandPt= r cmd, } =20 =20 +/* Add a --image-opts to the qemu-img resize command line: + * --image-opts driver=3Dluks,file.filename=3D$volpath,key-secret=3D$se= cretAlias + * + * NB: format=3Draw is assumed + */ +static int +storageBackendResizeQemuImgImageOpts(virCommandPtr cmd, + const char *path, + const char *secretAlias) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + char *commandStr =3D NULL; + + virBufferAsprintf(&buf, "driver=3Dluks,key-secret=3D%s,file.filename= =3D", + secretAlias); + virQEMUBuildBufferEscapeComma(&buf, path); + + if (virBufferCheckError(&buf) < 0) { + virBufferFreeAndReset(&buf); + return -1; + } + + commandStr =3D virBufferContentAndReset(&buf); + + virCommandAddArgList(cmd, "--image-opts", commandStr, NULL); + + VIR_FREE(commandStr); + return 0; +} + + /* Create a qemu-img virCommand from the supplied binary path, * volume definitions and imgformat */ @@ -2286,12 +2317,17 @@ virStorageBackendVolRefreshLocal(virConnectPtr conn, =20 =20 static int -storageBackendResizeQemuImg(virStorageVolDefPtr vol, +storageBackendResizeQemuImg(virConnectPtr conn, + virStoragePoolObjPtr pool, + virStorageVolDefPtr vol, unsigned long long capacity) { int ret =3D -1; - char *img_tool; + char *img_tool =3D NULL; virCommandPtr cmd =3D NULL; + const char *type; + char *secretPath =3D NULL; + char *secretAlias =3D NULL; =20 img_tool =3D virFindFileInPath("qemu-img"); if (!img_tool) { @@ -2300,19 +2336,56 @@ storageBackendResizeQemuImg(virStorageVolDefPtr vol, return -1; } =20 + if (vol->target.encryption) { + if (vol->target.format =3D=3D VIR_STORAGE_FILE_RAW) + type =3D "luks"; + else + type =3D virStorageFileFormatTypeToString(vol->target.format); + + storageBackendLoadDefaultSecrets(conn, vol); + + if (storageBackendCreateQemuImgCheckEncryption(vol->target.format, + type, NULL, vol) < = 0) + goto cleanup; + + if (!(secretPath =3D + storageBackendCreateQemuImgSecretPath(conn, pool, vol))) + goto cleanup; + + if (virAsprintf(&secretAlias, "%s_luks0", vol->name) < 0) + goto cleanup; + } + /* Round capacity as qemu-img resize errors out on sizes which are not * a multiple of 512 */ capacity =3D VIR_ROUND_UP(capacity, 512); =20 cmd =3D virCommandNew(img_tool); - virCommandAddArgList(cmd, "resize", vol->target.path, NULL); + if (!vol->target.encryption) { + virCommandAddArgList(cmd, "resize", vol->target.path, NULL); + } else { + virCommandAddArgList(cmd, "resize", NULL); + + if (storageBackendCreateQemuImgSecretObject(cmd, secretPath, + secretAlias) < 0) + goto cleanup; + + if (storageBackendResizeQemuImgImageOpts(cmd, vol->target.path, + secretAlias) < 0) + goto cleanup; + } virCommandAddArgFormat(cmd, "%llu", capacity); =20 ret =3D virCommandRun(cmd, NULL); =20 + cleanup: VIR_FREE(img_tool); + if (secretPath) { + unlink(secretPath); + VIR_FREE(secretPath); + } + VIR_FREE(secretAlias); virCommandFree(cmd); - return ret; } =20 @@ -2321,8 +2394,8 @@ storageBackendResizeQemuImg(virStorageVolDefPtr vol, * Resize a volume */ int -virStorageBackendVolResizeLocal(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, +virStorageBackendVolResizeLocal(virConnectPtr conn, + virStoragePoolObjPtr pool, virStorageVolDefPtr vol, unsigned long long capacity, unsigned int flags) @@ -2332,8 +2405,17 @@ virStorageBackendVolResizeLocal(virConnectPtr conn A= TTRIBUTE_UNUSED, virCheckFlags(VIR_STORAGE_VOL_RESIZE_ALLOCATE | VIR_STORAGE_VOL_RESIZE_SHRINK, -1); =20 - if (vol->target.format =3D=3D VIR_STORAGE_FILE_RAW) { + if (vol->target.format =3D=3D VIR_STORAGE_FILE_RAW && !vol->target.enc= ryption) { return virStorageFileResize(vol->target.path, capacity, pre_alloca= te); + } else if (vol->target.format =3D=3D VIR_STORAGE_FILE_RAW && vol->targ= et.encryption) { + if (pre_allocate) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("preallocate is only supported for raw " + "type volume")); + return -1; + } + + return storageBackendResizeQemuImg(conn, pool, vol, capacity); } else if (vol->target.format =3D=3D VIR_STORAGE_FILE_PLOOP) { return storagePloopResize(vol, capacity); } else { @@ -2344,7 +2426,7 @@ virStorageBackendVolResizeLocal(virConnectPtr conn AT= TRIBUTE_UNUSED, return -1; } =20 - return storageBackendResizeQemuImg(vol, capacity); + return storageBackendResizeQemuImg(conn, pool, vol, capacity); } } =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 11:21:24 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1507316705812901.0610743355129; Fri, 6 Oct 2017 12:05:05 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 8B91B8210A; Fri, 6 Oct 2017 19:05:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 684495D9C8; Fri, 6 Oct 2017 19:05:04 +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 E60C8410B4; Fri, 6 Oct 2017 19:05:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v96IDhPJ030625 for ; Fri, 6 Oct 2017 14:13:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9D2F760C48; Fri, 6 Oct 2017 18:13:43 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-17.phx2.redhat.com [10.3.116.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66C1C5D9C9 for ; Fri, 6 Oct 2017 18:13:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8B91B8210A Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Fri, 6 Oct 2017 14:13:32 -0400 Message-Id: <20171006181332.16531-6-jferlan@redhat.com> In-Reply-To: <20171006181332.16531-1-jferlan@redhat.com> References: <20171006181332.16531-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/5] docs: Add news article for bug fix 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 06 Oct 2017 19:05:05 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: John Ferlan --- docs/news.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/news.xml b/docs/news.xml index ff36c800a4..116f4a76c9 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -55,6 +55,14 @@ way. + + Properly resize local LUKS encrypted volume + + + Resizing of a local LUKS encrypted volume will now use qemu-img + to resize the volume. This will require configuring a secret for + the LUKS encrypted volume. + --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list