]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Add per-VM control of deprecation behavior
authorPeter Krempa <pkrempa@redhat.com>
Mon, 15 Mar 2021 14:06:29 +0000 (15:06 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 6 Apr 2021 15:07:56 +0000 (17:07 +0200)
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@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
docs/drvqemu.rst
docs/schemas/domaincommon.rng
src/qemu/qemu_domain.c
src/qemu/qemu_domain.h
tests/qemuxml2argvdata/qemu-ns.xml
tests/qemuxml2xmloutdata/qemu-ns.x86_64-latest.xml

index 0f8fd9e47d3ab7a9d280719c294500f05637a259..12e3369e5d1dd8ac3af87aa7e0e3a8c6f81ad569 100644 (file)
@@ -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 commands 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
 -------------------------
 
index 2ff786253956c70084ecbefc92c67e35e0865eb8..73ce2538214c56681edd51939b1fa0c33dc2c916 100644 (file)
@@ -77,6 +77,9 @@
         <optional>
           <ref name="qemucapabilities"/>
         </optional>
+        <optional>
+          <ref name="qemudeprecation"/>
+        </optional>
         <optional>
           <ref name="lxcsharens"/>
         </optional>
     </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:
index 76e8903dbcda4a1e9d958b18ea0f8713dbfecb7f..03858a1340ef58a2159e62a2b0b2e1cd13d8ba2d 100644 (file)
@@ -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;
 }
 
index 949307229bdb2f6c2adfb887e1f994b2372ca526..1c80b8cfaab79818db0969e0440db95956c47e74 100644 (file)
@@ -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;
 };
 
 
index 515d4fabec627ebed53d9554375e19d18791414b..3e7590237e4038c6ac8c04bcf0c287c821ac3e16 100644 (file)
@@ -32,4 +32,5 @@
     <qemu:add capability="blockdev"/>
     <qemu:del capability="name"/>
   </qemu:capabilities>
+  <qemu:deprecation behavior='crash'/>
 </domain>
index 53e21edfaf7905f9f02d822f404b40a6532866ae..e655e87cbf3e013d6fe895eca5cd5ff49144626c 100644 (file)
@@ -48,4 +48,5 @@
     <qemu:add capability='blockdev'/>
     <qemu:del capability='name'/>
   </qemu:capabilities>
+  <qemu:deprecation behavior='crash'/>
 </domain>