[sheepdog] [PATCH v2 2/3] fix coding sytle errors detected by checkpatch.pl

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Thu Oct 18 09:23:23 CEST 2012


Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 collie/cluster.c          |    2 +-
 collie/collie.c           |    4 +-
 collie/node.c             |    2 +-
 collie/vdi.c              |   12 ++---
 include/bitops.h          |   10 ++--
 include/list.h            |    8 ++--
 include/logger.h          |    2 +-
 include/rbtree.h          |   14 ++---
 include/sha1.h            |    8 ++--
 include/util.h            |   10 ++--
 lib/event.c               |    3 +-
 lib/logger.c              |   35 +++++++------
 lib/net.c                 |    3 +-
 lib/rbtree.c              |  117 +++++++++++++++++----------------------------
 lib/sha1.c                |   13 ++---
 lib/util.c                |    2 +-
 sheep/cluster/accord.c    |    2 +-
 sheep/cluster/corosync.c  |    6 +-
 sheep/cluster/zookeeper.c |    3 +-
 sheep/farm/sha1_file.c    |    2 +-
 sheep/group.c             |    2 +-
 sheep/journal.c           |    2 +-
 sheep/recovery.c          |    4 +-
 sheep/sheep.c             |   12 ++--
 sheep/sheep_priv.h        |    2 +-
 sheep/vdi.c               |    2 +-
 sheep/work.c              |    4 +-
 27 files changed, 129 insertions(+), 157 deletions(-)

diff --git a/collie/cluster.c b/collie/cluster.c
index 18e834a..59cdc65 100644
--- a/collie/cluster.c
+++ b/collie/cluster.c
@@ -343,7 +343,7 @@ static int cluster_force_recover(int argc, char **argv)
 		l = strlen(str);
 		for (i = 0; i < l; i++)
 			str[i] = tolower(str[i]);
-		if (strncmp(str, "yes", 3) !=0)
+		if (strncmp(str, "yes", 3) != 0)
 			return EXIT_SUCCESS;
 	}
 
diff --git a/collie/collie.c b/collie/collie.c
index edb7907..060e53c 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -17,11 +17,11 @@
 #include "sheep.h"
 #include "collie.h"
 
-static char program_name[] = "collie";
+static const char program_name[] = "collie";
 const char *sdhost = "localhost";
 int sdport = SD_LISTEN_PORT;
 bool highlight = true;
