[RFC PATCH v2 02/12] domain_conf: introduce cpu def helpers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



virDomainCPUDefFree - free memory allocated
virDomainCPUDefParseXML - parse job type
virDomainCPUDefFormat - output job type

Signed-off-by: Zhu Guihua <zhugh.fnst@xxxxxxxxxxxxxx>
---
 docs/formatdomain.html.in     | 28 +++++++++++++++
 docs/schemas/domaincommon.rng |  3 ++
 src/conf/domain_conf.c        | 82 +++++++++++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h        |  1 +
 src/libvirt_private.syms      |  1 +
 5 files changed, 115 insertions(+)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index f8d5f89..10cbd29 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -5830,6 +5830,34 @@ qemu-kvm -net nic,model=? /dev/null
     </dd>
   </dl>
 
+  <h4><a name="elementsCpu">CPU device</a></h4>
+  <p>
+    CPU device allows to be hot added to the guest.
+    <span class="since">Since 1.2.12, QEMU and KVM only</span>
+  </p>
+
+<pre>
+  ...
+  &lt;devices&gt;
+    &lt;cpu match='exact'&gt;
+      &lt;model fallback='allow'&gt;core2duo&lt;/model&gt;
+      &lt;vendor&gt;Intel&lt;/vendor&gt;
+      &lt;topology sockets='1' cores='2' threads='1'/&gt;
+      &lt;feature policy='disable' name='lahf_lm'/&gt;
+    &lt;/cpu&gt;
+  &lt;devices&gt;
+  ...
+</pre>
+  <dl>
+    <dt><code>model</code></dt>
+    <dd>
+      <p>
+        The attribute can be omitted and will default to a model
+        started up by the guest.
+      </p>
+    </dd>
+  </dl>
+
     <h3><a name="seclabel">Security label</a></h3>
 
     <p>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 9d6c1ee..1ceb811 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -4003,6 +4003,9 @@
         <optional>
           <ref name="panic"/>
         </optional>
+        <optional>
+          <ref name='cpu'>
+        </optional>
       </interleave>
     </element>
   </define>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0f4baaf..dfe0d65 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1913,6 +1913,18 @@ void virDomainRedirFilterDefFree(virDomainRedirFilterDefPtr def)
     VIR_FREE(def);
 }
 
