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 <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2023-11-03 14:30:35 +01:00
parent 813ccd553b
commit 6ab5ee9a9a

View File

@ -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 */