-bool raw_output = false;
+bool raw_output;
 
 static const struct sd_option collie_options[] = {
 
diff --git a/collie/node.c b/collie/node.c
index fe4cb23..a24fb3f 100644
--- a/collie/node.c
+++ b/collie/node.c
@@ -11,7 +11,7 @@
 
 #include "collie.h"
 
-static void cal_total_vdi_size(uint32_t vid, char *name, char * tag,
+static void cal_total_vdi_size(uint32_t vid, char *name, char *tag,
 			       uint32_t snapid, uint32_t flags,
 			       struct sheepdog_inode *i, void *data)
 {
diff --git a/collie/vdi.c b/collie/vdi.c
index 88e8c9c..a86055d 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -141,7 +141,7 @@ static void print_vdi_list(uint32_t vid, char *name, char *tag, uint32_t snapid,
 	}
 }
 
-static void print_vdi_tree(uint32_t vid, char *name, char * tag, uint32_t snapid,
+static void print_vdi_tree(uint32_t vid, char *name, char *tag, uint32_t snapid,
 			   uint32_t flags, struct sheepdog_inode *i, void *data)
 {
 	time_t ti;
@@ -161,7 +161,7 @@ static void print_vdi_tree(uint32_t vid, char *name, char * tag, uint32_t snapid
 	add_vdi_tree(name, buf, vid, i->parent_vdi_id, highlight && is_current(i));
 }
 
-static void print_vdi_graph(uint32_t vid, char *name, char * tag, uint32_t snapid,
+static void print_vdi_graph(uint32_t vid, char *name, char *tag, uint32_t snapid,
 			    uint32_t flags, struct sheepdog_inode *i, void *data)
 {
 	time_t ti;
@@ -1299,8 +1299,7 @@ static int vdi_write(int argc, char **argv)
 				memset(buf + (len - remain), 0, remain);
 				total = done + len;
 				break;
-			}
-			else if (ret < 0) {
+			} else if (ret < 0) {
 				fprintf(stderr, "Failed to read from stdin: %m\n");
 				ret = EXIT_SYSFAIL;
 				goto out;
@@ -1476,7 +1475,7 @@ static int vdi_check(int argc, char **argv)
 		goto out;
 
 	total = inode->vdi_size;
-	while(done < total) {
+	while (done < total) {
 		vid = inode->data_vdi_id[idx];
 		if (vid) {
 			oid = vid_to_data_oid(vid, idx);
@@ -1722,9 +1721,8 @@ static uint32_t do_restore(char *vdiname, int snapid, const char *tag)
 	struct sheepdog_inode *inode = xzalloc(sizeof(*inode));
 
 	ret = xread(STDIN_FILENO, &hdr, sizeof(hdr));
-	if (ret != sizeof(hdr)) {
+	if (ret != sizeof(hdr))
 		fprintf(stderr, "failed to read backup header, %m\n");
-	}
 
 	if (hdr.version != VDI_BACKUP_FORMAT_VERSION ||
 	    hdr.magic != VDI_BACKUP_MAGIC) {
diff --git a/include/bitops.h b/include/bitops.h
index cdf5c96..26be625 100644
--- a/include/bitops.h
+++ b/include/bitops.h
@@ -5,10 +5,10 @@
 
 #include "util.h"
 
-#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
 #define BITS_PER_BYTE		8
 #define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
-#define DECLARE_BITMAP(name,bits) \
+#define DECLARE_BITMAP(name, bits) \
 	unsigned long name[BITS_TO_LONGS(bits)]
 #define BITS_PER_LONG (BITS_PER_BYTE * sizeof(long))
 
@@ -39,7 +39,8 @@ static inline unsigned long find_next_zero_bit(const unsigned long *addr, unsign
 		result += BITS_PER_LONG;
 	}
 	while (size & ~(BITS_PER_LONG-1)) {
-		if (~(tmp = *(p++)))
+		tmp = *(p++);
+		if (~tmp)
 			goto found_middle;
 		result += BITS_PER_LONG;
 		size -= BITS_PER_LONG;
@@ -78,7 +79,8 @@ static inline unsigned long find_next_bit(const unsigned long *addr, unsigned lo
 		result += BITS_PER_LONG;
 	}
 	while (size & ~(BITS_PER_LONG-1)) {
-		if ((tmp = *(p++)))
+		tmp = *(p++);
+		if (tmp)
 			goto found_middle;
 		result += BITS_PER_LONG;
 		size -= BITS_PER_LONG;
diff --git a/include/list.h b/include/list.h
index 0c9d156..9514764 100644
--- a/include/list.h
+++ b/include/list.h
@@ -6,8 +6,8 @@
 #include <stddef.h>
 
 #define container_of(ptr, type, member) ({			\
-        const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
-        (type *)( (char *)__mptr - offsetof(type,member) );})
+	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
+	(type *)( (char *)__mptr - offsetof(type,member) );})
 
 struct list_head {
 	struct list_head *next, *prev;
@@ -69,7 +69,7 @@ static inline void list_add_tail(struct list_head *new, struct list_head *head)
 	__list_add(new, head->prev, head);
 }
 
-static inline void __list_del(struct list_head * prev, struct list_head * next)
+static inline void __list_del(struct list_head *prev, struct list_head *next)
 {
 	next->prev = prev;
 	prev->next = next;
@@ -213,7 +213,7 @@ static inline void hlist_add_after(struct hlist_node *n,
 	n->next = next;
 	next->pprev = &n->next;
 
-	if(next->next)
+	if (next->next)
 		next->next->pprev  = &next->next;
 }
 
diff --git a/include/logger.h b/include/logger.h
index 9a6e6dd..4ee5956 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -20,7 +20,7 @@
 #define LOG_SPACE_SIZE 1048576
 #define MAX_MSG_SIZE 256
 
-extern int log_init(char *progname, int size, bool to_stdout, int level,
+extern int log_init(const char *progname, int size, bool to_stdout, int level,
 		    char *outfile);
 extern void log_close(void);
 extern void dump_logmsg(void *);
diff --git a/include/rbtree.h b/include/rbtree.h
index a559b23..83a29f0 100644
--- a/include/rbtree.h
+++ b/include/rbtree.h
@@ -1,8 +1,7 @@
 #ifndef __RBTREE_H_
 #define __RBTREE_H_
 
-struct rb_node
-{
+struct rb_node {
 	unsigned long  rb_parent_color;
 #define RB_RED          0
 #define RB_BLACK        1
@@ -10,8 +9,7 @@ struct rb_node
 	struct rb_node *rb_left;
 };
 
-struct rb_root
-{
+struct rb_root {
 	struct rb_node *rb_node;
 };
 
@@ -32,7 +30,7 @@ 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_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)
@@ -68,10 +66,10 @@ extern struct rb_node *rb_last(const struct rb_root *);
 extern void rb_replace_node(struct rb_node *victim, struct rb_node *new,
 		struct rb_root *root);
 
-static inline void rb_link_node(struct rb_node * node, struct rb_node * parent,
-		struct rb_node ** rb_link)
+static inline void rb_link_node(struct rb_node *node, struct rb_node *parent,
+		struct rb_node **rb_link)
 {
-	node->rb_parent_color = (unsigned long )parent;
+	node->rb_parent_color = (unsigned long)parent;
 	node->rb_left = node->rb_right = NULL;
 
 	*rb_link = node;
diff --git a/include/sha1.h b/include/sha1.h
index cc60dc1..1043b30 100644
--- a/include/sha1.h
+++ b/include/sha1.h
@@ -15,13 +15,13 @@
 #include <inttypes.h>
 
 struct sha1_ctx {
-        uint64_t count;
-        uint32_t state[5];
-        uint8_t buffer[64];
+	uint64_t count;
+	uint32_t state[5];
+	uint8_t buffer[64];
 };
 
 void sha1_init(void *ctx);
 void sha1_update(void *ctx, const uint8_t *data, unsigned int len);
-void sha1_final(void* ctx, uint8_t *out);
+void sha1_final(void *ctx, uint8_t *out);
 
 #endif
diff --git a/include/util.h b/include/util.h
index cf792ef..d0bf659 100644
--- a/include/util.h
+++ b/include/util.h
@@ -38,11 +38,11 @@
 
 #define notrace __attribute__((no_instrument_function))
 
-#define uninitialized_var(x) x = x
+#define uninitialized_var(x) (x = x)
 
 static inline int before(uint32_t seq1, uint32_t seq2)
 {
-        return (int32_t)(seq1 - seq2) < 0;
+	return (int32_t)(seq1 - seq2) < 0;
 }
 
 static inline int after(uint32_t seq1, uint32_t seq2)
@@ -50,13 +50,13 @@ static inline int after(uint32_t seq1, uint32_t seq2)
 	return (int32_t)(seq2 - seq1) < 0;
 }
 
-#define min(x,y) ({ \
+#define min(x, y) ({ \
 	typeof(x) _x = (x);	\
 	typeof(y) _y = (y);	\
 	(void) (&_x == &_y);		\
 	_x < _y ? _x : _y; })
 
-#define max(x,y) ({ \
+#define max(x, y) ({ \
 	typeof(x) _x = (x);	\
 	typeof(y) _y = (y);	\
 	(void) (&_x == &_y);		\
@@ -81,7 +81,7 @@ extern ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset);
 extern int rmdir_r(char *dir_path);
 
 void trim_zero_sectors(void *buf, uint64_t *offset, uint32_t *len);
-void set_trimmed_sectors(void *buf, uint64_t offset,uint32_t len,
+void set_trimmed_sectors(void *buf, uint64_t offset, uint32_t len,
 			 uint32_t requested_len);
 
 #ifdef assert
diff --git a/lib/event.c b/lib/event.c
index 2154a56..6b00e06 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -60,9 +60,8 @@ void add_timer(struct timer *t, unsigned int mseconds)
 		return;
 	}
 
-	if (register_event(tfd, timer_handler, t) < 0) {
+	if (register_event(tfd, timer_handler, t) < 0)
 		eprintf("failed to register timer fd\n");
-	}
 }
 
 struct event_info {
diff --git a/lib/logger.c b/lib/logger.c
index c6effe5..6eead56 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -78,7 +78,7 @@ static int log_fd = -1;
 static __thread const char *worker_name;
 static __thread int worker_idx;
 static struct logarea *la;
-static char *log_name;
+static const char *log_name;
 static char *log_nowname;
 static int log_level = SDOG_INFO;
 static pid_t sheep_pid;
@@ -95,8 +95,9 @@ static notrace int logarea_init(int size)
 
 	logdbg(stderr, "entering logarea_init\n");
 
-	if ((shmid = shmget(IPC_PRIVATE, sizeof(struct logarea),
-			    0644 | IPC_CREAT | IPC_EXCL)) == -1) {
+	shmid = shmget(IPC_PRIVATE, sizeof(struct logarea),
+		       0644 | IPC_CREAT | IPC_EXCL);
+	if (shmid == -1) {
 		syslog(LOG_ERR, "shmget logarea failed: %m");
 		return 1;
 	}
@@ -112,8 +113,8 @@ static notrace int logarea_init(int size)
 	if (size < MAX_MSG_SIZE)
 		size = LOG_SPACE_SIZE;
 
-	if ((shmid = shmget(IPC_PRIVATE, size,
-			    0644 | IPC_CREAT | IPC_EXCL)) == -1) {
+	shmid = shmget(IPC_PRIVATE, size, 0644 | IPC_CREAT | IPC_EXCL);
+	if (shmid == -1) {
 		syslog(LOG_ERR, "shmget msg failed: %m");
 		shmdt(la);
 		return 1;
@@ -134,8 +135,9 @@ static notrace int logarea_init(int size)
 	la->head = la->start;
 	la->tail = la->start;
 
-	if ((shmid = shmget(IPC_PRIVATE, MAX_MSG_SIZE + sizeof(struct logmsg),
-			    0644 | IPC_CREAT | IPC_EXCL)) == -1) {
+	shmid = shmget(IPC_PRIVATE, MAX_MSG_SIZE + sizeof(struct logmsg),
+		       0644 | IPC_CREAT | IPC_EXCL);
+	if (shmid == -1) {
 		syslog(LOG_ERR, "shmget logmsg failed: %m");
 		shmdt(la->start);
 		shmdt(la);
@@ -151,7 +153,8 @@ static notrace int logarea_init(int size)
 
 	shmctl(shmid, IPC_RMID, NULL);
 
-	if ((la->semid = semget(semkey, 1, 0666 | IPC_CREAT)) < 0) {
+	la->semid = semget(semkey, 1, 0666 | IPC_CREAT);
+	if (la->semid < 0) {
 		syslog(LOG_ERR, "semget failed: %m");
 		shmdt(la->buff);
 		shmdt(la->start);
@@ -159,7 +162,7 @@ static notrace int logarea_init(int size)
 		return 1;
 	}
 
-	la->semarg.val=1;
+	la->semarg.val = 1;
 	if (semctl(la->semid, 0, SETVAL, la->semarg) < 0) {
 		syslog(LOG_ERR, "semctl failed: %m");
 		shmdt(la->buff);
@@ -184,7 +187,7 @@ static void notrace free_logarea(void)
 #if LOGDBG
 static void dump_logarea(void)
 {
-	struct logmsg * msg;
+	struct logmsg *msg;
 
 	logdbg(stderr, "\n==== area: start addr = %p, end addr = %p ====\n",
 		la->start, la->end);
@@ -285,9 +288,9 @@ static notrace int log_enqueue(int prio, const char *func, int line, const char
 
 static notrace int log_dequeue(void *buff)
 {
-	struct logmsg * src = (struct logmsg *)la->head;
-	struct logmsg * dst = (struct logmsg *)buff;
-	struct logmsg * lst = (struct logmsg *)la->tail;
+	struct logmsg *src = (struct logmsg *)la->head;
+	struct logmsg *dst = (struct logmsg *)buff;
+	struct logmsg *lst = (struct logmsg *)la->tail;
 	int len;
 
 	if (la->empty)
@@ -318,7 +321,7 @@ static notrace int log_dequeue(void *buff)
  */
 static notrace void log_syslog(void *buff)
 {
-	struct logmsg * msg = (struct logmsg *)buff;
+	struct logmsg *msg = (struct logmsg *)buff;
 
 	if (log_fd >= 0)
 		xwrite(log_fd, (char *)&msg->str, strlen((char *)&msg->str));
@@ -510,8 +513,8 @@ static notrace void logger(char *log_dir, char *outfile)
 	exit(0);
 }
 
-notrace int log_init(char *program_name, int size, bool to_stdout, int level,
-		char *outfile)
+notrace int log_init(const char *program_name, int size, bool to_stdout,
+		     int level, char *outfile)
 {
 	char log_dir[PATH_MAX], tmp[PATH_MAX];
 
diff --git a/lib/net.c b/lib/net.c
index 29a53cf..cfc9625 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -395,7 +395,8 @@ char *addr_to_str(char *str, int size, uint8_t *addr, uint16_t port)
 	/* Find address family type */
 	if (addr[12]) {
 		int  oct_no = 0;
-		while (!addr[oct_no] && oct_no++ < 12 );
+		while (!addr[oct_no] && oct_no++ < 12)
+			;
 		if (oct_no == 12) {
 			af = AF_INET;
 			addr_start_idx = 12;
diff --git a/lib/rbtree.c b/lib/rbtree.c
index 8aec5c6..cb2076a 100644
--- a/lib/rbtree.c
+++ b/lib/rbtree.c
@@ -27,20 +27,19 @@ static void __rb_rotate_left(struct rb_node *node, struct rb_root *root)
 	struct rb_node *right = node->rb_right;
 	struct rb_node *parent = rb_parent(node);
 
-	if ((node->rb_right = right->rb_left))
+	node->rb_right = right->rb_left;
+	if (node->rb_right)
 		rb_set_parent(right->rb_left, node);
 	right->rb_left = node;
 
 	rb_set_parent(right, parent);
 
-	if (parent)
-	{
+	if (parent) {
 		if (node == parent->rb_left)
 			parent->rb_left = right;
 		else
 			parent->rb_right = right;
-	}
-	else
+	} else
 		root->rb_node = right;
 	rb_set_parent(node, right);
 }
@@ -50,20 +49,19 @@ static void __rb_rotate_right(struct rb_node *node, struct rb_root *root)
 	struct rb_node *left = node->rb_left;
 	struct rb_node *parent = rb_parent(node);
 
-	if ((node->rb_left = left->rb_right))
+	node->rb_left = left->rb_right;
+	if (node->rb_left)
 		rb_set_parent(left->rb_right, node);
 	left->rb_right = node;
 
 	rb_set_parent(left, parent);
 
-	if (parent)
-	{
+	if (parent) {
 		if (node == parent->rb_right)
 			parent->rb_right = left;
 		else
 			parent->rb_left = left;
-	}
-	else
+	} else
 		root->rb_node = left;
 	rb_set_parent(node, left);
 }
@@ -72,26 +70,20 @@ void rb_insert_color(struct rb_node *node, struct rb_root *root)
 {
 	struct rb_node *parent, *gparent;
 
-	while ((parent = rb_parent(node)) && rb_is_red(parent))
-	{
+	while ((parent = rb_parent(node)) && rb_is_red(parent)) {
 		gparent = rb_parent(parent);
 
-		if (parent == gparent->rb_left)
-		{
-			{
-				register struct rb_node *uncle = gparent->rb_right;
-				if (uncle && rb_is_red(uncle))
-				{
-					rb_set_black(uncle);
-					rb_set_black(parent);
-					rb_set_red(gparent);
-					node = gparent;
-					continue;
-				}
+		if (parent == gparent->rb_left) {
+			register struct rb_node *uncle = gparent->rb_right;
+			if (uncle && rb_is_red(uncle)) {
+				rb_set_black(uncle);
+				rb_set_black(parent);
+				rb_set_red(gparent);
+				node = gparent;
+				continue;
 			}
 
-			if (parent->rb_right == node)
-			{
+			if (parent->rb_right == node) {
 				register struct rb_node *tmp;
 				__rb_rotate_left(parent, root);
 				tmp = parent;
@@ -103,20 +95,16 @@ void rb_insert_color(struct rb_node *node, struct rb_root *root)
 			rb_set_red(gparent);
 			__rb_rotate_right(gparent, root);
 		} else {
-			{
-				register struct rb_node *uncle = gparent->rb_left;
-				if (uncle && rb_is_red(uncle))
-				{
-					rb_set_black(uncle);
-					rb_set_black(parent);
-					rb_set_red(gparent);
-					node = gparent;
-					continue;
-				}
+			register struct rb_node *uncle = gparent->rb_left;
+			if (uncle && rb_is_red(uncle)) {
+				rb_set_black(uncle);
+				rb_set_black(parent);
+				rb_set_red(gparent);
+				node = gparent;
+				continue;
 			}
 
-			if (parent->rb_left == node)
-			{
+			if (parent->rb_left == node) {
 				register struct rb_node *tmp;
 				__rb_rotate_right(parent, root);
 				tmp = parent;
@@ -138,29 +126,22 @@ static void __rb_erase_color(struct rb_node *node, struct rb_node *parent,
 {
 	struct rb_node *other;
 
-	while ((!node || rb_is_black(node)) && node != root->rb_node)
-	{
-		if (parent->rb_left == node)
-		{
+	while ((!node || rb_is_black(node)) && node != root->rb_node) {
+		if (parent->rb_left == node) {
 			other = parent->rb_right;
-			if (rb_is_red(other))
-			{
+			if (rb_is_red(other)) {
 				rb_set_black(other);
 				rb_set_red(parent);
 				__rb_rotate_left(parent, root);
 				other = parent->rb_right;
 			}
 			if ((!other->rb_left || rb_is_black(other->rb_left)) &&
-			    (!other->rb_right || rb_is_black(other->rb_right)))
-			{
+			    (!other->rb_right || rb_is_black(other->rb_right))) {
 				rb_set_red(other);
 				node = parent;
 				parent = rb_parent(node);
-			}
-			else
-			{
-				if (!other->rb_right || rb_is_black(other->rb_right))
-				{
+			} else {
+				if (!other->rb_right || rb_is_black(other->rb_right)) {
 					rb_set_black(other->rb_left);
 					rb_set_red(other);
 					__rb_rotate_right(other, root);
@@ -173,28 +154,21 @@ static void __rb_erase_color(struct rb_node *node, struct rb_node *parent,
 				node = root->rb_node;
 				break;
 			}
-		}
-		else
-		{
+		} else {
 			other = parent->rb_left;
-			if (rb_is_red(other))
-			{
+			if (rb_is_red(other)) {
 				rb_set_black(other);
 				rb_set_red(parent);
 				__rb_rotate_right(parent, root);
 				other = parent->rb_left;
 			}
 			if ((!other->rb_left || rb_is_black(other->rb_left)) &&
-			    (!other->rb_right || rb_is_black(other->rb_right)))
-			{
+			    (!other->rb_right || rb_is_black(other->rb_right))) {
 				rb_set_red(other);
 				node = parent;
 				parent = rb_parent(node);
-			}
-			else
-			{
-				if (!other->rb_left || rb_is_black(other->rb_left))
-				{
+			} else {
+				if (!other->rb_left || rb_is_black(other->rb_left)) {
 					rb_set_black(other->rb_right);
 					rb_set_red(other);
 					__rb_rotate_left(other, root);
@@ -222,8 +196,7 @@ void rb_erase(struct rb_node *node, struct rb_root *root)
 		child = node->rb_right;
 	else if (!node->rb_right)
 		child = node->rb_left;
-	else
-	{
+	else {
 		struct rb_node *old = node, *left;
 
 		node = node->rb_right;
@@ -242,9 +215,9 @@ void rb_erase(struct rb_node *node, struct rb_root *root)
 		parent = rb_parent(node);
 		color = rb_color(node);
 
-		if (parent == old) {
+		if (parent == old)
 			parent = node;
-		} else {
+		else {
 			if (child)
 				rb_set_parent(child, parent);
 			parent->rb_left = child;
@@ -265,14 +238,12 @@ void rb_erase(struct rb_node *node, struct rb_root *root)
 
 	if (child)
 		rb_set_parent(child, parent);
-	if (parent)
-	{
+	if (parent) {
 		if (parent->rb_left == node)
 			parent->rb_left = child;
 		else
 			parent->rb_right = child;
-	}
-	else
+	} else
 		root->rb_node = child;
 
  color:
@@ -387,7 +358,7 @@ struct rb_node *rb_next(const struct rb_node *node)
 	if (node->rb_right) {
 		node = node->rb_right;
 		while (node->rb_left)
-			node=node->rb_left;
+			node = node->rb_left;
 		return (struct rb_node *)node;
 	}
 
@@ -415,7 +386,7 @@ struct rb_node *rb_prev(const struct rb_node *node)
 	if (node->rb_left) {
 		node = node->rb_left;
 		while (node->rb_right)
-			node=node->rb_right;
+			node = node->rb_right;
 		return (struct rb_node *)node;
 	}
 
diff --git a/lib/sha1.c b/lib/sha1.c
index 5cf444a..26a29ed 100644
--- a/lib/sha1.c
+++ b/lib/sha1.c
@@ -25,7 +25,7 @@
 
 static inline uint32_t rol(uint32_t value, uint32_t bits)
 {
-	return (((value) << (bits)) | ((value) >> (32 - (bits))));
+	return (value << bits) | (value >> (32 - bits));
 }
 
 /* blk0() and blk() perform the initial expand. */
@@ -91,7 +91,7 @@ static void sha1_transform(uint32_t *state, const uint8_t *in)
 	state[4] += e;
 	/* Wipe variables */
 	a = b = c = d = e = 0;
-	memset (block32, 0x00, sizeof block32);
+	memset(block32, 0x00, sizeof block32);
 }
 
 void sha1_init(void *ctx)
@@ -117,18 +117,17 @@ void sha1_update(void *ctx, const uint8_t *data, unsigned int len)
 	if ((j + len) > 63) {
 		memcpy(&sctx->buffer[j], data, (i = 64-j));
 		sha1_transform(sctx->state, sctx->buffer);
-		for ( ; i + 63 < len; i += 64) {
+		for ( ; i + 63 < len; i += 64)
 			sha1_transform(sctx->state, &data[i]);
-		}
 		j = 0;
-	}
-	else i = 0;
+	} else
+		i = 0;
 	memcpy(&sctx->buffer[j], &data[i], len - i);
 }
 
 
 /* Add padding and return the message digest. */
-void sha1_final(void* ctx, uint8_t *out)
+void sha1_final(void *ctx, uint8_t *out)
 {
 	struct sha1_ctx *sctx = ctx;
 	uint32_t i, j, idx, padlen;
diff --git a/lib/util.c b/lib/util.c
index 3c28165..9ef27ff 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -303,5 +303,5 @@ void set_trimmed_sectors(void *buf, uint64_t offset, uint32_t len,
 	}
 
 	if (offset + len < requested_len)
-		memset(p + offset + len, 0, requested_len- offset - len);
+		memset(p + offset + len, 0, requested_len - offset - len);
 }
diff --git a/sheep/cluster/accord.c b/sheep/cluster/accord.c
index d57df58..a6edf2a 100644
--- a/sheep/cluster/accord.c
+++ b/sheep/cluster/accord.c
@@ -310,7 +310,7 @@ static bool need_cleanup;
 static void acrd_join_fn(struct acrd_handle *ah, const uint64_t *member_list,
 			 size_t member_list_entries, uint64_t nodeid, void *arg)
 {
-	static bool init = false;
+	static bool init;
 
 	if (!init) {
 		this_id = nodeid;
diff --git a/sheep/cluster/corosync.c b/sheep/cluster/corosync.c
index 2a564ff..e238145 100644
--- a/sheep/cluster/corosync.c
+++ b/sheep/cluster/corosync.c
@@ -520,9 +520,9 @@ static void cdrv_cpg_deliver(cpg_handle_t handle,
 
 		master = is_master(&cmsg->sender);
 		if (master >= 0)
-		/* Master is down before new nodes finish joining.
-		 * We have to revoke its mastership to avoid cluster hanging
-		 */
+			/* Master is down before new nodes finish joining.
+			 * We have to revoke its mastership to avoid cluster
+			 * hanging */
 			cpg_nodes[master].gone = 1;
 
 		cevent->sender = cmsg->sender;
diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index 9d4216b..9c87c89 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -531,7 +531,8 @@ static int leave_event(zhandle_t *zh, struct zk_node *znode)
 	return 0;
 }
 
-static void watcher(zhandle_t *zh, int type, int state, const char *path, void* ctx)
+static void watcher(zhandle_t *zh, int type, int state, const char *path,
+		    void *ctx)
 {
 	eventfd_t value = 1;
 	const clientid_t *cid;
diff --git a/sheep/farm/sha1_file.c b/sheep/farm/sha1_file.c
index b0abc16..4516078 100644
--- a/sheep/farm/sha1_file.c
+++ b/sheep/farm/sha1_file.c
@@ -37,7 +37,7 @@ static void fill_sha1_path(char *pathbuf, const unsigned char *sha1)
 {
 	int i;
 	for (i = 0; i < SHA1_LEN; i++) {
-		static char hex[] = "0123456789abcdef";
+		static const char hex[] = "0123456789abcdef";
 		unsigned int val = sha1[i];
 		char *pos = pathbuf + i*2 + (i > 0);
 		*pos++ = hex[val >> 4];
diff --git a/sheep/group.c b/sheep/group.c
index 33c808d..517fd68 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -223,7 +223,7 @@ int local_get_node_list(const struct sd_req *req, struct sd_rsp *rsp,
 /*
  * Indicator if a cluster operation is currently running.
  */
-static bool cluster_op_running = false;
+static bool cluster_op_running;
 
 static struct vdi_op_message *prepare_cluster_msg(struct request *req,
 		size_t *sizep)
diff --git a/sheep/journal.c b/sheep/journal.c
index a1456c7..b6beabc 100644
--- a/sheep/journal.c
+++ b/sheep/journal.c
@@ -205,7 +205,7 @@ err:
 	return NULL;
 }
 
-int jrnl_end(struct jrnl_descriptor * jd)
+int jrnl_end(struct jrnl_descriptor *jd)
 {
 	int ret = 0;
 	if (!jd)
diff --git a/sheep/recovery.c b/sheep/recovery.c
index 6406c57..6251040 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -226,7 +226,7 @@ static inline void prepare_schedule_oid(uint64_t oid)
 	int i;
 
 	for (i = 0; i < rw->nr_prio_oids; i++)
-		if (rw->prio_oids[i] == oid )
+		if (rw->prio_oids[i] == oid)
 			return;
 	/*
 	 * We need this check because oid might not be recovered.
@@ -456,7 +456,7 @@ static void recover_object_main(struct work *work)
 		return;
 	}
 
-	if (rw->stop){
+	if (rw->stop) {
 		/*
 		 * Stop this recovery process and wait for epoch to be
 		 * lifted and flush wait_obj queue to requeue those
diff --git a/sheep/sheep.c b/sheep/sheep.c
index a5567eb..3ec2c4d 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -37,7 +37,7 @@
 #define LOG_FILE_NAME "sheep.log"
 
 LIST_HEAD(cluster_drivers);
-static char program_name[] = "sheep";
+static const char program_name[] = "sheep";
 
 static struct option const long_options[] = {
 	{"bindaddr", required_argument, NULL, 'b'},
@@ -112,9 +112,9 @@ static int create_pidfile(const char *filename)
 	int len;
 	char buffer[128];
 
-	if ((fd = open(filename, O_RDWR|O_CREAT|O_SYNC, 0600)) == -1) {
+	fd = open(filename, O_RDWR|O_CREAT|O_SYNC, 0600);
+	if (fd == -1)
 		return -1;
-	}
 
 	if (lockf(fd, F_TLOCK, 0) == -1) {
 		close(fd);
@@ -143,10 +143,10 @@ static void signal_handler(int listen_fd, int events, void *data)
 	dprintf("signal %d\n", siginfo.ssi_signo);
 	switch (siginfo.ssi_signo) {
 	case SIGTERM:
-		sys->status= SD_STATUS_KILLED;
+		sys->status = SD_STATUS_KILLED;
 		break;
 	default:
-		eprintf("signal %d unhandled \n", siginfo.ssi_signo);
+		eprintf("signal %d unhandled\n", siginfo.ssi_signo);
 		break;
 	}
 }
@@ -506,7 +506,7 @@ int main(int argc, char **argv)
 		if (!sys->reclaim_wqueue)
 			exit(1);
 	}
-	if (!sys->gateway_wqueue || !sys->io_wqueue ||!sys->recovery_wqueue ||
+	if (!sys->gateway_wqueue || !sys->io_wqueue || !sys->recovery_wqueue ||
 	    !sys->deletion_wqueue || !sys->block_wqueue || !sys->sockfd_wqueue)
 		exit(1);
 
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 4612cef..3251816 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -335,7 +335,7 @@ int gateway_to_peer_opcode(int opcode);
 /* Journal */
 struct jrnl_descriptor *jrnl_begin(const void *buf, size_t count, off_t offset,
 				   const char *path, const char *jrnl_dir);
-int jrnl_end(struct jrnl_descriptor * jd);
+int jrnl_end(struct jrnl_descriptor *jd);
 int jrnl_recover(const char *jrnl_dir);
 
 static inline bool is_myself(uint8_t *addr, uint16_t port)
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 0893a02..45219ed 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -396,7 +396,7 @@ static int do_lookup_vdi(char *name, int namelen, uint32_t *vid, char *tag,
 	if (nr == start_nr) {
 		return SD_RES_NO_VDI;
 	} else if (nr < SD_NR_VDIS) {
-	right_side:
+right_side:
 		/* look up on the right side of the hash point */
 		ret = find_first_vdi(nr - 1, start_nr, name,
 				     tag, snapid, vid, deleted_nr, next_snapid,
diff --git a/sheep/work.c b/sheep/work.c
index d32e7ad..0ef169d 100644
--- a/sheep/work.c
+++ b/sheep/work.c
@@ -62,7 +62,7 @@ static void *run_short_thread(void *arg)
 {
 	struct short_work *sw = arg;
 	eventfd_t value = 1;
-	static unsigned long idx = 0;
+	static unsigned long idx;
 	int err;
 
 	/* Tell runtime to release resources after termination */
@@ -187,7 +187,7 @@ retest:
 static int init_eventfd(void)
 {
 	int ret;
-	static bool done = false;
+	static bool done;
 
 	if (done)
 		return 0;
-- 
1.7.2.5




More information about the sheepdog mailing list