render / rpms / libvirt

Forked from rpms/libvirt 4 months ago
Clone
5c27b6
From 57e803e520ac98e747a35e5f7454ea6890efa1ee Mon Sep 17 00:00:00 2001
5c27b6
Message-Id: <57e803e520ac98e747a35e5f7454ea6890efa1ee@dist-git>
5c27b6
From: Laine Stump <laine@laine.org>
5c27b6
Date: Thu, 13 Apr 2017 14:29:35 -0400
5c27b6
Subject: [PATCH] util: remove unused functions from virnetdev.c
5c27b6
5c27b6
The global functions virNetDevReplaceMacAddress(),
5c27b6
virNetDevReplaceNetConfig(), virNetDevRestoreMacAddress(), and
5c27b6
virNetDevRestoreNetConfig() are no longer used, as their functionality
5c27b6
has been replaced by virNetDev(Save|Read|Set)NetConfig().
5c27b6
5c27b6
The static functions virNetDevReplaceVfConfig() and
5c27b6
virNetDevRestoreVfConfig() were only used by the above-named global
5c27b6
functions that were removed.
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 bc4168f3e199a9167da544dfaa5847573a5f5d6b)
5c27b6
---
5c27b6
 src/libvirt_private.syms |   4 -
5c27b6
 src/util/virnetdev.c     | 332 -----------------------------------------------
5c27b6
 src/util/virnetdev.h     |   9 --
5c27b6
 3 files changed, 345 deletions(-)
5c27b6
5c27b6
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
5c27b6
index 9b0bc0100..e2dbee92d 100644
5c27b6
--- a/src/libvirt_private.syms
5c27b6
+++ b/src/libvirt_private.syms
5c27b6
@@ -1901,10 +1901,6 @@ virNetDevIfStateTypeToString;
5c27b6
 virNetDevIsVirtualFunction;
5c27b6
 virNetDevPFGetVF;
5c27b6
 virNetDevReadNetConfig;
5c27b6
-virNetDevReplaceMacAddress;
5c27b6
-virNetDevReplaceNetConfig;
5c27b6
-virNetDevRestoreMacAddress;
5c27b6
-virNetDevRestoreNetConfig;
5c27b6
 virNetDevRunEthernetScript;
5c27b6
 virNetDevRxFilterFree;
5c27b6
 virNetDevRxFilterModeTypeFromString;
