[ovs-dev] [PATCH] config: Add explicit support for building on ESX.

Ethan Jackson ethan at nicira.com
Mon Oct 8 19:49:21 UTC 2012


The ESX userspace looks quite a bit like linux, but has some key
differences which need to be specially handled in the build.  To
distinguish between ESX and systems use the linux datapath module,
this patch adds two new macros "ESX" and "LINUX_DATAPATH".  It uses
these macros to disable building code on ESX which only applies to
a true Linux environment.  In addition, it adds a new
route-table-stub implementation which is required for the build to
complete successfully on ESX.

Signed-off-by: Ethan Jackson <ethan at nicira.com>
---
 configure.ac            |  6 ++++++
 lib/automake.mk         |  7 ++++++-
 lib/command-line.c      |  6 +++---
 lib/dpif.c              |  2 +-
 lib/netdev.c            |  2 +-
 lib/route-table-stub.c  | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/socket-util.c       | 12 ++++++------
 lib/timeval.c           |  2 +-
 lib/vlandev.c           |  4 ++--
 m4/openvswitch.m4       | 10 ++++++++++
 utilities/automake.mk   |  2 +-
 vswitchd/automake.mk    |  2 +-
 vswitchd/system-stats.c |  6 +++---
 13 files changed, 88 insertions(+), 20 deletions(-)
 create mode 100644 lib/route-table-stub.c

diff --git a/configure.ac b/configure.ac
index 9ec5548..ba1e936 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,6 +45,7 @@ AC_SEARCH_LIBS([clock_gettime], [rt])
 AC_SEARCH_LIBS([timer_create], [rt])
 AC_SEARCH_LIBS([pcap_open_live], [pcap])
 
+OVS_CHECK_ESX
 OVS_CHECK_COVERAGE
 OVS_CHECK_NDEBUG
 OVS_CHECK_NETLINK
@@ -112,4 +113,9 @@ AC_CONFIG_COMMANDS([include/openflow/openflow.h.stamp])
 AC_CONFIG_COMMANDS([ovsdb/ovsdbmonitor/dummy], [:])
 AC_CONFIG_COMMANDS([utilities/bugtool/dummy], [:])
 
+AM_CONDITIONAL([LINUX_DATAPATH], [test "$HAVE_NETLINK" = yes -a "$ESX" = no])
+if test "$HAVE_NETLINK" = yes -a "$ESX" = no; then
+    AC_DEFINE([LINUX_DATAPATH], [1], [System uses the linux datapath module.])
+fi
+
 AC_OUTPUT
diff --git a/lib/automake.mk b/lib/automake.mk
index d5927d6..f6b2aa1 100644
--- a/lib/automake.mk
+++ b/lib/automake.mk
@@ -227,7 +227,7 @@ if HAVE_WNO_UNUSED_PARAMETER
 lib_libsflow_a_CFLAGS += -Wno-unused-parameter
 endif
 
-if HAVE_NETLINK
+if LINUX_DATAPATH
 lib_libopenvswitch_a_SOURCES += \
 	lib/dpif-linux.c \
 	lib/dpif-linux.h \
@@ -246,6 +246,11 @@ lib_libopenvswitch_a_SOURCES += \
 	lib/route-table.h
 endif
 
+if ESX
+lib_libopenvswitch_a_SOURCES += \
+        lib/route-table-stub.c
+endif
+
 if HAVE_IF_DL
 lib_libopenvswitch_a_SOURCES += \
 	lib/netdev-bsd.c \
diff --git a/lib/command-line.c b/lib/command-line.c
index ca443a3..76a4e74 100644
--- a/lib/command-line.c
+++ b/lib/command-line.c
@@ -92,7 +92,7 @@ run_command(int argc, char *argv[], const struct command commands[])
 
 /* Process title. */
 
-#ifdef __linux__
+#ifdef LINUX_DATAPATH
 static char *argv_start;       /* Start of command-line arguments in memory. */
 static size_t argv_size;       /* Number of bytes of command-line arguments. */
 static char *saved_proctitle;  /* Saved command-line arguments. */
@@ -179,7 +179,7 @@ proctitle_restore(void)
         saved_proctitle = NULL;
     }
 }
-#else  /* !__linux__ */
+#else  /* !LINUX_DATAPATH*/
 /* Stubs that don't do anything on non-Linux systems. */
 
 void
