From: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx> Allow vfio-ccw mdev devices to be created besides vfio-pci mdev devices as well. Reviewed-by: Bjoern Walk <bwalk@xxxxxxxxxxxxx> Signed-off-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx> --- src/conf/domain_addr.c | 2 +- src/conf/domain_addr.h | 3 ++ src/libvirt_private.syms | 1 + src/node_device/node_device_driver.c | 49 +++++++++++++++++++++++----- 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 1068cbf1..1bfa164a 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -1365,7 +1365,7 @@ virDomainPCIAddressSetAllMulti(virDomainDefPtr def) } -static char* +char* virDomainCCWAddressAsString(virDomainDeviceCCWAddressPtr addr) { return g_strdup_printf("%x.%x.%04x", addr->cssid, addr->ssid, addr->devno); diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index c1363c14..a0460b40 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -208,6 +208,9 @@ int virDomainCCWAddressAssign(virDomainDeviceInfoPtr dev, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); void virDomainCCWAddressSetFree(virDomainCCWAddressSetPtr addrs); +char* virDomainCCWAddressAsString(virDomainDeviceCCWAddressPtr addr) + ATTRIBUTE_NONNULL(1); + virDomainCCWAddressSetPtr virDomainCCWAddressSetCreateFromDomain(virDomainDefPtr def) ATTRIBUTE_NONNULL(1); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 01c2e710..e1342569 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -143,6 +143,7 @@ virPCIDeviceAddressParseXML; # conf/domain_addr.h virDomainCCWAddressAssign; +virDomainCCWAddressAsString; virDomainCCWAddressSetCreateFromDomain; virDomainCCWAddressSetFree; virDomainPCIAddressBusIsFullyReserved; diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index e89c8b0e..bee2ef93 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -28,6 +28,7 @@ #include "virerror.h" #include "datatypes.h" +#include "domain_addr.h" #include "viralloc.h" #include "virfile.h" #include "virjson.h" @@ -628,7 +629,7 @@ nodeDeviceFindAddressByName(const char *name) { virNodeDeviceDefPtr def = NULL; virNodeDevCapsDefPtr caps = NULL; - char *pci_addr = NULL; + char *addr = NULL; virNodeDeviceObjPtr dev = virNodeDeviceObjListFindByName(driver->devs, name); if (!dev) { @@ -639,22 +640,52 @@ nodeDeviceFindAddressByName(const char *name) def = virNodeDeviceObjGetDef(dev); for (caps = def->caps; caps != NULL; caps = caps->next) { - if (caps->data.type == VIR_NODE_DEV_CAP_PCI_DEV) { - virPCIDeviceAddress addr = { + switch ((virNodeDevCapType) caps->data.type) { + case VIR_NODE_DEV_CAP_PCI_DEV: { + virPCIDeviceAddress pci_addr = { .domain = caps->data.pci_dev.domain, .bus = caps->data.pci_dev.bus, .slot = caps->data.pci_dev.slot, .function = caps->data.pci_dev.function }; - pci_addr = virPCIDeviceAddressAsString(&addr); + addr = virPCIDeviceAddressAsString(&pci_addr); break; } + case VIR_NODE_DEV_CAP_CSS_DEV: { + virDomainDeviceCCWAddress ccw_addr = { + .cssid = caps->data.ccw_dev.cssid, + .ssid = caps->data.ccw_dev.ssid, + .devno = caps->data.ccw_dev.devno + }; + + addr = virDomainCCWAddressAsString(&ccw_addr); + break; + } + + case VIR_NODE_DEV_CAP_SYSTEM: + case VIR_NODE_DEV_CAP_USB_DEV: + case VIR_NODE_DEV_CAP_USB_INTERFACE: + case VIR_NODE_DEV_CAP_NET: + case VIR_NODE_DEV_CAP_SCSI_HOST: + case VIR_NODE_DEV_CAP_SCSI_TARGET: + case VIR_NODE_DEV_CAP_SCSI: + case VIR_NODE_DEV_CAP_STORAGE: + case VIR_NODE_DEV_CAP_FC_HOST: + case VIR_NODE_DEV_CAP_VPORTS: + case VIR_NODE_DEV_CAP_SCSI_GENERIC: + case VIR_NODE_DEV_CAP_DRM: + case VIR_NODE_DEV_CAP_MDEV_TYPES: + case VIR_NODE_DEV_CAP_MDEV: + case VIR_NODE_DEV_CAP_CCW_DEV: + case VIR_NODE_DEV_CAP_LAST: + continue; + } } virNodeDeviceObjEndAPI(&dev); - return pci_addr; + return addr; } @@ -664,11 +695,11 @@ nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def, { virCommandPtr cmd; g_autofree char *json = NULL; - g_autofree char *parent_pci = nodeDeviceFindAddressByName(def->parent); + g_autofree char *parent_addr = nodeDeviceFindAddressByName(def->parent); - if (!parent_pci) { + if (!parent_addr) { virReportError(VIR_ERR_NO_NODE_DEVICE, - _("unable to find PCI address for parent device '%s'"), def->parent); + _("unable to find address for parent device '%s'"), def->parent); return NULL; } @@ -679,7 +710,7 @@ nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def, } cmd = virCommandNewArgList(MDEVCTL, "start", - "-p", parent_pci, + "-p", parent_addr, "--jsonfile", "/dev/stdin", NULL); -- 2.24.1