Refactor the code which assigns the 'storage' layer nodenames for disks. scsi hostdevs and pflash backend. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_domain.c | 25 ++++++++++++++----------- src/qemu/qemu_migration.c | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 78dc99d243..885c5ee96b 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11143,7 +11143,10 @@ qemuDomainPrepareStorageSourceBlockdevNodename(virDomainDiskDef *disk, qemuDomainObjPrivate *priv, virQEMUDriverConfig *cfg) { - src->nodestorage = g_strdup_printf("%s-storage", nodenameprefix); + char *nodestorage = g_strdup_printf("%s-storage", nodenameprefix); + + /* qemuBlockStorageSourceSetStorageNodename steals 'nodestorage' */ + qemuBlockStorageSourceSetStorageNodename(src, nodestorage); src->nodeformat = g_strdup_printf("%s-format", nodenameprefix); if (qemuBlockStorageSourceNeedsStorageSliceLayer(src)) @@ -11162,18 +11165,17 @@ qemuDomainPrepareStorageSourceBlockdevNodename(virDomainDiskDef *disk, src->nodeformat) < 0) return -1; - if (!qemuDomainPrepareStorageSourceNbdkit(src, cfg, src->nodestorage, priv)) { + 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 */ - if (qemuDomainSecretStorageSourcePrepareAuth(priv, src, - src->nodestorage) < 0) + if (qemuDomainSecretStorageSourcePrepareAuth(priv, src, nodestorage) < 0) return -1; } - if (qemuDomainPrepareStorageSourcePR(src, priv, src->nodestorage) < 0) + if (qemuDomainPrepareStorageSourcePR(src, priv, nodestorage) < 0) return -1; - if (qemuDomainPrepareStorageSourceTLS(src, cfg, src->nodestorage, + if (qemuDomainPrepareStorageSourceTLS(src, cfg, nodestorage, priv) < 0) return -1; @@ -11297,12 +11299,14 @@ qemuDomainPrepareHostdevSCSI(virDomainHostdevDef *hostdev, } if (src) { - const char *backendalias = hostdev->info->alias; + char *backendalias; src->readonly = hostdev->readonly; src->id = qemuDomainStorageIDNew(priv); - src->nodestorage = g_strdup_printf("libvirt-%d-backend", src->id); - backendalias = src->nodestorage; + backendalias = g_strdup_printf("libvirt-%d-backend", src->id); + + /* 'src' takes ownership of 'backendalias' */ + qemuBlockStorageSourceSetStorageNodename(src, backendalias); if (src->auth) { virSecretUsageType usageType = VIR_SECRET_USAGE_TYPE_ISCSI; @@ -11695,8 +11699,7 @@ qemuDomainInitializePflashStorageSource(virDomainObj *vm, pflash0->readonly = false; virTristateBoolToBool(def->os.loader->readonly, &pflash0->readonly); pflash0->nodeformat = g_strdup("libvirt-pflash0-format"); - pflash0->nodestorage = g_strdup("libvirt-pflash0-storage"); - + qemuBlockStorageSourceSetStorageNodename(pflash0, g_strdup("libvirt-pflash0-storage")); if (def->os.loader->nvram) { if (qemuDomainPrepareStorageSourceBlockdevNodename(NULL, diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 011482c2b5..7d08df1fc5 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1011,7 +1011,7 @@ qemuMigrationSrcNBDStorageCopyBlockdevPrepareSource(virDomainDiskDef *disk, copysrc->tlsAlias = g_strdup(tlsAlias); copysrc->tlsHostname = g_strdup(tlsHostname); - copysrc->nodestorage = g_strdup_printf("migration-%s-storage", disk->dst); + qemuBlockStorageSourceSetStorageNodename(copysrc, g_strdup_printf("migration-%s-storage", disk->dst)); copysrc->nodeformat = g_strdup_printf("migration-%s-format", disk->dst); return g_steal_pointer(©src); -- 2.41.0