]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
virnetdev: fix build with old kernel
authorPavel Hrdina <phrdina@redhat.com>
Tue, 10 Mar 2015 16:00:15 +0000 (17:00 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Thu, 12 Mar 2015 16:48:02 +0000 (17:48 +0100)
Commit c9027d8f added a detection of NIC HW features, but some of them
are not available in old kernel.  Very old kernels lack enum
ethtool_flags and even if this enum is present, not all values are
available for all kernels.  To be sure that we have everything in kernel
that we need, we must check for existence of most of that flags, because
only few of them were defined at first.

Also to successfully build libvirt with older kernel we need to include
<linux/types.h> before <linux/ethtool.h> to have __u32 and friends
defined.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
configure.ac
src/util/virnetdev.c

index e0718134516cbb3e5a074789668986bab743d4d9..2fedd1a34d27db7d62e52074e4c4b9a7fdb70a61 100644 (file)
@@ -383,6 +383,11 @@ AC_CHECK_TYPE([struct ifreq],
         #include <net/if.h>
   ]])
 
+AC_CHECK_DECLS([ETH_FLAG_TXVLAN, ETH_FLAG_NTUPLE, ETH_FLAG_RXHASH, ETH_FLAG_LRO,
+                ETHTOOL_GGSO, ETHTOOL_GGRO, ETHTOOL_GFLAGS],
+  [], [], [[#include <linux/ethtool.h>
+  ]])
+
 dnl Our only use of libtasn1.h is in the testsuite, and can be skipped
 dnl if the header is not present.  Assume -ltasn1 is present if the
 dnl header could be found.
index 971db437dcda53782987de9f930309676fbcffa4..093c99c83c44e813fff7306308c27d633f00bc73 100644 (file)
@@ -48,6 +48,7 @@
 #endif
 
 #if defined(SIOCETHTOOL) && defined(HAVE_STRUCT_IFREQ)
+# include <linux/types.h>
 # include <linux/ethtool.h>
 #endif
 
@@ -2800,9 +2801,7 @@ int
 virNetDevGetFeatures(const char *ifname,
                      virBitmapPtr *out)
 {
-    int ret = -1;
     size_t i = -1;
-    size_t j = -1;
     struct ethtool_value cmd = { 0 };
 
     struct elem{
@@ -2815,20 +2814,16 @@ virNetDevGetFeatures(const char *ifname,
         {ETHTOOL_GTXCSUM, VIR_NET_DEV_FEAT_GTXCSUM},
         {ETHTOOL_GSG, VIR_NET_DEV_FEAT_GSG},
         {ETHTOOL_GTSO, VIR_NET_DEV_FEAT_GTSO},
+# if HAVE_DECL_ETHTOOL_GGSO
         {ETHTOOL_GGSO, VIR_NET_DEV_FEAT_GGSO},
+# endif
+# if HAVE_DECL_ETHTOOL_GGRO
         {ETHTOOL_GGRO, VIR_NET_DEV_FEAT_GGRO},
-    };
-    /* ethtool masks */
-    struct elem flags[] = {
-        {ETH_FLAG_LRO, VIR_NET_DEV_FEAT_LRO},
-        {ETH_FLAG_RXVLAN, VIR_NET_DEV_FEAT_RXVLAN},
-        {ETH_FLAG_TXVLAN, VIR_NET_DEV_FEAT_TXVLAN},
-        {ETH_FLAG_NTUPLE, VIR_NET_DEV_FEAT_NTUPLE},
-        {ETH_FLAG_RXHASH, VIR_NET_DEV_FEAT_RXHASH},
+# endif
     };
 
     if (!(*out = virBitmapNew(VIR_NET_DEV_FEAT_LAST)))
-        goto cleanup;
+        return -1;
 
     for (i = 0; i < ARRAY_CARDINALITY(cmds); i++) {
         cmd.cmd = cmds[i].cmd;
@@ -2836,6 +2831,25 @@ virNetDevGetFeatures(const char *ifname,
             ignore_value(virBitmapSetBit(*out, cmds[i].feat));
     }
 
+# if HAVE_DECL_ETHTOOL_GFLAGS
+    size_t j = -1;
+    /* ethtool masks */
+    struct elem flags[] = {
+#  if HAVE_DECL_ETH_FLAG_LRO
+        {ETH_FLAG_LRO, VIR_NET_DEV_FEAT_LRO},
+#  endif
+#  if HAVE_DECL_ETH_FLAG_TXVLAN
+        {ETH_FLAG_RXVLAN, VIR_NET_DEV_FEAT_RXVLAN},
+        {ETH_FLAG_TXVLAN, VIR_NET_DEV_FEAT_TXVLAN},
+#  endif
+#  if HAVE_DECL_ETH_FLAG_NTUBLE
+        {ETH_FLAG_NTUPLE, VIR_NET_DEV_FEAT_NTUPLE},
+#  endif
+#  if HAVE_DECL_ETH_FLAG_RXHASH
+        {ETH_FLAG_RXHASH, VIR_NET_DEV_FEAT_RXHASH},
+#  endif
+    };
+
     cmd.cmd = ETHTOOL_GFLAGS;
     if (virNetDevFeatureAvailable(ifname, &cmd)) {
         for (j = 0; j < ARRAY_CARDINALITY(flags); j++) {
@@ -2843,12 +2857,9 @@ virNetDevGetFeatures(const char *ifname,
                 ignore_value(virBitmapSetBit(*out, flags[j].feat));
         }
     }
+# endif
 
-    ret = 0;
- cleanup:
-
-    return ret;
-
+    return 0;
 }
 #else
 int