This is pretty straightforward and self explanatory.
Resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=1837990
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_command.c | 38 ++++++++++++++++++++++++++++++
tests/qemuxml2argvdata/fw_cfg.args | 32 +++++++++++++++++++++++++
tests/qemuxml2argvtest.c | 1 +
3 files changed, 71 insertions(+)
create mode 100644 tests/qemuxml2argvdata/fw_cfg.args
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 419eca5675..b1e047690b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5794,6 +5794,41 @@ qemuBuildSmbiosCommandLine(virCommandPtr cmd,
}
+static int
+qemuBuildFWCfgCommandLine(virCommandPtr cmd,
+ virQEMUCapsPtr qemuCaps,
+ const virDomainDef *def)
+{
+ size_t i;
+
+ if (def->nfw_cfgs == 0)
+ return 0;
+
+ if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_FW_CFG)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("fw_cfg is not supported with this QEMU"));
+ return -1;
+ }
+
+ for (i = 0; i < def->nfw_cfgs; i++) {
+ const virDomainFWCfgDef *f = &def->fw_cfgs[i];
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+
+ virBufferAsprintf(&buf, "name=%s", f->name);
+
+ if (f->value)
+ virBufferEscapeString(&buf, ",string=%s", f->value);
+ else
+ virBufferEscapeString(&buf, ",file=%s", f->file);
+
+ virCommandAddArg(cmd, "-fw_cfg");
+ virCommandAddArgBuffer(cmd, &buf);
+ }
+
+ return 0;
+}
+
+
static int
qemuBuildVMGenIDCommandLine(virCommandPtr cmd,
const virDomainDef *def)
@@ -9634,6 +9669,9 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
if (qemuBuildSmbiosCommandLine(cmd, driver, def) < 0)
return NULL;
+ if (qemuBuildFWCfgCommandLine(cmd, qemuCaps, def) < 0)
+ return NULL;
+
if (qemuBuildVMGenIDCommandLine(cmd, def) < 0)
return NULL;
diff --git a/tests/qemuxml2argvdata/fw_cfg.args b/tests/qemuxml2argvdata/fw_cfg.args
new file mode 100644
index 0000000000..95cbe55435
--- /dev/null
+++ b/tests/qemuxml2argvdata/fw_cfg.args
@@ -0,0 +1,32 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-QEMUGuest1 \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-i386 \
+-name QEMUGuest1 \
+-S \
+-machine pc,accel=tcg,usb=off,dump-guest-core=off \
+-m 214 \
+-realtime mlock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-fw_cfg 'name=opt/com.example/name,string=example value' \
+-fw_cfg name=opt/com.coreos/config,file=/tmp/provision.ign \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\
+server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-usb \
+-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
+-device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 3103cac884..dc10b30fe5 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1684,6 +1684,7 @@ mymain(void)
DO_TEST("smbios", NONE);
DO_TEST_PARSE_ERROR("smbios-date", NONE);
DO_TEST_PARSE_ERROR("smbios-uuid-match", NONE);
+ DO_TEST("fw_cfg", QEMU_CAPS_FW_CFG);
DO_TEST("watchdog", NONE);
DO_TEST("watchdog-device", NONE);
--
2.26.2