79b470
From 606da680fb4c7ee0f8a7ecc76057592433ea6ac9 Mon Sep 17 00:00:00 2001
79b470
Message-Id: <606da680fb4c7ee0f8a7ecc76057592433ea6ac9@dist-git>
79b470
From: Cornelia Huck <cohuck@redhat.com>
79b470
Date: Fri, 2 Oct 2020 13:39:12 +0200
79b470
Subject: [PATCH] virDomainNetFindIdx: add support for CCW addresses
79b470
MIME-Version: 1.0
79b470
Content-Type: text/plain; charset=UTF-8
79b470
Content-Transfer-Encoding: 8bit
79b470
79b470
Allow to match with CCW addresses in addition to PCI addresses
79b470
(and MAC addresses).
79b470
79b470
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
79b470
Reviewed-by: Ján Tomko <jtomko@redhat.com>
79b470
Signed-off-by: Ján Tomko <jtomko@redhat.com>
79b470
(cherry picked from commit 2fefbd03ab09f32b1b15d093096fa44870817751)
79b470
79b470
https://bugzilla.redhat.com/show_bug.cgi?id=1837495
79b470
79b470
Signed-off-by: Ján Tomko <jtomko@redhat.com>
79b470
Message-Id: <a53fc421152b209c5a7fe69d4d5714a2f35077a8.1601638699.git.jtomko@redhat.com>
79b470
Acked-by: Cornelia Huck <cohuck@redhat.com>
79b470
---
79b470
 src/conf/device_conf.c   | 12 ++++++++++++
79b470
 src/conf/device_conf.h   |  3 +++
79b470
 src/conf/domain_conf.c   | 23 ++++++++++++++++++++++-
79b470
 src/libvirt_private.syms |  1 +
79b470
 4 files changed, 38 insertions(+), 1 deletion(-)
79b470
79b470
diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
79b470
index 4dbd5c1ac9..9e96d08394 100644
79b470
--- a/src/conf/device_conf.c
79b470
+++ b/src/conf/device_conf.c
79b470
@@ -370,6 +370,18 @@ virDomainDeviceCCWAddressParseXML(xmlNodePtr node,
79b470
     return ret;
79b470
 }
79b470
 
79b470
+bool
79b470
+virDomainDeviceCCWAddressEqual(virDomainDeviceCCWAddressPtr addr1,
79b470
+                               virDomainDeviceCCWAddressPtr addr2)
79b470
+{
79b470
+    if (addr1->cssid == addr2->cssid &&
79b470
+        addr1->ssid == addr2->ssid &&
79b470
+        addr1->devno == addr2->devno) {
79b470
+        return true;
79b470
+    }
79b470
+    return false;
79b470
+}
79b470
+
79b470
 int
79b470
 virDomainDeviceDriveAddressParseXML(xmlNodePtr node,
79b470
                                     virDomainDeviceDriveAddressPtr addr)
79b470
diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
79b470
index e091d7cfe2..7a8227e743 100644
79b470
--- a/src/conf/device_conf.h
79b470
+++ b/src/conf/device_conf.h
79b470
@@ -208,6 +208,9 @@ void virPCIDeviceAddressFormat(virBufferPtr buf,
79b470
 bool virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddressPtr addr);
79b470
 int virDomainDeviceCCWAddressParseXML(xmlNodePtr node,
79b470
                                       virDomainDeviceCCWAddressPtr addr);
79b470
+bool virDomainDeviceCCWAddressEqual(virDomainDeviceCCWAddressPtr addr1,
79b470
+                                    virDomainDeviceCCWAddressPtr addr2);
79b470
+#define VIR_CCW_DEVICE_ADDRESS_FMT "%x.%x.%04x"
79b470
 
79b470
 int virDomainDeviceDriveAddressParseXML(xmlNodePtr node,
79b470
                                         virDomainDeviceDriveAddressPtr addr);
