[PATCH] interface: list all interfaces with flags == 0

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

 



virConnectListAllInterfaces should support to list all of
interfaces when the value of flags is 0. The behaviour is
consistent with other virConnectListAll* APIs
---
 src/conf/interface_conf.h               |  4 ++++
 src/interface/interface_backend_netcf.c | 27 +++++++++++++--------------
 src/interface/interface_backend_udev.c  | 23 ++++++++++-------------
 3 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h
index e636c35..ae93811 100644
--- a/src/conf/interface_conf.h
+++ b/src/conf/interface_conf.h
@@ -211,4 +211,8 @@ char *virInterfaceDefFormat(const virInterfaceDefPtr def);
 void virInterfaceObjLock(virInterfaceObjPtr obj);
 void virInterfaceObjUnlock(virInterfaceObjPtr obj);
 
+#define VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE   \
+                (VIR_CONNECT_LIST_INTERFACES_ACTIVE | \
+                 VIR_CONNECT_LIST_INTERFACES_INACTIVE)
+
 #endif /* __INTERFACE_CONF_H__ */
diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c
index cbba4fd..c6e069a 100644
--- a/src/interface/interface_backend_netcf.c
+++ b/src/interface/interface_backend_netcf.c
@@ -260,6 +260,7 @@ static int netcfConnectListDefinedInterfaces(virConnectPtr conn, char **const na
 
 }
 
+#define MATCH(FLAG) (flags & (FLAG))
 static int
 netcfConnectListAllInterfaces(virConnectPtr conn,
                               virInterfacePtr **ifaces,
@@ -276,8 +277,7 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
     int ret = -1;
     char **names = NULL;
 
-    virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE |
-                  VIR_CONNECT_LIST_INTERFACES_INACTIVE, -1);
+    virCheckFlags(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE, -1);
 
     interfaceDriverLock(driver);
 
@@ -293,7 +293,6 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
                        _("failed to get number of host interfaces: %s%s%s"),
                        errmsg, details ? " - " : "",
                        details ? details : "");
-        ret = -1;
         goto cleanup;
     }
 
@@ -304,7 +303,6 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
 
     if (VIR_ALLOC_N(names, count) < 0) {
         virReportOOMError();
-        ret = -1;
         goto cleanup;
     }
 
@@ -361,16 +359,17 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
         /* XXX: Filter the result, need to be splitted once new filter flags
          * except active|inactive are supported.
          */
-        if (((status & NETCF_IFACE_ACTIVE) &&
-             (flags & VIR_CONNECT_LIST_INTERFACES_ACTIVE)) ||
-            ((status & NETCF_IFACE_INACTIVE) &&
-             (flags & VIR_CONNECT_LIST_INTERFACES_INACTIVE))) {
-            if (ifaces) {
-                iface_obj = virGetInterface(conn, ncf_if_name(iface),
-                                            ncf_if_mac_string(iface));
-                tmp_iface_objs[niface_objs] = iface_obj;
-            }
-            niface_objs++;
+        if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) &&
+            !((MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) &&
+               (status & NETCF_IFACE_ACTIVE)) ||
+              (MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) &&
+               (status & NETCF_IFACE_INACTIVE))))
+            continue;
+
+        if (ifaces) {
+            iface_obj = virGetInterface(conn, ncf_if_name(iface),
+                                        ncf_if_mac_string(iface));
+            tmp_iface_objs[niface_objs++] = iface_obj;
         }
 
         ncf_if_free(iface);
diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c
index 1fd7d46..242fc15 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -282,6 +282,7 @@ udevConnectListDefinedInterfaces(virConnectPtr conn,
                                       VIR_UDEV_IFACE_INACTIVE);
 }
 
+#define MATCH(FLAG) (flags & (FLAG))
 static int
 udevConnectListAllInterfaces(virConnectPtr conn,
                              virInterfacePtr **ifaces,
@@ -299,8 +300,7 @@ udevConnectListAllInterfaces(virConnectPtr conn,
     int status = 0;
     int ret;
 
-    virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE |
-                  VIR_CONNECT_LIST_INTERFACES_INACTIVE, -1);
+    virCheckFlags(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE, -1);
 
     /* Grab a udev reference */
     udev = udev_ref(driverState->udev);
@@ -354,7 +354,6 @@ udevConnectListAllInterfaces(virConnectPtr conn,
         const char *path;
         const char *name;
         const char *macaddr;
-        int add_to_list = 0;
 
         path = udev_list_entry_get_name(dev_entry);
         dev = udev_device_new_from_syspath(udev, path);
@@ -363,18 +362,15 @@ udevConnectListAllInterfaces(virConnectPtr conn,
         status = STREQ(udev_device_get_sysattr_value(dev, "operstate"), "up");
 
         /* Filter the results */
-        if (status && (flags & VIR_CONNECT_LIST_INTERFACES_ACTIVE))
-            add_to_list = 1;
-        else if (!status && (flags & VIR_CONNECT_LIST_INTERFACES_INACTIVE))
-            add_to_list = 1;
+        if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) &&
+            !((MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) && status) ||
+              (MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) && !status)))
+            continue;
 
         /* If we matched a filter, then add it */
-        if (add_to_list) {
-            if (ifaces) {
-                iface_obj = virGetInterface(conn, name, macaddr);
-                ifaces_list[count] = iface_obj;
-            }
-            count++;
+        if (ifaces) {
+            iface_obj = virGetInterface(conn, name, macaddr);
+            ifaces_list[count++] = iface_obj;
         }
         udev_device_unref(dev);
     }
@@ -387,6 +383,7 @@ udevConnectListAllInterfaces(virConnectPtr conn,
     if (ifaces) {
         ignore_value(VIR_REALLOC_N(ifaces_list, count + 1));
         *ifaces = ifaces_list;
+        ifaces_list = NULL;
     }
 
     return count;
-- 
1.8.1.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]