Blob Blame History Raw
From 2386cc610a24c88e45741f04bc63445b3542a512 Mon Sep 17 00:00:00 2001
Message-Id: <2386cc610a24c88e45741f04bc63445b3542a512@dist-git>
From: Laine Stump <laine@redhat.com>
Date: Sun, 23 Apr 2017 21:33:53 -0400
Subject: [PATCH] util: allow ignoring SIOCSIFHWADDR when errno is EPERM

Commit f4ef3a71 made a variation of virNetDevSetMAC that would return
without logging an error message if errno was set to
EADDRNOTAVAIL. This errno is set by some SRIOV VF drivers (in
particular igbvf) when they fail to set the device's MAC address due
to the PF driver refusing the request. This is useful if we want to
try a different method of setting the VF MAC address before giving up
(Commit 86556e16 actually does this, setting the desired MAC address
to the "admin MAC in the PF, then detaching and reattaching the VF
netdev driver to force a reinit of the MAC address).

During testing of Bug 1442040 it was discovered that the ixgbe driver
returns EPERM in this situation, so this patch changes the exception
case for silent+non-terminal failure to account for this difference.

Completes resolution to: https://bugzilla.redhat.com/1442040 (RHEL 7.3.z)
                         https://bugzilla.redhat.com/1415609 (RHEL 7.4)

(cherry picked from commit 997134fb8b17eef6eba439303b382b239996208b)
---
 src/util/virnetdev.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 37e47d165..6f933740a 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -226,7 +226,8 @@ int virNetDevExists(const char *ifname)
  * virNetDevSetMACInternal:
  * @ifname: interface name to set MTU for
  * @macaddr: MAC address
- * @quiet: true if a failure to set MAC address with errno == EADDRNOTAVAIL
+ * @quiet: true if a failure to set MAC address with
+ *         errno == EADDRNOTAVAIL || errno == EPERM
  *         should be silent (still returns error, but without log)
  *
  * This function sets the @macaddr for a given interface @ifname.
@@ -258,7 +259,8 @@ virNetDevSetMACInternal(const char *ifname,
 
     if (ioctl(fd, SIOCSIFHWADDR, &ifr) < 0) {
 
-        if (quiet && errno == EADDRNOTAVAIL)
+        if (quiet &&
+            (errno == EADDRNOTAVAIL || errno == EPERM))
             goto cleanup;
 
         virReportSystemError(errno,
@@ -305,7 +307,8 @@ virNetDevSetMACInternal(const char *ifname,
         ifr.ifr_addr.sa_len = VIR_MAC_BUFLEN;
 
         if (ioctl(s, SIOCSIFLLADDR, &ifr) < 0) {
-            if (quiet && errno == EADDRNOTAVAIL)
+            if (quiet &&
+                (errno == EADDRNOTAVAIL || errno == EPERM))
                 goto cleanup;
 
             virReportSystemError(errno,
@@ -2150,11 +2153,12 @@ virNetDevSetNetConfig(const char *linkdev, int vf,
             int retries = 100;
 
             /* if pfDevOrig == NULL, this isn't a VF, so we've failed */
-            if (!pfDevOrig || errno != EADDRNOTAVAIL)
+            if (!pfDevOrig ||
+                (errno != EADDRNOTAVAIL && errno != EPERM))
                 goto cleanup;
 
             /* Otherwise this is a VF, and virNetDevSetMAC failed with
-             * EADDRNOTAVAIL, which could be due to the
+             * EADDRNOTAVAIL/EPERM, which could be due to the
              * "administratively set" flag being set in the PF for
              * this VF.  When this happens, we can attempt to use an
              * alternate method to set the VF MAC: first set it into
-- 
2.12.2