]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: use new virNetDev*NetConfig() functions for hostdev setup/teardown
authorLaine Stump <laine@laine.org>
Mon, 6 Mar 2017 01:28:08 +0000 (20:28 -0500)
committerLaine Stump <laine@laine.org>
Mon, 27 Mar 2017 14:19:12 +0000 (10:19 -0400)
virHostdevNetConfigReplace() and virHostdevNetConfigRestore() are
modified to use the new virNetDev*NetConfig() functions.

Note that due to the VF's original MAC addresses being saved after it
has already been un-bound from the host net driver, the actual current
VF MAC address won't be saved (because it no longer exists) - only the
"admin MAC" will be saved. This reflects existing behavior that will
be fixed in an upcoming patch.

src/util/virhostdev.c

index 5da06eb0354d76802fd2f8ea0731b4b8023fc44f..15e2982f8e3c23005bd655971f568808b29c628d 100644 (file)
@@ -450,10 +450,13 @@ virHostdevNetConfigReplace(virDomainHostdevDefPtr hostdev,
             goto cleanup;
         }
     } else {
-        /* Set only mac and vlan */
-        if (virNetDevReplaceNetConfig(linkdev, vf,
-                                      &hostdev->parent.data.net->mac,
-                                      vlan, stateDir) < 0) {
+        /* Save/Set only mac and vlan */
+
+        if (virNetDevSaveNetConfig(linkdev, vf, stateDir, true) < 0)
+            goto cleanup;
+
+        if (virNetDevSetNetConfig(linkdev, vf, &hostdev->parent.data.net->mac,
+                                  vlan, NULL, true) < 0) {
             goto cleanup;
         }
     }
@@ -506,9 +509,23 @@ virHostdevNetConfigRestore(virDomainHostdevDefPtr hostdev,
                                                  NULL,
                                                  port_profile_associate);
     } else {
-        ret = virNetDevRestoreNetConfig(linkdev, vf, stateDir);
-        if (ret < 0 && oldStateDir != NULL)
-            ret = virNetDevRestoreNetConfig(linkdev, vf, oldStateDir);
+        virMacAddrPtr MAC = NULL;
+        virMacAddrPtr adminMAC = NULL;
+        virNetDevVlanPtr vlan = NULL;
+
+        ret = virNetDevReadNetConfig(linkdev, vf, stateDir, &adminMAC, &vlan, &MAC);
+        if (ret < 0 && oldStateDir)
+            ret = virNetDevReadNetConfig(linkdev, vf, oldStateDir,
+                                         &adminMAC, &vlan, &MAC);
+
+        if (ret == 0) {
+            ignore_value(virNetDevSetNetConfig(linkdev, vf,
+                                               adminMAC, vlan, MAC, true));
+        }
+
+        VIR_FREE(MAC);
+        VIR_FREE(adminMAC);
+        virNetDevVlanFree(vlan);
     }
 
     VIR_FREE(linkdev);