Remove ifaceUp, ifaceDown, ifaceCtrl & ifaceIsUp APIs

The ifaceUp, ifaceDown, ifaceCtrl & ifaceIsUp APIs can be replaced
with calls to virNetDevSetOnline and virNetDevIsOnline

* src/util/interface.c, src/util/interface.h: Delete ifaceUp,
  ifaceDown, ifaceCtrl & ifaceIsUp
* src/nwfilter/nwfilter_gentech_driver.c, src/util/macvtap.c:
  Update to use virNetDevSetOnline and virNetDevIsOnline
This commit is contained in:
Daniel P. Berrange 2011-11-02 16:10:56 +00:00
parent 428cffb1e7
commit 268085c3bd
5 changed files with 10 additions and 177 deletions

View File

@ -576,8 +576,6 @@ virHookPresent;
# interface.h # interface.h
ifaceCheck; ifaceCheck;
ifaceCtrl;
ifaceGetFlags;
ifaceGetIndex; ifaceGetIndex;
ifaceGetMacAddress; ifaceGetMacAddress;
ifaceGetIPAddress; ifaceGetIPAddress;
@ -585,7 +583,6 @@ ifaceGetNthParent;
ifaceGetPhysicalFunction; ifaceGetPhysicalFunction;
ifaceGetVirtualFunctionIndex; ifaceGetVirtualFunctionIndex;
ifaceGetVlanID; ifaceGetVlanID;
ifaceIsUp;
ifaceIsVirtualFunction; ifaceIsVirtualFunction;
ifaceLinkDel; ifaceLinkDel;
ifaceMacvtapLinkAdd; ifaceMacvtapLinkAdd;

View File

