Use __linux__ instead of LINUX_DATAPATH in C code.
authorBen Pfaff <blp@nicira.com>
Thu, 23 Jan 2014 23:33:25 +0000 (15:33 -0800)
committerBen Pfaff <blp@nicira.com>
Wed, 5 Mar 2014 15:51:55 +0000 (07:51 -0800)
The LINUX_DATAPATH C preprocessor symbol was originally meant to be used as
a signal for whether the Linux datapath module could be used, but it was
used as a proxy for a lot of other stuff that is really just Linux
specific.  This commit switches all of these users to just test for
__linux__, which is more straightforward and should have the same result.

CC: Luigi Rizzo <rizzo@iet.unipi.it>
Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/command-line.c
lib/dpif.c
lib/netdev.c
lib/socket-util.c
lib/vlandev.c
vswitchd/system-stats.c

index 805e51b..cb73a25 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011, 2013 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2013, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -93,7 +93,7 @@ run_command(int argc, char *argv[], const struct command commands[])
 \f
 /* Process title. */
 
-#ifdef LINUX_DATAPATH
+#ifdef __linux__
 static struct ovs_mutex proctitle_mutex = OVS_MUTEX_INITIALIZER;
 
 /* Start of command-line arguments in memory. */
@@ -199,7 +199,7 @@ proctitle_restore(void)
     }
     ovs_mutex_unlock(&proctitle_mutex);
 }
-#else  /* !LINUX_DATAPATH*/
+#else  /* !__linux__ */
 /* Stubs that don't do anything on non-Linux systems. */
 
 void
@@ -219,4 +219,4 @@ void
 proctitle_restore(void)
 {
 }
-#endif  /* !LINUX_DATAPATH */
+#endif  /* !__linux__ */
index 8cb2145..b983b25 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -57,7 +57,7 @@ COVERAGE_DEFINE(dpif_purge);
 COVERAGE_DEFINE(dpif_execute_with_help);
 
 static const struct dpif_class *base_dpif_classes[] = {
-#ifdef LINUX_DATAPATH
+#ifdef __linux__
     &dpif_linux_class,
 #endif
     &dpif_netdev_class,
index 4c1d38a..0567759 100644 (file)
@@ -102,7 +102,7 @@ netdev_initialize(void)
         fatal_signal_add_hook(restore_all_flags, NULL, NULL, true);
         netdev_vport_patch_register();
 
-#ifdef LINUX_DATAPATH
+#ifdef __linux__
         netdev_register_provider(&netdev_linux_class);
         netdev_register_provider(&netdev_internal_class);
         netdev_register_provider(&netdev_tap_class);
index f7d2d0f..4c79cd6 100644 (file)
@@ -39,7 +39,7 @@
 #include "poll-loop.h"
 #include "util.h"
 #include "vlog.h"
-#if AF_PACKET && LINUX_DATAPATH
+#ifdef __linux__
 #include <linux/if_packet.h>
 #endif
 #ifdef HAVE_NETLINK
@@ -51,9 +51,11 @@ 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_DATAPATH)" instead of "#ifdef __linux__". */
-#ifndef LINUX_DATAPATH
-#define LINUX_DATAPATH 0
+ * writing "if (LINUX)" instead of "#ifdef __linux__". */
+#ifdef __linux__
+#define LINUX 0
+#else
+#define LINUX 1
 #endif
 
 #ifndef O_DIRECTORY
@@ -292,7 +294,7 @@ drain_rcvbuf(int fd)
          *
          * On other Unix-like OSes, MSG_TRUNC has no effect in the flags
          * argument. */