+void virDomainCPUDefFree(virDomainCPUDefPtr def)
+{
+    if (!def)
+        return;
+
+    virCPUDefFree(def->virCPU);
+
+    virDomainDeviceInfoClear(&def->info);
+
+    VIR_FREE(def);
+}
+
 void virDomainDeviceDefFree(virDomainDeviceDefPtr def)
 {
     if (!def)
@@ -1983,6 +1995,8 @@ void virDomainDeviceDefFree(virDomainDeviceDefPtr def)
         virDomainPanicDefFree(def->data.panic);
         break;
     case VIR_DOMAIN_DEVICE_CPU:
+        virDomainCPUDefFree(def->data.cpu);
+        break;
     case VIR_DOMAIN_DEVICE_LAST:
     case VIR_DOMAIN_DEVICE_NONE:
         break;
@@ -11052,6 +11066,44 @@ virDomainPMStateParseXML(xmlXPathContextPtr ctxt,
     return ret;
 }
 
+static virDomainCPUDefPtr
+virDomainCPUDefParseXML(xmlNodePtr node,
+                        xmlXPathContextPtr ctxt,
+                        const virDomainDef *def,
+                        unsigned int flags)
+{
+    virDomainCPUDefPtr dev;
+
+    if (VIR_ALLOC(dev) < 0)
+        return NULL;
+
+    dev->virCPU = virCPUDefParseXML(node, ctxt, VIR_CPU_TYPE_AUTO);
+    if (!dev->virCPU)
+        goto cleanup;
+
+    if (!dev->virCPU->model) {
+        if (def->cpu->model) {
+            dev->virCPU->model = def->cpu->model;
+        } else if (def->os.arch == VIR_ARCH_I686) {
+            if (virAsprintf(&dev->virCPU->model, "qemu32") < 0)
+                goto cleanup;
+        } else {
+            if (virAsprintf(&dev->virCPU->model, "qemu64") < 0)
+                goto cleanup;
+        }
+    }
+
+    if (virDomainDeviceInfoParseXML(node, NULL, &dev->info, flags) < 0)
+        goto cleanup;
+
+    return dev;
+
+ cleanup:
+    virDomainCPUDefFree(dev);
+    dev = NULL;
+    return dev;
+}
+
 virDomainDeviceDefPtr
 virDomainDeviceDefParse(const char *xmlStr,
                         const virDomainDef *def,
@@ -11187,6 +11239,9 @@ virDomainDeviceDefParse(const char *xmlStr,
             goto error;
         break;
     case VIR_DOMAIN_DEVICE_CPU:
+        if (!(dev->data.cpu = virDomainCPUDefParseXML(node, ctxt, def, flags)))
+            goto error;
+        break;
     case VIR_DOMAIN_DEVICE_NONE:
     case VIR_DOMAIN_DEVICE_LAST:
         break;
@@ -18145,6 +18200,27 @@ virDomainChrDefFormat(virBufferPtr buf,
 }
 
 static int
+virDomainCPUDefFormat(virBufferPtr buf,
+                      virDomainCPUDefPtr def,
+                      unsigned int flags)
+{
+    if (virCPUDefFormatBufFull(buf, def->virCPU, false) < 0)
+        return -1;
+
+    virBufferTrim(buf, "</cpu>\n", -1);
+    virBufferTrim(buf, "", 4);
+    virBufferAdjustIndent(buf, 2);
+
+    if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
+        return -1;
+
+    virBufferAdjustIndent(buf, -2);
+    virBufferAddLit(buf, "</cpu>\n");
+
+    return 0;
+}
+
+static int
 virDomainSmartcardDefFormat(virBufferPtr buf,
                             virDomainSmartcardDefPtr def,
                             unsigned int flags)
@@ -20065,6 +20141,10 @@ virDomainDefFormatInternal(virDomainDefPtr def,
             goto error;
     }
 
+    for (n = 0; n < def->ncpus; n++)
+        if (virDomainCPUDefFormat(buf, def->cpus[n], flags) < 0)
+            goto error;
+
     if (def->nvram)
         virDomainNVRAMDefFormat(buf, def->nvram, flags);
 
@@ -21480,6 +21560,8 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
         rc = virDomainPanicDefFormat(&buf, src->data.panic);
         break;
     case VIR_DOMAIN_DEVICE_CPU:
+        rc = virDomainCPUDefFormat(&buf, src->data.cpu, flags);
+        break;
     case VIR_DOMAIN_DEVICE_NONE:
     case VIR_DOMAIN_DEVICE_SMARTCARD:
     case VIR_DOMAIN_DEVICE_MEMBALLOON:
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index b9d4e7c..4096ecc 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2371,6 +2371,7 @@ void virDomainHostdevDefFree(virDomainHostdevDefPtr def);
 void virDomainHubDefFree(virDomainHubDefPtr def);
 void virDomainRedirdevDefFree(virDomainRedirdevDefPtr def);
 void virDomainRedirFilterDefFree(virDomainRedirFilterDefPtr def);
+void virDomainCPUDefFree(virDomainCPUDefPtr def);
 void virDomainShmemDefFree(virDomainShmemDefPtr def);
 void virDomainDeviceDefFree(virDomainDeviceDefPtr def);
 virDomainDeviceDefPtr virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 75a6d83..897a598 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -181,6 +181,7 @@ virDomainControllerModelUSBTypeFromString;
 virDomainControllerModelUSBTypeToString;
 virDomainControllerRemove;
 virDomainControllerTypeToString;
+virDomainCPUDefFree;
 virDomainCpuPlacementModeTypeFromString;
 virDomainCpuPlacementModeTypeToString;
 virDomainDefAddImplicitControllers;
-- 
1.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]