@ -34,7 +34,7 @@
#include "nwfilter_gentech_driver.h" #include "nwfilter_gentech_driver.h"
#include "nwfilter_ebiptables_driver.h" #include "nwfilter_ebiptables_driver.h"
#include "nwfilter_learnipaddr.h" #include "nwfilter_learnipaddr.h"
#include "virnetdev.h"
#define VIR_FROM_THIS VIR_FROM_NWFILTER #define VIR_FROM_THIS VIR_FROM_NWFILTER
@ -963,7 +963,7 @@ virNWFilterInstantiateFilterLate(virConnectPtr conn,
if (rc) { if (rc) {
/* something went wrong... 'DOWN' the interface */ /* something went wrong... 'DOWN' the interface */
if ((ifaceCheck(false, ifname, NULL, ifindex) < 0) || if ((ifaceCheck(false, ifname, NULL, ifindex) < 0) ||
(ifaceDown(ifname) < 0)) { (virNetDevSetOnline(ifname, false) < 0)) {
/* assuming interface disappeared... */ /* assuming interface disappeared... */
_virNWFilterTeardownFilter(ifname); _virNWFilterTeardownFilter(ifname);
} }

View File

@ -54,156 +54,6 @@
virReportErrorHelper(VIR_FROM_NET, code, __FILE__, \ virReportErrorHelper(VIR_FROM_NET, code, __FILE__, \
__FUNCTION__, __LINE__, __VA_ARGS__) __FUNCTION__, __LINE__, __VA_ARGS__)
#if __linux__
static int
getFlags(int fd, const char *ifname, struct ifreq *ifr) {
memset(ifr, 0, sizeof(*ifr));
if (virStrncpy(ifr->ifr_name,
ifname, strlen(ifname), sizeof(ifr->ifr_name)) == NULL)
return -ENODEV;
if (ioctl(fd, SIOCGIFFLAGS, ifr) < 0)
return -errno;
return 0;
}
/**
* ifaceGetFlags
*
* @ifname : name of the interface
* @flags : pointer to short holding the flags on success
*
* Get the flags of the interface. Returns 0 on success, -errno on failure.
*/
int
ifaceGetFlags(const char *ifname, short *flags) {
struct ifreq ifr;
int rc;
int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
if (fd < 0)
return -errno;
rc = getFlags(fd, ifname, &ifr);
*flags = ifr.ifr_flags;
VIR_FORCE_CLOSE(fd);
return rc;
}
int
ifaceIsUp(const char *ifname, bool *up) {
short flags = 0;
int rc = ifaceGetFlags(ifname, &flags);
if (rc < 0)
return rc;
*up = ((flags & IFF_UP) == IFF_UP);
return 0;
}
#else
/* Note: Showstopper on cygwin is only missing PF_PACKET */
int
ifaceGetFlags(const char *ifname ATTRIBUTE_UNUSED,
short *flags ATTRIBUTE_UNUSED) {
ifaceError(VIR_ERR_INTERNAL_ERROR, "%s",
_("ifaceGetFlags is not supported on non-linux platforms"));
return -ENOSYS;
}
int
ifaceIsUp(const char *ifname ATTRIBUTE_UNUSED,
bool *up ATTRIBUTE_UNUSED) {
ifaceError(VIR_ERR_INTERNAL_ERROR, "%s",
_("ifaceIsUp is not supported on non-linux platforms"));
return -ENOSYS;
}
#endif /* __linux__ */
/*
* chgIfaceFlags: Change flags on an interface
*
* @ifname : name of the interface
* @flagclear : the flags to clear
* @flagset : the flags to set
*
* The new flags of the interface will be calculated as
* flagmask = (~0 ^ flagclear)
* newflags = (curflags & flagmask) | flagset;
*
* Returns 0 on success, -errno on failure.
*/
#ifdef __linux__
static int chgIfaceFlags(const char *ifname, short flagclear, short flagset) {
struct ifreq ifr;
int rc = 0;
short flags;
short flagmask = (~0 ^ flagclear);
int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
if (fd < 0)
return -errno;
rc = getFlags(fd, ifname, &ifr);
if (rc < 0)
goto cleanup;
flags = (ifr.ifr_flags & flagmask) | flagset;
if (ifr.ifr_flags != flags) {
ifr.ifr_flags = flags;
if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0)
rc = -errno;
}
cleanup:
VIR_FORCE_CLOSE(fd);
return rc;
}
/*
* ifaceCtrl
* @name: name of the interface
* @up: true (1) for up, false (0) for down
*
* Function to control if an interface is activated (up, 1) or not (down, 0)
*
* Returns 0 on success, -errno on failure.
*/
int
ifaceCtrl(const char *name, bool up)
{
return chgIfaceFlags(name,
(up) ? 0 : IFF_UP,
(up) ? IFF_UP : 0);
}
#else
int
ifaceCtrl(const char *name ATTRIBUTE_UNUSED, bool up ATTRIBUTE_UNUSED)
{
return -ENOSYS;
}
#endif /* __linux__ */
/** /**
* ifaceCheck * ifaceCheck
* *

View File

@ -29,18 +29,6 @@ struct nlattr;
# define NET_SYSFS "/sys/class/net/" # define NET_SYSFS "/sys/class/net/"
int ifaceGetFlags(const char *name, short *flags);
int ifaceIsUp(const char *name, bool *up);
int ifaceCtrl(const char *name, bool up);
static inline int ifaceUp(const char *name) {
return ifaceCtrl(name, true);
}
static inline int ifaceDown(const char *name) {
return ifaceCtrl(name, false);
}
int ifaceCheck(bool reportError, const char *ifname, int ifaceCheck(bool reportError, const char *ifname,
const unsigned char *macaddr, int ifindex); const unsigned char *macaddr, int ifindex);

View File

@ -50,6 +50,7 @@
#include "util.h" #include "util.h"
#include "macvtap.h" #include "macvtap.h"
#include "virnetdev.h"
VIR_ENUM_IMPL(virMacvtapMode, VIR_MACVTAP_MODE_LAST, VIR_ENUM_IMPL(virMacvtapMode, VIR_MACVTAP_MODE_LAST,
"vepa", "vepa",
@ -342,13 +343,7 @@ create_name:
goto link_del_exit; goto link_del_exit;
} }
rc = ifaceUp(cr_ifname); if (virNetDevSetOnline(cr_ifname, true) < 0) {
if (rc < 0) {
virReportSystemError(errno,
_("cannot 'up' interface %s -- another "
"macvtap device may be 'up' and have the same "
"MAC address"),
cr_ifname);
rc = -1; rc = -1;
goto disassociate_exit; goto disassociate_exit;
} }
@ -1129,8 +1124,11 @@ vpAssociatePortProfileId(const char *macvtap_ifname,
(vmOp == VIR_VM_OP_MIGRATE_IN_START) (vmOp == VIR_VM_OP_MIGRATE_IN_START)
? VIR_NETDEV_VPORT_PROFILE_LINK_OP_PREASSOCIATE_RR ? VIR_NETDEV_VPORT_PROFILE_LINK_OP_PREASSOCIATE_RR
: VIR_NETDEV_VPORT_PROFILE_LINK_OP_ASSOCIATE); : VIR_NETDEV_VPORT_PROFILE_LINK_OP_ASSOCIATE);
if (vmOp != VIR_VM_OP_MIGRATE_IN_START && !rc) if (vmOp != VIR_VM_OP_MIGRATE_IN_START && !rc) {
ifaceUp(linkdev); /* XXX bogus error handling */
ignore_value(virNetDevSetOnline(linkdev, true));
}
break; break;
} }
@ -1180,7 +1178,7 @@ vpDisassociatePortProfileId(const char *macvtap_ifname,
/* avoid disassociating twice */ /* avoid disassociating twice */
if (vmOp == VIR_VM_OP_MIGRATE_IN_FINISH) if (vmOp == VIR_VM_OP_MIGRATE_IN_FINISH)
break; break;
ifaceDown(linkdev); ignore_value(virNetDevSetOnline(linkdev, false));
rc = doPortProfileOp8021Qbh(linkdev, macvtap_macaddr, rc = doPortProfileOp8021Qbh(linkdev, macvtap_macaddr,
virtPort, NULL, virtPort, NULL,
VIR_NETDEV_VPORT_PROFILE_LINK_OP_DISASSOCIATE); VIR_NETDEV_VPORT_PROFILE_LINK_OP_DISASSOCIATE);