]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Change handling for empty NVRAM path
authorAndrea Bolognani <abologna@redhat.com>
Tue, 31 Jan 2023 13:35:28 +0000 (14:35 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Fri, 3 Mar 2023 12:49:56 +0000 (13:49 +0100)
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@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/domain_conf.c
src/qemu/qemu_firmware.c

index f61874e8ab52b62329cf3055524cd1015f4d2de8..cc27e63bd32d559abff96817005892100506b626 100644 (file)
@@ -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;
index ac1ae1e923cb714d9d03a88e7882176924d0b645..4d34062ebf01501ec0070e6dde98b69840c372e3 100644 (file)
@@ -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;