render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 606da680fb4c7ee0f8a7ecc76057592433ea6ac9 Mon Sep 17 00:00:00 2001
Message-Id: <606da680fb4c7ee0f8a7ecc76057592433ea6ac9@dist-git>
From: Cornelia Huck <cohuck@redhat.com>
Date: Fri, 2 Oct 2020 13:39:12 +0200
Subject: [PATCH] virDomainNetFindIdx: add support for CCW addresses
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Allow to match with CCW addresses in addition to PCI addresses
(and MAC addresses).

Signed-off-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 2fefbd03ab09f32b1b15d093096fa44870817751)

https://bugzilla.redhat.com/show_bug.cgi?id=1837495

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Message-Id: <a53fc421152b209c5a7fe69d4d5714a2f35077a8.1601638699.git.jtomko@redhat.com>
Acked-by: Cornelia Huck <cohuck@redhat.com>
---
 src/conf/device_conf.c   | 12 ++++++++++++
 src/conf/device_conf.h   |  3 +++
 src/conf/domain_conf.c   | 23 ++++++++++++++++++++++-
 src/libvirt_private.syms |  1 +
 4 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
index 4dbd5c1ac9..9e96d08394 100644
--- a/src/conf/device_conf.c
+++ b/src/conf/device_conf.c
@@ -370,6 +370,18 @@ virDomainDeviceCCWAddressParseXML(xmlNodePtr node,
     return ret;
 }
 
+bool
+virDomainDeviceCCWAddressEqual(virDomainDeviceCCWAddressPtr addr1,
+                               virDomainDeviceCCWAddressPtr addr2)
+{
+    if (addr1->cssid == addr2->cssid &&
+        addr1->ssid == addr2->ssid &&
+        addr1->devno == addr2->devno) {
+        return true;
+    }
+    return false;
+}
+
 int
 virDomainDeviceDriveAddressParseXML(xmlNodePtr node,
                                     virDomainDeviceDriveAddressPtr addr)
diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index e091d7cfe2..7a8227e743 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -208,6 +208,9 @@ void virPCIDeviceAddressFormat(virBufferPtr buf,
 bool virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddressPtr addr);
 int virDomainDeviceCCWAddressParseXML(xmlNodePtr node,
                                       virDomainDeviceCCWAddressPtr addr);
+bool virDomainDeviceCCWAddressEqual(virDomainDeviceCCWAddressPtr addr1,
+                                    virDomainDeviceCCWAddressPtr addr2);
+#define VIR_CCW_DEVICE_ADDRESS_FMT "%x.%x.%04x"
 
 int virDomainDeviceDriveAddressParseXML(xmlNodePtr node,
                                         virDomainDeviceDriveAddressPtr addr);
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 60962ee7c1..306926b64c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -17385,6 +17385,8 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net)
     bool MACAddrSpecified = !net->mac_generated;
     bool PCIAddrSpecified = virDomainDeviceAddressIsValid(&net->info,
                                                           VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI);
+    bool CCWAddrSpecified = virDomainDeviceAddressIsValid(&net->info,
+                                                          VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW);
 
     for (i = 0; i < def->nnets; i++) {
         if (MACAddrSpecified &&
@@ -17396,9 +17398,14 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net)
                                       &net->info.addr.pci))
             continue;
 
+        if (CCWAddrSpecified &&
+            !virDomainDeviceCCWAddressEqual(&def->nets[i]->info.addr.ccw,
+                                            &net->info.addr.ccw))
+            continue;
+
         if (matchidx >= 0) {
             /* there were multiple matches on mac address, and no
-             * qualifying guest-side PCI address was given, so we must
+             * qualifying guest-side PCI/CCW address was given, so we must
              * fail (NB: a USB address isn't adequate, since it may
              * specify only vendor and product ID, and there may be
              * multiples of those.
@@ -17428,6 +17435,14 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net)
                            net->info.addr.pci.bus,
                            net->info.addr.pci.slot,
                            net->info.addr.pci.function);
+        } else if (MACAddrSpecified && CCWAddrSpecified) {
+            virReportError(VIR_ERR_DEVICE_MISSING,
+                           _("no device matching MAC address %s found on "
+                             VIR_CCW_DEVICE_ADDRESS_FMT),
+                           virMacAddrFormat(&net->mac, mac),
+                           net->info.addr.ccw.cssid,
+                           net->info.addr.ccw.ssid,
+                           net->info.addr.ccw.devno);
         } else if (PCIAddrSpecified) {
             virReportError(VIR_ERR_DEVICE_MISSING,
                            _("no device found on " VIR_PCI_DEVICE_ADDRESS_FMT),
@@ -17435,6 +17450,12 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net)
                            net->info.addr.pci.bus,
                            net->info.addr.pci.slot,
                            net->info.addr.pci.function);
+        } else if (CCWAddrSpecified) {
+            virReportError(VIR_ERR_DEVICE_MISSING,
+                           _("no device found on " VIR_CCW_DEVICE_ADDRESS_FMT),
+                           net->info.addr.ccw.cssid,
+                           net->info.addr.ccw.ssid,
+                           net->info.addr.ccw.devno);
         } else if (MACAddrSpecified) {
             virReportError(VIR_ERR_DEVICE_MISSING,
                            _("no device matching MAC address %s found"),
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 9e290c7bdf..130828706a 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -128,6 +128,7 @@ virDeviceInfoPCIAddressIsWanted;
 virDomainDeviceAddressIsValid;
 virDomainDeviceAddressTypeToString;
 virDomainDeviceCcidAddressParseXML;
+virDomainDeviceCCWAddressEqual;
 virDomainDeviceCCWAddressIsValid;
 virDomainDeviceCCWAddressParseXML;
 virDomainDeviceDriveAddressParseXML;
-- 
2.28.0