qemu: command: Extract formatting of -drive for pflash

Extract the old way to instantiate pflash devices to hold the firmware
via -drive to a separate function so that it can later be conditionally
disabled when -blockdev will be used.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2019-11-01 12:14:43 +01:00
parent c78fadb57c
commit 316223b6ad

View File

@ -9415,13 +9415,50 @@ qemuBuildRedirdevCommandLine(virLogManagerPtr logManager,
}
static void
qemuBuldDomainLoaderPflashCommandLine(virCommandPtr cmd,
virDomainLoaderDefPtr loader)
{
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
int unit = 0;
if (loader->secure == VIR_TRISTATE_BOOL_YES) {
virCommandAddArgList(cmd,
"-global",
"driver=cfi.pflash01,property=secure,value=on",
NULL);
}
virBufferAddLit(&buf, "file=");
virQEMUBuildBufferEscapeComma(&buf, loader->path);
virBufferAsprintf(&buf, ",if=pflash,format=raw,unit=%d", unit);
unit++;
if (loader->readonly) {
virBufferAsprintf(&buf, ",readonly=%s",
virTristateSwitchTypeToString(loader->readonly));
}
virCommandAddArg(cmd, "-drive");
virCommandAddArgBuffer(cmd, &buf);
if (loader->nvram) {
virBufferFreeAndReset(&buf);
virBufferAddLit(&buf, "file=");
virQEMUBuildBufferEscapeComma(&buf, loader->nvram);
virBufferAsprintf(&buf, ",if=pflash,format=raw,unit=%d", unit);
virCommandAddArg(cmd, "-drive");
virCommandAddArgBuffer(cmd, &buf);
}
}
static void
qemuBuildDomainLoaderCommandLine(virCommandPtr cmd,
virDomainDefPtr def)
{
virDomainLoaderDefPtr loader = def->os.loader;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
int unit = 0;
if (!loader)
return;
@ -9433,36 +9470,7 @@ qemuBuildDomainLoaderCommandLine(virCommandPtr cmd,
break;
case VIR_DOMAIN_LOADER_TYPE_PFLASH:
if (loader->secure == VIR_TRISTATE_BOOL_YES) {
virCommandAddArgList(cmd,
"-global",
"driver=cfi.pflash01,property=secure,value=on",
NULL);
}
virBufferAddLit(&buf, "file=");
virQEMUBuildBufferEscapeComma(&buf, loader->path);
virBufferAsprintf(&buf, ",if=pflash,format=raw,unit=%d", unit);
unit++;
if (loader->readonly) {
virBufferAsprintf(&buf, ",readonly=%s",
virTristateSwitchTypeToString(loader->readonly));
}
virCommandAddArg(cmd, "-drive");
virCommandAddArgBuffer(cmd, &buf);
if (loader->nvram) {
virBufferFreeAndReset(&buf);
virBufferAddLit(&buf, "file=");
virQEMUBuildBufferEscapeComma(&buf, loader->nvram);
virBufferAsprintf(&buf, ",if=pflash,format=raw,unit=%d", unit);
virCommandAddArg(cmd, "-drive");
virCommandAddArgBuffer(cmd, &buf);
}
qemuBuldDomainLoaderPflashCommandLine(cmd, loader);
break;
case VIR_DOMAIN_LOADER_TYPE_NONE: