util: log all setting of MAC addresses and vlan tags

Having this information available will make it easier to determine the
culprit when MAC or vlan tag appear to not be set, eg.:

  https://bugzilla.redhat.com/1364073

(This patch doesn't fix that bug, just makes it easier to diagnose)
This commit is contained in:
Laine Stump 2017-03-11 10:29:29 -05:00
parent 86556e167a
commit 6ec36b0699

View File

@ -241,6 +241,7 @@ virNetDevSetMACInternal(const char *ifname,
int fd = -1; int fd = -1;
int ret = -1; int ret = -1;
struct ifreq ifr; struct ifreq ifr;
char macstr[VIR_MAC_STRING_BUFLEN];
if ((fd = virNetDevSetupControl(ifname, &ifr)) < 0) if ((fd = virNetDevSetupControl(ifname, &ifr)) < 0)
return -1; return -1;
@ -256,7 +257,6 @@ virNetDevSetMACInternal(const char *ifname,
virMacAddrGetRaw(macaddr, (unsigned char *)ifr.ifr_hwaddr.sa_data); virMacAddrGetRaw(macaddr, (unsigned char *)ifr.ifr_hwaddr.sa_data);
if (ioctl(fd, SIOCSIFHWADDR, &ifr) < 0) { if (ioctl(fd, SIOCSIFHWADDR, &ifr) < 0) {
char macstr[VIR_MAC_STRING_BUFLEN];
if (quiet && errno == EADDRNOTAVAIL) if (quiet && errno == EADDRNOTAVAIL)
goto cleanup; goto cleanup;
@ -270,6 +270,10 @@ virNetDevSetMACInternal(const char *ifname,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_DEBUG("SIOCSIFHWADDR %s MAC=%s - %s",
ifname, virMacAddrFormat(macaddr, macstr),
ret < 0 ? "Fail" : "Success");
VIR_FORCE_CLOSE(fd); VIR_FORCE_CLOSE(fd);
return ret; return ret;
} }
@ -312,6 +316,9 @@ virNetDevSetMACInternal(const char *ifname,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_DEBUG("SIOCSIFLLADDR %s MAC=%s - %s", ifname, mac + 1),
ret < 0 ? "Fail" : "Success");
VIR_FORCE_CLOSE(s); VIR_FORCE_CLOSE(s);
return ret; return ret;
@ -1508,6 +1515,7 @@ virNetDevSetVfConfig(const char *ifname, int vf,
bool *allowRetry) bool *allowRetry)
{ {
int rc = -1; int rc = -1;
char macstr[VIR_MAC_STRING_BUFLEN];
struct nlmsghdr *resp = NULL; struct nlmsghdr *resp = NULL;
struct nlmsgerr *err; struct nlmsgerr *err;
unsigned int recvbuflen = 0; unsigned int recvbuflen = 0;
@ -1591,8 +1599,6 @@ virNetDevSetVfConfig(const char *ifname, int vf,
goto cleanup; goto cleanup;
} else if (err->error) { } else if (err->error) {
/* other errors are permanent */ /* other errors are permanent */
char macstr[VIR_MAC_STRING_BUFLEN];
virReportSystemError(-err->error, virReportSystemError(-err->error,
_("Cannot set interface MAC/vlanid to %s/%d " _("Cannot set interface MAC/vlanid to %s/%d "
"for ifname %s vf %d"), "for ifname %s vf %d"),
@ -1616,6 +1622,11 @@ virNetDevSetVfConfig(const char *ifname, int vf,
rc = 0; rc = 0;
cleanup: cleanup:
VIR_DEBUG("RTM_SETLINK %s vf %d MAC=%s vlanid=%d - %s",
ifname, vf,
macaddr ? virMacAddrFormat(macaddr, macstr) : "(unchanged)",
vlanid, rc < 0 ? "Fail" : "Success");
nlmsg_free(nl_msg); nlmsg_free(nl_msg);
VIR_FREE(resp); VIR_FREE(resp);
return rc; return rc;