From: Peter Krempa Date: Fri, 3 Nov 2023 13:30:35 +0000 (+0100) Subject: qemuDomainPrepareStorageSourceBlockdevNodename: Restructure code to allow missing... X-Git-Tag: v9.10.0-rc1~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6ab5ee9a9a19e797b0641e47d0a906ceba9b49a7;p=thirdparty%2Flibvirt.git qemuDomainPrepareStorageSourceBlockdevNodename: Restructure code to allow missing 'format' layer Similarly to other bits of code, we don't need to setup the format layer if it will not be formatted. Add logic which uses qemuBlockStorageSourceNeedsFormatLayer to see whether the setup of the format node is needed. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 413f67577e..953808fcfe 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11108,11 +11108,21 @@ qemuDomainPrepareStorageSourceBlockdevNodename(virDomainDiskDef *disk, virQEMUDriverConfig *cfg) { char *nodestorage = g_strdup_printf("%s-storage", nodenameprefix); - char *nodeformat = g_strdup_printf("%s-format", nodenameprefix); + const char *encryptionAlias = nodestorage; /* qemuBlockStorageSourceSetStorageNodename steals 'nodestorage' */ qemuBlockStorageSourceSetStorageNodename(src, nodestorage); - qemuBlockStorageSourceSetFormatNodename(src, nodeformat); + + if (qemuBlockStorageSourceNeedsFormatLayer(src)) { + char *nodeformat = g_strdup_printf("%s-format", nodenameprefix); + + qemuBlockStorageSourceSetFormatNodename(src, nodeformat); + + encryptionAlias = nodeformat; + } + + if (qemuDomainSecretStorageSourcePrepareEncryption(priv, src, encryptionAlias) < 0) + return -1; if (qemuBlockStorageSourceNeedsStorageSliceLayer(src)) src->sliceStorage->nodename = g_strdup_printf("libvirt-%u-slice-sto", src->id); @@ -11126,9 +11136,6 @@ qemuDomainPrepareStorageSourceBlockdevNodename(virDomainDiskDef *disk, qemuDomainPrepareStorageSourceConfig(src, cfg); qemuDomainPrepareDiskSourceData(disk, src); - if (qemuDomainSecretStorageSourcePrepareEncryption(priv, src, nodeformat) < 0) - return -1; - if (!qemuDomainPrepareStorageSourceNbdkit(src, cfg, nodestorage, priv)) { /* If we're using nbdkit to serve the storage source, we don't pass * authentication secrets to qemu, but will pass them to nbdkit instead */