提交 50897ffb 编写于 作者: D Daniel P. Berrange

Slightly refactor hostdev parsing / formating

Rename virDomainHostdevPartsParse to virDomainHostdevDefParseSubsys
to reflect the fact that it only deals with hostdevs uing the
traditional mode=subsystem, and not mode=capabilities

Rename virDomainHostSourceFormat to virDomainHostdevDefFormatSubsys
for the same reason.
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
上级 3f0010a6
...@@ -2951,31 +2951,16 @@ out: ...@@ -2951,31 +2951,16 @@ out:
} }
static int static int
virDomainHostdevPartsParse(xmlNodePtr node, virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
const char *mode, const char *type,
const char *type, virDomainHostdevDefPtr def,
virDomainHostdevDefPtr def, unsigned int flags)
unsigned int flags)
{ {
xmlNodePtr sourcenode; xmlNodePtr sourcenode;
char *managed = NULL; char *managed = NULL;
int ret = -1; int ret = -1;
/* @mode is passed in separately from the caller, since an
* 'intelligent hostdev' has no place for 'mode' in the XML (it is
* always 'subsys').
*/
if (mode) {
if ((def->mode=virDomainHostdevModeTypeFromString(mode)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown hostdev mode '%s'"), mode);
goto error;
}
} else {
def->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
}
/* @managed can be read from the xml document - it is always an /* @managed can be read from the xml document - it is always an
* attribute of the toplevel element, no matter what type of * attribute of the toplevel element, no matter what type of
* element that might be (pure hostdev, or higher level device * element that might be (pure hostdev, or higher level device
...@@ -4815,8 +4800,9 @@ virDomainActualNetDefParseXML(xmlNodePtr node, ...@@ -4815,8 +4800,9 @@ virDomainActualNetDefParseXML(xmlNodePtr node,
virReportOOMError(); virReportOOMError();
goto error; goto error;
} }
if (virDomainHostdevPartsParse(node, ctxt, NULL, addrtype, hostdev->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
hostdev, flags) < 0) { if (virDomainHostdevDefParseXMLSubsys(node, ctxt, addrtype,
hostdev, flags) < 0) {
goto error; goto error;
} }
} else if (actual->type == VIR_DOMAIN_NET_TYPE_NETWORK) { } else if (actual->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
...@@ -5205,8 +5191,9 @@ virDomainNetDefParseXML(virCapsPtr caps, ...@@ -5205,8 +5191,9 @@ virDomainNetDefParseXML(virCapsPtr caps,
virReportOOMError(); virReportOOMError();
goto error; goto error;
} }
if (virDomainHostdevPartsParse(node, ctxt, NULL, addrtype, hostdev->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
hostdev, flags) < 0) { if (virDomainHostdevDefParseXMLSubsys(node, ctxt, addrtype,
hostdev, flags) < 0) {
goto error; goto error;
} }
break; break;
...@@ -7375,9 +7362,27 @@ virDomainHostdevDefParseXML(const xmlNodePtr node, ...@@ -7375,9 +7362,27 @@ virDomainHostdevDefParseXML(const xmlNodePtr node,
if (!(def = virDomainHostdevDefAlloc())) if (!(def = virDomainHostdevDefAlloc()))
goto error; goto error;
/* parse managed/mode/type, and the <source> element */ if (mode) {
if (virDomainHostdevPartsParse(node, ctxt, mode, type, def, flags) < 0) if ((def->mode = virDomainHostdevModeTypeFromString(mode)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown hostdev mode '%s'"), mode);
goto error;
}
} else {
def->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
}
switch (def->mode) {
case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
/* parse managed/mode/type, and the <source> element */
if (virDomainHostdevDefParseXMLSubsys(node, ctxt, type, def, flags) < 0)
goto error;
break;
default:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unexpected hostdev mode %d"), def->mode);
goto error; goto error;
}
if (def->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) { if (def->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
if (virDomainDeviceInfoParseXML(node, bootMap, def->info, if (virDomainDeviceInfoParseXML(node, bootMap, def->info,
...@@ -12394,10 +12399,10 @@ virDomainFSDefFormat(virBufferPtr buf, ...@@ -12394,10 +12399,10 @@ virDomainFSDefFormat(virBufferPtr buf,
} }
static int static int
virDomainHostdevSourceFormat(virBufferPtr buf, virDomainHostdevDefFormatSubsys(virBufferPtr buf,
virDomainHostdevDefPtr def, virDomainHostdevDefPtr def,
unsigned int flags, unsigned int flags,
bool includeTypeInAddr) bool includeTypeInAddr)
{ {
virBufferAddLit(buf, "<source"); virBufferAddLit(buf, "<source");
if (def->startupPolicy) { if (def->startupPolicy) {
...@@ -12515,8 +12520,8 @@ virDomainActualNetDefFormat(virBufferPtr buf, ...@@ -12515,8 +12520,8 @@ virDomainActualNetDefFormat(virBufferPtr buf,
break; break;
case VIR_DOMAIN_NET_TYPE_HOSTDEV: case VIR_DOMAIN_NET_TYPE_HOSTDEV:
if (virDomainHostdevSourceFormat(buf, &def->data.hostdev.def, if (virDomainHostdevDefFormatSubsys(buf, &def->data.hostdev.def,
flags, true) < 0) { flags, true) < 0) {
return -1; return -1;
} }
break; break;
...@@ -12624,8 +12629,8 @@ virDomainNetDefFormat(virBufferPtr buf, ...@@ -12624,8 +12629,8 @@ virDomainNetDefFormat(virBufferPtr buf,
break; break;
case VIR_DOMAIN_NET_TYPE_HOSTDEV: case VIR_DOMAIN_NET_TYPE_HOSTDEV:
if (virDomainHostdevSourceFormat(buf, &def->data.hostdev.def, if (virDomainHostdevDefFormatSubsys(buf, &def->data.hostdev.def,
flags, true) < 0) { flags, true) < 0) {
return -1; return -1;
} }
break; break;
...@@ -13520,19 +13525,25 @@ virDomainHostdevDefFormat(virBufferPtr buf, ...@@ -13520,19 +13525,25 @@ virDomainHostdevDefFormat(virBufferPtr buf,
const char *mode = virDomainHostdevModeTypeToString(def->mode); const char *mode = virDomainHostdevModeTypeToString(def->mode);
const char *type; const char *type;
if (!mode || def->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { if (!mode) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected hostdev mode %d"), def->mode); _("unexpected hostdev mode %d"), def->mode);
return -1; return -1;
} }
type = virDomainHostdevSubsysTypeToString(def->source.subsys.type); switch (def->mode) {
if (!type || case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
(def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB && type = virDomainHostdevSubsysTypeToString(def->source.subsys.type);
def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)) { if (!type) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected hostdev type %d"),
def->source.subsys.type);
return -1;
}
break;
default:
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected hostdev type %d"), _("unexpected hostdev mode %d"), def->mode);
def->source.subsys.type);
return -1; return -1;
} }
...@@ -13540,8 +13551,12 @@ virDomainHostdevDefFormat(virBufferPtr buf, ...@@ -13540,8 +13551,12 @@ virDomainHostdevDefFormat(virBufferPtr buf,
mode, type, def->managed ? "yes" : "no"); mode, type, def->managed ? "yes" : "no");
virBufferAdjustIndent(buf, 6); virBufferAdjustIndent(buf, 6);
if (virDomainHostdevSourceFormat(buf, def, flags, false) < 0) switch (def->mode) {
return -1; case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
if (virDomainHostdevDefFormatSubsys(buf, def, flags, false) < 0)
return -1;
break;
}
virBufferAdjustIndent(buf, -6); virBufferAdjustIndent(buf, -6);
if (virDomainDeviceInfoFormat(buf, def->info, if (virDomainDeviceInfoFormat(buf, def->info,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册