From b3b81e60e451f2aa66bc362fd9e976f852c94dc3 Mon Sep 17 00:00:00 2001 From: Andrea Bolognani Date: Tue, 31 Jan 2023 14:35:28 +0100 Subject: [PATCH] conf: Change handling for empty NVRAM path Right now, this results in loader->nvram being NULL, which is reasonable: loader->nvramTemplate is stored separately, so if the 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 Reviewed-by: Michal Privoznik --- 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 f61874e8ab..cc27e63bd3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16775,16 +16775,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;