On Fri, Mar 19, 2021 at 07:33:54PM +0100, Peter Krempa wrote:
Enable '-compat' if requested in qemu.conf and supported by
qemu to
instruct qemu to crash when a deprecated command is used and stop
returning deprecated fields.
This setting is meant for libvirt developers and such.
---
src/qemu/qemu_command.c | 80 +++++++++++++++++++
.../qemu-ns.x86_64-latest.args | 1 +
2 files changed, 81 insertions(+)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 1b4fa77867..2388b1a1a1 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -10325,6 +10325,84 @@ qemuBuildVsockCommandLine(virCommandPtr cmd,
}
+typedef enum {
+ QEMU_COMMAND_DEPRECATION_BEHAVIOR_NONE = 0,
+ QEMU_COMMAND_DEPRECATION_BEHAVIOR_OMIT,
+ QEMU_COMMAND_DEPRECATION_BEHAVIOR_REJECT,
+ QEMU_COMMAND_DEPRECATION_BEHAVIOR_CRASH,
+
+ QEMU_COMMAND_DEPRECATION_BEHAVIOR_LAST
+} qemuCommnadDeprecationBehavior;
+
+
+VIR_ENUM_DECL(qemuCommnadDeprecationBehavior);
+VIR_ENUM_IMPL(qemuCommnadDeprecationBehavior,
+ QEMU_COMMAND_DEPRECATION_BEHAVIOR_LAST,
+ "none",
+ "omit",
+ "reject",
+ "crash");
+
+static void
+qemuBuildCompatDeprecatedCommandLine(virCommand *cmd,
+ virQEMUDriverConfig *cfg,
+ virDomainDef *def,
+ virQEMUCaps *qemuCaps)
+{
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+ qemuDomainXmlNsDefPtr nsdata = def->namespaceData;
+ qemuCommnadDeprecationBehavior behavior = QEMU_COMMAND_DEPRECATION_BEHAVIOR_NONE;
+ const char *behaviorStr = cfg->deprecationBehavior;
+ int tmp;
+
+ if (nsdata && nsdata->deprecationBehavior)
+ behaviorStr = nsdata->deprecationBehavior;
+
+ if ((tmp = qemuCommnadDeprecationBehaviorTypeFromString(behaviorStr)) < 0) {
+ VIR_WARN("Unsupported deprecation behavior '%s' for VM
'%s'",
+ behaviorStr, def->name);
+ return;
+ }
+
+ behavior = tmp;
+
+ if (behavior == QEMU_COMMAND_DEPRECATION_BEHAVIOR_NONE)
+ return;
+
+ /* we don't try to enable this feature at all if qemu doesn't support it,
+ * so that a downgrade of qemu version doesn't impact startup of the VM */
+ if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_COMPAT_DEPRECATED)) {
+ VIR_DEBUG("-compat not supported for VM '%s'", def->name);
+ return;
+ }
+
+ /* all active options hide output fields from qemu */
+ virBufferAddLit(&buf, "deprecated-output=hide,");
+
+ switch (behavior) {
+ case QEMU_COMMAND_DEPRECATION_BEHAVIOR_OMIT:
+ case QEMU_COMMAND_DEPRECATION_BEHAVIOR_NONE:
+ case QEMU_COMMAND_DEPRECATION_BEHAVIOR_LAST:
+ default:
+ /* output field hiding is default for all cases */
+ break;
+
+ case QEMU_COMMAND_DEPRECATION_BEHAVIOR_REJECT:
+ virBufferAddLit(&buf, "deprecated-input=reject,");
+ break;
+
+ case QEMU_COMMAND_DEPRECATION_BEHAVIOR_CRASH:
+ virBufferAddLit(&buf, "deprecated-input=crash,");
+ break;
+ }
I wonder whether it would be beneficial to not hide the deprecated
outputs (so that qemu output behaves just as it would without this
option) but it would still crash when any deprecated field is used
when instructing qemu. Probably does not make sense, just a thought.