79b470
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
79b470
index 60962ee7c1..306926b64c 100644
79b470
--- a/src/conf/domain_conf.c
79b470
+++ b/src/conf/domain_conf.c
79b470
@@ -17385,6 +17385,8 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net)
79b470
     bool MACAddrSpecified = !net->mac_generated;
79b470
     bool PCIAddrSpecified = virDomainDeviceAddressIsValid(&net->info,
79b470
                                                           VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI);
79b470
+    bool CCWAddrSpecified = virDomainDeviceAddressIsValid(&net->info,
79b470
+                                                          VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW);
79b470
 
79b470
     for (i = 0; i < def->nnets; i++) {
79b470
         if (MACAddrSpecified &&
79b470
@@ -17396,9 +17398,14 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net)
79b470
                                       &net->info.addr.pci))
79b470
             continue;
79b470
 
79b470
+        if (CCWAddrSpecified &&
79b470
+            !virDomainDeviceCCWAddressEqual(&def->nets[i]->info.addr.ccw,
79b470
+                                            &net->info.addr.ccw))
79b470
+            continue;
79b470
+
79b470
         if (matchidx >= 0) {
79b470
             /* there were multiple matches on mac address, and no
79b470
-             * qualifying guest-side PCI address was given, so we must
79b470
+             * qualifying guest-side PCI/CCW address was given, so we must
79b470
              * fail (NB: a USB address isn't adequate, since it may
79b470
              * specify only vendor and product ID, and there may be
79b470
              * multiples of those.
79b470
@@ -17428,6 +17435,14 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net)
79b470
                            net->info.addr.pci.bus,
79b470
                            net->info.addr.pci.slot,
79b470
                            net->info.addr.pci.function);
79b470
+        } else if (MACAddrSpecified && CCWAddrSpecified) {
79b470
+            virReportError(VIR_ERR_DEVICE_MISSING,
79b470
+                           _("no device matching MAC address %s found on "
79b470
+                             VIR_CCW_DEVICE_ADDRESS_FMT),
79b470
+                           virMacAddrFormat(&net->mac, mac),
79b470
+                           net->info.addr.ccw.cssid,
79b470
+                           net->info.addr.ccw.ssid,
79b470
+                           net->info.addr.ccw.devno);
79b470
         } else if (PCIAddrSpecified) {
79b470
             virReportError(VIR_ERR_DEVICE_MISSING,
79b470
                            _("no device found on " VIR_PCI_DEVICE_ADDRESS_FMT),
79b470
@@ -17435,6 +17450,12 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net)
79b470
                            net->info.addr.pci.bus,
79b470
                            net->info.addr.pci.slot,
79b470
                            net->info.addr.pci.function);
79b470
+        } else if (CCWAddrSpecified) {
79b470
+            virReportError(VIR_ERR_DEVICE_MISSING,
79b470
+                           _("no device found on " VIR_CCW_DEVICE_ADDRESS_FMT),
79b470
+                           net->info.addr.ccw.cssid,
79b470
+                           net->info.addr.ccw.ssid,
79b470
+                           net->info.addr.ccw.devno);
79b470
         } else if (MACAddrSpecified) {
79b470
             virReportError(VIR_ERR_DEVICE_MISSING,
79b470
                            _("no device matching MAC address %s found"),
79b470
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
79b470
index 9e290c7bdf..130828706a 100644
79b470
--- a/src/libvirt_private.syms
79b470
+++ b/src/libvirt_private.syms
79b470
@@ -128,6 +128,7 @@ virDeviceInfoPCIAddressIsWanted;
79b470
 virDomainDeviceAddressIsValid;
79b470
 virDomainDeviceAddressTypeToString;
79b470
 virDomainDeviceCcidAddressParseXML;
79b470
+virDomainDeviceCCWAddressEqual;
79b470
 virDomainDeviceCCWAddressIsValid;
79b470
 virDomainDeviceCCWAddressParseXML;
79b470
 virDomainDeviceDriveAddressParseXML;
79b470
-- 
79b470
2.28.0
79b470