Blame SOURCES/libvirt-util-replace-virHostdevNetConfigReplace-with-.-Save-Set-NetConfig.patch

5c27b6
From 75d8b7e1afe532a93605e8ec83878830238d1fc2 Mon Sep 17 00:00:00 2001
5c27b6
Message-Id: <75d8b7e1afe532a93605e8ec83878830238d1fc2@dist-git>
5c27b6
From: Laine Stump <laine@laine.org>
5c27b6
Date: Thu, 13 Apr 2017 14:29:32 -0400
5c27b6
Subject: [PATCH] util: replace virHostdevNetConfigReplace with
5c27b6
 ...(Save|Set)NetConfig()
5c27b6
5c27b6
These two operations will need to be separated so that saving of the
5c27b6
original config is done before detaching the host net driver, and
5c27b6
setting the new config is done after attaching vfio-pci. This patch
5c27b6
splits the single function into two, but for now calls them together
5c27b6
(to make bisecting easier if there is a regression).
5c27b6
5c27b6
Resolves: https://bugzilla.redhat.com/1442040 (RHEL 7.3.z)
5c27b6
Resolves: https://bugzilla.redhat.com/1415609 (RHEL 7.4)
5c27b6
5c27b6
(cherry picked from commit b684734bef7d475a5d3f20acf6d46c4a34e77d63)
5c27b6
---
5c27b6
 src/util/virhostdev.c | 93 ++++++++++++++++++++++++++++++++++++++-------------
5c27b6
 1 file changed, 70 insertions(+), 23 deletions(-)
5c27b6
5c27b6
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
5c27b6
index a715aae12..b869ebc0c 100644
5c27b6
--- a/src/util/virhostdev.c
5c27b6
+++ b/src/util/virhostdev.c
5c27b6
@@ -390,10 +390,65 @@ virHostdevNetConfigVirtPortProfile(const char *linkdev, int vf,
5c27b6
 }
5c27b6
 
5c27b6
 
5c27b6
+/**
5c27b6
+ * virHostdevSaveNetConfig:
5c27b6
+ * @hostdev: config object describing a hostdev device
5c27b6
+ * @stateDir: directory to save device state into
5c27b6
+ *
5c27b6
+ * If the given hostdev device is an SRIOV network VF and *does not*
5c27b6
+ * have a <virtualport> element (ie, it isn't being configured via
5c27b6
+ * 802.11Qbh), determine its PF+VF#, and use that to save its current
5c27b6
+ * "admin" MAC address and VF tag (the ones saved in the PF
5c27b6
+ * driver).
5c27b6
+ *
5c27b6
+ * Returns 0 on success, -1 on failure.
5c27b6
+ */
5c27b6
 static int