5c27b6
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
5c27b6
index b61ed0f0b..4739f573a 100644
5c27b6
--- a/src/util/virnetdev.c
5c27b6
+++ b/src/util/virnetdev.c
5c27b6
@@ -391,92 +391,6 @@ int virNetDevGetMAC(const char *ifname,
5c27b6
 #endif
5c27b6
 
5c27b6
 
5c27b6
-/**
5c27b6
- * virNetDevReplaceMacAddress:
5c27b6
- * @macaddress: new MAC address for interface
5c27b6
- * @linkdev: name of interface
5c27b6
- * @stateDir: directory to store old MAC address
5c27b6
- *
5c27b6
- * Returns 0 on success, -1 on failure
5c27b6
- *
5c27b6
- */
5c27b6
-int
5c27b6
-virNetDevReplaceMacAddress(const char *linkdev,
5c27b6
-                           const virMacAddr *macaddress,
5c27b6
-                           const char *stateDir)
5c27b6
-{
5c27b6
-    virMacAddr oldmac;
5c27b6
-    char *path = NULL;
5c27b6
-    char macstr[VIR_MAC_STRING_BUFLEN];
5c27b6
-    int ret = -1;
5c27b6
-
5c27b6
-    if (virNetDevGetMAC(linkdev, &oldmac) < 0)
5c27b6
-        return -1;
5c27b6
-
5c27b6
-    if (virAsprintf(&path, "%s/%s",
5c27b6
-                    stateDir,
5c27b6
-                    linkdev) < 0)
5c27b6
-        return -1;
5c27b6
-    virMacAddrFormat(&oldmac, macstr);
5c27b6
-    if (virFileWriteStr(path, macstr, O_CREAT|O_TRUNC|O_WRONLY) < 0) {
5c27b6
-        virReportSystemError(errno, _("Unable to preserve mac for %s"),
5c27b6
-                             linkdev);
5c27b6
-        goto cleanup;
5c27b6
-    }
5c27b6
-
5c27b6
-    if (virNetDevSetMAC(linkdev, macaddress) < 0)
5c27b6
-        goto cleanup;
5c27b6
-
5c27b6
-    ret = 0;
5c27b6
- cleanup:
5c27b6
-    VIR_FREE(path);
5c27b6
-    return ret;
5c27b6
-}
5c27b6
-
5c27b6
-/**
5c27b6
- * virNetDevRestoreMacAddress:
5c27b6
- * @linkdev: name of interface
5c27b6
- * @stateDir: directory containing old MAC address
5c27b6
- *
5c27b6
- * Returns 0 on success, -errno on failure.
5c27b6
- *
5c27b6
- */
5c27b6
-int
5c27b6
-virNetDevRestoreMacAddress(const char *linkdev,
5c27b6
-                           const char *stateDir)
5c27b6
-{
5c27b6
-    int rc = -1;
5c27b6
-    char *oldmacname = NULL;
5c27b6
-    char *macstr = NULL;
5c27b6
-    char *path = NULL;
5c27b6
-    virMacAddr oldmac;
5c27b6
-
5c27b6
-    if (virAsprintf(&path, "%s/%s",
5c27b6
-                    stateDir,
5c27b6
-                    linkdev) < 0)
5c27b6
-        return -1;
5c27b6
-
5c27b6
-    if (virFileReadAll(path, VIR_MAC_STRING_BUFLEN, &macstr) < 0)
5c27b6
-        goto cleanup;
5c27b6
-
5c27b6
-    if (virMacAddrParse(macstr, &oldmac) != 0) {
5c27b6
-        virReportError(VIR_ERR_INTERNAL_ERROR,
5c27b6
-                       _("Cannot parse MAC address from '%s'"),
5c27b6
-                       oldmacname);
5c27b6
-        goto cleanup;
5c27b6
-    }
5c27b6
-
5c27b6
-    /*reset mac and remove file-ignore results*/
5c27b6
-    rc = virNetDevSetMAC(linkdev, &oldmac);
5c27b6
-    ignore_value(unlink(path));
5c27b6
-
5c27b6
- cleanup:
5c27b6
-    VIR_FREE(macstr);
5c27b6
-    VIR_FREE(path);
5c27b6
-    return rc;
5c27b6
-}
5c27b6
-
5c27b6
-
5c27b6
 #if defined(SIOCGIFMTU) && defined(HAVE_STRUCT_IFREQ)
5c27b6
 /**
5c27b6
  * virNetDevGetMTU:
5c27b6
@@ -1679,229 +1593,6 @@ virNetDevGetVfConfig(const char *ifname, int vf, virMacAddrPtr mac,
5c27b6
     return rc;
5c27b6
 }
5c27b6
 
5c27b6
-static int
5c27b6
-virNetDevReplaceVfConfig(const char *pflinkdev, int vf,
5c27b6
-                         const virMacAddr *macaddress,
5c27b6
-                         int vlanid,
5c27b6
-                         const char *stateDir)
5c27b6
-{
5c27b6
-    int ret = -1;
5c27b6
-    virMacAddr oldmac;
5c27b6
-    int oldvlanid = -1;
5c27b6
-    char *path = NULL;
5c27b6
-    char macstr[VIR_MAC_STRING_BUFLEN];
5c27b6
-    char *fileData = NULL;
5c27b6
-    bool pfIsOnline;
5c27b6
-
5c27b6
-    /* Assure that PF is online prior to twiddling with the VF.  It
5c27b6
-     * *should* be, but if the PF isn't online the changes made to the
5c27b6
-     * VF via the PF won't take effect, yet there will be no error
5c27b6
-     * reported. In the case that it isn't online, fail and report the
5c27b6
-     * error, since setting an unconfigured interface online
5c27b6
-     * automatically turns on IPv6 autoconfig, which may not be what
5c27b6
-     * the admin expects, so we want them to explicitly enable the PF
5c27b6
-     * in the host system network config.
5c27b6
-     */
5c27b6
-    if (virNetDevGetOnline(pflinkdev, &pfIsOnline) < 0)
5c27b6
-       goto cleanup;
5c27b6
-    if (!pfIsOnline) {
5c27b6
-        virReportError(VIR_ERR_INTERNAL_ERROR,
5c27b6
-                       _("Unable to configure VF %d of PF '%s' "
5c27b6
-                         "because the PF is not online. Please "
5c27b6
-                         "change host network config to put the "
5c27b6
-                         "PF online."),
5c27b6
-                       vf, pflinkdev);
5c27b6
-        goto cleanup;
5c27b6
-    }
5c27b6
-
5c27b6
-    if (virNetDevGetVfConfig(pflinkdev, vf, &oldmac, &oldvlanid) < 0)
5c27b6
-        goto cleanup;
5c27b6
-
5c27b6
-    if (virAsprintf(&path, "%s/%s_vf%d",
5c27b6
-                    stateDir, pflinkdev, vf) < 0)
5c27b6
-        goto cleanup;
5c27b6
-
5c27b6
-    if (virAsprintf(&fileData, "%s\n%d\n",
5c27b6
-                    virMacAddrFormat(&oldmac, macstr), oldvlanid) < 0)
5c27b6
-        goto cleanup;
5c27b6
-    if (virFileWriteStr(path, fileData, O_CREAT|O_TRUNC|O_WRONLY) < 0) {
5c27b6
-        virReportSystemError(errno, _("Unable to preserve mac/vlan tag "
5c27b6
-                                      "for pf = %s, vf = %d"), pflinkdev, vf);
5c27b6
-        goto cleanup;
5c27b6
-    }
5c27b6
-
5c27b6
-    ret = virNetDevSetVfConfig(pflinkdev, vf, macaddress, vlanid);
5c27b6
-
5c27b6
- cleanup:
5c27b6
-    VIR_FREE(path);
5c27b6
-    VIR_FREE(fileData);
5c27b6
-    return ret;
5c27b6
-}
5c27b6
-
5c27b6
-static int
5c27b6
-virNetDevRestoreVfConfig(const char *pflinkdev,
5c27b6
-                         int vf, const char *vflinkdev,
5c27b6
-                         const char *stateDir)
5c27b6
-{
5c27b6
-    int rc = -1;
5c27b6
-    char *path = NULL;
5c27b6
-    char *fileData = NULL;
5c27b6
-    char *vlan = NULL;
5c27b6
-    virMacAddr oldmac;
5c27b6
-    int vlanid = -1;
5c27b6
-
5c27b6
-    if (virAsprintf(&path, "%s/%s_vf%d",
5c27b6
-                    stateDir, pflinkdev, vf) < 0)
5c27b6
-        return rc;
5c27b6
-
5c27b6
-    if (vflinkdev && !virFileExists(path)) {
5c27b6
-        /* this VF's config may have been stored with
5c27b6
-         * virNetDevReplaceMacAddress while running an older version
5c27b6
-         * of libvirt. If so, the ${pf}_vf${id} file won't exist. In
5c27b6
-         * that case, try to restore using the older method with the
5c27b6
-         * VF's name directly.
5c27b6
-         */
5c27b6
-        rc = virNetDevRestoreMacAddress(vflinkdev, stateDir);
5c27b6
-        goto cleanup;
5c27b6
-    }
5c27b6
-
5c27b6
-    if (virFileReadAll(path, 128, &fileData) < 0)
5c27b6
-        goto cleanup;
5c27b6
-
5c27b6
-    if ((vlan = strchr(fileData, '\n'))) {
5c27b6
-        char *endptr;
5c27b6
-
5c27b6
-        *vlan++ = 0; /* NULL terminate the mac address */
5c27b6
-        if (*vlan) {
5c27b6
-            if ((virStrToLong_i(vlan, &endptr, 10, &vlanid) < 0) ||
5c27b6
-                (endptr && *endptr != '\n' && *endptr != 0)) {
5c27b6
-                virReportError(VIR_ERR_INTERNAL_ERROR,
5c27b6
-                               _("Cannot parse vlan tag from '%s'"),
5c27b6
-                               vlan);
5c27b6
-                goto cleanup;
5c27b6
-            }
5c27b6
-        }
5c27b6
-    }
5c27b6
-
5c27b6
-    if (virMacAddrParse(fileData, &oldmac) != 0) {
5c27b6
-        virReportError(VIR_ERR_INTERNAL_ERROR,
5c27b6
-                       _("Cannot parse MAC address from '%s'"),
5c27b6
-                       fileData);
5c27b6
-        goto cleanup;
5c27b6
-    }
5c27b6
-
5c27b6
-    /*reset mac and remove file-ignore results*/
5c27b6
-    rc = virNetDevSetVfConfig(pflinkdev, vf, &oldmac, vlanid);
5c27b6
-    ignore_value(unlink(path));
5c27b6
-
5c27b6
- cleanup:
5c27b6
-    VIR_FREE(path);
5c27b6
-    VIR_FREE(fileData);
5c27b6
-
5c27b6
-    return rc;
5c27b6
-}
5c27b6
-
5c27b6
-/**
5c27b6
- * virNetDevReplaceNetConfig:
5c27b6
- * @linkdev: name of the interface
5c27b6
- * @vf: vf index if linkdev is a pf
5c27b6
- * @macaddress: new MAC address for interface
5c27b6
- * @vlanid: new vlanid
5c27b6
- * @stateDir: directory to store old net config
5c27b6
- *
5c27b6
- * Returns 0 on success, -1 on failure
5c27b6
- *
5c27b6
- */
5c27b6
-int
5c27b6
-virNetDevReplaceNetConfig(const char *linkdev, int vf,
5c27b6
-                          const virMacAddr *macaddress,
5c27b6
-                          virNetDevVlanPtr vlan,
5c27b6
-                          const char *stateDir)
5c27b6
-{
5c27b6
-    int ret = -1;
5c27b6
-    char *pfdevname = NULL;
5c27b6
-
5c27b6
-    if (vf == -1 && virNetDevIsVirtualFunction(linkdev) == 1) {
5c27b6
-        /* If this really *is* a VF and the caller just didn't know
5c27b6
-         * it, we should set the MAC address via PF+vf# instead of
5c27b6
-         * setting directly via VF, because the latter will be
5c27b6
-         * rejected any time after the former has been done.
5c27b6
-         */
5c27b6
-        if (virNetDevGetPhysicalFunction(linkdev, &pfdevname) < 0)
5c27b6
-            goto cleanup;
5c27b6
-        if (virNetDevGetVirtualFunctionIndex(pfdevname, linkdev, &vf) < 0)
5c27b6
-            goto cleanup;
5c27b6
-        linkdev = pfdevname;
5c27b6
-    }
5c27b6
-
5c27b6
-    if (vf == -1) {
5c27b6
-        if (vlan) {
5c27b6
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
5c27b6
-                           _("vlan can only be set for SR-IOV VFs, but "
5c27b6
-                             "%s is not a VF"), linkdev);
5c27b6
-            goto cleanup;
5c27b6
-        }
5c27b6
-        ret = virNetDevReplaceMacAddress(linkdev, macaddress, stateDir);
5c27b6
-    } else {
5c27b6
-        int vlanid = 0; /* assure any current vlan tag is reset */
5c27b6
-
5c27b6
-        if (vlan) {
5c27b6
-            if (vlan->nTags != 1 || vlan->trunk) {
5c27b6
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
5c27b6
-                               _("vlan trunking is not supported "
5c27b6
-                                 "by SR-IOV network devices"));
5c27b6
-                goto cleanup;
5c27b6
-            }
5c27b6
-            vlanid = vlan->tag[0];
5c27b6
-        }
5c27b6
-        ret = virNetDevReplaceVfConfig(linkdev, vf, macaddress, vlanid,
5c27b6
-                                       stateDir);
5c27b6
-    }
5c27b6
-
5c27b6
- cleanup:
5c27b6
-    VIR_FREE(pfdevname);
5c27b6
-    return ret;
5c27b6
-}
5c27b6
-
5c27b6
-/**
5c27b6
- * virNetDevRestoreNetConfig:
5c27b6
- * @linkdev: name of the interface
5c27b6
- * @vf: vf index if linkdev is a pf
5c27b6
- * @stateDir: directory containing old net config
5c27b6
- *
5c27b6
- * Returns 0 on success, -errno on failure.
5c27b6
- *
5c27b6
- */
5c27b6
-int
5c27b6
-virNetDevRestoreNetConfig(const char *linkdev, int vf, const char *stateDir)
5c27b6
-{
5c27b6
-    int ret = -1;
5c27b6
-    char *pfdevname = NULL;
5c27b6
-    const char *vfdevname = NULL;
5c27b6
-
5c27b6
-    if (vf == -1 && virNetDevIsVirtualFunction(linkdev) == 1) {
5c27b6
-        /* If this really *is* a VF and the caller just didn't know
5c27b6
-         * it, we should set the MAC address via PF+vf# instead of
5c27b6
-         * setting directly via VF, because the latter will be
5c27b6
-         * rejected any time after the former has been done.
5c27b6
-         */
5c27b6
-        if (virNetDevGetPhysicalFunction(linkdev, &pfdevname) < 0)
5c27b6
-            goto cleanup;
5c27b6
-        if (virNetDevGetVirtualFunctionIndex(pfdevname, linkdev, &vf) < 0)
5c27b6
-            goto cleanup;
5c27b6
-        vfdevname = linkdev;
5c27b6
-        linkdev = pfdevname;
5c27b6
-    }
5c27b6
-
5c27b6
-    if (vf == -1)
5c27b6
-        ret = virNetDevRestoreMacAddress(linkdev, stateDir);
5c27b6
-    else
5c27b6
-        ret = virNetDevRestoreVfConfig(linkdev, vf, vfdevname, stateDir);
5c27b6
-
5c27b6
- cleanup:
5c27b6
-    VIR_FREE(pfdevname);
5c27b6
-    return ret;
5c27b6
-}
5c27b6
 
