[libvirt] [PATCH 5/5] qemu: add support for os.nvram 'format' attribute

Dmitry Andreev dandreev at virtuozzo.com
Tue Dec 8 14:11:15 UTC 2015


UEFI firmwares may want to use a non-volatile memory to store some
variables. os.nvram tag is used to specify image file path for this
store.

'format' attribute is used to specify this image format.
---
 src/qemu/qemu_command.c |  8 ++++++--
 src/qemu/qemu_process.c | 17 +++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 4ff31dc..26f294c 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9132,10 +9132,14 @@ qemuBuildDomainLoaderCommandLine(virCommandPtr cmd,
         virCommandAddArgBuffer(cmd, &buf);
 
         if (loader->nvram) {
+            const char* format;
+
+            format = loader->format <= 0 ? "raw" :
+                     virStorageFileFormatTypeToString(loader->format);
             virBufferFreeAndReset(&buf);
             virBufferAsprintf(&buf,
-                              "file=%s,if=pflash,format=raw,unit=%d",
-                              loader->nvram, unit);
+                              "file=%s,if=pflash,format=%s,unit=%d",
+                              loader->nvram, format, unit);
 
             virCommandAddArg(cmd, "-drive");
             virCommandAddArgBuffer(cmd, &buf);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 4201962..733282c 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -69,6 +69,7 @@
 #include "virstring.h"
 #include "virhostdev.h"
 #include "storage/storage_driver.h"
+#include "storage/storage_backend.h"
 #include "configmake.h"
 #include "nwfilter_conf.h"
 #include "netdev_bandwidth_conf.h"
@@ -4014,6 +4015,22 @@ qemuPrepareNVRAM(virQEMUDriverConfigPtr cfg,
             goto cleanup;
         }
 
+        /* if the nvram format is configured and it is not equal to 'raw'
+         * we should convert the master var store instead of copy it */
+        if (loader->format > VIR_STORAGE_FILE_RAW) {
+            if (virStorageBackendConvertImage(master_nvram_path,
+                                              VIR_STORAGE_FILE_RAW,
+                                              loader->nvram,
+                                              loader->format,
+                                              cfg->user, cfg->group,
+                                              S_IRUSR | S_IWUSR) == 0)
+                return 0;
+            virReportError(VIR_ERR_OPERATION_FAILED,
+                           _("Failed to conver master var storage %s to %s "
+                             "for loader"), master_nvram_path, loader->nvram);
+            goto cleanup;
+        }
+
         if ((srcFD = virFileOpenAs(master_nvram_path, O_RDONLY,
                                    0, -1, -1, 0)) < 0) {
             virReportSystemError(-srcFD,
-- 
1.8.3.1




More information about the libvir-list mailing list