[sheepdog] [PATCH RFC] employ gnu99 style of GCC

Hitoshi Mitake mitake.hitoshi at gmail.com
Mon Apr 29 11:15:06 CEST 2013


This patch lets sheepdog employ gnu99 (C99 + gnu extensions) style of
GCC. The main benefit of gnu99 is allowing interleaved statements and
declarations. sheepdog source tree has many functions with lots of
local variable declarations on their head part. They are harmful from
the perspective of readability. Basically, variable declarations
should be delayed until they are actually required. With gnu99, we can
write interleaved statements and declarations, so this can improve the
readability of sheepdog.

The RB_ROOT constant is not friendly with gnu99, so this patch also
eliminate them. The essential role of the constant is
zero-clearing rb_root. It should not be done with static declared
variables. For not static declared rb_root, this patch adds
rb_init_root() for initialization.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>

---
 configure.ac              |    2 +-
 include/rbtree.h          |    6 +++++-
 sheep/cluster/zookeeper.c |    2 +-
 sheep/object_cache.c      |    2 +-
 sheep/object_list_cache.c |    1 -
 sheep/sockfd_cache.c      |    1 -
 sheep/vdi.c               |    2 +-
 sheepfs/volume.c          |    2 +-
 8 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/configure.ac b/configure.ac
index 0787b6f..fac698b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -354,7 +354,7 @@ fi
 # final build of *FLAGS
 CFLAGS="$ENV_CFLAGS $OPT_CFLAGS $GDB_FLAGS $OS_CFLAGS \
 	$TRACE_CFLAGS $COVERAGE_CFLAGS $EXTRA_WARNINGS $WERROR_CFLAGS $NSS_CFLAGS \
-	-D_GNU_SOURCE -D_LGPL_SOURCE"
+	-D_GNU_SOURCE -D_LGPL_SOURCE -std=gnu99"
 CPPFLAGS="$ENV_CPPFLAGS $ANSI_CPPFLAGS $OS_CPPFLAGS"
 LDFLAGS="$ENV_LDFLAGS $COVERAGE_LDFLAGS $OS_LDFLAGS $TRACE_LDFLAGS"
 
diff --git a/include/rbtree.h b/include/rbtree.h
index 27c511b..933a0b5 100644
--- a/include/rbtree.h
+++ b/include/rbtree.h
@@ -30,7 +30,6 @@ static inline void rb_set_color(struct rb_node *rb, int color)
 	rb->rb_parent_color = (rb->rb_parent_color & ~1) | color;
 }
 
-#define RB_ROOT ((struct rb_root) { NULL, })
 #define rb_entry(ptr, type, member) container_of(ptr, type, member)
 
 #define RB_EMPTY_ROOT(root)     ((root)->rb_node == NULL)
@@ -45,6 +44,11 @@ static inline void rb_init_node(struct rb_node *rb)
 	RB_CLEAR_NODE(rb);
 }
 
+static inline void rb_init_root(struct rb_root *rb)
+{
+	rb->rb_node = NULL;
+}
+
 void rb_insert_color(struct rb_node *, struct rb_root *);
 void rb_erase(struct rb_node *, struct rb_root *);
 
diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index 25152b3..8cd5c30 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -69,7 +69,7 @@ struct zk_event {
 
 static struct sd_node sd_nodes[SD_MAX_NODES];
 static size_t nr_sd_nodes;
-static struct rb_root zk_node_root = RB_ROOT;
+static struct rb_root zk_node_root;
 static pthread_rwlock_t zk_tree_lock = PTHREAD_RWLOCK_INITIALIZER;
 static LIST_HEAD(zk_block_list);
 
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 4eb8e9b..0bf5de8 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -591,7 +591,7 @@ not_found:
 	if (create) {
 		cache = xzalloc(sizeof(*cache));
 		cache->vid = vid;
-		cache->lru_tree = RB_ROOT;
+		rb_init_root(&cache->lru_tree);
 		create_dir_for(vid);
 		cache->push_efd = eventfd(0, 0);
 
diff --git a/sheep/object_list_cache.c b/sheep/object_list_cache.c
index 28a75ee..1ece8b9 100644
--- a/sheep/object_list_cache.c
+++ b/sheep/object_list_cache.c
@@ -44,7 +44,6 @@ struct objlist_deletion_work {
 
 static struct objlist_cache obj_list_cache = {
 	.tree_version	= 1,
-	.root		= RB_ROOT,
 	.entry_list     = LIST_HEAD_INIT(obj_list_cache.entry_list),
 	.lock		= PTHREAD_RWLOCK_INITIALIZER,
 };
diff --git a/sheep/sockfd_cache.c b/sheep/sockfd_cache.c
index 217472d..7ffeb02 100644
--- a/sheep/sockfd_cache.c
+++ b/sheep/sockfd_cache.c
@@ -45,7 +45,6 @@ struct sockfd_cache {
 };
 
 static struct sockfd_cache sockfd_cache = {
-	.root = RB_ROOT,
 	.lock = PTHREAD_RWLOCK_INITIALIZER,
 };
 
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 8b7a11f..987cbd0 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -23,7 +23,7 @@ struct vdi_copy_entry {
 };
 
 static uint32_t max_copies;
-static struct rb_root vdi_copy_root = RB_ROOT;
+static struct rb_root vdi_copy_root;
 static pthread_rwlock_t vdi_copy_lock = PTHREAD_RWLOCK_INITIALIZER;
 
 static struct vdi_copy_entry *vdi_copy_search(struct rb_root *root,
diff --git a/sheepfs/volume.c b/sheepfs/volume.c
index 701d488..44648ad 100644
--- a/sheepfs/volume.c
+++ b/sheepfs/volume.c
@@ -62,7 +62,7 @@ struct vdi_inode {
 	unsigned socket_poll_adder;
 };
 
-static struct rb_root vdi_inode_tree = RB_ROOT;
+static struct rb_root vdi_inode_tree;
 static pthread_rwlock_t vdi_inode_tree_lock = PTHREAD_RWLOCK_INITIALIZER;
 
 static struct vdi_inode *vdi_inode_tree_insert(struct vdi_inode *new)
-- 
1.7.10.rc0.41.gfa678




More information about the sheepdog mailing list