-        char buffer[LINUX_DATAPATH ? 1 : 2048];
+        char buffer[LINUX ? 1 : 2048];
         ssize_t n_bytes = recv(fd, buffer, sizeof buffer,
                                MSG_TRUNC | MSG_DONTWAIT);
         if (n_bytes <= 0 || n_bytes >= rcvbuf) {
@@ -350,7 +352,7 @@ shorten_name_via_proc(const char *name, char short_name[MAX_UN_LEN + 1],
     int dirfd;
     int len;
 
-    if (!LINUX_DATAPATH) {
+    if (LINUX) {
         return ENAMETOOLONG;
     }
 
@@ -1146,7 +1148,7 @@ describe_sockaddr(struct ds *string, int fd,
             }
         }
 #endif
-#if AF_PACKET && LINUX_DATAPATH
+#if __linux__
         else if (ss.ss_family == AF_PACKET) {
             struct sockaddr_ll sll;
 
@@ -1176,7 +1178,7 @@ describe_sockaddr(struct ds *string, int fd,
 }
 
 
-#ifdef LINUX_DATAPATH
+#ifdef __linux__
 static void
 put_fd_filename(struct ds *string, int fd)
 {
@@ -1221,7 +1223,7 @@ describe_fd(int fd)
                               : S_ISFIFO(s.st_mode) ? "FIFO"
                               : S_ISLNK(s.st_mode) ? "symbolic link"
                               : "unknown"));
-#ifdef LINUX_DATAPATH
+#ifdef __linux__
         put_fd_filename(&string, fd);
 #endif
     }
index b793f77..382487c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2013 Nicira, Inc.
+ * Copyright (c) 2011, 2013, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ struct vlandev_class {
     int (*vd_del)(const char *vlan_dev);
 };
 
-#ifdef LINUX_DATAPATH
+#ifdef __linux__
 static const struct vlandev_class vlandev_linux_class;
 #endif
 static const struct vlandev_class vlandev_stub_class;
@@ -61,7 +61,7 @@ static const struct vlandev_class *
 vlandev_get_class(void)
 {
     if (!vd_class) {
-#ifdef LINUX_DATAPATH
+#if __linux__
         vd_class = &vlandev_linux_class;
 #else
         vd_class = &vlandev_stub_class;
@@ -161,7 +161,7 @@ vlandev_get_name(const char *real_dev_name, int vid)
 \f
 /* The Linux vlandev implementation. */
 
-#ifdef LINUX_DATAPATH
+#ifdef __linux__
 #include "rtnetlink-link.h"
 #include <linux/if_vlan.h>
 #include <linux/sockios.h>
index 1d9cb78..ca98b03 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010, 2012, 2013 Nicira, Inc.
+/* Copyright (c) 2010, 2012, 2013, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -48,12 +48,13 @@ 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_DATAPATH)" instead of "#ifdef
- * __linux__" where this is possible. */
-#ifdef LINUX_DATAPATH
+ * of the target, by writing "if (LINUX)" instead of "#ifdef __linux__" where
+ * this is possible. */
+#ifdef __linux__
+#define LINUX 1
 #include <asm/param.h>
 #else
-#define LINUX_DATAPATH 0
+#define LINUX 0
 #endif
 
 static void
@@ -96,7 +97,7 @@ get_page_size(void)
 static void
 get_memory_stats(struct smap *stats)
 {
-    if (!LINUX_DATAPATH) {
+    if (!LINUX) {
         unsigned int pagesize = get_page_size();
 #ifdef _SC_PHYS_PAGES
         long int phys_pages = sysconf(_SC_PHYS_PAGES);
@@ -174,7 +175,7 @@ get_boot_time(void)
     static long long int cache_expiration = LLONG_MIN;
     static long long int boot_time;
 
-    ovs_assert(LINUX_DATAPATH);
+    ovs_assert(LINUX);
 
     if (time_msec() >= cache_expiration) {
         static const char stat_file[] = "/proc/stat";
@@ -207,7 +208,7 @@ get_boot_time(void)
 static unsigned long long int
 ticks_to_ms(unsigned long long int ticks)
 {
-    ovs_assert(LINUX_DATAPATH);
+    ovs_assert(LINUX);
 
 #ifndef USER_HZ
 #define USER_HZ 100
@@ -240,7 +241,7 @@ get_raw_process_info(pid_t pid, struct raw_process_info *raw)
     FILE *stream;
     int n;
 
-    ovs_assert(LINUX_DATAPATH);
+    ovs_assert(LINUX);
 
     sprintf(file_name, "/proc/%lu/stat", (unsigned long int) pid);
     stream = fopen(file_name, "r");
@@ -326,7 +327,7 @@ count_crashes(pid_t pid)
     int crashes = 0;
     FILE *stream;
 
-    ovs_assert(LINUX_DATAPATH);
+    ovs_assert(LINUX);
 
     sprintf(file_name, "/proc/%lu/cmdline", (unsigned long int) pid);
     stream = fopen(file_name, "r");
@@ -369,7 +370,7 @@ get_process_info(pid_t pid, struct process_info *pinfo)
 {
     struct raw_process_info child;
 
-    ovs_assert(LINUX_DATAPATH);
+    ovs_assert(LINUX);
     if (!get_raw_process_info(pid, &child)) {
         return false;
     }
@@ -435,7 +436,7 @@ get_process_stats(struct smap *stats)
         key = xasprintf("process_%.*s",
                         (int) (extension - de->d_name), de->d_name);
         if (!smap_get(stats, key)) {
-            if (LINUX_DATAPATH && get_process_info(pid, &pinfo)) {
+            if (LINUX && get_process_info(pid, &pinfo)) {
                 smap_add_format(stats, key, "%lu,%lu,%lld,%d,%lld,%lld",
                                 pinfo.vsz, pinfo.rss, pinfo.cputime,
                                 pinfo.crashes, pinfo.booted, pinfo.uptime);