render / rpms / libvirt

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