Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / libcfs / include / libcfs / libcfs_private.h
index e0a27a9..dd04602 100644 (file)
@@ -87,7 +87,7 @@
          else {                                                         \
                  libcfs_debug_msg(NULL, DEBUG_SUBSYSTEM, D_EMERG,       \
                                   __FILE__, __FUNCTION__,__LINE__,      \
-                                  "ASSERTION(" #cond ") failed:" fmt,   \
+                                  "ASSERTION(" #cond ") failed: " fmt,  \
                                   ## a);                                \
                  LBUG();                                                \
          }                                                              \
         if (unlikely(!(cond))) {                                        \
                 libcfs_debug_msg(NULL, DEBUG_SUBSYSTEM, D_EMERG,        \
                                  __FILE__, __FUNCTION__,__LINE__,       \
-                                 "ASSERTION(" #cond ") failed:" fmt,    \
+                                 "ASSERTION(" #cond ") failed: " fmt,   \
                                  ## a);                                 \
                 LBUG();                                                 \
         }                                                               \
 
 
 #endif /* !LASSERT_CHECKED */
-
-
 #else /* !LIBCFS_DEBUG */
-#define LASSERT(e) ((void)(0))
-#define LASSERTF(cond, fmt...) ((void)(0))
+/* sizeof is to use expression without evaluating it. */
+# define LASSERT(e) ((void)sizeof!!(e))
+# define LASSERTF(cond, fmt...) ((void)sizeof!!(cond))
 #endif /* !LIBCFS_DEBUG */
 
+#ifdef INVARIANT_CHECK
+/**
+ * This is for more expensive checks that one doesn't want to be enabled all
+ * the time. LINVRNT() has to be explicitly enabled by --enable-invariants
+ * configure option.
+ */
+# define LINVRNT(exp) LASSERT(exp)
+#else
+# define LINVRNT(exp) ((void)sizeof!!(exp))
+#endif
+
 #define KLASSERT(e) LASSERT(e)
 
-void lbug_with_loc(char *file, const char *func, const int line)
+void lbug_with_loc(const char *file, const char *func, const int line)
         __attribute__((noreturn));
 
 #define LBUG() lbug_with_loc(__FILE__, __FUNCTION__, __LINE__)
@@ -213,12 +223,12 @@ do {                                                                    \
 
 void libcfs_debug_dumpstack(cfs_task_t *tsk);
 void libcfs_run_upcall(char **argv);
-void libcfs_run_lbug_upcall(char * file, const char *fn, const int line);
+void libcfs_run_lbug_upcall(const char * file, const char *fn, const int line);
 void libcfs_debug_dumplog(void);
 int libcfs_debug_init(unsigned long bufsize);
 int libcfs_debug_cleanup(void);
 int libcfs_debug_clear_buffer(void);
-int libcfs_debug_mark_buffer(char *text);
+int libcfs_debug_mark_buffer(const char *text);
 
 void libcfs_debug_set_level(unsigned int debug_level);
 
@@ -234,12 +244,18 @@ do {                                                                           \
           assert(cond);                                                        \
 } while (0)
 #  define LBUG()   assert(0)
+#  ifdef INVARIANT_CHECK
+#   define LINVRNT(exp) LASSERT(exp)
+#  else
+#   define LINVRNT(exp) ((void)sizeof!!(exp))
+#  endif
 # else
-#  define LASSERT(e) ((void)(0))
-#  define LASSERTF(cond, args...) do { } while (0)
+#  define LASSERT(e) ((void)sizeof!!(e))
+#  define LASSERTF(cond, args...) ((void)sizeof!!(cond))
 #  define LBUG()   ((void)(0))
+#  define LINVRNT(exp) ((void)sizeof!!(exp))
 # endif /* LIBCFS_DEBUG */
-# define KLASSERT(e) do { } while (0)
+# define KLASSERT(e) ((void)0)
 # define printk(format, args...) printf (format, ## args)
 # ifdef CRAY_XT3                                /* buggy calloc! */
 #  define LIBCFS_ALLOC(ptr, size)               \
@@ -262,8 +278,8 @@ int libcfs_debug_cleanup(void);
  * specific implementations come from the above header files
  */
 
-#define likely(x)      __builtin_expect(!!(x), 1)
-#define unlikely(x)    __builtin_expect(!!(x), 0)
+#define likely(x)      __builtin_expect(!!(x), 1)
+#define unlikely(x)    __builtin_expect(!!(x), 0)
 
 /* !__KERNEL__ */
 #endif