[sheepdog] [PATCH v2 1/2] clean up logger.h and util.h include
MORITA Kazutaka
morita.kazutaka at gmail.com
Sat Jul 13 16:29:21 CEST 2013
From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
This also fixes a compiler error which happens when NDEBUG is not
defined.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
collie/farm/farm.h | 1 -
include/compiler.h | 3 +++
include/logger.h | 54 +++++++++++++++-------------------------------
include/sheep.h | 1 -
include/sheepdog_proto.h | 3 ++-
include/strbuf.h | 1 -
include/util.h | 20 ++++++++---------
lib/event.c | 1 -
lib/logger.c | 1 -
lib/net.c | 1 -
lib/util.c | 2 --
lib/work.c | 1 -
sheep/cluster.h | 1 -
sheep/sheep_priv.h | 2 +-
sheepfs/volume.c | 1 -
shepherd/shepherd.c | 1 -
16 files changed, 32 insertions(+), 62 deletions(-)
diff --git a/collie/farm/farm.h b/collie/farm/farm.h
index 5aca4d8..b2d82ed 100644
--- a/collie/farm/farm.h
+++ b/collie/farm/farm.h
@@ -15,7 +15,6 @@
#include "collie.h"
#include "sheep.h"
-#include "logger.h"
#include "strbuf.h"
#include "sha1.h"
diff --git a/include/compiler.h b/include/compiler.h
index 1cd2440..b2ae002 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -17,4 +17,7 @@
#define __printf(a, b) __attribute__((format(printf, a, b)))
+/* Force a compilation error if the condition is true */
+#define BUILD_BUG_ON(condition) ((void)sizeof(struct { int: -!!(condition); }))
+
#endif /* SD_COMPILER_H */
diff --git a/include/logger.h b/include/logger.h
index c2c4237..79eb108 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -46,45 +46,25 @@ int __sd_dump_variable(const char *var, const void *base_sp);
void sd_backtrace(void);
/* sheep log priorities, comliant with syslog spec */
-#define SDOG_EMERG LOG_EMERG
-#define SDOG_ALERT LOG_ALERT
-#define SDOG_CRIT LOG_CRIT
-#define SDOG_ERR LOG_ERR
+#define SDOG_EMERG LOG_EMERG
+#define SDOG_ALERT LOG_ALERT
+#define SDOG_CRIT LOG_CRIT
+#define SDOG_ERR LOG_ERR
#define SDOG_WARNING LOG_WARNING
-#define SDOG_NOTICE LOG_NOTICE
-#define SDOG_INFO LOG_INFO
-#define SDOG_DEBUG LOG_DEBUG
+#define SDOG_NOTICE LOG_NOTICE
+#define SDOG_INFO LOG_INFO
+#define SDOG_DEBUG LOG_DEBUG
-#define sd_printf(level, fmt, args...) \
- do { \
- log_write(level, __func__, __LINE__, fmt, ##args); \
- } while (0)
+#define sd_printf(level, fmt, args...) \
+ log_write(level, __func__, __LINE__, fmt, ##args)
+#define sd_iprintf(fmt, args...) sd_printf(SDOG_INFO, fmt, ##args)
+#define sd_eprintf(fmt, args...) sd_printf(SDOG_ERR, fmt, ##args)
+#define sd_dprintf(fmt, args...) sd_printf(SDOG_DEBUG, fmt, ##args)
-#define panic(fmt, args...) \
- ({ \
- sd_printf(SDOG_EMERG, "PANIC: " fmt, ##args); \
- abort(); \
- })
-
-#define sd_iprintf(fmt, args...) \
- do { \
- log_write(SDOG_INFO, __func__, __LINE__, fmt, ##args); \
- } while (0)
-
-#define sd_eprintf(fmt, args...) \
- do { \
- log_write(SDOG_ERR, __func__, __LINE__, fmt, ##args); \
- } while (0)
-
-#define sd_dprintf(fmt, args...) \
- do { \
- 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();
-}
+#define panic(fmt, args...) \
+({ \
+ sd_printf(SDOG_EMERG, "PANIC: " fmt, ##args); \
+ abort(); \
+})
#endif /* LOG_H */
diff --git a/include/sheep.h b/include/sheep.h
index 9c7f96d..b8d7901 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -16,7 +16,6 @@
#include "util.h"
#include "list.h"
#include "net.h"
-#include "logger.h"
struct sd_vnode {
struct node_id nid;
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 156457a..4e302e9 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -13,9 +13,10 @@
#include <inttypes.h>
#include <stdint.h>
+#include <stdbool.h>
#include <linux/limits.h>
-#include "util.h"
+#include "compiler.h"
#define SD_PROTO_VER 0x02
diff --git a/include/strbuf.h b/include/strbuf.h
index 62eada1..5f599a2 100644
--- a/include/strbuf.h
+++ b/include/strbuf.h
@@ -7,7 +7,6 @@
#include <stdio.h>
#include <stdlib.h>
-#include "logger.h"
#include "util.h"
struct strbuf {
diff --git a/include/util.h b/include/util.h
index 4611cae..b2c5395 100644
--- a/include/util.h
+++ b/include/util.h
@@ -11,6 +11,7 @@
#include <search.h>
#include <urcu/uatomic.h>
+#include "logger.h"
#include "bitops.h"
#include "list.h"
#include "compiler.h"
@@ -159,18 +160,19 @@ int atomic_create_and_write(const char *path, char *buf, size_t len,
})
#ifdef assert
-#undef assert
+#error "Don't include assert.h, use util.h for assert()"
#endif
#ifndef NDEBUG
-
-#define assert(expr) ((expr) ? \
- (void)0 : do_assert(#expr, __func__, __LINE__))
-
+#define assert(expr) \
+({ \
+ if (!(expr)) { \
+ sd_printf(SDOG_EMERG, "Asserting `%s' failed.", #expr); \
+ abort(); \
+ } \
+})
#else
-
#define assert(expr) ((void)0)
-
#endif /* NDEBUG */
/* urcu helpers */
@@ -266,8 +268,4 @@ static inline bool is_stdout_console(void)
extern mode_t sd_def_fmode;
extern mode_t sd_def_dmode;
-
-/* Force a compilation error if the condition is true */
-#define BUILD_BUG_ON(condition) ((void)sizeof(struct { int: -!!(condition); }))
-
#endif
diff --git a/lib/event.c b/lib/event.c
index 3f29d97..0c69ac8 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -19,7 +19,6 @@
#include "list.h"
#include "util.h"
#include "event.h"
-#include "logger.h"
static int efd;
static LIST_HEAD(events_list);
diff --git a/lib/logger.c b/lib/logger.c
index e957706..ad2bc6a 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -35,7 +35,6 @@
#include <execinfo.h>
#include <linux/limits.h>
-#include "logger.h"
#include "util.h"
static bool colorize;
diff --git a/lib/net.c b/lib/net.c
index d3e8e91..97be3df 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -32,7 +32,6 @@
#include "util.h"
#include "event.h"
#include "net.h"
-#include "logger.h"
int conn_tx_off(struct connection *conn)
{
diff --git a/lib/util.c b/lib/util.c
index 417328b..69bedfb 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -18,14 +18,12 @@
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
-#include <assert.h>
#include <ctype.h>
#include <signal.h>
#include <sys/xattr.h>
#include <fcntl.h>
#include "util.h"
-#include "logger.h"
mode_t sd_def_dmode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP;
mode_t sd_def_fmode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
diff --git a/lib/work.c b/lib/work.c
index b09c0db..49364c7 100644
--- a/lib/work.c
+++ b/lib/work.c
@@ -30,7 +30,6 @@
#include "list.h"
#include "util.h"
#include "work.h"
-#include "logger.h"
#include "event.h"
/*
diff --git a/sheep/cluster.h b/sheep/cluster.h
index 041578b..2c9c779 100644
--- a/sheep/cluster.h
+++ b/sheep/cluster.h
@@ -21,7 +21,6 @@
#include "sheepdog_proto.h"
#include "sheep.h"
-#include "logger.h"
#include "config.h"
/* maximum payload size sent in ->notify and ->unblock */
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index ab7778b..4d7f28e 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -33,7 +33,7 @@
#include "sheepdog_proto.h"
#include "event.h"
-#include "logger.h"
+#include "util.h"
#include "work.h"
#include "net.h"
#include "sheep.h"
diff --git a/sheepfs/volume.c b/sheepfs/volume.c
index 4000e97..f387962 100644
--- a/sheepfs/volume.c
+++ b/sheepfs/volume.c
@@ -18,7 +18,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
-#include <assert.h>
#include <urcu/uatomic.h>
#include <pthread.h>
diff --git a/shepherd/shepherd.c b/shepherd/shepherd.c
index 6e102b3..f85832f 100644
--- a/shepherd/shepherd.c
+++ b/shepherd/shepherd.c
@@ -15,7 +15,6 @@
#include <stdbool.h>
#include <stdint.h>
#include <errno.h>
-#include <assert.h>
#include <getopt.h>
#include <unistd.h>
--
1.7.9.5
More information about the sheepdog
mailing list