[PATCH 16/33] Remove ifaceUp, ifaceDown, ifaceCtrl & ifaceIsUp APIs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

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
---
 src/libvirt_private.syms               |    3 -
 src/nwfilter/nwfilter_gentech_driver.c |    4 +-
 src/util/interface.c                   |  150 --------------------------------
 src/util/interface.h                   |   12 ---
 src/util/macvtap.c                     |   18 ++--
 5 files changed, 10 insertions(+), 177 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 4bc9217..a88b806 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -576,8 +576,6 @@ virHookPresent;
 
 # interface.h
 ifaceCheck;
-ifaceCtrl;
-ifaceGetFlags;
 ifaceGetIndex;
 ifaceGetMacAddress;
 ifaceGetIPAddress;
@@ -585,7 +583,6 @@ ifaceGetNthParent;
 ifaceGetPhysicalFunction;
 ifaceGetVirtualFunctionIndex;
 ifaceGetVlanID;
-ifaceIsUp;
 ifaceIsVirtualFunction;
 ifaceLinkDel;
 ifaceMacvtapLinkAdd;
diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c
index 7891983..899bd32 100644
--- a/src/nwfilter/nwfilter_gentech_driver.c
+++ b/src/nwfilter/nwfilter_gentech_driver.c
@@ -34,7 +34,7 @@
 #include "nwfilter_gentech_driver.h"
 #include "nwfilter_ebiptables_driver.h"
 #include "nwfilter_learnipaddr.h"
-
+#include "virnetdev.h"
 
 #define VIR_FROM_THIS VIR_FROM_NWFILTER
 
@@ -963,7 +963,7 @@ virNWFilterInstantiateFilterLate(virConnectPtr conn,
     if (rc) {
         /* something went wrong... 'DOWN' the interface */
         if ((ifaceCheck(false, ifname, NULL, ifindex) < 0) ||
-            (ifaceDown(ifname) < 0)) {
+            (virNetDevSetOnline(ifname, false) < 0)) {
             /* assuming interface disappeared... */
             _virNWFilterTeardownFilter(ifname);
         }
diff --git a/src/util/interface.c b/src/util/interface.c
index 12bf7bc..913beb5 100644
--- a/src/util/interface.c
+++ b/src/util/interface.c
@@ -54,156 +54,6 @@
         virReportErrorHelper(VIR_FROM_NET, code, __FILE__, \
                              __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
  *
diff --git a/src/util/interface.h b/src/util/interface.h
index 3603c68..5068adb 100644
--- a/src/util/interface.h
+++ b/src/util/interface.h
@@ -29,18 +29,6 @@ struct nlattr;
 
 # 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,
                const unsigned char *macaddr, int ifindex);
diff --git a/src/util/macvtap.c b/src/util/macvtap.c
index c4629ed..bd3c33c 100644
--- a/src/util/macvtap.c
+++ b/src/util/macvtap.c
@@ -50,6 +50,7 @@
 
 #include "util.h"
 #include "macvtap.h"
+#include "virnetdev.h"
 
 VIR_ENUM_IMPL(virMacvtapMode, VIR_MACVTAP_MODE_LAST,
               "vepa",
@@ -342,13 +343,7 @@ create_name:
         goto link_del_exit;
     }
 
-    rc = ifaceUp(cr_ifname);
-    if (rc < 0) {
-        virReportSystemError(errno,
-                             _("cannot 'up' interface %s -- another "
-                             "macvtap device may be 'up' and have the same "
-                             "MAC address"),
-                             cr_ifname);
+    if (virNetDevSetOnline(cr_ifname, true) < 0) {
         rc = -1;
         goto disassociate_exit;
     }
@@ -1129,8 +1124,11 @@ vpAssociatePortProfileId(const char *macvtap_ifname,
                                     (vmOp == VIR_VM_OP_MIGRATE_IN_START)
                                       ? PREASSOCIATE_RR
                                       : ASSOCIATE);
-        if (vmOp != VIR_VM_OP_MIGRATE_IN_START && !rc)
-            ifaceUp(linkdev);
+        if (vmOp != VIR_VM_OP_MIGRATE_IN_START && !rc) {
+            /* XXX bogus error handling */
+            ignore_value(virNetDevSetOnline(linkdev, true));
+        }
+
         break;
     }
 
@@ -1180,7 +1178,7 @@ vpDisassociatePortProfileId(const char *macvtap_ifname,
         /* avoid disassociating twice */
         if (vmOp == VIR_VM_OP_MIGRATE_IN_FINISH)
             break;
-        ifaceDown(linkdev);
+        ignore_value(virNetDevSetOnline(linkdev, false));
         rc = doPortProfileOp8021Qbh(linkdev, macvtap_macaddr,
                                     virtPort, NULL, DISASSOCIATE);
         break;
-- 
1.7.6.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]