Introduce a validation function for vf-token support in qemu
and generate vf-token device attribute in qmeu command line.
Signed-off-by: Vivek Kashyap <vivek.kashyap(a)linux.intel.com>
---
src/qemu/qemu_command.c | 27 ++++++++++++++++++++++++---
src/qemu/qemu_validate.c | 19 +++++++++++++++++++
2 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 8a7b80719f..91d7836f5c 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1979,7 +1979,6 @@ qemuBuildZPCIDevProps(virDomainDeviceInfo *dev)
return props;
}
-
static int
qemuCommandAddExtDevice(virCommand *cmd,
virDomainDeviceInfo *dev,
@@ -4729,6 +4728,8 @@ qemuBuildPCIHostdevDevProps(const virDomainDef *def,
pcisrc->addr.slot,
pcisrc->addr.function);
const char *failover_pair_id = NULL;
+ g_autofree char *token = NULL;
+ int ret = 0;
/* caller has to assign proper passthrough backend type */
switch (pcisrc->backend) {
@@ -4755,13 +4756,33 @@ qemuBuildPCIHostdevDevProps(const virDomainDef *def,
teaming->persistent)
failover_pair_id = teaming->persistent;
- if (virJSONValueObjectAdd(&props,
+ if ((dev->info->pciAddrExtFlags & VIR_PCI_ADDRESS_EXTENSION_VFTOKEN)
&&
+ pcisrc->addr.token.isSet) {
+ const unsigned char *uuid = pcisrc->addr.token.uuid;
+
+ token = g_strdup_printf(VIR_PCI_DEVICE_TOKEN_FMT,
+ uuid[0], uuid[1], uuid[2], uuid[3],
+ uuid[4], uuid[5], uuid[6], uuid[7],
+ uuid[8], uuid[9], uuid[10], uuid[11],
+ uuid[12], uuid[13], uuid[14], uuid[15]);
+
+ ret = virJSONValueObjectAdd(&props,
"s:driver", "vfio-pci",
"s:host", host,
+ "s:vf-token", token,
"s:id", dev->info->alias,
"p:bootindex",
dev->info->effectiveBootIndex,
"S:failover_pair_id", failover_pair_id,
- NULL) < 0)
+ NULL);
+ } else
+ ret = virJSONValueObjectAdd(&props,
+ "s:driver", "vfio-pci",
+ "s:host", host,
+ "s:id", dev->info->alias,
+ "p:bootindex",
dev->info->effectiveBootIndex,
+ "S:failover_pair_id", failover_pair_id,
+ NULL);
+ if (ret < 0)
return NULL;
if (qemuBuildDeviceAddressProps(props, def, dev->info) < 0)
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 93df9e4c8e..d628949597 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -1363,6 +1363,23 @@ qemuValidateDomainDeviceDefZPCIAddress(virDomainDeviceInfo *info,
return 0;
}
+static int
+qemuValidateDomainDeviceDefVFTokenId(virDomainDeviceInfo *info,
+ virQEMUCaps *qemuCaps)
+{
+ virPCIDeviceToken *vftoken = &info->addr.pci.token;
+
+ if (virPCIVFIOTokenIDIsPresent(vftoken) &&
+ !virQEMUCapsGet(qemuCaps, QEMU_CAPS_VFIO_VFTOKEN)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ "%s",
+ _("This QEMU binary doesn't support vf token
ids"));
+ return -1;
+ }
+
+ return 0;
+}
+
static int
qemuValidateDomainDeviceDefAddressDrive(virDomainDeviceInfo *info,
@@ -1483,6 +1500,8 @@ qemuValidateDomainDeviceDefAddress(const virDomainDeviceDef *dev,
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
if (qemuValidateDomainDeviceDefZPCIAddress(info, qemuCaps) < 0)
return -1;
+ if (qemuValidateDomainDeviceDefVFTokenId(info, qemuCaps) < 0)
+ return -1;
break;
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
--
2.25.1