]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf, qemu: Add support for shmem model
authorMartin Kletzander <mkletzan@redhat.com>
Fri, 19 Aug 2016 12:57:07 +0000 (14:57 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Wed, 2 Nov 2016 15:05:39 +0000 (16:05 +0100)
Just the default one now, new ones will be added in following commits.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
docs/formatdomain.html.in
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms
src/qemu/qemu_command.c
tests/qemuxml2argvdata/qemuxml2argv-shmem.xml
tests/qemuxml2xmloutdata/qemuxml2xmlout-shmem.xml

index c70377ba4847077f237d3cdcab8fa768f0b76cb6..10a692de25531c15576758062b791bde33b3af33 100644 (file)
@@ -6829,6 +6829,7 @@ qemu-kvm -net nic,model=? /dev/null
       &lt;size unit='M'&gt;4&lt;/size&gt;
     &lt;/shmem&gt;
     &lt;shmem name='shmem_server'&gt;
+      &lt;model type='ivshmem'/&gt;
       &lt;size unit='M'&gt;2&lt;/size&gt;
       &lt;server path='/tmp/socket-shmem'/&gt;
       &lt;msi vectors='32' ioeventfd='on'/&gt;
@@ -6843,6 +6844,13 @@ qemu-kvm -net nic,model=? /dev/null
       The <code>shmem</code> element has one mandatory attribute,
       <code>name</code> to identify the shared memory.
     </dd>
+    <dt><code>model</code></dt>
+    <dd>
+      Attribute <code>type</code> of the optional element <code>model</code>
+      specifies the model of the underlying device providing the
+      <code>shmem</code> device.  Currently the only supported model is
+      <code>ivshmem</code>.
+    </dd>
     <dt><code>size</code></dt>
     <dd>
       The optional <code>size</code> element specifies the size of the shared
index dba9187aa716f6d45ed919f125f4ae8332fad641..99e0eb6cb448bcb1d9943d4d4a4f7337609740ef 100644 (file)
     <element name="shmem">
       <attribute name="name"/>
       <interleave>
+        <optional>
+          <element name="model">
+            <attribute name="type">
+              <choice>
+                <value>ivshmem</value>
+              </choice>
+            </attribute>
+          </element>
+        </optional>
         <optional>
           <element name="size">
             <ref name="scaledInteger"/>
index 03506cbec142d0686c6e2d03ca2af9e9bf4eeb9a..108a48ee974ed743cd0ddada089defe1655c46e2 100644 (file)
@@ -844,6 +844,9 @@ VIR_ENUM_IMPL(virDomainBlockJob, VIR_DOMAIN_BLOCK_JOB_TYPE_LAST,
 VIR_ENUM_IMPL(virDomainMemoryModel, VIR_DOMAIN_MEMORY_MODEL_LAST,
               "", "dimm")
 
+VIR_ENUM_IMPL(virDomainShmemModel, VIR_DOMAIN_SHMEM_MODEL_LAST,
+              "ivshmem")
+
 static virClassPtr virDomainObjClass;
 static virClassPtr virDomainXMLOptionClass;
 static void virDomainObjDispose(void *obj);
@@ -12351,6 +12354,20 @@ virDomainShmemDefParseXML(xmlNodePtr node,
 
     ctxt->node = node;
 
+    tmp = virXPathString("string(./model/@type)", ctxt);
+    if (tmp) {
+        /* If there's none, we will automatically have the first one
+         * (as default).  Unfortunately this has to be done for
+         * compatibility reasons. */
+        if ((def->model = virDomainShmemModelTypeFromString(tmp)) < 0) {
+            virReportError(VIR_ERR_XML_ERROR,
+                           _("Unknown shmem model type '%s'"), tmp);
+            goto cleanup;
+        }
+
+        VIR_FREE(tmp);
+    }
+
     if (!(def->name = virXMLPropString(node, "name"))) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("shmem element must contain 'name' attribute"));
@@ -14939,6 +14956,9 @@ virDomainShmemDefEquals(virDomainShmemDefPtr src,
     if (src->size != dst->size)
         return false;
 
+    if (src->model != dst->model)
+        return false;
+
     if (src->server.enabled != dst->server.enabled)
         return false;
 
@@ -18927,6 +18947,15 @@ virDomainShmemDefCheckABIStability(virDomainShmemDefPtr src,
         return false;
     }
 
+    if (src->model != dst->model) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Target shared memory model '%s' does not match "
+                         "source model '%s'"),
+                       virDomainShmemModelTypeToString(dst->model),
+                       virDomainShmemModelTypeToString(src->model));
+        return false;
+    }
+
     if (src->size != dst->size) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("Target shared memory size '%llu' does not match "
@@ -21980,20 +22009,13 @@ virDomainShmemDefFormat(virBufferPtr buf,
                         virDomainShmemDefPtr def,
                         unsigned int flags)
 {
-    virBufferEscapeString(buf, "<shmem name='%s'", def->name);
-
-    if (!def->size &&
-        !def->server.enabled &&
-        !def->msi.enabled &&
-        !virDomainDeviceInfoNeedsFormat(&def->info, flags)) {
-        virBufferAddLit(buf, "/>\n");
-        return 0;
-    } else {
-        virBufferAddLit(buf, ">\n");
-    }
+    virBufferEscapeString(buf, "<shmem name='%s'>\n", def->name);
 
     virBufferAdjustIndent(buf, 2);
 
+    virBufferAsprintf(buf, "<model type='%s'/>\n",
+                      virDomainShmemModelTypeToString(def->model));
+
     if (def->size)
         virBufferAsprintf(buf, "<size unit='M'>%llu</size>\n", def->size >> 20);
 
index 24aa79cdc9e45efefd462867a48ddd801e8d1af5..d2a9289e077d330c467ee40e9070b761ec111cf3 100644 (file)
@@ -1562,9 +1562,16 @@ struct _virDomainNVRAMDef {
     virDomainDeviceInfo info;
 };
 
+typedef enum {
+    VIR_DOMAIN_SHMEM_MODEL_IVSHMEM,
+
+    VIR_DOMAIN_SHMEM_MODEL_LAST
+} virDomainShmemModel;
+
 struct _virDomainShmemDef {
     char *name;
     unsigned long long size;
+    int model; /* enum virDomainShmemModel */
     struct {
         bool enabled;
         virDomainChrSourceDef chr;
@@ -3084,6 +3091,7 @@ VIR_ENUM_DECL(virDomainTPMBackend)
 VIR_ENUM_DECL(virDomainMemoryModel)
 VIR_ENUM_DECL(virDomainMemoryBackingModel)
 VIR_ENUM_DECL(virDomainIOMMUModel)
+VIR_ENUM_DECL(virDomainShmemModel)
 /* from libvirt.h */
 VIR_ENUM_DECL(virDomainState)
 VIR_ENUM_DECL(virDomainNostateReason)
index 162fda54f95201e79ad7c011a6e8e07107d3182b..74dd5271a8bde9f3ed2ece926b72c5ede8e569f8 100644 (file)
@@ -474,6 +474,8 @@ virDomainShmemDefFind;
 virDomainShmemDefFree;
 virDomainShmemDefInsert;
 virDomainShmemDefRemove;
+virDomainShmemModelTypeFromString;
+virDomainShmemModelTypeToString;
 virDomainShutdownReasonTypeFromString;
 virDomainShutdownReasonTypeToString;
 virDomainShutoffReasonTypeFromString;
index b68da3db5fc76a6a53fd7ef29a5e77df939c299e..5ed288c02a93181c9e4f0b0fc98fac67b630bb05 100644 (file)
@@ -8525,7 +8525,16 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManager,
         return -1;
     }
 
-    if (!(devstr = qemuBuildShmemDevLegacyStr(def, shmem, qemuCaps)))
+    switch ((virDomainShmemModel)shmem->model) {
+    case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM:
+        devstr = qemuBuildShmemDevLegacyStr(def, shmem, qemuCaps);
+        break;
+
+    case VIR_DOMAIN_SHMEM_MODEL_LAST:
+        break;
+    }
+
+    if (!devstr)
         return -1;
     virCommandAddArgList(cmd, "-device", devstr, NULL);
     VIR_FREE(devstr);
index 5bc49044894c9f042e37b2ffa5a1ff01b22a724b..b56e9e1878955e5dc6d89115a77f6d9f7dbfcda8 100644 (file)
@@ -28,6 +28,7 @@
       <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
     </shmem>
     <shmem name='shmem3'>
+      <model type='ivshmem'/>
       <size unit='M'>512</size>
       <server/>
     </shmem>
@@ -41,6 +42,7 @@
       <msi ioeventfd='off'/>
     </shmem>
     <shmem name='shmem6'>
+      <model type='ivshmem'/>
       <size unit='M'>4096</size>
       <server path='/tmp/shmem6-sock'/>
       <msi vectors='16'/>
index 1197f361e3c47635a27791c814b4758b984d431f..5602913648bcdf09344fa3f5863a9404c00faf64 100644 (file)
     <input type='keyboard' bus='ps2'/>
     <memballoon model='none'/>
     <shmem name='shmem0'>
+      <model type='ivshmem'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
     </shmem>
     <shmem name='shmem1'>
+      <model type='ivshmem'/>
       <size unit='M'>128</size>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
     </shmem>
     <shmem name='shmem2'>
+      <model type='ivshmem'/>
       <size unit='M'>256</size>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
     </shmem>
     <shmem name='shmem3'>
+      <model type='ivshmem'/>
       <size unit='M'>512</size>
       <server/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
     </shmem>
     <shmem name='shmem4'>
+      <model type='ivshmem'/>
       <size unit='M'>1024</size>
       <server path='/tmp/shmem4-sock'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
     </shmem>
     <shmem name='shmem5'>
+      <model type='ivshmem'/>
       <size unit='M'>2048</size>
       <server path='/tmp/shmem5-sock'/>
       <msi ioeventfd='off'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
     </shmem>
     <shmem name='shmem6'>
+      <model type='ivshmem'/>
       <size unit='M'>4096</size>
       <server path='/tmp/shmem6-sock'/>
       <msi vectors='16'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
     </shmem>
     <shmem name='shmem7'>
+      <model type='ivshmem'/>
       <size unit='M'>8192</size>
       <server path='/tmp/shmem7-sock'/>
       <msi vectors='32' ioeventfd='on'/>