qemu: Generate command line for -fw_cfg

This is pretty straightforward and self explanatory.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1837990

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Michal Privoznik 2020-06-02 17:07:59 +02:00
parent d024a7da7a
commit 14c32cd10f
3 changed files with 83 additions and 0 deletions

View File

@ -5800,6 +5800,47 @@ qemuBuildSmbiosCommandLine(virCommandPtr cmd,
}
static int
qemuBuildSysinfoCommandLine(virCommandPtr cmd,
virQEMUCapsPtr qemuCaps,
const virDomainDef *def)
{
size_t i;
/* We need to handle VIR_SYSINFO_FWCFG here, because
* VIR_SYSINFO_SMBIOS is handled in qemuBuildSmbiosCommandLine() */
for (i = 0; i < def->nsysinfo; i++) {
size_t j;
if (def->sysinfo[i]->type != VIR_SYSINFO_FWCFG)
continue;
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_FW_CFG)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("fw_cfg is not supported with this QEMU"));
return -1;
}
for (j = 0; j < def->sysinfo[i]->nfw_cfgs; j++) {
const virSysinfoFWCfgDef *f = &def->sysinfo[i]->fw_cfgs[j];
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)
@ -9655,6 +9696,9 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
if (qemuBuildSmbiosCommandLine(cmd, driver, def) < 0)
return NULL;
if (qemuBuildSysinfoCommandLine(cmd, qemuCaps, def) < 0)
return NULL;
if (qemuBuildVMGenIDCommandLine(cmd, def) < 0)
return NULL;

View File

@ -0,0 +1,38 @@
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 \
-smbios 'type=0,vendor=LENOVO,version=6FET82WW (3.12 )' \
-smbios 'type=1,manufacturer=Fedora,product=Virt-Manager,version=0.8.2-3.fc14,\
serial=32dfcb37-5af1-552b-357c-be8c3aa38310,\
uuid=c7a5fdbd-edaf-9455-926a-d65c16db1809,sku=1234567890,family=Red Hat' \
-smbios 'type=2,manufacturer=Lenovo,product=20BE0061MC,version=0B98401 Pro,\
serial=W1KS427111E,location=Not Available' \
-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

View File

@ -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("smbios-type-fwcfg", QEMU_CAPS_FW_CFG);
DO_TEST("watchdog", NONE);
DO_TEST("watchdog-device", NONE);