@@ -196,4 +196,4 @@ void
 proctitle_restore(void)
 {
 }
-#endif  /* !__linux__ */
+#endif  /* !LINUX_DATAPATH */
diff --git a/lib/dpif.c b/lib/dpif.c
index 7f859d7..fa9b30a 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -58,7 +58,7 @@ COVERAGE_DEFINE(dpif_execute);
 COVERAGE_DEFINE(dpif_purge);
 
 static const struct dpif_class *base_dpif_classes[] = {
-#ifdef HAVE_NETLINK
+#ifdef LINUX_DATAPATH
     &dpif_linux_class,
 #endif
     &dpif_netdev_class,
diff --git a/lib/netdev.c b/lib/netdev.c
index 394d895..c135c6f 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -75,7 +75,7 @@ netdev_initialize(void)
 
         fatal_signal_add_hook(close_all_netdevs, NULL, NULL, true);
 
-#ifdef HAVE_NETLINK
+#ifdef LINUX_DATAPATH
         netdev_register_provider(&netdev_linux_class);
         netdev_register_provider(&netdev_internal_class);
         netdev_register_provider(&netdev_tap_class);
diff --git a/lib/route-table-stub.c b/lib/route-table-stub.c
new file mode 100644
index 0000000..fafad28
--- /dev/null
+++ b/lib/route-table-stub.c
@@ -0,0 +1,47 @@
+/* Copyright (c) 2012 Nicira, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. */
+
+#include <config.h>
+#include "route-table.h"
+
+#include "compiler.h"
+
+bool
+route_table_get_name(ovs_be32 ip OVS_UNUSED, char name[IFNAMSIZ] OVS_UNUSED)
+{
+    name[0] = '\0';
+    return false;
+}
+
+bool
+route_table_get_ifindex(ovs_be32 ip OVS_UNUSED, int *ifindex)
+{
+    *ifindex = 0;
+    return false;
+}
+
+void
+route_table_register(void)
+{
+}
+
+void
+route_table_unregister(void)
+{
+}
+
+void
+route_table_run(void)
+{
+}
diff --git a/lib/socket-util.c b/lib/socket-util.c
index f8b44cc..ca9e406 100644
--- a/lib/socket-util.c
+++ b/lib/socket-util.c
@@ -39,7 +39,7 @@
 #include "poll-loop.h"
 #include "util.h"
 #include "vlog.h"
-#if AF_PACKET && __linux__
+#if AF_PACKET && LINUX_DATAPATH
 #include <linux/if_packet.h>
 #endif
 #ifdef HAVE_NETLINK
@@ -51,8 +51,8 @@ VLOG_DEFINE_THIS_MODULE(socket_util);
 
 /* #ifdefs make it a pain to maintain code: you have to try to build both ways.
  * Thus, this file compiles all of the code regardless of the target, by
- * writing "if (LINUX)" instead of "#ifdef __linux__". */
-#ifdef __linux__
+ * writing "if (LINUX)" instead of "#ifdef LINUX_DATAPATH". */
+#ifdef LINUX_DATAPATH
 #define LINUX 1
 #else
 #define LINUX 0
@@ -988,7 +988,7 @@ describe_sockaddr(struct ds *string, int fd,
             }
         }
 #endif
-#if AF_PACKET && __linux__
+#if AF_PACKET && LINUX_DATAPATH
         else if (ss.ss_family == AF_PACKET) {
             struct sockaddr_ll sll;
 
@@ -1018,7 +1018,7 @@ describe_sockaddr(struct ds *string, int fd,
 }
 
 
-#ifdef __linux__
+#ifdef LINUX_DATAPATH
 static void
 put_fd_filename(struct ds *string, int fd)
 {
@@ -1062,7 +1062,7 @@ describe_fd(int fd)
                               : S_ISFIFO(s.st_mode) ? "FIFO"
                               : S_ISLNK(s.st_mode) ? "symbolic link"
                               : "unknown"));
-#ifdef __linux__
+#ifdef LINUX_DATAPATH
         put_fd_filename(&string, fd);
 #endif
     }
diff --git a/lib/timeval.c b/lib/timeval.c
index 77247e8..9c9cf0e 100644
--- a/lib/timeval.c
+++ b/lib/timeval.c
@@ -42,7 +42,7 @@ static clockid_t monotonic_clock;
 
 /* Controls whether or not calls to clock_gettime() are cached.  See
  * time_cached() for a detailed explanation. */