5c27b6
 # define VIR_NETDEV_KEYNAME_ADMIN_MAC "adminMac"
5c27b6
 # define VIR_NETDEV_KEYNAME_VLAN_TAG "vlanTag"
5c27b6
@@ -2449,29 +2140,6 @@ virNetDevSetNetConfig(const char *linkdev, int vf,
5c27b6
 
5c27b6
 #else /* defined(__linux__) && defined(HAVE_LIBNL)  && defined(IFLA_VF_MAX) */
5c27b6
 
5c27b6
-int
5c27b6
-virNetDevReplaceNetConfig(const char *linkdev ATTRIBUTE_UNUSED,
5c27b6
-                          int vf ATTRIBUTE_UNUSED,
5c27b6
-                          const virMacAddr *macaddress ATTRIBUTE_UNUSED,
5c27b6
-                          virNetDevVlanPtr vlan ATTRIBUTE_UNUSED,
5c27b6
-                          const char *stateDir ATTRIBUTE_UNUSED)
5c27b6
-{
5c27b6
-    virReportSystemError(ENOSYS, "%s",
5c27b6
-                         _("Unable to replace net config on this platform"));
5c27b6
-    return -1;
5c27b6
-
5c27b6
-}
5c27b6
-
5c27b6
-int
5c27b6
-virNetDevRestoreNetConfig(const char *linkdev ATTRIBUTE_UNUSED,
5c27b6
-                          int vf ATTRIBUTE_UNUSED,
5c27b6
-                          const char *stateDir ATTRIBUTE_UNUSED)
5c27b6
-{
5c27b6
-    virReportSystemError(ENOSYS, "%s",
5c27b6
-                         _("Unable to restore net config on this platform"));
5c27b6
-    return -1;
5c27b6
-}
5c27b6
-
5c27b6
 
5c27b6
 int
5c27b6
 virNetDevSaveNetConfig(const char *linkdev ATTRIBUTE_UNUSED,
5c27b6
diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h
5c27b6
index b5abf7a7b..a097ba300 100644
5c27b6
--- a/src/util/virnetdev.h
5c27b6
+++ b/src/util/virnetdev.h
5c27b6
@@ -209,15 +209,6 @@ virNetDevSetNetConfig(const char *linkdev, int vf,
5c27b6
                       bool setVLan)
5c27b6
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
5c27b6
 
5c27b6
-int virNetDevReplaceNetConfig(const char *linkdev, int vf,
5c27b6
-                              const virMacAddr *macaddress,
5c27b6
-                              virNetDevVlanPtr vlan,
5c27b6
-                              const char *stateDir)
5c27b6
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(5);
5c27b6
-
5c27b6
-int virNetDevRestoreNetConfig(const char *linkdev, int vf, const char *stateDir)
5c27b6
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
5c27b6
-
5c27b6
 int virNetDevGetVirtualFunctionInfo(const char *vfname, char **pfname,
5c27b6
                                     int *vf)
5c27b6
     ATTRIBUTE_NONNULL(1);
5c27b6
-- 
5c27b6
2.12.2
5c27b6