conf: add support for <acpi index='NNN'/> for PCI devices

PCI devices can be associated with a unique integer index that is
exposed via ACPI. In Linux OS with systemd, this value is used for
provide a NIC device naming scheme that is stable across changes
in PCI slot configuration.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2021-04-06 11:07:44 +01:00
parent ee4abd6312
commit a9fe9569ab
4 changed files with 102 additions and 0 deletions

View File

@ -4363,6 +4363,7 @@ Network interfaces
<mac address='52:54:00:5d:c7:9e'/> <mac address='52:54:00:5d:c7:9e'/>
<boot order='1'/> <boot order='1'/>
<rom bar='off'/> <rom bar='off'/>
<acpi index='4'/>
</interface> </interface>
</devices> </devices>
... ...
@ -4389,6 +4390,12 @@ when it's in the reserved VMware range by adding a ``type="static"`` attribute
to the ``<mac/>`` element. Note that this attribute is useless if the provided to the ``<mac/>`` element. Note that this attribute is useless if the provided
MAC address is outside of the reserved VMWare ranges. MAC address is outside of the reserved VMWare ranges.
:since:`Since 7.3.0`, one can set the ACPI index against network interfaces.
With some operating systems (eg Linux with systemd), the ACPI index is used
to provide network interface device naming, that is stable across changes
in PCI addresses assigned to the device. This value is required to be unique
across all devices and be between 1 and (16*1024-1).
:anchor:`<a id="elementsNICSVirtual"/>` :anchor:`<a id="elementsNICSVirtual"/>`
Virtual network Virtual network

View File

@ -1444,6 +1444,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>
@ -2435,6 +2438,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>
@ -2863,6 +2869,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>
@ -3520,6 +3529,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>
@ -4146,6 +4158,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>
@ -4286,6 +4301,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>
@ -4538,6 +4556,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>
@ -4942,6 +4963,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>
@ -5011,6 +5035,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>
@ -5043,6 +5070,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>
@ -5121,6 +5151,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>
@ -5165,6 +5198,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>
@ -5192,6 +5228,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>
@ -5287,6 +5326,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<element name="driver"> <element name="driver">
<ref name="virtioOptions"/> <ref name="virtioOptions"/>
@ -5389,6 +5431,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>
@ -5404,6 +5449,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>
@ -5423,6 +5471,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>
@ -5454,6 +5505,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="deviceBoot"/> <ref name="deviceBoot"/>
</optional> </optional>
@ -6425,6 +6479,16 @@
</element> </element>
</define> </define>
<define name="acpi">
<element name="acpi">
<optional>
<attribute name="index">
<ref name="unsignedInt"/>
</attribute>
</optional>
</element>
</define>
<define name="memorydev"> <define name="memorydev">
<element name="memory"> <element name="memory">
<attribute name="model"> <attribute name="model">
@ -6463,6 +6527,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
</interleave> </interleave>
</element> </element>
</define> </define>
@ -6554,6 +6621,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>
@ -7546,6 +7616,9 @@
<optional> <optional>
<ref name="alias"/> <ref name="alias"/>
</optional> </optional>
<optional>
<ref name="acpi"/>
</optional>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
</optional> </optional>

View File

@ -159,6 +159,9 @@ struct _virDomainDeviceInfo {
/* bootIndex is only used for disk, network interface, hostdev /* bootIndex is only used for disk, network interface, hostdev
* and redirdev devices */ * and redirdev devices */
unsigned int bootIndex; unsigned int bootIndex;
/* Valid for any PCI device. Can be used for NIC to get
* stable numbering in Linux */
unsigned int acpiIndex;
/* pciConnectFlags is only used internally during address /* pciConnectFlags is only used internally during address
* assignment, never saved and never reported. * assignment, never saved and never reported.

View File

@ -6335,6 +6335,9 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
} }
if (info->acpiIndex != 0)
virBufferAsprintf(buf, "<acpi index='%u'/>\n", info->acpiIndex);
if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE || if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE ||
info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390) info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390)
/* We're done here */ /* We're done here */
@ -6661,6 +6664,7 @@ virDomainDeviceInfoParseXML(virDomainXMLOptionPtr xmlopt,
g_autofree char *romenabled = NULL; g_autofree char *romenabled = NULL;
g_autofree char *rombar = NULL; g_autofree char *rombar = NULL;
g_autofree char *aliasStr = NULL; g_autofree char *aliasStr = NULL;
g_autofree char *acpiIndex = NULL;
VIR_XPATH_NODE_AUTORESTORE(ctxt) VIR_XPATH_NODE_AUTORESTORE(ctxt)
virDomainDeviceInfoClear(info); virDomainDeviceInfoClear(info);
@ -6709,6 +6713,14 @@ virDomainDeviceInfoParseXML(virDomainXMLOptionPtr xmlopt,
} }
} }
acpiIndex = virXPathString("string(./acpi/@index)", ctxt);
if (acpiIndex &&
virStrToLong_ui(acpiIndex, NULL, 10, &info->acpiIndex) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Cannot parse ACPI index value '%s'"), acpiIndex);
goto cleanup;
}
if ((address = virXPathNode("./address", ctxt)) && if ((address = virXPathNode("./address", ctxt)) &&
virDomainDeviceAddressParseXML(address, info) < 0) virDomainDeviceAddressParseXML(address, info) < 0)
goto cleanup; goto cleanup;
@ -22193,6 +22205,13 @@ virDomainDeviceInfoCheckABIStability(virDomainDeviceInfoPtr src,
break; break;
} }
if (src->acpiIndex != dst->acpiIndex) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target ACPI index '%u' does not match source '%u'"),
dst->acpiIndex, src->acpiIndex);
return false;
}
return true; return true;
} }