[PATCH 02/28] util: move virInterface(State|Link)/virNetDevFeature from conf to util

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

 



These had been declared in conf/device_conf.h, but then used in
util/virnetdev.c, meaning that we had to #include conf/device_conf.h
in virnetdev.c (which we have for a long time said shouldn't be done.

This caused a bigger problem when I tried to #include util/virnetdev.h
in a file in src/conf (which is allowed) - for some reason the
"device_conf.h: File not found" error.

The solution is to move the data types and functions used in util
sources from conf to util. Some names were adjusted during the move
("virInterface" --> "virNetDevIf", and "VIR_INTERFACE" -->
"VIR_NETDEV_IF")
---
 src/conf/device_conf.c      | 31 ++++---------------------------
 src/conf/device_conf.h      | 44 +++-----------------------------------------
 src/conf/domain_conf.c      |  1 +
 src/conf/interface_conf.h   |  2 +-
 src/conf/node_device_conf.h |  2 +-
 src/libvirt_private.syms    |  6 ++++--
 src/util/virnetdev.c        | 31 +++++++++++++++++++++++++++----
 src/util/virnetdev.h        | 40 ++++++++++++++++++++++++++++++++++++++--
 tests/virnetdevtest.c       | 14 +++++++-------
 9 files changed, 86 insertions(+), 85 deletions(-)

diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
index 4280513..f58b9d0 100644
--- a/src/conf/device_conf.c
+++ b/src/conf/device_conf.c
@@ -32,29 +32,6 @@
 
 #define VIR_FROM_THIS VIR_FROM_DEVICE
 
-VIR_ENUM_IMPL(virInterfaceState,
-              VIR_INTERFACE_STATE_LAST,
-              "" /* value of zero means no state */,
-              "unknown", "notpresent",
-              "down", "lowerlayerdown",
-              "testing", "dormant", "up")
-
-VIR_ENUM_IMPL(virNetDevFeature,
-              VIR_NET_DEV_FEAT_LAST,
-              "rx",
-              "tx",
-              "sg",
-              "tso",
-              "gso",
-              "gro",
-              "lro",
-              "rxvlan",
-              "txvlan",
-              "ntuple",
-              "rxhash",
-              "rdma",
-              "txudptnl")
-
 int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr,
                                bool report)
 {
@@ -196,7 +173,7 @@ virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1,
 
 int
 virInterfaceLinkParseXML(xmlNodePtr node,
-                         virInterfaceLinkPtr lnk)
+                         virNetDevIfLinkPtr lnk)
 {
     int ret = -1;
     char *stateStr, *speedStr;
@@ -206,7 +183,7 @@ virInterfaceLinkParseXML(xmlNodePtr node,
     speedStr = virXMLPropString(node, "speed");
 
     if (stateStr) {
-        if ((state = virInterfaceStateTypeFromString(stateStr)) < 0) {
+        if ((state = virNetDevIfStateTypeFromString(stateStr)) < 0) {
             virReportError(VIR_ERR_XML_ERROR,
                            _("unknown link state: %s"),
                            stateStr);
@@ -232,7 +209,7 @@ virInterfaceLinkParseXML(xmlNodePtr node,
 
 int
 virInterfaceLinkFormat(virBufferPtr buf,
-                       const virInterfaceLink *lnk)
+                       const virNetDevIfLink *lnk)
 {
     if (!lnk->speed && !lnk->state) {
         /* If there's nothing to format, return early. */
@@ -244,7 +221,7 @@ virInterfaceLinkFormat(virBufferPtr buf,
         virBufferAsprintf(buf, " speed='%u'", lnk->speed);
     if (lnk->state)
         virBufferAsprintf(buf, " state='%s'",
-                          virInterfaceStateTypeToString(lnk->state));
+                          virNetDevIfStateTypeToString(lnk->state));
     virBufferAddLit(buf, "/>\n");
     return 0;
 }
diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index 847564b..fdd7c3c 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -32,45 +32,7 @@
 # include "virthread.h"
 # include "virbuffer.h"
 # include "virpci.h"
-
-typedef enum {
-    VIR_INTERFACE_STATE_UNKNOWN = 1,
-    VIR_INTERFACE_STATE_NOT_PRESENT,
-    VIR_INTERFACE_STATE_DOWN,
-    VIR_INTERFACE_STATE_LOWER_LAYER_DOWN,
-    VIR_INTERFACE_STATE_TESTING,
-    VIR_INTERFACE_STATE_DORMANT,
-    VIR_INTERFACE_STATE_UP,
-    VIR_INTERFACE_STATE_LAST
-} virInterfaceState;
-
-VIR_ENUM_DECL(virInterfaceState)
-
-typedef struct _virInterfaceLink virInterfaceLink;
-typedef virInterfaceLink *virInterfaceLinkPtr;
-struct _virInterfaceLink {
-    virInterfaceState state; /* link state */
-    unsigned int speed;      /* link speed in Mbits per second */
-};
-
-typedef enum {
-    VIR_NET_DEV_FEAT_GRXCSUM,
-    VIR_NET_DEV_FEAT_GTXCSUM,
-    VIR_NET_DEV_FEAT_GSG,
-    VIR_NET_DEV_FEAT_GTSO,
-    VIR_NET_DEV_FEAT_GGSO,
-    VIR_NET_DEV_FEAT_GGRO,
-    VIR_NET_DEV_FEAT_LRO,
-    VIR_NET_DEV_FEAT_RXVLAN,
-    VIR_NET_DEV_FEAT_TXVLAN,
-    VIR_NET_DEV_FEAT_NTUPLE,
-    VIR_NET_DEV_FEAT_RXHASH,
-    VIR_NET_DEV_FEAT_RDMA,
-    VIR_NET_DEV_FEAT_TXUDPTNL,
-    VIR_NET_DEV_FEAT_LAST
-} virNetDevFeature;
-
-VIR_ENUM_DECL(virNetDevFeature)
+# include "virnetdev.h"
 
 typedef enum {
     VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE,
@@ -216,9 +178,9 @@ bool virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1,
                               virPCIDeviceAddress *addr2);
 
 int virInterfaceLinkParseXML(xmlNodePtr node,
-                             virInterfaceLinkPtr lnk);
+                             virNetDevIfLinkPtr lnk);
 
 int virInterfaceLinkFormat(virBufferPtr buf,
-                           const virInterfaceLink *lnk);
+                           const virNetDevIfLink *lnk);
 
 #endif /* __DEVICE_CONF_H__ */
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 75ad03f..8ff836c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -53,6 +53,7 @@
 #include "network_conf.h"
 #include "virtpm.h"
 #include "virstring.h"
+#include "virnetdev.h"
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h
index ac212fb..5cabec7 100644
--- a/src/conf/interface_conf.h
+++ b/src/conf/interface_conf.h
@@ -147,7 +147,7 @@ struct _virInterfaceDef {
     char *name;              /* interface name */
     unsigned int mtu;        /* maximum transmit size in byte */
     char *mac;               /* MAC address */
-    virInterfaceLink lnk;    /* interface link info */
+    virNetDevIfLink lnk;    /* interface link info */
 
     virInterfaceStartMode startmode; /* how it is started */
 
diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index be6dd5e..9e3e6fe 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -140,7 +140,7 @@ typedef struct _virNodeDevCapData {
             char *address;
             unsigned int address_len;
             char *ifname;
-            virInterfaceLink lnk;
+            virNetDevIfLink lnk;
             virNodeDevNetCapType subtype;  /* LAST -> no subtype */
             virBitmapPtr features; /* enum virNetDevFeature */
         } net;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 00fa673..df2dfc3 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -78,8 +78,6 @@ virCPUModeTypeToString;
 # conf/device_conf.h
 virInterfaceLinkFormat;
 virInterfaceLinkParseXML;
-virInterfaceStateTypeFromString;
-virInterfaceStateTypeToString;
 virPCIDeviceAddressEqual;
 virPCIDeviceAddressFormat;
 virPCIDeviceAddressIsValid;
@@ -1855,6 +1853,8 @@ virNetDevAddRoute;
 virNetDevClearIPAddress;
 virNetDevDelMulti;
 virNetDevExists;
+virNetDevFeatureTypeFromString;
+virNetDevFeatureTypeToString;
 virNetDevGetFeatures;
 virNetDevGetIndex;
 virNetDevGetIPAddress;
@@ -1871,6 +1871,8 @@ virNetDevGetVirtualFunctionIndex;
 virNetDevGetVirtualFunctionInfo;
 virNetDevGetVirtualFunctions;
 virNetDevGetVLanID;
+virNetDevIfStateTypeFromString;
+virNetDevIfStateTypeToString;
 virNetDevIsVirtualFunction;
 virNetDevReplaceMacAddress;
 virNetDevReplaceNetConfig;
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 4cd51cb..fb71c7b 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -2547,10 +2547,33 @@ virNetDevRestoreNetConfig(const char *linkdev ATTRIBUTE_UNUSED,
 
 #endif /* defined(__linux__) && defined(HAVE_LIBNL) */
 
+VIR_ENUM_IMPL(virNetDevIfState,
+              VIR_NETDEV_IF_STATE_LAST,
+              "" /* value of zero means no state */,
+              "unknown", "notpresent",
+              "down", "lowerlayerdown",
+              "testing", "dormant", "up")
+
+VIR_ENUM_IMPL(virNetDevFeature,
+              VIR_NET_DEV_FEAT_LAST,
+              "rx",
+              "tx",
+              "sg",
+              "tso",
+              "gso",
+              "gro",
+              "lro",
+              "rxvlan",
+              "txvlan",
+              "ntuple",
+              "rxhash",
+              "rdma",
+              "txudptnl")
+
 #ifdef __linux__
 int
 virNetDevGetLinkInfo(const char *ifname,
-                     virInterfaceLinkPtr lnk)
+                     virNetDevIfLinkPtr lnk)
 {
     int ret = -1;
     char *path = NULL;
@@ -2580,7 +2603,7 @@ virNetDevGetLinkInfo(const char *ifname,
 
     /* We shouldn't allow 0 here, because
      * virInterfaceState enum starts from 1. */
-    if ((tmp_state = virInterfaceStateTypeFromString(buf)) <= 0) {
+    if ((tmp_state = virNetDevIfStateTypeFromString(buf)) <= 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Unable to parse: %s"),
                        buf);
@@ -2593,7 +2616,7 @@ virNetDevGetLinkInfo(const char *ifname,
      * report several misleading values. While igb reports 65535, realtek goes
      * with 10. To avoid muddying XML with insane values, don't report link
      * speed if that's the case. */
-    if (lnk->state != VIR_INTERFACE_STATE_UP) {
+    if (lnk->state != VIR_NETDEV_IF_STATE_UP) {
         lnk->speed = 0;
         ret = 0;
         goto cleanup;
@@ -2638,7 +2661,7 @@ virNetDevGetLinkInfo(const char *ifname,
 
 int
 virNetDevGetLinkInfo(const char *ifname,
-                     virInterfaceLinkPtr lnk)
+                     virNetDevIfLinkPtr lnk)
 {
     /* Port me */
     VIR_DEBUG("Getting link info on %s is not implemented on this platform",
diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h
index 522536f..849f8e7 100644
--- a/src/util/virnetdev.h
+++ b/src/util/virnetdev.h
@@ -30,7 +30,6 @@
 # include "virmacaddr.h"
 # include "virpci.h"
 # include "virnetdevvlan.h"
-# include "device_conf.h"
 
 # ifdef HAVE_STRUCT_IFREQ
 typedef struct ifreq virIfreq;
@@ -74,6 +73,43 @@ struct _virNetDevRxFilter {
     } vlan;
 };
 
+typedef enum {
+    VIR_NETDEV_IF_STATE_UNKNOWN = 1,
+    VIR_NETDEV_IF_STATE_NOT_PRESENT,
+    VIR_NETDEV_IF_STATE_DOWN,
+    VIR_NETDEV_IF_STATE_LOWER_LAYER_DOWN,
+    VIR_NETDEV_IF_STATE_TESTING,
+    VIR_NETDEV_IF_STATE_DORMANT,
+    VIR_NETDEV_IF_STATE_UP,
+    VIR_NETDEV_IF_STATE_LAST
+} virNetDevIfState;
+
+VIR_ENUM_DECL(virNetDevIfState)
+
+typedef struct {
+    virNetDevIfState state; /* link state */
+    unsigned int speed;      /* link speed in Mbits per second */
+} virNetDevIfLink, *virNetDevIfLinkPtr;
+
+typedef enum {
+    VIR_NET_DEV_FEAT_GRXCSUM,
+    VIR_NET_DEV_FEAT_GTXCSUM,
+    VIR_NET_DEV_FEAT_GSG,
+    VIR_NET_DEV_FEAT_GTSO,
+    VIR_NET_DEV_FEAT_GGSO,
+    VIR_NET_DEV_FEAT_GGRO,
+    VIR_NET_DEV_FEAT_LRO,
+    VIR_NET_DEV_FEAT_RXVLAN,
+    VIR_NET_DEV_FEAT_TXVLAN,
+    VIR_NET_DEV_FEAT_NTUPLE,
+    VIR_NET_DEV_FEAT_RXHASH,
+    VIR_NET_DEV_FEAT_RDMA,
+    VIR_NET_DEV_FEAT_TXUDPTNL,
+    VIR_NET_DEV_FEAT_LAST
+} virNetDevFeature;
+
+VIR_ENUM_DECL(virNetDevFeature)
+
 int virNetDevSetupControl(const char *ifname,
                           virIfreq *ifr)
     ATTRIBUTE_RETURN_CHECK;
@@ -187,7 +223,7 @@ int virNetDevGetFeatures(const char *ifname,
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
 
 int virNetDevGetLinkInfo(const char *ifname,
-                         virInterfaceLinkPtr lnk)
+                         virNetDevIfLinkPtr lnk)
     ATTRIBUTE_NONNULL(1);
 
 virNetDevRxFilterPtr virNetDevRxFilterNew(void)
diff --git a/tests/virnetdevtest.c b/tests/virnetdevtest.c
index 3987a8a..7c8a03f 100644
--- a/tests/virnetdevtest.c
+++ b/tests/virnetdevtest.c
@@ -30,7 +30,7 @@
 
 struct testVirNetDevGetLinkInfoData {
     const char *ifname;         /* ifname to get info on */
-    virInterfaceState state;    /* expected state */
+    virNetDevIfState state;     /* expected state */
     unsigned int speed;         /* expected speed */
 };
 
@@ -39,7 +39,7 @@ testVirNetDevGetLinkInfo(const void *opaque)
 {
     int ret = -1;
     const struct testVirNetDevGetLinkInfoData *data = opaque;
-    virInterfaceLink lnk;
+    virNetDevIfLink lnk;
 
     if (virNetDevGetLinkInfo(data->ifname, &lnk) < 0)
         goto cleanup;
@@ -47,8 +47,8 @@ testVirNetDevGetLinkInfo(const void *opaque)
     if (lnk.state != data->state) {
         fprintf(stderr,
                 "Fetched link state (%s) doesn't match the expected one (%s)",
-                virInterfaceStateTypeToString(lnk.state),
-                virInterfaceStateTypeToString(data->state));
+                virNetDevIfStateTypeToString(lnk.state),
+                virNetDevIfStateTypeToString(data->state));
         goto cleanup;
     }
 
@@ -77,9 +77,9 @@ mymain(void)
             ret = -1;                                                       \
     } while (0)
 
-    DO_TEST_LINK("eth0", VIR_INTERFACE_STATE_UP, 1000);
-    DO_TEST_LINK("lo", VIR_INTERFACE_STATE_UNKNOWN, 0);
-    DO_TEST_LINK("eth0-broken", VIR_INTERFACE_STATE_DOWN, 0);
+    DO_TEST_LINK("eth0", VIR_NETDEV_IF_STATE_UP, 1000);
+    DO_TEST_LINK("lo", VIR_NETDEV_IF_STATE_UNKNOWN, 0);
+    DO_TEST_LINK("eth0-broken", VIR_NETDEV_IF_STATE_DOWN, 0);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
-- 
2.5.5

--
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]