From 122b975e4004c83b6fc442ec6cdfd71eb5b55cc4 Mon Sep 17 00:00:00 2001 From: Boris Fiuczynski Date: Fri, 13 May 2022 12:31:15 +0200 Subject: [PATCH] nodedev: add optional device address of channel device to css device Add the new introduced sysfs attribute dev_busid which provides the address of the device in the subchannel independent from the bound device driver. It is added if available in the sysfs as optional channel_dev_addr element into the css device capabilty providing the ccw deivce address attributes cssid, ssid and devno. Signed-off-by: Boris Fiuczynski Signed-off-by: Michal Privoznik Reviewed-by: Michal Privoznik --- src/conf/node_device_conf.c | 28 ++++++++++++++++++++++++++++ src/conf/node_device_conf.h | 2 ++ src/conf/schemas/nodedev.rng | 5 +++++ src/node_device/node_device_udev.c | 8 ++++++++ 4 files changed, 43 insertions(+) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 5aafcbb838..e7dd093972 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -645,6 +645,17 @@ virNodeDeviceCapCSSDefFormat(virBuffer *buf, virNodeDeviceCapCCWDefFormat(buf, data); + if (ccw_dev.channel_dev_addr) { + virCCWDeviceAddress *ccw = ccw_dev.channel_dev_addr; + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + virBufferAsprintf(buf, "0x%x\n", ccw->cssid); + virBufferAsprintf(buf, "0x%x\n", ccw->ssid); + virBufferAsprintf(buf, "0x%04x\n", ccw->devno); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + } + if (ccw_dev.flags & VIR_NODE_DEV_CAP_FLAG_CSS_MDEV) virNodeDeviceCapMdevTypesFormat(buf, ccw_dev.mdev_types, @@ -1257,6 +1268,7 @@ virNodeDevCapCSSParseXML(xmlXPathContextPtr ctxt, g_autofree xmlNodePtr *nodes = NULL; int n = 0; size_t i = 0; + xmlNodePtr channel_ddno = NULL; ctxt->node = node; @@ -1271,6 +1283,21 @@ virNodeDevCapCSSParseXML(xmlXPathContextPtr ctxt, return -1; } + /* channel_dev_addr is optional */ + if ((channel_ddno = virXPathNode("./channel_dev_addr[1]", ctxt))) { + g_autofree virCCWDeviceAddress *channel_dev = NULL; + + channel_dev = g_new0(virCCWDeviceAddress, 1); + + if (virNodeDevCCWDeviceAddressParseXML(ctxt, + channel_ddno, + def->name, + channel_dev) < 0) + return -1; + + ccw_dev->channel_dev_addr = g_steal_pointer(&channel_dev); + } + return 0; } @@ -2639,6 +2666,7 @@ virNodeDevCapsDefFree(virNodeDevCapsDef *caps) for (i = 0; i < data->ccw_dev.nmdev_types; i++) virMediatedDeviceTypeFree(data->ccw_dev.mdev_types[i]); g_free(data->ccw_dev.mdev_types); + g_free(data->ccw_dev.channel_dev_addr); break; case VIR_NODE_DEV_CAP_AP_MATRIX: g_free(data->ap_matrix.addr); diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index e4d1f67d53..d1751ed874 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -24,6 +24,7 @@ #include "internal.h" #include "virbitmap.h" +#include "virccw.h" #include "virpcivpd.h" #include "virscsihost.h" #include "virpci.h" @@ -279,6 +280,7 @@ struct _virNodeDevCapCCW { unsigned int flags; /* enum virNodeDevCCWCapFlags */ virMediatedDeviceType **mdev_types; size_t nmdev_types; + virCCWDeviceAddress *channel_dev_addr; }; typedef struct _virNodeDevCapVDPA virNodeDevCapVDPA; diff --git a/src/conf/schemas/nodedev.rng b/src/conf/schemas/nodedev.rng index a9f83e048c..e40243e257 100644 --- a/src/conf/schemas/nodedev.rng +++ b/src/conf/schemas/nodedev.rng @@ -682,6 +682,11 @@ css + + + + + diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 4bb841c66b..656130e98a 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1124,6 +1124,8 @@ static int udevProcessCSS(struct udev_device *device, virNodeDeviceDef *def) { + g_autofree char *dev_busid = NULL; + /* only process IO subchannel and vfio-ccw devices to keep the list sane */ if (!def->driver || (STRNEQ(def->driver, "io_subchannel") && @@ -1135,6 +1137,12 @@ udevProcessCSS(struct udev_device *device, udevGenerateDeviceName(device, def, NULL); + /* process optional channel devices information */ + udevGetStringSysfsAttr(device, "dev_busid", &dev_busid); + + if (dev_busid != NULL) + def->caps->data.ccw_dev.channel_dev_addr = virCCWDeviceAddressFromString(dev_busid); + if (virNodeDeviceGetCSSDynamicCaps(def->sysfs_path, &def->caps->data.ccw_dev) < 0) return -1;