提交 ac5979ed 编写于 作者: P Peter Krempa

conf: Improve adding of new address types

Use typecasted switch statement and note the type used to select the
address type in a comment.
上级 64f56286
...@@ -3306,7 +3306,7 @@ virDomainDeviceInfoFormat(virBufferPtr buf, ...@@ -3306,7 +3306,7 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
virBufferAsprintf(buf, "<address type='%s'", virBufferAsprintf(buf, "<address type='%s'",
virDomainDeviceAddressTypeToString(info->type)); virDomainDeviceAddressTypeToString(info->type));
switch (info->type) { switch ((virDomainDeviceAddressType) info->type) {
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
virBufferAsprintf(buf, " domain='0x%.4x' bus='0x%.2x' slot='0x%.2x' function='0x%.1x'", virBufferAsprintf(buf, " domain='0x%.4x' bus='0x%.2x' slot='0x%.2x' function='0x%.1x'",
info->addr.pci.domain, info->addr.pci.domain,
...@@ -3368,10 +3368,10 @@ virDomainDeviceInfoFormat(virBufferPtr buf, ...@@ -3368,10 +3368,10 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
virBufferAsprintf(buf, " irq='0x%x'", info->addr.isa.irq); virBufferAsprintf(buf, " irq='0x%x'", info->addr.isa.irq);
break; break;
default: case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
virReportError(VIR_ERR_INTERNAL_ERROR, case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
_("unknown address type '%d'"), info->type); case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
return -1; break;
} }
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
...@@ -3816,7 +3816,7 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, ...@@ -3816,7 +3816,7 @@ virDomainDeviceInfoParseXML(xmlNodePtr node,
type = virXMLPropString(address, "type"); type = virXMLPropString(address, "type");
if (type) { if (type) {
if ((info->type = virDomainDeviceAddressTypeFromString(type)) < 0) { if ((info->type = virDomainDeviceAddressTypeFromString(type)) <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown address type '%s'"), type); _("unknown address type '%s'"), type);
goto cleanup; goto cleanup;
...@@ -3827,7 +3827,7 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, ...@@ -3827,7 +3827,7 @@ virDomainDeviceInfoParseXML(xmlNodePtr node,
goto cleanup; goto cleanup;
} }
switch (info->type) { switch ((virDomainDeviceAddressType) info->type) {
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
if (virDevicePCIAddressParseXML(address, &info->addr.pci) < 0) if (virDevicePCIAddressParseXML(address, &info->addr.pci) < 0)
goto cleanup; goto cleanup;
...@@ -3873,11 +3873,14 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, ...@@ -3873,11 +3873,14 @@ virDomainDeviceInfoParseXML(xmlNodePtr node,
goto cleanup; goto cleanup;
break; break;
default: case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
/* Should not happen */ virReportError(VIR_ERR_XML_ERROR, "%s",
virReportError(VIR_ERR_INTERNAL_ERROR, _("virtio-s390 bus doesn't have an address"));
"%s", _("Unknown device address type"));
goto cleanup; goto cleanup;
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
break;
} }
ret = 0; ret = 0;
...@@ -14223,7 +14226,7 @@ virDomainDeviceInfoCheckABIStability(virDomainDeviceInfoPtr src, ...@@ -14223,7 +14226,7 @@ virDomainDeviceInfoCheckABIStability(virDomainDeviceInfoPtr src,
return false; return false;
} }
switch (src->type) { switch ((virDomainDeviceAddressType) src->type) {
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
if (src->addr.pci.domain != dst->addr.pci.domain || if (src->addr.pci.domain != dst->addr.pci.domain ||
src->addr.pci.bus != dst->addr.pci.bus || src->addr.pci.bus != dst->addr.pci.bus ||
...@@ -14297,6 +14300,15 @@ virDomainDeviceInfoCheckABIStability(virDomainDeviceInfoPtr src, ...@@ -14297,6 +14300,15 @@ virDomainDeviceInfoCheckABIStability(virDomainDeviceInfoPtr src,
return false; return false;
} }
break; break;
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
break;
} }
return true; return true;
......
...@@ -308,7 +308,7 @@ struct _virDomainDeviceInfo { ...@@ -308,7 +308,7 @@ struct _virDomainDeviceInfo {
* to consider the new fields * to consider the new fields
*/ */
char *alias; char *alias;
int type; int type; /* virDomainDeviceAddressType */
union { union {
virDevicePCIAddress pci; virDevicePCIAddress pci;
virDomainDeviceDriveAddress drive; virDomainDeviceDriveAddress drive;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册