From 316223b6ad779f53bd6c88348d4c9987ac70a544 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 1 Nov 2019 12:14:43 +0100 Subject: [PATCH] qemu: command: Extract formatting of -drive for pflash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Daniel P. Berrangé Reviewed-by: Ján Tomko --- src/qemu/qemu_command.c | 72 +++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index ca1bd12594..c82d13483e 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -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: