Right now, this results in loader->nvram being NULL, which is
reasonable: loader->nvramTemplate is stored separately, so if
the <nvram> element doesn't contain a path there is really no
useful information inside it.
However, this is about to change, so we will find ourselves
needing to hold on to loader->nvram even when no path is
present. Change the firmware handling code so that such a
scenario is dealt with appropriately.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
src/conf/domain_conf.c | 9 +++------
src/qemu/qemu_firmware.c | 7 ++++++-
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 8117cff83e..30a3261dab 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16766,16 +16766,13 @@ virDomainLoaderDefParseXMLNvram(virDomainLoaderDef *loader,
return -1;
if (!typePresent) {
- g_autofree char *path = NULL;
-
- if (!(path = virXMLNodeContentString(nvramNode)))
+ if (!(src->path = virXMLNodeContentString(nvramNode)))
return -1;
- if (STREQ(path, ""))
- return 0;
+ if (STREQ(src->path, ""))
+ VIR_FREE(src->path);
src->type = VIR_STORAGE_TYPE_FILE;
- src->path = g_steal_pointer(&path);
} else {
if (!nvramSourceNode)
return -1;
diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c
index ac1ae1e923..4d34062ebf 100644
--- a/src/qemu/qemu_firmware.c
+++ b/src/qemu/qemu_firmware.c
@@ -997,9 +997,14 @@ qemuFirmwareEnsureNVRAM(virDomainDef *def,
if (!loader)
return;
- if (loader->nvram)
+ /* If the source already exists and is fully specified, including
+ * the path, leave it alone */
+ if (loader->nvram && loader->nvram->path)
return;
+ if (loader->nvram)
+ virObjectUnref(loader->nvram);
+
loader->nvram = virStorageSourceNew();
loader->nvram->type = VIR_STORAGE_TYPE_FILE;
loader->nvram->format = VIR_STORAGE_FILE_RAW;
--
2.39.1