separate virDomainDefParseDeviceInfo from virDomainDefParseXML,
separate virDomainDefParseControllerInfo from virDomainDefParseXML,
move virDomainDefParseControllerInfo into virDomainDefParseDeviceInfo
---
src/conf/domain_conf.c | 153 ++++++++++++++++++++++++++++++++-----------------
1 file changed, 101 insertions(+), 52 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 92a6522..22db391 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19793,6 +19793,106 @@ virDomainDefParseBootOptionsInfo(virDomainParseTotalParamPtr
param)
return 0;
}
+
+static int
+virDomainDefParseControllerInfo(virDomainParseTotalParamPtr param)
+
+{
+ virDomainDefPtr def = param->def;
+ virDomainXMLOptionPtr xmlopt = param->xmlopt;
+ xmlXPathContextPtr ctxt = param->ctxt;
+ unsigned int flags = param->flags;
+
+ int ret = -1;
+ int n = 0;
+ size_t i;
+ xmlNodePtr *nodes = NULL;
+
+ /* analysis of the controller devices */
+ if ((n = virXPathNodeSet("./devices/controller", ctxt, &nodes)) <
0)
+ goto cleanup;
+
+ if (n && VIR_ALLOC_N(def->controllers, n) < 0)
+ goto cleanup;
+
+ for (i = 0; i < n; i++) {
+ virDomainControllerDefPtr controller = virDomainControllerDefParseXML(xmlopt,
+ nodes[i],
+ ctxt,
+ flags);
+
+ if (!controller)
+ goto cleanup;
+
+ /* sanitize handling of "none" usb controller */
+ if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_USB) {
+ if (controller->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) {
+ if (param->usb_other || param->usb_none) {
+ virDomainControllerDefFree(controller);
+ virReportError(VIR_ERR_XML_DETAIL, "%s",
+ _("Can't add another USB controller: "
+ "USB is disabled for this domain"));
+ goto cleanup;
+ }
+ param->usb_none = true;
+ } else {
+ if (param->usb_none) {
+ virDomainControllerDefFree(controller);
+ virReportError(VIR_ERR_XML_DETAIL, "%s",
+ _("Can't add another USB controller: "
+ "USB is disabled for this domain"));
+ goto cleanup;
+ }
+ param->usb_other = true;
+ }
+
+ if (controller->info.mastertype == VIR_DOMAIN_CONTROLLER_MASTER_NONE)
+ param->usb_master = true;
+ }
+
+ virDomainControllerInsertPreAlloced(def, controller);
+ }
+ VIR_FREE(nodes);
+
+ if (param->usb_other && !param->usb_master) {
+ virReportError(VIR_ERR_XML_DETAIL, "%s",
+ _("No master USB controller specified"));
+ goto cleanup;
+ }
+
+ ret = 0;
+
+ cleanup:
+ VIR_FREE(nodes);
+ return ret;
+}
+
+
+static int
+virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param)
+{
+ typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param);
+ int ret = -1;
+ size_t i = 0;
+
+ virDomainPreaseDeviceFuc parseFuc[] = {
+ virDomainDefParseControllerInfo,
+ NULL
+ };
+
+ while (parseFuc[i]) {
+ if (parseFuc[i](param) < 0)
+ goto out;
+ i++;
+ }
+ ret = 0;
+
+ out:
+ return ret;
+
+
+}
+
static virDomainDefPtr
virDomainDefParseXML(xmlDocPtr xml,
xmlNodePtr root,
@@ -19813,8 +19913,6 @@ virDomainDefParseXML(xmlDocPtr xml,
bool uuid_generated = false;
virHashTablePtr bootHash = NULL;
bool usb_none = false;
- bool usb_other = false;
- bool usb_master = false;
char *netprefix = NULL;
virDomainParseTotalParam param = {
NULL,
@@ -19852,6 +19950,7 @@ virDomainDefParseXML(xmlDocPtr xml,
virDomainDefParsePerfEventInfo,
virDomainDefParseClockInfo,
virDomainDefParseBootOptionsInfo,
+ virDomainDefParseDeviceInfo,
NULL
};
@@ -19905,57 +20004,7 @@ virDomainDefParseXML(xmlDocPtr xml,
}
VIR_FREE(nodes);
- /* analysis of the controller devices */
- if ((n = virXPathNodeSet("./devices/controller", ctxt, &nodes)) <
0)
- goto error;
-
- if (n && VIR_ALLOC_N(def->controllers, n) < 0)
- goto error;
-
- for (i = 0; i < n; i++) {
- virDomainControllerDefPtr controller = virDomainControllerDefParseXML(xmlopt,
- nodes[i],
- ctxt,
- flags);
-
- if (!controller)
- goto error;
-
- /* sanitize handling of "none" usb controller */
- if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_USB) {
- if (controller->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) {
- if (usb_other || usb_none) {
- virDomainControllerDefFree(controller);
- virReportError(VIR_ERR_XML_DETAIL, "%s",
- _("Can't add another USB controller: "
- "USB is disabled for this domain"));
- goto error;
- }
- usb_none = true;
- } else {
- if (usb_none) {
- virDomainControllerDefFree(controller);
- virReportError(VIR_ERR_XML_DETAIL, "%s",
- _("Can't add another USB controller: "
- "USB is disabled for this domain"));
- goto error;
- }
- usb_other = true;
- }
-
- if (controller->info.mastertype == VIR_DOMAIN_CONTROLLER_MASTER_NONE)
- usb_master = true;
- }
-
- virDomainControllerInsertPreAlloced(def, controller);
- }
- VIR_FREE(nodes);
- if (usb_other && !usb_master) {
- virReportError(VIR_ERR_XML_DETAIL, "%s",
- _("No master USB controller specified"));
- goto error;
- }
/* analysis of the resource leases */
if ((n = virXPathNodeSet("./devices/lease", ctxt, &nodes)) < 0) {
--
2.8.3