From nobody Thu May 15 11:27:40 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1507325030901500.1057524074844; Fri, 6 Oct 2017 14:23:50 -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 96C5F780CB; Fri, 6 Oct 2017 21:23:49 +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 76E6C5C3FA; Fri, 6 Oct 2017 21:23:49 +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 00E5118355C6; Fri, 6 Oct 2017 21:23:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v96KxVHu021954 for ; Fri, 6 Oct 2017 16:59:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 037005D75E; Fri, 6 Oct 2017 20:59:31 +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 C03B15D75C for ; Fri, 6 Oct 2017 20:59:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 96C5F780CB Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.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 16:59:24 -0400 Message-Id: <20171006205925.28633-4-jferlan@redhat.com> In-Reply-To: <20171006205925.28633-1-jferlan@redhat.com> References: <20171006205925.28633-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/4] storage: Allow creation of a LUKS using logical volume 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.27]); Fri, 06 Oct 2017 21:23:50 +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=3D1427049 Use virStorageBackendCreateVolUsingQemuImg to apply the LUKS information to the logical volume just created. As part of the processing of the lvcreate command add 2MB to the capacity to account for the LUKS header when it's determined that the volume desires to use encryption. Signed-off-by: John Ferlan --- src/storage/storage_backend_logical.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_ba= ckend_logical.c index 8d28be3adb..4e2775abb1 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -941,13 +941,14 @@ virStorageBackendLogicalLVCreate(virStorageVolDefPtr = vol, virStoragePoolDefPtr def) { int ret; + unsigned long long capacity =3D vol->target.capacity; virCommandPtr cmd =3D NULL; =20 cmd =3D virCommandNewArgList(LVCREATE, "--name", vol->name, NULL); virCommandAddArg(cmd, "-L"); - if (vol->target.capacity !=3D vol->target.allocation) { + if (capacity !=3D vol->target.allocation) { virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->target.allocation ? vol->target.allocation : 1, 10= 24)); @@ -955,8 +956,13 @@ virStorageBackendLogicalLVCreate(virStorageVolDefPtr v= ol, virCommandAddArg(cmd, "--virtualsize"); vol->target.sparse =3D true; } - virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->target.capacity, - 1024)); + + /* If we're going to encrypt using LUKS, then we could need up to + * an extra 2MB for the LUKS header - so account for that now */ + if (vol->target.encryption && + vol->target.encryption->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMA= T_LUKS) + capacity +=3D 2 * 1024 * 1024; + virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(capacity, 1024)); if (vol->target.backingStore) virCommandAddArgList(cmd, "-s", vol->target.backingStore->path, NU= LL); else @@ -978,13 +984,6 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn, virErrorPtr err; struct stat sb; =20 - if (vol->target.encryption !=3D NULL) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - "%s", _("storage pool does not support encrypted " - "volumes")); - return -1; - } - vol->type =3D VIR_STORAGE_VOL_BLOCK; =20 VIR_FREE(vol->target.path); @@ -995,6 +994,10 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn, if (virStorageBackendLogicalLVCreate(vol, def) < 0) return -1; =20 + if (vol->target.encryption && + virStorageBackendCreateVolUsingQemuImg(conn, pool, vol, NULL, 0) <= 0) + goto error; + if ((fd =3D virStorageBackendVolOpen(vol->target.path, &sb, VIR_STORAGE_VOL_OPEN_DEFAULT)) < 0) goto error; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list