-#if defined __x86_64__ && defined __linux__
+#if defined __x86_64__ && defined LINUX_DATAPATH
 static bool cache_time = false;
 #else
 static bool cache_time = true;
diff --git a/lib/vlandev.c b/lib/vlandev.c
index ffb8e73..2440def 100644
--- a/lib/vlandev.c
+++ b/lib/vlandev.c
@@ -28,7 +28,7 @@
 
 VLOG_DEFINE_THIS_MODULE(vlandev);
 
-#ifdef __linux__
+#ifdef LINUX_DATAPATH
 #include "rtnetlink-link.h"
 #include <linux/if_vlan.h>
 #include <linux/sockios.h>
@@ -208,7 +208,7 @@ vlandev_del(const char *vlan_dev)
     }
     return error;
 }
-#else  /* !__linux__ */
+#else  /* !LINUX_DATAPATH */
 /* Stubs. */
 
 int
diff --git a/m4/openvswitch.m4 b/m4/openvswitch.m4
index 939f296..9d062a7 100644
--- a/m4/openvswitch.m4
+++ b/m4/openvswitch.m4
@@ -46,6 +46,16 @@ AC_DEFUN([OVS_CHECK_NDEBUG],
      [ndebug=false])
    AM_CONDITIONAL([NDEBUG], [test x$ndebug = xtrue])])
 
+dnl Checks for ESX.
+AC_DEFUN([OVS_CHECK_ESX],
+  [AC_CHECK_HEADER([vmware.h],
+                   [ESX=yes],
+                   [ESX=no])
+   AM_CONDITIONAL([ESX], [test "$ESX" = yes])
+   if test "$ESX" = yes; then
+      AC_DEFINE([ESX], [1], [Define to 1 if building on ESX.])
+   fi])
+
 dnl Checks for Netlink support.
 AC_DEFUN([OVS_CHECK_NETLINK],
   [AC_CHECK_HEADER([linux/netlink.h],
diff --git a/utilities/automake.mk b/utilities/automake.mk
index fdd26b8..890f867 100644
--- a/utilities/automake.mk
+++ b/utilities/automake.mk
@@ -108,7 +108,7 @@ utilities_ovs_ofctl_LDADD = \
 utilities_ovs_vsctl_SOURCES = utilities/ovs-vsctl.c
 utilities_ovs_vsctl_LDADD = lib/libopenvswitch.a $(SSL_LIBS)
 
-if HAVE_NETLINK
+if LINUX_DATAPATH
 sbin_PROGRAMS += utilities/ovs-vlan-bug-workaround
 utilities_ovs_vlan_bug_workaround_SOURCES = utilities/ovs-vlan-bug-workaround.c
 utilities_ovs_vlan_bug_workaround_LDADD = lib/libopenvswitch.a $(SSL_LIBS)
diff --git a/vswitchd/automake.mk b/vswitchd/automake.mk
index 9092129..fe513ac 100644
--- a/vswitchd/automake.mk
+++ b/vswitchd/automake.mk
@@ -24,7 +24,7 @@ EXTRA_DIST += vswitchd/INTERNALS
 MAN_ROOTS += vswitchd/ovs-vswitchd.8.in
 
 if BUILD_BRCOMPAT
-if HAVE_NETLINK
+if LINUX_DATAPATH
 sbin_PROGRAMS += vswitchd/ovs-brcompatd
 vswitchd_ovs_brcompatd_SOURCES = \
 	vswitchd/ovs-brcompatd.c
diff --git a/vswitchd/system-stats.c b/vswitchd/system-stats.c
index e0937a3..766e846 100644
--- a/vswitchd/system-stats.c
+++ b/vswitchd/system-stats.c
@@ -48,9 +48,9 @@ VLOG_DEFINE_THIS_MODULE(system_stats);
 
 /* #ifdefs make it a pain to maintain code: you have to try to build both ways.
  * Thus, this file tries to compile as much of the code as possible regardless
- * of the target, by writing "if (LINUX)" instead of "#ifdef __linux__" where
- * this is possible. */
-#ifdef __linux__
+ * of the target, by writing "if (LINUX)" instead of "#ifdef LINUX_DATAPATH"
+ * where this is possible. */
+#ifdef LINUX_DATAPATH
 #include <asm/param.h>
 #define LINUX 1
 #else
-- 
1.7.12




More information about the dev mailing list