[sheepdog] [PATCH 1/8] util: clean assert

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Tue Jul 9 04:36:35 CEST 2013


Current sheepdog specialized assert() in util.h cannot be used by
util.h itself because it depends on logger.h and logger.h depends on
util.h, too.

This patch solves this cyclic dependency.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 collie/treeview.c     |    1 +
 include/logger.h      |    6 ++++++
 include/util.h        |   32 +++++++++++++++++---------------
 sheepfs/shadow_file.c |    1 +
 4 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/collie/treeview.c b/collie/treeview.c
index 2910170..3715663 100644
--- a/collie/treeview.c
+++ b/collie/treeview.c
@@ -15,6 +15,7 @@
 
 #include "util.h"
 #include "treeview.h"
+#include "logger.h"
 
 #ifndef MAX_DEPTH
 #define MAX_DEPTH    100
diff --git a/include/logger.h b/include/logger.h
index 5c9aab6..41a1488 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -81,4 +81,10 @@ void sd_backtrace(void);
 		log_write(SDOG_DEBUG, __func__, __LINE__, fmt, ##args);	\
 	} while (0)
 
+static inline void do_assert(const char *expr, const char *func, int line)
+{
+	log_write(SDOG_EMERG, func, line, "Asserting `%s' failed.", expr);
+	abort();
+}
+
 #endif	/* LOG_H */
diff --git a/include/util.h b/include/util.h
index e70bb9f..ce5ce07 100644
--- a/include/util.h
+++ b/include/util.h
@@ -14,6 +14,23 @@
 #include "bitops.h"
 #include "list.h"
 
+static inline void do_assert(const char *expr, const char *func, int line);
+
+#ifdef assert
+#undef assert
+#endif
+
+#ifndef NDEBUG
+
+#define assert(expr) ((expr) ?				\
+			(void)0 : do_assert(#expr, __func__, __LINE__))
+
+#else
+
+#define assert(expr) ((void)0)
+
+#endif	/* NDEBUG */
+
 #define SECTOR_SIZE (1U << 9)
 #define BLOCK_SIZE (1U << 12)
 
@@ -161,21 +178,6 @@ int atomic_create_and_write(const char *path, char *buf, size_t len);
 	__removed;							\
 })
 
-#ifdef assert
-#undef assert
-#endif
-
-#ifndef NDEBUG
-
-#define assert(expr) ((expr) ?						\
-			(void)0 : panic("Asserting `%s' failed.", #expr))
-
-#else
-
-#define assert(expr) ((void)0)
-
-#endif	/* NDEBUG */
-
 /* urcu helpers */
 
 /* Boolean data type which can be accessed by multiple threads */
diff --git a/sheepfs/shadow_file.c b/sheepfs/shadow_file.c
index 9579c78..fdb1cc4 100644
--- a/sheepfs/shadow_file.c
+++ b/sheepfs/shadow_file.c
@@ -26,6 +26,7 @@
 
 #include "util.h"
 #include "sheepfs.h"
+#include "logger.h"
 
 int shadow_file_read(const char *path, char *buf, size_t size, off_t offset)
 {
-- 
1.7.10.4




More information about the sheepdog mailing list