render / rpms / libvirt

Forked from rpms/libvirt a year ago
Clone
2cf05b
From 5921eeddf0a284ccbec04896901c9bd4177de6dd Mon Sep 17 00:00:00 2001
2cf05b
Message-Id: <5921eeddf0a284ccbec04896901c9bd4177de6dd@dist-git>
2cf05b
From: Boris Fiuczynski <fiuczy@linux.ibm.com>
2cf05b
Date: Fri, 13 May 2022 12:31:15 +0200
2cf05b
Subject: [PATCH] nodedev: add optional device address of channel device to css
2cf05b
 device
2cf05b
2cf05b
Add the new introduced sysfs attribute dev_busid which provides the address
2cf05b
of the device in the subchannel independent from the bound device driver.
2cf05b
It is added if available in the sysfs as optional channel_dev_addr element into
2cf05b
the css device capabilty providing the ccw deivce address attributes cssid,
2cf05b
ssid and devno.
2cf05b
2cf05b
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
2cf05b
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2cf05b
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2cf05b
(cherry picked from commit 122b975e4004c83b6fc442ec6cdfd71eb5b55cc4)
2cf05b
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2165011
2cf05b
Signed-off-by: Thomas Huth <thuth@redhat.com>
2cf05b
---
2cf05b
 docs/schemas/nodedev.rng           |  5 +++++
2cf05b
 src/conf/node_device_conf.c        | 28 ++++++++++++++++++++++++++++
2cf05b
 src/conf/node_device_conf.h        |  2 ++
2cf05b
 src/node_device/node_device_udev.c |  8 ++++++++
2cf05b
 4 files changed, 43 insertions(+)
2cf05b
2cf05b
diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng
2cf05b
index 29515d2d7e..43f1abc247 100644
2cf05b
--- a/docs/schemas/nodedev.rng
2cf05b
+++ b/docs/schemas/nodedev.rng
2cf05b
@@ -677,6 +677,11 @@
2cf05b
       <value>css</value>
2cf05b
     </attribute>
2cf05b
     <ref name="capccwaddress"/>
2cf05b
+    <optional>
2cf05b
+      <element name="channel_dev_addr">
2cf05b
+        <ref name="capccwaddress"/>
2cf05b
+      </element>
2cf05b
+    </optional>
2cf05b
     <optional>
2cf05b
       <ref name="mdev_types"/>
2cf05b
     </optional>