5c27b6
-virHostdevNetConfigReplace(virDomainHostdevDefPtr hostdev,
5c27b6
-                           const unsigned char *uuid,
5c27b6
-                           const char *stateDir)
5c27b6
+virHostdevSaveNetConfig(virDomainHostdevDefPtr hostdev,
5c27b6
+                        const char *stateDir)
5c27b6
+{
5c27b6
+    int ret = -1;
5c27b6
+    char *linkdev = NULL;
5c27b6
+    int vf = -1;
5c27b6
+
5c27b6
+    if (!virHostdevIsPCINetDevice(hostdev) ||
5c27b6
+        virDomainNetGetActualVirtPortProfile(hostdev->parent.data.net))
5c27b6
+       return 0;
5c27b6
+
5c27b6
+    if (virHostdevIsVirtualFunction(hostdev) != 1) {
5c27b6
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
5c27b6
+                       _("Interface type hostdev is currently supported on"
5c27b6
+                         " SR-IOV Virtual Functions only"));
5c27b6
+        goto cleanup;
5c27b6
+    }
5c27b6
+
5c27b6
+    if (virHostdevNetDevice(hostdev, &linkdev, &vf) < 0)
5c27b6
+        goto cleanup;
5c27b6
+
5c27b6
+    if (virNetDevSaveNetConfig(linkdev, vf, stateDir, true) < 0)
5c27b6
+        goto cleanup;
5c27b6
+
5c27b6
+    ret = 0;
5c27b6
+ cleanup:
5c27b6
+    VIR_FREE(linkdev);
5c27b6
+    return ret;
5c27b6
+}
5c27b6
+
5c27b6
+
5c27b6
+/**
5c27b6
+ * virHostdevSetNetConfig:
5c27b6
+ * @hostdev: config object describing a hostdev device
5c27b6
+ * @uuid: uuid of the domain
5c27b6
+ *
5c27b6
+ * If the given hostdev device is an SRIOV network VF, determine its
5c27b6
+ * PF+VF#, and use that to set the "admin" MAC address and VF tag (the
5c27b6
+ * ones saved in the PF driver).xs
5c27b6
+ *
5c27b6
+ * Returns 0 on success, -1 on failure.
5c27b6
+ */
5c27b6
+static int
5c27b6
+virHostdevSetNetConfig(virDomainHostdevDefPtr hostdev,
5c27b6
+                       const unsigned char *uuid)
5c27b6
 {
5c27b6
     char *linkdev = NULL;
5c27b6
     virNetDevVlanPtr vlan;
5c27b6
@@ -402,12 +457,8 @@ virHostdevNetConfigReplace(virDomainHostdevDefPtr hostdev,
5c27b6
     int vf = -1;
5c27b6
     bool port_profile_associate = true;
5c27b6
 
5c27b6
-    if (virHostdevIsVirtualFunction(hostdev) != 1) {
5c27b6
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
5c27b6
-                       _("Interface type hostdev is currently supported on"
5c27b6
-                         " SR-IOV Virtual Functions only"));
5c27b6
-        goto cleanup;
5c27b6
-    }
5c27b6
+    if (!virHostdevIsPCINetDevice(hostdev))
5c27b6
+        return 0;
5c27b6
 
5c27b6
     if (virHostdevNetDevice(hostdev, &linkdev, &vf) < 0)
5c27b6
         goto cleanup;
5c27b6
@@ -428,11 +479,6 @@ virHostdevNetConfigReplace(virDomainHostdevDefPtr hostdev,
5c27b6
             goto cleanup;
5c27b6
         }
5c27b6
     } else {
5c27b6
-        /* Save/Set only mac and vlan */
5c27b6
-
5c27b6
-        if (virNetDevSaveNetConfig(linkdev, vf, stateDir, true) < 0)
5c27b6
-            goto cleanup;
5c27b6
-
5c27b6
         if (virNetDevSetNetConfig(linkdev, vf, &hostdev->parent.data.net->mac,
5c27b6
                                   vlan, NULL, true) < 0) {
5c27b6
             goto cleanup;
5c27b6
@@ -445,6 +491,7 @@ virHostdevNetConfigReplace(virDomainHostdevDefPtr hostdev,
5c27b6
     return ret;
5c27b6
 }
5c27b6
 
5c27b6
+
5c27b6
 /* @oldStateDir:
5c27b6
  * For upgrade purpose:
5c27b6
  * To an existing VM on QEMU, the hostdev netconfig file is originally stored
5c27b6
@@ -660,16 +707,16 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr,
5c27b6
     }
5c27b6
 
5c27b6
     /* Step 4: For SRIOV network devices, Now that we have detached the
5c27b6
-     * the network device, set the netdev config */
5c27b6
+     * the network device, set the new netdev config */
5c27b6
     for (i = 0; i < nhostdevs; i++) {
5c27b6
-         virDomainHostdevDefPtr hostdev = hostdevs[i];
5c27b6
-         if (!virHostdevIsPCINetDevice(hostdev))
5c27b6
-             continue;
5c27b6
-         if (virHostdevNetConfigReplace(hostdev, uuid,
5c27b6
-                                        mgr->stateDir) < 0) {
5c27b6
-             goto resetvfnetconfig;
5c27b6
-         }
5c27b6
-         last_processed_hostdev_vf = i;
5c27b6
+
5c27b6
+        if (virHostdevSaveNetConfig(hostdevs[i], mgr->stateDir) < 0)
5c27b6
+            goto resetvfnetconfig;
5c27b6
+
5c27b6
+        if (virHostdevSetNetConfig(hostdevs[i], uuid) < 0)
5c27b6
+            goto resetvfnetconfig;
5c27b6
+
5c27b6
+        last_processed_hostdev_vf = i;
5c27b6
     }
5c27b6
 
5c27b6
     /* Step 5: Move devices from the inactive list to the active list */
5c27b6
-- 
5c27b6
2.12.2
5c27b6