util: use new virNetDev*NetConfig() functions for hostdev setup/teardown

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.
This commit is contained in:
Laine Stump 2017-03-05 20:28:08 -05:00
parent b91a336384
commit 9c004d55d0

View File

@ -450,10 +450,13 @@ virHostdevNetConfigReplace(virDomainHostdevDefPtr hostdev,
goto cleanup; goto cleanup;
} }
} else { } else {
/* Set only mac and vlan */ /* Save/Set only mac and vlan */
if (virNetDevReplaceNetConfig(linkdev, vf,
&hostdev->parent.data.net->mac, if (virNetDevSaveNetConfig(linkdev, vf, stateDir, true) < 0)
vlan, stateDir) < 0) { goto cleanup;
if (virNetDevSetNetConfig(linkdev, vf, &hostdev->parent.data.net->mac,
vlan, NULL, true) < 0) {
goto cleanup; goto cleanup;
} }
} }
@ -506,9 +509,23 @@ virHostdevNetConfigRestore(virDomainHostdevDefPtr hostdev,
NULL, NULL,
port_profile_associate); port_profile_associate);
} else { } else {
ret = virNetDevRestoreNetConfig(linkdev, vf, stateDir); virMacAddrPtr MAC = NULL;
if (ret < 0 && oldStateDir != NULL) virMacAddrPtr adminMAC = NULL;
ret = virNetDevRestoreNetConfig(linkdev, vf, oldStateDir); 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); VIR_FREE(linkdev);