2cf05b
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
2cf05b
index fcb5be24e1..16b9497faf 100644
2cf05b
--- a/src/conf/node_device_conf.c
2cf05b
+++ b/src/conf/node_device_conf.c
2cf05b
@@ -643,6 +643,17 @@ virNodeDeviceCapCSSDefFormat(virBuffer *buf,
2cf05b
 
2cf05b
     virNodeDeviceCapCCWDefFormat(buf, data);
2cf05b
 
2cf05b
+    if (ccw_dev.channel_dev_addr) {
2cf05b
+        virCCWDeviceAddress *ccw = ccw_dev.channel_dev_addr;
2cf05b
+        virBufferAddLit(buf, "<channel_dev_addr>\n");
2cf05b
+        virBufferAdjustIndent(buf, 2);
2cf05b
+        virBufferAsprintf(buf, "<cssid>0x%x</cssid>\n", ccw->cssid);
2cf05b
+        virBufferAsprintf(buf, "<ssid>0x%x</ssid>\n", ccw->ssid);
2cf05b
+        virBufferAsprintf(buf, "<devno>0x%04x</devno>\n", ccw->devno);
2cf05b
+        virBufferAdjustIndent(buf, -2);
2cf05b
+        virBufferAddLit(buf, "</channel_dev_addr>\n");
2cf05b
+    }
2cf05b
+
2cf05b
     if (ccw_dev.flags & VIR_NODE_DEV_CAP_FLAG_CSS_MDEV)
2cf05b
         virNodeDeviceCapMdevTypesFormat(buf,
2cf05b
                                         ccw_dev.mdev_types,
2cf05b
@@ -1255,6 +1266,7 @@ virNodeDevCapCSSParseXML(xmlXPathContextPtr ctxt,
2cf05b
     g_autofree xmlNodePtr *nodes = NULL;
2cf05b
     int n = 0;
2cf05b
     size_t i = 0;
2cf05b
+    xmlNodePtr channel_ddno = NULL;
2cf05b
 
2cf05b
     ctxt->node = node;
2cf05b
 
2cf05b
@@ -1269,6 +1281,21 @@ virNodeDevCapCSSParseXML(xmlXPathContextPtr ctxt,
2cf05b
             return -1;
2cf05b
     }
2cf05b
 
2cf05b
+    /* channel_dev_addr is optional */
2cf05b
+    if ((channel_ddno = virXPathNode("./channel_dev_addr[1]", ctxt))) {
2cf05b
+        g_autofree virCCWDeviceAddress *channel_dev = NULL;
2cf05b
+
2cf05b
+        channel_dev = g_new0(virCCWDeviceAddress, 1);
2cf05b
+
2cf05b
+        if (virNodeDevCCWDeviceAddressParseXML(ctxt,
2cf05b
+                                               channel_ddno,
2cf05b
+                                               def->name,
2cf05b
+                                               channel_dev) < 0)
2cf05b
+            return -1;
2cf05b
+
2cf05b
+        ccw_dev->channel_dev_addr = g_steal_pointer(&channel_dev);
2cf05b
+    }
2cf05b
+
2cf05b
     return 0;
2cf05b
 }
2cf05b
 
2cf05b
@@ -2637,6 +2664,7 @@ virNodeDevCapsDefFree(virNodeDevCapsDef *caps)
2cf05b
         for (i = 0; i < data->ccw_dev.nmdev_types; i++)
2cf05b
             virMediatedDeviceTypeFree(data->ccw_dev.mdev_types[i]);
2cf05b
         g_free(data->ccw_dev.mdev_types);
2cf05b
+        g_free(data->ccw_dev.channel_dev_addr);
2cf05b
         break;
2cf05b
     case VIR_NODE_DEV_CAP_AP_MATRIX:
2cf05b
         g_free(data->ap_matrix.addr);
2cf05b
diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
2cf05b
index e4d1f67d53..d1751ed874 100644
2cf05b
--- a/src/conf/node_device_conf.h
2cf05b
+++ b/src/conf/node_device_conf.h
2cf05b
@@ -24,6 +24,7 @@
2cf05b
 
2cf05b
 #include "internal.h"
2cf05b
 #include "virbitmap.h"
2cf05b
+#include "virccw.h"
2cf05b
 #include "virpcivpd.h"
2cf05b
 #include "virscsihost.h"
2cf05b
 #include "virpci.h"
2cf05b
@@ -279,6 +280,7 @@ struct _virNodeDevCapCCW {
2cf05b
     unsigned int flags; /* enum virNodeDevCCWCapFlags */
2cf05b
     virMediatedDeviceType **mdev_types;
2cf05b
     size_t nmdev_types;
2cf05b
+    virCCWDeviceAddress *channel_dev_addr;
2cf05b
 };
2cf05b
 
2cf05b
 typedef struct _virNodeDevCapVDPA virNodeDevCapVDPA;
2cf05b
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
2cf05b
index ffcb3e8640..611a2592ca 100644
2cf05b
--- a/src/node_device/node_device_udev.c
2cf05b
+++ b/src/node_device/node_device_udev.c
2cf05b
@@ -1128,6 +1128,8 @@ static int
2cf05b
 udevProcessCSS(struct udev_device *device,
2cf05b
                virNodeDeviceDef *def)
2cf05b
 {
2cf05b
+    g_autofree char *dev_busid = NULL;
2cf05b
+
2cf05b
     /* only process IO subchannel and vfio-ccw devices to keep the list sane */
2cf05b
     if (!def->driver ||
2cf05b
         (STRNEQ(def->driver, "io_subchannel") &&
2cf05b
@@ -1139,6 +1141,12 @@ udevProcessCSS(struct udev_device *device,
2cf05b
 
2cf05b
     udevGenerateDeviceName(device, def, NULL);
2cf05b
 
2cf05b
+    /* process optional channel devices information */
2cf05b
+    udevGetStringSysfsAttr(device, "dev_busid", &dev_busid);
2cf05b
+
2cf05b
+    if (dev_busid != NULL)
2cf05b
+        def->caps->data.ccw_dev.channel_dev_addr = virCCWDeviceAddressFromString(dev_busid);
2cf05b
+
2cf05b
     if (virNodeDeviceGetCSSDynamicCaps(def->sysfs_path, &def->caps->data.ccw_dev) < 0)
2cf05b
         return -1;
2cf05b
 
2cf05b
-- 
2cf05b
2.39.1
2cf05b