From: Yi Min Zhao <zyimin(a)linux.ibm.com>
This patch introduces new XML parser/formatter functions. Uid is
16-bit and non-zero. Fid is 32-bit. They are added as two new
attributes of PCI address, and parsed/formatted along with PCI
address parser/formatter.
Signed-off-by: Yi Min Zhao <zyimin(a)linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy(a)linux.vnet.ibm.com>
Reviewed-by: Stefan Zimmermann <stzi(a)linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk(a)linux.vnet.ibm.com>
---
docs/schemas/basictypes.rng | 28 ++++++++++++++++
docs/schemas/domaincommon.rng | 1 +
src/conf/device_conf.c | 74 +++++++++++++++++++++++++++++++++++++++++++
src/conf/domain_addr.c | 3 ++
src/conf/domain_conf.c | 4 +++
src/util/virpci.h | 3 ++
6 files changed, 113 insertions(+)
diff --git a/docs/schemas/basictypes.rng b/docs/schemas/basictypes.rng
index 1a18cd31b1..8050a3ebc4 100644
--- a/docs/schemas/basictypes.rng
+++ b/docs/schemas/basictypes.rng
@@ -111,6 +111,34 @@
</attribute>
</optional>
</define>
+ <define name="zpciaddress">
+ <optional>
+ <attribute name="uid">
+ <choice>
+ <data type="string">
+ <param name="pattern">(0x)?[0-9a-fA-F]{1,4}</param>
+ </data>
+ <data type="unsignedInt">
+ <param name="minInclusive">1</param>
+ <param name="maxInclusive">65535</param>
+ </data>
+ </choice>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="fid">
+ <choice>
+ <data type="string">
+ <param name="pattern">(0x)?[0-9a-fA-F]{1,8}</param>
+ </data>
+ <data type="unsignedLong">
+ <param name="minInclusive">0</param>
+ <param name="maxInclusive">4294967295</param>
+ </data>
+ </choice>
+ </attribute>
+ </optional>
+ </define>
<!-- a 6 byte MAC address in ASCII-hex format, eg "12:34:56:78:9A:BC"
-->
<!-- The lowest bit of the 1st byte is the "multicast" bit. a
-->
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index f16e157397..6ab92cfde4 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -5046,6 +5046,7 @@
<value>pci</value>
</attribute>
<ref name="pciaddress"/>
+ <ref name="zpciaddress"/>
</group>
<group>
<attribute name="type">
diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
index d69f94fadf..0df1afa2af 100644
--- a/src/conf/device_conf.c
+++ b/src/conf/device_conf.c
@@ -32,6 +32,74 @@
#define VIR_FROM_THIS VIR_FROM_DEVICE
+static int
+virZPCIDeviceAddressIsValid(virZPCIDeviceAddressPtr zpci)
+{
+ if (!zpci->uid_assigned)
+ return 1;
+
+ if (zpci->zpciuid > VIR_DOMAIN_DEVICE_ZPCI_MAX_UID ||
+ zpci->zpciuid == 0) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("Invalid PCI address uid='0x%x', "
+ "must be > 0x0 and <= 0x%x"),
+ zpci->zpciuid,
+ VIR_DOMAIN_DEVICE_ZPCI_MAX_UID);
+ return 0;
+ }
+
+ return 1;
+}
+
+static int
+virZPCIDeviceAddressParseXML(xmlNodePtr node,
+ virPCIDeviceAddressPtr addr)
+{
+ char *uid, *fid;
+ int ret = -1;
+ virZPCIDeviceAddressPtr def = NULL;
+
+ if (VIR_ALLOC(def) < 0)
+ return -1;
+
+ uid = virXMLPropString(node, "uid");
+ fid = virXMLPropString(node, "fid");
+
+ if (uid) {
+ if (virStrToLong_uip(uid, NULL, 0, &def->zpciuid) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Cannot parse <address> 'uid'
attribute"));
+ goto cleanup;
+ }
+ def->uid_assigned = true;
+ }
+
+ if (fid) {
+ if (virStrToLong_uip(fid, NULL, 0, &def->zpcifid) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Cannot parse <address> 'fid'
attribute"));
+ goto cleanup;
+ }
+ def->fid_assigned = true;
+ }
+
+ if (uid || fid) {
+ if (!virZPCIDeviceAddressIsValid(def))
+ goto cleanup;
+
+ addr->zpci = def;
+ def = NULL;
+ }
+
+ ret = 0;
+
+ cleanup:
+ VIR_FREE(uid);
+ VIR_FREE(fid);
+ VIR_FREE(def);
+ return ret;
+}
+
int
virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst,
virDomainDeviceInfoPtr src)
@@ -57,6 +125,8 @@ void
virDomainDeviceInfoClear(virDomainDeviceInfoPtr info)
{
VIR_FREE(info->alias);
+ if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI)
+ VIR_FREE(info->addr.pci.zpci);
memset(&info->addr, 0, sizeof(info->addr));
info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE;
VIR_FREE(info->romfile);
@@ -187,6 +257,7 @@ int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr,
"one of domain, bus, or slot must be > 0"));
return 0;
}
+
return 1;
}
@@ -245,6 +316,9 @@ virPCIDeviceAddressParseXML(xmlNodePtr node,
if (!virPCIDeviceAddressIsEmpty(addr) && !virPCIDeviceAddressIsValid(addr,
true))
goto cleanup;
+ if (virZPCIDeviceAddressParseXML(node, addr) < 0)
+ goto cleanup;
+
ret = 0;
cleanup:
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index 8964973e03..e685b9ccf7 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -959,6 +959,9 @@ virDomainPCIAddressReserveNextAddr(virDomainPCIAddressSetPtr addrs,
dev->isolationGroup, function) < 0)
return -1;
+ if (dev->pciAddressExtFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI)
+ addr.zpci = dev->addr.pci.zpci;
+
if (virDomainPCIAddressReserveAddrInternal(addrs, &addr, flags,
dev->isolationGroup, false) < 0)
return -1;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 2253098090..83ef5d4a4f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6171,6 +6171,10 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
info->addr.pci.slot,
info->addr.pci.function);
}
+ if (info->addr.pci.zpci) {
+ virBufferAsprintf(buf, " uid='0x%.4x'",
info->addr.pci.zpci->zpciuid);
+ virBufferAsprintf(buf, " fid='0x%.8x'",
info->addr.pci.zpci->zpcifid);
+ }
if (info->addr.pci.multi) {
virBufferAsprintf(buf, " multifunction='%s'",
virTristateSwitchTypeToString(info->addr.pci.multi));
diff --git a/src/util/virpci.h b/src/util/virpci.h
index 250e9278ba..d948a16cb8 100644
--- a/src/util/virpci.h
+++ b/src/util/virpci.h
@@ -36,6 +36,9 @@ typedef virPCIDeviceAddress *virPCIDeviceAddressPtr;
typedef struct _virPCIDeviceList virPCIDeviceList;
typedef virPCIDeviceList *virPCIDeviceListPtr;
+# define VIR_DOMAIN_DEVICE_ZPCI_MAX_UID 0xFFFF
+# define VIR_DOMAIN_DEVICE_ZPCI_MAX_FID 0xFFFFFFFF
+
typedef struct _virZPCIDeviceAddress virZPCIDeviceAddress;
typedef virZPCIDeviceAddress *virZPCIDeviceAddressPtr;
struct _virZPCIDeviceAddress {
--
2.16.3