virDomainCPUDefFree - free memory allocated
virDomainCPUDefParseXML - parse job type
virDomainCPUDefFormat - output job type
Signed-off-by: Zhu Guihua <zhugh.fnst(a)cn.fujitsu.com>
---
src/conf/domain_conf.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 100 insertions(+)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e036d75..1f05056 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1913,6 +1913,19 @@ void virDomainRedirFilterDefFree(virDomainRedirFilterDefPtr def)
VIR_FREE(def);
}
+void virDomainCPUDefFree(virDomainCPUDefPtr def)
+{
+ if (!def)
+ return;
+
+ if (def->driver)
+ VIR_FREE(def->driver);
+
+ virDomainDeviceInfoClear(&def->info);
+
+ VIR_FREE(def);
+}
+
void virDomainDeviceDefFree(virDomainDeviceDefPtr def)
{
if (!def)
@@ -1983,6 +1996,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 +11067,57 @@ virDomainPMStateParseXML(xmlXPathContextPtr ctxt,
return ret;
}
+virDomainCPUDefPtr
+virDomainCPUDefNew(void)
+{
+ virDomainCPUDefPtr def = NULL;
+
+ if (VIR_ALLOC(def) < 0)
+ return NULL;
+
+ return def;
+}
+
+static virDomainCPUDefPtr
+virDomainCPUDefParseXML(xmlNodePtr node, virDomainDefPtr def)
+{
+ char *driver = NULL;
+ char *apic_id = NULL;
+ virDomainCPUDefPtr dev;
+
+ if (!(dev = virDomainCPUDefNew()))
+ return NULL;
+
+ driver = virXMLPropString(node, "driver");
+ if (driver == NULL) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("missing cpu device driver"));
+ goto error;
+ }
+ dev->driver = driver;
+
+ apic_id = virXMLPropString(node, "apic_id");
+
+ if (!apic_id)
+ dev->apic_id = virDomainCPUGetFreeApicID(def);
+ else
+ dev->apic_id = atoi (apic_id);
+
+ driver = NULL;
+ apic_id = NULL;
+
+ cleanup:
+ VIR_FREE(driver);
+ VIR_FREE(apic_id);
+
+ return dev;
+
+ error:
+ virDomainCPUDefFree(dev);
+ dev = NULL;
+ goto cleanup;
+}
+
virDomainDeviceDefPtr
virDomainDeviceDefParse(const char *xmlStr,
const virDomainDef *def,
@@ -11187,6 +11253,9 @@ virDomainDeviceDefParse(const char *xmlStr,
goto error;
break;
case VIR_DOMAIN_DEVICE_CPU:
+ if (!(dev->data.cpu = virDomainCPUDefParseXML(node, (virDomainDefPtr)def)))
+ goto error;
+ break;
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_LAST:
break;
@@ -18142,6 +18211,31 @@ virDomainChrDefFormat(virBufferPtr buf,
}
static int
+virDomainCPUDefFormat(virBufferPtr buf,
+ virDomainCPUDefPtr def,
+ unsigned int flags)
+{
+ char *apic_id = NULL;
+
+ ignore_value(virAsprintf(&apic_id, "%d", def->apic_id));
+
+ virBufferAsprintf(buf, "<cpu driver='%s'", def->driver);
+
+ virBufferEscapeString(buf, " apic_id='%s'", apic_id);
+
+ virBufferAddLit(buf, ">\n");
+ 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)
@@ -20062,6 +20156,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);
@@ -21477,6 +21575,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:
--
1.9.3