mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
util: fix build on non-Linux
Build fails on non-Linux systems with this error: CC util/libvirt_util_la-virnetdev.lo util/virnetdev.c:364:1: error: unused function 'virNetDevReplaceMacAddress' [-Werror,-Wunused-function] virNetDevReplaceMacAddress(const char *linkdev, ^ util/virnetdev.c:406:1: error: unused function 'virNetDevRestoreMacAddress' [-Werror,-Wunused-function] virNetDevRestoreMacAddress(const char *linkdev, ^ 2 errors generated. The virNetDev{Restore,Replace}MacAddress() functions are only used by VF-related routines that are available on Linux only. So move these functions under the same #ifdef.
This commit is contained in:
parent
74acc4cabf
commit
584db1054c
@ -350,94 +350,6 @@ int virNetDevGetMAC(const char *ifname,
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* virNetDevReplaceMacAddress:
|
||||
* @macaddress: new MAC address for interface
|
||||
* @linkdev: name of interface
|
||||
* @stateDir: directory to store old MAC address
|
||||
*
|
||||
* Returns 0 on success, -1 on failure
|
||||
*
|
||||
*/
|
||||
static int
|
||||
virNetDevReplaceMacAddress(const char *linkdev,
|
||||
const virMacAddr *macaddress,
|
||||
const char *stateDir)
|
||||
{
|
||||
virMacAddr oldmac;
|
||||
char *path = NULL;
|
||||
char macstr[VIR_MAC_STRING_BUFLEN];
|
||||
int ret = -1;
|
||||
|
||||
if (virNetDevGetMAC(linkdev, &oldmac) < 0)
|
||||
return -1;
|
||||
|
||||
if (virAsprintf(&path, "%s/%s",
|
||||
stateDir,
|
||||
linkdev) < 0)
|
||||
return -1;
|
||||
virMacAddrFormat(&oldmac, macstr);
|
||||
if (virFileWriteStr(path, macstr, O_CREAT|O_TRUNC|O_WRONLY) < 0) {
|
||||
virReportSystemError(errno, _("Unable to preserve mac for %s"),
|
||||
linkdev);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virNetDevSetMAC(linkdev, macaddress) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* virNetDevRestoreMacAddress:
|
||||
* @linkdev: name of interface
|
||||
* @stateDir: directory containing old MAC address
|
||||
*
|
||||
* Returns 0 on success, -errno on failure.
|
||||
*
|
||||
*/
|
||||
static int
|
||||
virNetDevRestoreMacAddress(const char *linkdev,
|
||||
const char *stateDir)
|
||||
{
|
||||
int rc = -1;
|
||||
char *oldmacname = NULL;
|
||||
char *macstr = NULL;
|
||||
char *path = NULL;
|
||||
virMacAddr oldmac;
|
||||
|
||||
if (virAsprintf(&path, "%s/%s",
|
||||
stateDir,
|
||||
linkdev) < 0)
|
||||
return -1;
|
||||
|
||||
if (virFileReadAll(path, VIR_MAC_STRING_BUFLEN, &macstr) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virMacAddrParse(macstr, &oldmac) != 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Cannot parse MAC address from '%s'"),
|
||||
oldmacname);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/*reset mac and remove file-ignore results*/
|
||||
rc = virNetDevSetMAC(linkdev, &oldmac);
|
||||
ignore_value(unlink(path));
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(macstr);
|
||||
VIR_FREE(path);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
#if defined(SIOCGIFMTU) && defined(HAVE_STRUCT_IFREQ)
|
||||
/**
|
||||
* virNetDevGetMTU:
|
||||
@ -1923,6 +1835,93 @@ virNetDevSysfsFile(char **pf_sysfs_device_link ATTRIBUTE_UNUSED,
|
||||
#endif /* !__linux__ */
|
||||
#if defined(__linux__) && defined(HAVE_LIBNL) && defined(IFLA_VF_MAX)
|
||||
|
||||
/**
|
||||
* virNetDevReplaceMacAddress:
|
||||
* @macaddress: new MAC address for interface
|
||||
* @linkdev: name of interface
|
||||
* @stateDir: directory to store old MAC address
|
||||
*
|
||||
* Returns 0 on success, -1 on failure
|
||||
*
|
||||
*/
|
||||
static int
|
||||
virNetDevReplaceMacAddress(const char *linkdev,
|
||||
const virMacAddr *macaddress,
|
||||
const char *stateDir)
|
||||
{
|
||||
virMacAddr oldmac;
|
||||
char *path = NULL;
|
||||
char macstr[VIR_MAC_STRING_BUFLEN];
|
||||
int ret = -1;
|
||||
|
||||
if (virNetDevGetMAC(linkdev, &oldmac) < 0)
|
||||
return -1;
|
||||
|
||||
if (virAsprintf(&path, "%s/%s",
|
||||
stateDir,
|
||||
linkdev) < 0)
|
||||
return -1;
|
||||
virMacAddrFormat(&oldmac, macstr);
|
||||
if (virFileWriteStr(path, macstr, O_CREAT|O_TRUNC|O_WRONLY) < 0) {
|
||||
virReportSystemError(errno, _("Unable to preserve mac for %s"),
|
||||
linkdev);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virNetDevSetMAC(linkdev, macaddress) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* virNetDevRestoreMacAddress:
|
||||
* @linkdev: name of interface
|
||||
* @stateDir: directory containing old MAC address
|
||||
*
|
||||
* Returns 0 on success, -errno on failure.
|
||||
*
|
||||
*/
|
||||
static int
|
||||
virNetDevRestoreMacAddress(const char *linkdev,
|
||||
const char *stateDir)
|
||||
{
|
||||
int rc = -1;
|
||||
char *oldmacname = NULL;
|
||||
char *macstr = NULL;
|
||||
char *path = NULL;
|
||||
virMacAddr oldmac;
|
||||
|
||||
if (virAsprintf(&path, "%s/%s",
|
||||
stateDir,
|
||||
linkdev) < 0)
|
||||
return -1;
|
||||
|
||||
if (virFileReadAll(path, VIR_MAC_STRING_BUFLEN, &macstr) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virMacAddrParse(macstr, &oldmac) != 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Cannot parse MAC address from '%s'"),
|
||||
oldmacname);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/*reset mac and remove file-ignore results*/
|
||||
rc = virNetDevSetMAC(linkdev, &oldmac);
|
||||
ignore_value(unlink(path));
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(macstr);
|
||||
VIR_FREE(path);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
static struct nla_policy ifla_vf_policy[IFLA_VF_MAX+1] = {
|
||||
[IFLA_VF_MAC] = { .type = NLA_UNSPEC,
|
||||
.maxlen = sizeof(struct ifla_vf_mac) },
|
||||
|
Loading…
x
Reference in New Issue
Block a user