Similar to the qemu.conf knob 'deprecation_behavior' add a per-VM knob in the QEMU namespace: <qemu:deprecation behavior='...'/> Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- docs/drvqemu.rst | 48 +++++++++++++++++++ docs/schemas/domaincommon.rng | 16 +++++++ src/qemu/qemu_domain.c | 10 +++- src/qemu/qemu_domain.h | 5 ++ tests/qemuxml2argvdata/qemu-ns.xml | 1 + .../qemu-ns.x86_64-latest.xml | 1 + 6 files changed, 80 insertions(+), 1 deletion(-) diff --git a/docs/drvqemu.rst b/docs/drvqemu.rst index 0f8fd9e47d..41c9c5d8e1 100644 --- a/docs/drvqemu.rst +++ b/docs/drvqemu.rst @@ -523,6 +523,54 @@ Example: </qemu:capabilities> </domain> +Control of QEMU deprecation warnings +------------------------------------ + +The following knob controls how QEMU behaves towards deprecated commands and +arguments used by libvirt: + +:: + + <domain type='qemu' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'> + <name>testvm</name> + + [...] + + <qemu:deprecation behavior='crash'/> + +This setting is meant for developers and CI efforts to make it obvious when +libvirt relies on fields which are deprecated so that it can be fixes as soon +as possible. + +Possible options are: + +``none`` + (default) qemu is supposed to accept and output deprecated fields and commands + +``omit`` + qemu is instructed to omit deprecated fields on output, behaviour towards + fields and commadns from libvirtd is not changed + +``reject`` + qemu is instructed to report an error if a deprecated command or field is + used by libvirtd + +``crash`` + qemu crashes when an deprecated command or field is used by libvirtd + +For both "reject" and "crash" qemu is instructed to omit any deprecated fields +on output. + +The "reject" option is less harsh towards the VMs but some code paths ignore +errors reported by qemu and thus it may not be obvious that a deprecated +command/field was used, thus it's suggested to use the "crash" option instead. + +In cases when qemu doesn't support configuring the behaviour this setting is +silently ignored to allow testing older qemu versions without having to +reconfigure libvirtd. + +*DO NOT* use in production. + Example domain XML config ------------------------- diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 1dbfc68f18..ffd992852a 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -77,6 +77,9 @@ <optional> <ref name="qemucapabilities"/> </optional> + <optional> + <ref name="qemudeprecation"/> + </optional> <optional> <ref name="lxcsharens"/> </optional> @@ -7271,6 +7274,19 @@ </element> </define> + <define name="qemudeprecation"> + <element name="deprecation" ns="http://libvirt.org/schemas/domain/qemu/1.0"> + <attribute name="behavior"> + <choice> + <value>none</value> + <value>omit</value> + <value>reject</value> + <value>crash</value> + </choice> + </attribute> + </element> + </define> + <!-- Optional hypervisor extensions in their own namespace: diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 5c98f8ff1a..ec3cb84518 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3316,6 +3316,8 @@ qemuDomainXmlNsDefFree(qemuDomainXmlNsDefPtr def) virStringListFreeCount(def->capsadd, def->ncapsadd); virStringListFreeCount(def->capsdel, def->ncapsdel); + g_free(def->deprecationBehavior); + g_free(def); } @@ -3468,8 +3470,11 @@ qemuDomainDefNamespaceParse(xmlXPathContextPtr ctxt, qemuDomainDefNamespaceParseCaps(nsdata, ctxt) < 0) goto cleanup; + nsdata->deprecationBehavior = virXPathString("string(./qemu:deprecation/@behavior)", ctxt); + if (nsdata->num_args > 0 || nsdata->num_env > 0 || - nsdata->ncapsadd > 0 || nsdata->ncapsdel > 0) + nsdata->ncapsadd > 0 || nsdata->ncapsdel > 0 || + nsdata->deprecationBehavior) *data = g_steal_pointer(&nsdata); ret = 0; @@ -3539,6 +3544,9 @@ qemuDomainDefNamespaceFormatXML(virBufferPtr buf, qemuDomainDefNamespaceFormatXMLCommandline(buf, cmd); qemuDomainDefNamespaceFormatXMLCaps(buf, cmd); + virBufferEscapeString(buf, "<qemu:deprecation behavior='%s'/>\n", + cmd->deprecationBehavior); + return 0; } diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 949307229b..1c80b8cfaa 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -485,6 +485,11 @@ struct _qemuDomainXmlNsDef { size_t ncapsdel; char **capsdel; + + /* We deliberatly keep this as a string so that it's parsed only when + * starting the VM to avoid any form of errors in the parser or when + * changing qemu versions. The knob is mainly for development/CI purposes */ + char *deprecationBehavior; }; diff --git a/tests/qemuxml2argvdata/qemu-ns.xml b/tests/qemuxml2argvdata/qemu-ns.xml index 515d4fabec..3e7590237e 100644 --- a/tests/qemuxml2argvdata/qemu-ns.xml +++ b/tests/qemuxml2argvdata/qemu-ns.xml @@ -32,4 +32,5 @@ <qemu:add capability="blockdev"/> <qemu:del capability="name"/> </qemu:capabilities> + <qemu:deprecation behavior='crash'/> </domain> diff --git a/tests/qemuxml2xmloutdata/qemu-ns.x86_64-latest.xml b/tests/qemuxml2xmloutdata/qemu-ns.x86_64-latest.xml index 53e21edfaf..e655e87cbf 100644 --- a/tests/qemuxml2xmloutdata/qemu-ns.x86_64-latest.xml +++ b/tests/qemuxml2xmloutdata/qemu-ns.x86_64-latest.xml @@ -48,4 +48,5 @@ <qemu:add capability='blockdev'/> <qemu:del capability='name'/> </qemu:capabilities> + <qemu:deprecation behavior='crash'/> </domain> -- 2.29.2