[sheepdog] [PATCH] use bool for boolean variables

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Sat Oct 6 13:03:49 CEST 2012


This improves code readability.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 collie/cluster.c          |   40 ++++++++++++------------
 collie/collie.c           |   23 +++++++------
 collie/collie.h           |   10 +++---
 collie/common.c           |    4 +-
 collie/treeview.c         |   12 +++---
 collie/treeview.h         |    4 ++-
 collie/vdi.c              |   77 +++++++++++++++++++++++----------------------
 include/logger.h          |    5 ++-
 include/net.h             |    2 +-
 include/sheep.h           |    9 +++--
 include/sheepdog_proto.h  |   10 +++---
 include/util.h            |    1 +
 lib/logger.c              |   16 +++++-----
 lib/net.c                 |    6 ++--
 sheep/cluster/accord.c    |   20 ++++++------
 sheep/cluster/corosync.c  |   38 +++++++++++-----------
 sheep/cluster/local.c     |    8 ++--
 sheep/cluster/zookeeper.c |   32 +++++++++---------
 sheep/group.c             |   14 ++++----
 sheep/object_cache.c      |   73 +++++++++++++++++++++---------------------
 sheep/ops.c               |   58 +++++++++++++++++-----------------
 sheep/plain_store.c       |    6 ++--
 sheep/recovery.c          |   22 ++++++------
 sheep/request.c           |   13 +++----
 sheep/sheep.c             |   14 ++++----
 sheep/sheep_priv.h        |   49 ++++++++++++++--------------
 sheep/store.c             |   24 +++++++-------
 sheep/trace/graph.c       |    2 +-
 sheep/trace/stabs.c       |    5 ++-
 sheep/trace/trace.c       |   14 ++++----
 sheep/trace/trace.h       |    2 +-
 sheep/vdi.c               |   33 ++++++++++---------
 sheep/work.c              |    6 ++-
 sheepfs/core.c            |   12 +++---
 sheepfs/shadow_file.c     |    6 ++--
 sheepfs/sheepfs.h         |    2 +-
 sheepfs/volume.c          |    6 ++--
 37 files changed, 344 insertions(+), 334 deletions(-)

diff --git a/collie/cluster.c b/collie/cluster.c
index 5d7be83..517b090 100644
--- a/collie/cluster.c
+++ b/collie/cluster.c
@@ -17,23 +17,23 @@
 #include "collie.h"
 
 static struct sd_option cluster_options[] = {
-	{'b', "store", 1, "specify backend store"},
-	{'c', "copies", 1, "specify the default data redundancy (number of copies)"},
-	{'m', "mode", 1, "mode (safe, quorum, unsafe)"},
-	{'f', "force", 0, "do not prompt for confirmation"},
-	{'R', "restore", 1, "restore the cluster"},
-	{'l', "list", 0, "list the user epoch information"},
-
-	{ 0, NULL, 0, NULL },
+	{'b', "store", true, "specify backend store"},
+	{'c', "copies", true, "specify the default data redundancy (number of copies)"},
+	{'m', "mode", true, "mode (safe, quorum, unsafe)"},
+	{'f', "force", false, "do not prompt for confirmation"},
+	{'R', "restore", true, "restore the cluster"},
+	{'l', "list", false, "list the user epoch information"},
+
+	{ 0, NULL, false, NULL },
 };
 
 struct cluster_cmd_data {
 	uint32_t epoch;
-	int list;
+	bool list;
 	int copies;
-	int nohalt;
-	int quorum;
-	int force;
+	bool nohalt;
+	bool quorum;
+	bool force;
 	char name[STORE_LEN];
 } cluster_cmd_data;
 
@@ -470,21 +470,21 @@ static int cluster_parser(int ch, char *opt)
 		break;
 	case 'm':
 		if (strcmp(opt, "safe") == 0) {
-			cluster_cmd_data.nohalt = 0;
-			cluster_cmd_data.quorum = 0;
+			cluster_cmd_data.nohalt = false;
+			cluster_cmd_data.quorum = false;
 		} else if (strcmp(opt, "quorum") == 0) {
-			cluster_cmd_data.nohalt = 0;
-			cluster_cmd_data.quorum = 1;
+			cluster_cmd_data.nohalt = false;
+			cluster_cmd_data.quorum = true;
 		} else if (strcmp(opt, "unsafe") == 0) {
-			cluster_cmd_data.nohalt = 1;
-			cluster_cmd_data.quorum = 0;
+			cluster_cmd_data.nohalt = true;
+			cluster_cmd_data.quorum = false;
 		} else {
 			fprintf(stderr, "Unknown mode '%s'\n", opt);
 			exit(EXIT_FAILURE);
 		}
 		break;
 	case 'f':
-		cluster_cmd_data.force = 1;
+		cluster_cmd_data.force = true;
 		break;
 	case 'R':
 		cluster_cmd_data.epoch = strtol(opt, &p, 10);
@@ -498,7 +498,7 @@ static int cluster_parser(int ch, char *opt)
 		}
 		break;
 	case 'l':
-		cluster_cmd_data.list = 1;
+		cluster_cmd_data.list = true;
 		break;
 	}
 
diff --git a/collie/collie.c b/collie/collie.c
index c1b1854..8897468 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -20,19 +20,19 @@
 static char program_name[] = "collie";
 const char *sdhost = "localhost";
 int sdport = SD_LISTEN_PORT;
-int highlight = 1;
-int raw_output = 0;
+bool highlight = true;
+bool raw_output = false;
 
 static const struct sd_option collie_options[] = {
 
 	/* common options for all collie commands */
-	{'a', "address", 1, "specify the daemon address (default: localhost)"},
-	{'p', "port", 1, "specify the daemon port"},
-	{'r', "raw", 0, "raw output mode: omit headers, separate fields with\n\
+	{'a', "address", true, "specify the daemon address (default: localhost)"},
+	{'p', "port", true, "specify the daemon port"},
+	{'r', "raw", false, "raw output mode: omit headers, separate fields with\n\
                           single spaces and print all sizes in decimal bytes"},
-	{'h', "help", 0, "display this help and exit"},
+	{'h', "help", false, "display this help and exit"},
 
-	{ 0, NULL, 0, NULL },
+	{ 0, NULL, false, NULL },
 };
 
 static void usage(const struct command *commands, int status);
@@ -225,13 +225,14 @@ static struct option *build_long_options(const char *opts)
 static unsigned long setup_commands(const struct command *commands,
 				    char *cmd, char *subcmd)
 {
-	int i, found = 0;
+	int i;
+	bool found = false;
 	struct subcommand *s;
 	unsigned long flags = 0;
 
 	for (i = 0; commands[i].name; i++) {
 		if (!strcmp(commands[i].name, cmd)) {
-			found = 1;
+			found = true;
 			if (commands[i].parser)
 				command_parser = commands[i].parser;
 			break;
@@ -382,7 +383,7 @@ int main(int argc, char **argv)
 			}
 			break;
 		case 'r':
-			raw_output = 1;
+			raw_output = true;
 			break;
 		case 'h':
 			subcommand_usage(argv[1], argv[2], EXIT_SUCCESS);
@@ -400,7 +401,7 @@ int main(int argc, char **argv)
 	}
 
 	if (!isatty(STDOUT_FILENO) || raw_output)
-		highlight = 0;
+		highlight = false;
 
 	if (flags & SUBCMD_FLAG_NEED_NODELIST) {
 		ret = update_node_list(SD_MAX_NODES, 0);
diff --git a/collie/collie.h b/collie/collie.h
index dcf12e4..347e5a9 100644
--- a/collie/collie.h
+++ b/collie/collie.h
@@ -32,7 +32,7 @@
 struct sd_option {
 	int val;
 	const char *name;
-	int has_arg;
+	bool has_arg;
 	const char *desc;
 };
 
@@ -56,8 +56,8 @@ void subcommand_usage(char *cmd, char *subcmd, int status);
 
 extern const char *sdhost;
 extern int sdport;
-extern int highlight;
-extern int raw_output;
+extern bool highlight;
+extern bool raw_output;
 
 extern uint32_t sd_epoch;
 extern struct sd_node sd_nodes[SD_MAX_NODES];
@@ -65,7 +65,7 @@ extern struct sd_vnode sd_vnodes[SD_MAX_VNODES];
 extern int sd_nodes_nr, sd_vnodes_nr;
 extern unsigned master_idx;
 
-int is_current(struct sheepdog_inode *i);
+bool is_current(struct sheepdog_inode *i);
 char *size_to_str(uint64_t _size, char *str, int str_size);
 typedef void (*vdi_parser_func_t)(uint32_t vid, char *name, char *tag,
 				  uint32_t snapid, uint32_t flags,
@@ -75,7 +75,7 @@ int sd_read_object(uint64_t oid, void *data, unsigned int datalen,
 		   uint64_t offset, bool direct);
 int sd_write_object(uint64_t oid, uint64_t cow_oid, void *data,
 		    unsigned int datalen, uint64_t offset, uint32_t flags,
-		    int copies, int create, bool direct);
+		    int copies, bool create, bool direct);
 int send_light_req(struct sd_req *hdr, const char *host, int port);
 int send_light_req_get_response(struct sd_req *hdr, const char *host, int port);
 
diff --git a/collie/common.c b/collie/common.c
index a29c86d..bca213b 100644
--- a/collie/common.c
+++ b/collie/common.c
@@ -11,7 +11,7 @@
 
 #include "collie.h"
 
-int is_current(struct sheepdog_inode *i)
+bool is_current(struct sheepdog_inode *i)
 {
 	return !i->snap_ctime;
 }
@@ -85,7 +85,7 @@ int sd_read_object(uint64_t oid, void *data, unsigned int datalen,
 
 int sd_write_object(uint64_t oid, uint64_t cow_oid, void *data,
 		    unsigned int datalen, uint64_t offset, uint32_t flags,
-		    int copies, int create, bool direct)
+		    int copies, bool create, bool direct)
 {
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
diff --git a/collie/treeview.c b/collie/treeview.c
index 29d265b..1938321 100644
--- a/collie/treeview.c
+++ b/collie/treeview.c
@@ -28,7 +28,7 @@ struct vdi_tree {
 	char label[256];
 	uint32_t vid;
 	uint32_t pvid;
-	int highlight;
+	bool highlight;
 	struct list_head children;
 	struct list_head siblings;
 };
@@ -53,7 +53,7 @@ static struct vdi_tree *find_vdi(struct vdi_tree *parent, uint32_t vid,
 }
 
 static struct vdi_tree *new_vdi(const char *name, const char *label,
-				uint64_t vid, uint64_t pvid, int highlight)
+				uint64_t vid, uint64_t pvid, bool highlight)
 {
 	struct vdi_tree *vdi;
 
@@ -77,7 +77,7 @@ void init_tree(void)
 }
 
 void add_vdi_tree(const char *name, const char *label, uint32_t vid,
-		  uint32_t pvid, int highlight)
+		  uint32_t pvid, bool highlight)
 {
 	struct vdi_tree *vdi, *parent;
 
@@ -124,7 +124,7 @@ static void spaces(int n)
 		putchar(' ');
 }
 
-static void indent(int level, int first, int last)
+static void indent(int level, bool first, bool last)
 {
 	int lvl;
 
@@ -141,7 +141,7 @@ static void indent(int level, int first, int last)
 	}
 }
 
-static void _dump_tree(struct vdi_tree *current, int level, int first, int last)
+static void _dump_tree(struct vdi_tree *current, int level, bool first, bool last)
 {
 	struct vdi_tree *vdi;
 
@@ -190,6 +190,6 @@ void dump_tree(void)
 		printf("%s", vdi->name);
 		more[0] = 0;
 		width[0] = strlen(vdi->name);
-		_dump_tree(vdi, 1, 1, 1);
+		_dump_tree(vdi, 1, true, true);
 	}
 }
diff --git a/collie/treeview.h b/collie/treeview.h
index 0e23c93..9787fbb 100644
--- a/collie/treeview.h
+++ b/collie/treeview.h
@@ -11,9 +11,11 @@
 #ifndef __TREEVIEW__
 #define __TREEVIEW__
 
+#include <stdbool.h>
+
 void init_tree(void);
 void add_vdi_tree(const char *label, const char *tag, uint32_t vid,
-		  uint32_t pvid, int highlight);
+		  uint32_t pvid, bool highlight);
 void dump_tree(void);
 
 #endif
diff --git a/collie/vdi.c b/collie/vdi.c
index 104fbb1..e5d05c5 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -20,24 +20,24 @@
 #include "treeview.h"
 
 static struct sd_option vdi_options[] = {
-	{'P', "prealloc", 0, "preallocate all the data objects"},
-	{'i', "index", 1, "specify the index of data objects"},
-	{'s', "snapshot", 1, "specify a snapshot id or tag name"},
-	{'x', "exclusive", 0, "write in an exclusive mode"},
-	{'d', "delete", 0, "delete a key"},
-	{'w', "writeback", 0, "use writeback mode"},
-	{'c', "copies", 1, "specify the data redundancy (number of copies)"},
-	{'F', "from", 1, "create a differential backup from the snapshot"},
-	{ 0, NULL, 0, NULL },
+	{'P', "prealloc", false, "preallocate all the data objects"},
+	{'i', "index", true, "specify the index of data objects"},
+	{'s', "snapshot", true, "specify a snapshot id or tag name"},
+	{'x', "exclusive", false, "write in an exclusive mode"},
+	{'d', "delete", false, "delete a key"},
+	{'w', "writeback", false, "use writeback mode"},
+	{'c', "copies", true, "specify the data redundancy (number of copies)"},
+	{'F', "from", true, "create a differential backup from the snapshot"},
+	{ 0, NULL, false, NULL },
 };
 
 struct vdi_cmd_data {
 	unsigned int index;
 	int snapshot_id;
 	char snapshot_tag[SD_MAX_VDI_TAG_LEN];
-	int exclusive;
-	int delete;
-	int prealloc;
+	bool exclusive;
+	bool delete;
+	bool prealloc;
 	int nr_copies;
 	bool writeback;
 	int from_snapshot_id;
@@ -84,7 +84,8 @@ static int parse_option_size(const char *value, uint64_t *ret)
 static void print_vdi_list(uint32_t vid, char *name, char *tag, uint32_t snapid,
 			   uint32_t flags, struct sheepdog_inode *i, void *data)
 {
-	int idx, is_clone = 0;
+	int idx;
+	bool is_clone = false;
 	uint64_t my_objs, cow_objs;
 	char vdi_size_str[16], my_objs_str[16], cow_objs_str[16];
 	time_t ti;
@@ -120,7 +121,7 @@ static void print_vdi_list(uint32_t vid, char *name, char *tag, uint32_t snapid,
 	size_to_str(cow_objs * SD_DATA_OBJ_SIZE, cow_objs_str, sizeof(cow_objs_str));
 
 	if (i->snap_id == 1 && i->parent_vdi_id != 0)
-		is_clone = 1;
+		is_clone = true;
 
 	if (raw_output) {
 		printf("%c ", is_current(i) ? (is_clone ? 'c' : '=') : 's');
@@ -240,7 +241,7 @@ static int do_print_obj(char *sheep, uint64_t oid, struct sd_rsp *rsp,
 }
 
 struct get_data_oid_info {
-	int success;
+	bool success;
 	uint64_t data_oid;
 	unsigned idx;
 };
@@ -255,7 +256,7 @@ static int get_data_oid(char *sheep, uint64_t oid, struct sd_rsp *rsp,
 	case SD_RES_SUCCESS:
 		if (info->success)
 			break;
-		info->success = 1;
+		info->success = true;
 		if (inode->data_vdi_id[info->idx]) {
 			info->data_oid = vid_to_data_oid(inode->data_vdi_id[info->idx], info->idx);
 			return 1;
@@ -547,7 +548,7 @@ static int vdi_create(int argc, char **argv)
 		oid = vid_to_data_oid(vid, idx);
 
 		ret = sd_write_object(oid, 0, buf, SD_DATA_OBJ_SIZE, 0, 0,
-				      inode->nr_copies, 1, true);
+				      inode->nr_copies, true, true);
 		if (ret != SD_RES_SUCCESS) {
 			ret = EXIT_FAILURE;
 			goto out;
@@ -556,7 +557,7 @@ static int vdi_create(int argc, char **argv)
 		inode->data_vdi_id[idx] = vid;
 		ret = sd_write_object(vid_to_vdi_oid(vid), 0, &vid, sizeof(vid),
 				      SD_INODE_HEADER_SIZE + sizeof(vid) * idx, 0,
-				      inode->nr_copies, 0, true);
+				      inode->nr_copies, false, true);
 		if (ret) {
 			ret = EXIT_FAILURE;
 			goto out;
@@ -591,7 +592,7 @@ static int vdi_snapshot(int argc, char **argv)
 		ret = sd_write_object(vid_to_vdi_oid(vid), 0, vdi_cmd_data.snapshot_tag,
 				      SD_MAX_VDI_TAG_LEN,
 				      offsetof(struct sheepdog_inode, tag),
-				      0, inode->nr_copies, 0, true);
+				      0, inode->nr_copies, false, true);
 	}
 
 	return do_vdi_create(vdiname, inode->vdi_size, vid, NULL, 1,
@@ -661,7 +662,7 @@ static int vdi_clone(int argc, char **argv)
 
 		oid = vid_to_data_oid(new_vid, idx);
 		ret = sd_write_object(oid, 0, buf, SD_DATA_OBJ_SIZE, 0, 0,
-				      inode->nr_copies, 1, true);
+				      inode->nr_copies, true, true);
 		if (ret != SD_RES_SUCCESS) {
 			ret = EXIT_FAILURE;
 			goto out;
@@ -669,7 +670,7 @@ static int vdi_clone(int argc, char **argv)
 
 		ret = sd_write_object(vid_to_vdi_oid(new_vid), 0, &new_vid, sizeof(new_vid),
 				      SD_INODE_HEADER_SIZE + sizeof(new_vid) * idx, 0,
-				      inode->nr_copies, 0, true);
+				      inode->nr_copies, false, true);
 		if (ret) {
 			ret = EXIT_FAILURE;
 			goto out;
@@ -714,7 +715,7 @@ static int vdi_resize(int argc, char **argv)
 	inode->vdi_size = new_size;
 
 	ret = sd_write_object(vid_to_vdi_oid(vid), 0, inode, SD_INODE_HEADER_SIZE, 0,
-			      0, inode->nr_copies, 0, true);
+			      0, inode->nr_copies, false, true);
 	if (ret != SD_RES_SUCCESS) {
 		fprintf(stderr, "Failed to update an inode header\n");
 		return EXIT_FAILURE;
@@ -833,7 +834,7 @@ static int vdi_object(int argc, char **argv)
 	} else {
 		struct get_data_oid_info oid_info = {0};
 
-		oid_info.success = 0;
+		oid_info.success = false;
 		oid_info.idx = idx;
 
 		if (idx >= MAX_DATA_OBJS) {
@@ -954,7 +955,7 @@ static int vdi_track(int argc, char **argv)
 	} else {
 		struct get_data_oid_info oid_info = {0};
 
-		oid_info.success = 0;
+		oid_info.success = false;
 		oid_info.idx = idx;
 
 		if (idx >= MAX_DATA_OBJS) {
@@ -986,7 +987,7 @@ static int vdi_track(int argc, char **argv)
 static int find_vdi_attr_oid(char *vdiname, char *tag, uint32_t snapid,
 			     char *key, void *value, unsigned int value_len,
 			     uint32_t *vid, uint64_t *oid, unsigned int *nr_copies,
-			     int create, int excl, int delete)
+			     bool create, bool excl, bool delete)
 {
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
@@ -1123,8 +1124,8 @@ static int vdi_getattr(int argc, char **argv)
 	}
 
 	ret = find_vdi_attr_oid(vdiname, vdi_cmd_data.snapshot_tag,
-				vdi_cmd_data.snapshot_id, key, NULL, 0,
-				&vid, &attr_oid, &nr_copies, 0, 0, 0);
+				vdi_cmd_data.snapshot_id, key, NULL, 0, &vid,
+				&attr_oid, &nr_copies, false, false, false);
 	if (ret == SD_RES_NO_OBJ) {
 		fprintf(stderr, "Attribute '%s' not found\n", key);
 		return EXIT_MISSING;
@@ -1245,7 +1246,7 @@ static int vdi_write(int argc, char **argv)
 	uint64_t offset = 0, oid, old_oid, done = 0, total = (uint64_t) -1;
 	unsigned int len, remain;
 	char *buf = NULL;
-	int create;
+	bool create;
 
 	if (argv[optind]) {
 		ret = parse_option_size(argv[optind++], &offset);
@@ -1285,15 +1286,15 @@ static int vdi_write(int argc, char **argv)
 	idx = offset / SD_DATA_OBJ_SIZE;
 	offset %= SD_DATA_OBJ_SIZE;
 	while (done < total) {
-		create = 0;
+		create = false;
 		old_oid = 0;
 		flags = 0;
 		len = min(total - done, SD_DATA_OBJ_SIZE - offset);
 
 		if (!inode->data_vdi_id[idx])
-			create = 1;
+			create = true;
 		else if (!is_data_obj_writeable(inode, idx)) {
-			create = 1;
+			create = true;
 			old_oid = vid_to_data_oid(inode->data_vdi_id[idx], idx);
 		}
 
@@ -1334,7 +1335,7 @@ static int vdi_write(int argc, char **argv)
 		if (create) {
 			ret = sd_write_object(vid_to_vdi_oid(vid), 0, &vid, sizeof(vid),
 					      SD_INODE_HEADER_SIZE + sizeof(vid) * idx,
-					      flags, inode->nr_copies, 0, false);
+					      flags, inode->nr_copies, false, false);
 			if (ret) {
 				ret = EXIT_FAILURE;
 				goto out;
@@ -1718,13 +1719,13 @@ static int restore_obj(struct obj_backup *backup, uint32_t vid,
 	/* send a copy-on-write request */
 	ret = sd_write_object(vid_to_data_oid(vid, backup->idx), parent_oid,
 			      backup->data, backup->length, backup->offset,
-			      0, parent_inode->nr_copies, 1, true);
+			      0, parent_inode->nr_copies, true, true);
 	if (ret != SD_RES_SUCCESS)
 		return ret;
 
 	return sd_write_object(vid_to_vdi_oid(vid), 0, &vid, sizeof(vid),
 			       SD_INODE_HEADER_SIZE + sizeof(vid) * backup->idx,
-			       0, parent_inode->nr_copies, 0, true);
+			       0, parent_inode->nr_copies, false, true);
 }
 
 static uint32_t do_restore(char *vdiname, int snapid, const char *tag)
@@ -1918,7 +1919,7 @@ static int vdi_parser(int ch, char *opt)
 
 	switch (ch) {
 	case 'P':
-		vdi_cmd_data.prealloc = 1;
+		vdi_cmd_data.prealloc = true;
 		break;
 	case 'i':
 		vdi_cmd_data.index = strtol(opt, &p, 10);
@@ -1936,13 +1937,13 @@ static int vdi_parser(int ch, char *opt)
 		}
 		break;
 	case 'x':
-		vdi_cmd_data.exclusive = 1;
+		vdi_cmd_data.exclusive = true;
 		break;
 	case 'd':
-		vdi_cmd_data.delete = 1;
+		vdi_cmd_data.delete = true;
 		break;
 	case 'w':
-		vdi_cmd_data.writeback = 1;
+		vdi_cmd_data.writeback = true;
 		break;
 	case 'c':
 		nr_copies = strtol(opt, &p, 10);
diff --git a/include/logger.h b/include/logger.h
index 019d0d8..9a6e6dd 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -14,13 +14,14 @@
 #ifndef LOGGER_H
 #define LOGGER_H
 
+#include <stdbool.h>
 #include <sys/syslog.h>
 
 #define LOG_SPACE_SIZE 1048576
 #define MAX_MSG_SIZE 256
 
-extern int log_init(char *progname, int size, int to_stdout, int level,
-		char *outfile);
+extern int log_init(char *progname, int size, bool to_stdout, int level,
+		    char *outfile);
 extern void log_close(void);
 extern void dump_logmsg(void *);
 extern void log_write(int prio, const char *func, int line, const char *fmt, ...)
diff --git a/include/net.h b/include/net.h
index 4e1e7f6..7fd9f46 100644
--- a/include/net.h
+++ b/include/net.h
@@ -36,7 +36,7 @@ int conn_tx_off(struct connection *conn);
 int conn_tx_on(struct connection *conn);
 int conn_rx_off(struct connection *conn);
 int conn_rx_on(struct connection *conn);
-int is_conn_dead(struct connection *conn);
+bool is_conn_dead(struct connection *conn);
 int do_read(int sockfd, void *buf, int len);
 int rx(struct connection *conn, enum conn_state next_state);
 int tx(struct connection *conn, enum conn_state next_state, int flags);
diff --git a/include/sheep.h b/include/sheep.h
index 03a2090..ed85b98 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -96,7 +96,8 @@ static inline int get_vnode_first_idx(struct sd_vnode *entries, int nr_entries,
 static inline int get_vnode_next_idx(struct sd_vnode *entries, int nr_entries,
 				     int *prev_idxs, int nr_prev_idxs)
 {
-	int i, found, idx, first_idx;
+	int i, idx, first_idx;
+	bool found;
 
 	first_idx = prev_idxs[0];
 	idx = prev_idxs[nr_prev_idxs - 1];
@@ -105,9 +106,9 @@ static inline int get_vnode_next_idx(struct sd_vnode *entries, int nr_entries,
 		if (idx == first_idx)
 			panic("can't find next new idx\n");
 
-		for (found = 0, i = 0; i < nr_prev_idxs; i++) {
+		for (found = false, i = 0; i < nr_prev_idxs; i++) {
 			if (same_zone(entries, idx, prev_idxs[i])) {
-				found = 1;
+				found = true;
 				break;
 			}
 		}
@@ -246,7 +247,7 @@ static inline int node_id_cmp(const void *a, const void *b)
 	return 0;
 }
 
-static inline int node_eq(const struct sd_node *a, const struct sd_node *b)
+static inline bool node_eq(const struct sd_node *a, const struct sd_node *b)
 {
 	return node_id_cmp(a, b) == 0;
 }
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index cccdfa2..7d205dc 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -222,27 +222,27 @@ static inline uint64_t hash_64(uint64_t val, unsigned int bits)
 	return hash & ((1 << bits) - 1);
 }
 
-static inline int is_data_obj_writeable(struct sheepdog_inode *inode, int idx)
+static inline bool is_data_obj_writeable(struct sheepdog_inode *inode, int idx)
 {
 	return inode->vdi_id == inode->data_vdi_id[idx];
 }
 
-static inline int is_vdi_obj(uint64_t oid)
+static inline bool is_vdi_obj(uint64_t oid)
 {
 	return !!(oid & VDI_BIT);
 }
 
-static inline int is_vmstate_obj(uint64_t oid)
+static inline bool is_vmstate_obj(uint64_t oid)
 {
 	return !!(oid & VMSTATE_BIT);
 }
 
-static inline int is_vdi_attr_obj(uint64_t oid)
+static inline bool is_vdi_attr_obj(uint64_t oid)
 {
 	return !!(oid & VDI_ATTR_BIT);
 }
 
-static inline int is_data_obj(uint64_t oid)
+static inline bool is_data_obj(uint64_t oid)
 {
 	return !is_vdi_obj(oid) && !is_vmstate_obj(oid) &&
 		!is_vdi_attr_obj(oid);
diff --git a/include/util.h b/include/util.h
index 6f0e993..cf792ef 100644
--- a/include/util.h
+++ b/include/util.h
@@ -3,6 +3,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <string.h>
 #include <limits.h>
 #include <stdint.h>
diff --git a/lib/logger.c b/lib/logger.c
index 5a3ddcf..409fad5 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -56,8 +56,8 @@ union semun {
 };
 
 struct logarea {
-	int empty;
-	int active;
+	bool empty;
+	bool active;
 	void *head;
 	void *tail;
 	void *start;
@@ -129,7 +129,7 @@ static notrace int logarea_init(int size)
 
 	shmctl(shmid, IPC_RMID, NULL);
 
-	la->empty = 1;
+	la->empty = true;
 	la->end = (char *)la->start + size;
 	la->head = la->start;
 	la->tail = la->start;
@@ -267,7 +267,7 @@ static notrace int log_enqueue(int prio, const char *func, int line, const char
 	}
 
 	/* ok, we can stage the msg in the area */
-	la->empty = 0;
+	la->empty = false;
 	msg = (struct logmsg *)la->tail;
 	msg->prio = prio;
 	memcpy((void *)&msg->str, buff, len);
@@ -300,7 +300,7 @@ static notrace int log_dequeue(void *buff)
 	memcpy(dst, src,  len);
 
 	if (la->tail == la->head)
-		la->empty = 1; /* we purge the last logmsg */
+		la->empty = true; /* we purge the last logmsg */
 	else {
 		la->head = src->next;
 		lst->next = la->head;
@@ -459,7 +459,7 @@ static notrace void logger(char *log_dir, char *outfile)
 		syslog(LOG_ERR, "failed to open %s\n", outfile);
 		exit(1);
 	}
-	la->active = 1;
+	la->active = true;
 
 	fd = open("/dev/null", O_RDWR);
 	if (fd < 0) {
@@ -510,7 +510,7 @@ static notrace void logger(char *log_dir, char *outfile)
 	exit(0);
 }
 
-notrace int log_init(char *program_name, int size, int to_stdout, int level,
+notrace int log_init(char *program_name, int size, bool to_stdout, int level,
 		char *outfile)
 {
 	char log_dir[PATH_MAX], tmp[PATH_MAX];
@@ -556,7 +556,7 @@ notrace int log_init(char *program_name, int size, int to_stdout, int level,
 notrace void log_close(void)
 {
 	if (la) {
-		la->active = 0;
+		la->active = false;
 		waitpid(logger_pid, NULL, 0);
 
 		vprintf(SDOG_WARNING, "logger pid %d stopped\n", logger_pid);
diff --git a/lib/net.c b/lib/net.c
index 70bb0c3..1c6a632 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -60,12 +60,12 @@ int conn_rx_on(struct connection *conn)
 	return modify_event(conn->fd, conn->events);
 }
 
-notrace int is_conn_dead(struct connection *conn)
+notrace bool is_conn_dead(struct connection *conn)
 {
 	if (conn->c_rx_state == C_IO_CLOSED || conn->c_tx_state == C_IO_CLOSED)
-		return 1;
+		return true;
 	else
-		return 0;
+		return false;
 }
 
 int rx(struct connection *conn, enum conn_state next_state)
diff --git a/sheep/cluster/accord.c b/sheep/cluster/accord.c
index a05fc34..770a3a9 100644
--- a/sheep/cluster/accord.c
+++ b/sheep/cluster/accord.c
@@ -133,7 +133,7 @@ static void acrd_unlock(struct acrd_handle *ah)
 static int queue_start_pos;
 static int queue_end_pos;
 
-static int acrd_queue_empty(struct acrd_handle *ah)
+static bool acrd_queue_empty(struct acrd_handle *ah)
 {
 	int rc;
 	char path[256];
@@ -143,9 +143,9 @@ static int acrd_queue_empty(struct acrd_handle *ah)
 
 	rc = acrd_read(ah, path, NULL, &count, 0, 0);
 	if (rc == ACRD_SUCCESS)
-		return 0;
+		return false;
 
-	return 1;
+	return true;
 }
 
 static void acrd_queue_push(struct acrd_handle *ah, struct acrd_event *ev)
@@ -305,24 +305,24 @@ static pthread_cond_t start_cond = PTHREAD_COND_INITIALIZER;
 /* protect queue_start_pos */
 static pthread_mutex_t queue_lock = PTHREAD_MUTEX_INITIALIZER;
 
-static int need_cleanup;
+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 int init = 0;
+	static bool init = false;
 
 	if (!init) {
 		this_id = nodeid;
 
 		if (member_list_entries == 1)
-			need_cleanup = 1;
+			need_cleanup = true;
 
 		pthread_mutex_lock(&start_lock);
 		pthread_cond_signal(&start_cond);
 		pthread_mutex_unlock(&start_lock);
 
-		init = 1;
+		init = true;
 	}
 }
 
@@ -376,14 +376,14 @@ static void acrd_leave_fn(struct acrd_handle *ah, const uint64_t *member_list,
 			  size_t member_list_entries, uint64_t nodeid, void *arg)
 {
 	struct acrd_leave_info *info;
-	static int left;
+	static bool left;
 
 	if (nodeid == this_id) {
-		left = 1;
+		left = true;
 		close(efd);
 	}
 
-	if(left)
+	if (left)
 		return;
 
 	info = zalloc(sizeof(*info));
diff --git a/sheep/cluster/corosync.c b/sheep/cluster/corosync.c
index e6a0083..645d61e 100644
--- a/sheep/cluster/corosync.c
+++ b/sheep/cluster/corosync.c
@@ -39,8 +39,8 @@ static LIST_HEAD(corosync_nonblock_event_list);
 
 static struct cpg_node cpg_nodes[SD_MAX_NODES];
 static size_t nr_cpg_nodes;
-static int self_elect;
-static int join_finished;
+static bool self_elect;
+static bool join_finished;
 static int cpg_fd;
 static size_t nr_majority; /* used for network partition detection */
 
@@ -74,7 +74,7 @@ struct corosync_event {
 	uint32_t nr_nodes;
 	struct cpg_node nodes[SD_MAX_NODES];
 
-	int callbacked;
+	bool callbacked;
 
 	struct list_head list;
 };
@@ -89,7 +89,7 @@ struct corosync_message {
 	uint8_t msg[0];
 };
 
-static int cpg_node_equal(struct cpg_node *a, struct cpg_node *b)
+static bool cpg_node_equal(struct cpg_node *a, struct cpg_node *b)
 {
 	return (a->nodeid == b->nodeid && a->pid == b->pid);
 }
@@ -275,9 +275,9 @@ static void build_node_list(struct cpg_node *nodes, size_t nr_nodes,
 /*
  * Process one dispatch event
  *
- * Returns 1 if the event is processed
+ * Returns true if the event is processed
  */
-static int __corosync_dispatch_one(struct corosync_event *cevent)
+static bool __corosync_dispatch_one(struct corosync_event *cevent)
 {
 	enum cluster_join_result res;
 	struct sd_node entries[SD_MAX_NODES];
@@ -286,15 +286,15 @@ static int __corosync_dispatch_one(struct corosync_event *cevent)
 	switch (cevent->type) {
 	case COROSYNC_EVENT_TYPE_JOIN_REQUEST:
 		if (is_master(&this_node) < 0)
-			return 0;
+			return false;
 
 		if (!cevent->msg)
 			/* we haven't receive JOIN_REQUEST yet */
-			return 0;
+			return false;
 
 		if (cevent->callbacked)
 			/* check_join() must be called only once */
-			return 0;
+			return false;
 
 		res = sd_check_join_cb(&cevent->sender.ent,
 						     cevent->msg);
@@ -310,8 +310,8 @@ static int __corosync_dispatch_one(struct corosync_event *cevent)
 			exit(1);
 		}
 
-		cevent->callbacked = 1;
-		return 0;
+		cevent->callbacked = true;
+		return false;
 	case COROSYNC_EVENT_TYPE_JOIN_RESPONSE:
 		switch (cevent->result) {
 		case CJ_RES_SUCCESS:
@@ -343,16 +343,16 @@ static int __corosync_dispatch_one(struct corosync_event *cevent)
 		if (cevent->callbacked)
 			/* block events until the unblock message
 			   removes this event */
-			return 0;
+			return false;
 		cevent->callbacked = sd_block_handler(&cevent->sender.ent);
-		return 0;
+		return false;
 	case COROSYNC_EVENT_TYPE_NOTIFY:
 		sd_notify_handler(&cevent->sender.ent, cevent->msg,
 						 cevent->msg_len);
 		break;
 	}
 
-	return 1;
+	return true;
 }
 
 static void __corosync_dispatch(void)
@@ -388,14 +388,14 @@ static void __corosync_dispatch(void)
 			switch (cevent->type) {
 			case COROSYNC_EVENT_TYPE_JOIN_REQUEST:
 				if (self_elect) {
-					join_finished = 1;
+					join_finished = true;
 					nr_cpg_nodes = 0;
 				}
 				break;
 			case COROSYNC_EVENT_TYPE_JOIN_RESPONSE:
 				if (cpg_node_equal(&cevent->sender,
 						   &this_node)) {
-					join_finished = 1;
+					join_finished = true;
 					nr_cpg_nodes = cevent->nr_nodes;
 					memcpy(cpg_nodes, cevent->nodes,
 					       sizeof(*cevent->nodes) *
@@ -578,7 +578,7 @@ static void cdrv_cpg_confchg(cpg_handle_t handle,
 	struct cpg_node member_sheep[SD_MAX_NODES];
 	struct cpg_node joined_sheep[SD_MAX_NODES];
 	struct cpg_node left_sheep[SD_MAX_NODES];
-	int promote = 1;
+	bool promote = true;
 
 	dprintf("mem:%zu, joined:%zu, left:%zu\n",
 		member_list_entries, joined_list_entries,
@@ -666,7 +666,7 @@ static void cdrv_cpg_confchg(cpg_handle_t handle,
 			if (!cevent) {
 				dprintf("Not promoting because member is "
 					"not in our event list.\n");
-				promote = 0;
+				promote = false;
 				break;
 			}
 		}
@@ -676,7 +676,7 @@ static void cdrv_cpg_confchg(cpg_handle_t handle,
 		 * master right here.
 		 */
 		if (promote)
-			self_elect = 1;
+			self_elect = true;
 	}
 	__corosync_dispatch();
 }
diff --git a/sheep/cluster/local.c b/sheep/cluster/local.c
index ec8289b..d17eab5 100644
--- a/sheep/cluster/local.c
+++ b/sheep/cluster/local.c
@@ -183,7 +183,7 @@ static void shm_queue_notify(void)
 	}
 }
 
-static int is_shm_queue_valid(void)
+static bool is_shm_queue_valid(void)
 {
 	int i;
 	size_t nr;
@@ -192,13 +192,13 @@ static int is_shm_queue_valid(void)
 	nr = get_nodes(lnodes);
 
 	if (nr == 0)
-		return 1;
+		return true;
 
 	for (i = 0; i < nr; i++)
 		if (process_exists(lnodes[i].pid))
-			return 1;
+			return true;
 
-	return 0;
+	return false;
 }
 
 static void shm_queue_init(void)
diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index e16e740..ae9a423 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -49,7 +49,7 @@ enum zk_event_type {
 };
 
 struct zk_node {
-	int joined;
+	bool joined;
 	clientid_t clientid;
 	struct sd_node node;
 };
@@ -79,7 +79,7 @@ static struct sd_node sd_nodes[SD_MAX_NODES];
 static size_t nr_sd_nodes;
 static size_t nr_zk_nodes;
 
-static inline int is_blocking_event(struct zk_event *ev)
+static inline bool is_blocking_event(struct zk_event *ev)
 {
 	return ev->type == EVENT_BLOCK || ev->type == EVENT_JOIN_REQUEST;
 }
@@ -163,7 +163,7 @@ static inline ZOOAPI int zk_get_children(zhandle_t *zh, const char *path,
 static int efd;
 static int32_t queue_pos;
 
-static int zk_queue_empty(zhandle_t *zh)
+static bool zk_queue_empty(zhandle_t *zh)
 {
 	int rc;
 	char path[256];
@@ -172,14 +172,14 @@ static int zk_queue_empty(zhandle_t *zh)
 
 	rc = zk_exists(zh, path, 1, NULL);
 	if (rc == ZOK)
-		return 0;
+		return false;
 
-	return 1;
+	return true;
 }
 
 static int32_t zk_queue_push(zhandle_t *zh, struct zk_event *ev)
 {
-	static int first_push = 1;
+	static bool first_push = true;
 	int32_t seq;
 	int rc, len;
 	char path[256], buf[256];
@@ -204,7 +204,7 @@ static int32_t zk_queue_push(zhandle_t *zh, struct zk_event *ev)
 		dprintf("write event to efd:%d\n", efd);
 		eventfd_write(efd, value);
 
-		first_push = 0;
+		first_push = false;
 	}
 
 	return seq;
@@ -430,22 +430,22 @@ static void node_btree_find_master_fn(const void *nodep,
 	}
 }
 
-static int is_master(zhandle_t *zh, struct zk_node *znode)
+static bool is_master(zhandle_t *zh, struct zk_node *znode)
 {
 	zk_master = NULL;
 
 	if (!zk_node_btroot) {
 		if (zk_member_empty(zh))
-			return 1;
+			return true;
 		else
-			return 0;
+			return false;
 	}
 
 	twalk(zk_node_btroot, node_btree_find_master_fn);
 	if (node_eq(&zk_master->node, &znode->node))
-		return 1;
+		return true;
 
-	return 0;
+	return false;
 }
 
 static void zk_queue_init(zhandle_t *zh)
@@ -457,7 +457,7 @@ static void zk_queue_init(zhandle_t *zh)
 
 static void zk_member_init(zhandle_t *zh)
 {
-	static int finished;
+	static bool finished;
 	int rc, len;
 	struct String_vector strs;
 	struct zk_node znode;
@@ -466,7 +466,7 @@ static void zk_member_init(zhandle_t *zh)
 	if (finished)
 		return;
 
-	finished = 1;
+	finished = true;
 
 	if (!zk_member_empty(zh)) {
 		FOR_EACH_ZNODE(zh, MEMBER_ZNODE, path, &strs) {
@@ -591,7 +591,7 @@ static int zk_join(struct sd_node *myself,
 	if (rc == ZOK)
 		panic("previous zookeeper session exist, shutdown\n");
 
-	this_node.joined = 0;
+	this_node.joined = false;
 	cid = zoo_client_id(zhandle);
 	assert(cid != NULL);
 	this_node.clientid = *cid;
@@ -684,7 +684,7 @@ static void zk_handler(int listen_fd, int events, void *data)
 		res = sd_check_join_cb(&ev.sender.node, ev.buf);
 		ev.join_result = res;
 		ev.type = EVENT_JOIN_RESPONSE;
-		ev.sender.joined = 1;
+		ev.sender.joined = true;
 
 		dprintf("I'm master, push back join event\n");
 		zk_queue_push_back(zhandle, &ev);
diff --git a/sheep/group.c b/sheep/group.c
index c9906b3..18564c5 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -42,7 +42,7 @@ struct get_vdis_work {
 
 pthread_mutex_t wait_vdis_lock = PTHREAD_MUTEX_INITIALIZER;
 pthread_cond_t wait_vdis_cond = PTHREAD_COND_INITIALIZER;
-static int is_vdi_list_ready = 1;
+static int is_vdi_list_ready = true;
 
 static struct vnode_info *current_vnode_info;
 
@@ -670,7 +670,7 @@ static void get_vdis_done(struct work *work)
 		container_of(work, struct get_vdis_work, work);
 
 	pthread_mutex_lock(&wait_vdis_lock);
-	is_vdi_list_ready = 1;
+	is_vdi_list_ready = true;
 	pthread_cond_broadcast(&wait_vdis_cond);
 	pthread_mutex_unlock(&wait_vdis_lock);
 
@@ -702,7 +702,7 @@ static struct vnode_info *alloc_old_vnode_info(struct sd_node *joined,
 static void finish_join(struct join_message *msg, struct sd_node *joined,
 		struct sd_node *nodes, size_t nr_nodes)
 {
-	sys->join_finished = 1;
+	sys->join_finished = true;
 	sys->epoch = msg->epoch;
 
 	if (msg->cluster_status != SD_STATUS_OK)
@@ -742,7 +742,7 @@ static void get_vdis(struct sd_node *nodes, size_t nr_nodes)
 	w->nr_members = nr_nodes;
 	memcpy(w->members, nodes, array_len);
 
-	is_vdi_list_ready = 0;
+	is_vdi_list_ready = false;
 
 	w->work.fn = do_get_vdis;
 	w->work.done = get_vdis_done;
@@ -1074,7 +1074,7 @@ void sd_join_handler(struct sd_node *joined, struct sd_node *members,
 		 * Now mastership transfer is done.
 		 */
 		if (!sys->join_finished) {
-			sys->join_finished = 1;
+			sys->join_finished = true;
 			sys->epoch = get_latest_epoch();
 
 			put_vnode_info(current_vnode_info);
@@ -1208,11 +1208,11 @@ int create_cluster(int port, int64_t zone, int nr_vnodes,
  */
 int leave_cluster(void)
 {
-	static int left;
+	static bool left;
 
 	if (left)
 		return 0;
 
-	left = 1;
+	left = true;
 	return sys->cdrv->leave();
 }
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index fb606c0..c6c479a 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -99,7 +99,7 @@ static inline int mark_cache_in_reclaim(void)
 	return uatomic_cmpxchg(&sys_cache.in_reclaim, 0, 1);
 }
 
-static inline int entry_is_dirty(struct object_cache_entry *entry)
+static inline bool entry_is_dirty(struct object_cache_entry *entry)
 {
 	return !!entry->bmap;
 }
@@ -123,9 +123,9 @@ static inline uint32_t object_cache_oid_to_idx(uint64_t oid)
 	return idx;
 }
 
-static inline int idx_has_vdi_bit(uint32_t idx)
+static inline bool idx_has_vdi_bit(uint32_t idx)
 {
-	return idx & CACHE_VDI_BIT;
+	return !!(idx & CACHE_VDI_BIT);
 }
 
 static uint64_t calc_object_bmap(size_t len, off_t offset)
@@ -238,7 +238,7 @@ out:
 
 static struct object_cache_entry *
 dirty_tree_and_list_insert(struct object_cache *oc, uint32_t idx,
-			   uint64_t bmap, int create)
+			   uint64_t bmap, bool create)
 {
 	struct rb_node **p = &oc->dirty_tree.rb_node;
 	struct rb_node *parent = NULL;
@@ -289,7 +289,7 @@ static inline void update_cache_entry(struct object_cache_entry *entry,
 		uint64_t bmap = calc_object_bmap(datalen, offset);
 
 		pthread_rwlock_wrlock(&oc->lock);
-		dirty_tree_and_list_insert(oc, idx, bmap, 0);
+		dirty_tree_and_list_insert(oc, idx, bmap, false);
 		pthread_rwlock_unlock(&oc->lock);
 	}
 
@@ -384,7 +384,7 @@ static int read_cache_object(struct object_cache_entry *entry, void *buf,
 }
 
 static int write_cache_object(struct object_cache_entry *entry, void *buf,
-			      size_t count, off_t offset, int create,
+			      size_t count, off_t offset, bool create,
 			      bool writeback)
 {
 	uint32_t vid = entry->oc->vid, idx = entry_idx(entry);
@@ -421,7 +421,7 @@ out:
 }
 
 static int push_cache_object(uint32_t vid, uint32_t idx, uint64_t bmap,
-			     int create)
+			     bool create)
 {
 	struct sd_req hdr;
 	void *buf;
@@ -580,7 +580,7 @@ err:
 	return ret;
 }
 
-static struct object_cache *find_object_cache(uint32_t vid, int create)
+static struct object_cache *find_object_cache(uint32_t vid, bool create)
 {
 	int h = hash(vid);
 	struct hlist_head *head = cache_hashtable + h;
@@ -636,7 +636,7 @@ void object_cache_try_to_reclaim(void)
 }
 
 static void add_to_object_cache(struct object_cache *oc, uint32_t idx,
-				int create)
+				bool create)
 {
 	struct object_cache_entry *entry, *old;
 	uint32_t data_length;
@@ -676,7 +676,7 @@ static void add_to_object_cache(struct object_cache *oc, uint32_t idx,
 }
 
 static int object_cache_lookup(struct object_cache *oc, uint32_t idx,
-			       int create, bool writeback)
+			       bool create, bool writeback)
 {
 	struct strbuf buf;
 	int fd, ret = SD_RES_SUCCESS, flags = def_open_flags;
@@ -806,7 +806,7 @@ static int object_cache_pull(struct object_cache *oc, uint32_t idx)
 		ret = create_cache_object(oc, idx, buf, rsp->data_length,
 					  rsp->obj.offset, data_length);
 		if (ret == SD_RES_SUCCESS)
-			add_to_object_cache(oc, idx, 0);
+			add_to_object_cache(oc, idx, false);
 		else if (ret == SD_RES_OID_EXIST)
 			ret = SD_RES_SUCCESS;
 	}
@@ -837,15 +837,15 @@ push_failed:
 	return ret;
 }
 
-int object_is_cached(uint64_t oid)
+bool object_is_cached(uint64_t oid)
 {
 	uint32_t vid = oid_to_vid(oid);
 	uint32_t idx = object_cache_oid_to_idx(oid);
 	struct object_cache *cache;
 
-	cache = find_object_cache(vid, 0);
+	cache = find_object_cache(vid, false);
 	if (!cache)
-		return 0;
+		return false;
 
 	return (object_cache_lookup(cache, idx, 0, false) == SD_RES_SUCCESS);
 }
@@ -857,7 +857,7 @@ void object_cache_delete(uint32_t vid)
 	struct object_cache_entry *entry, *t;
 	struct strbuf buf = STRBUF_INIT;
 
-	cache = find_object_cache(vid, 0);
+	cache = find_object_cache(vid, false);
 	if (!cache)
 		return;
 
@@ -935,7 +935,7 @@ static int object_cache_flush_and_delete(struct object_cache *oc)
 		idx = strtoul(d->d_name, NULL, 16);
 		if (idx == ULLONG_MAX)
 			continue;
-		if (push_cache_object(vid, idx, all, 1) !=
+		if (push_cache_object(vid, idx, all, true) !=
 				SD_RES_SUCCESS) {
 			dprintf("failed to push %"PRIx64"\n",
 				idx_to_oid(vid, idx));
@@ -951,7 +951,7 @@ out:
 	return ret;
 }
 
-int bypass_object_cache(struct request *req)
+bool bypass_object_cache(struct request *req)
 {
 	uint64_t oid = req->rq.obj.oid;
 
@@ -959,20 +959,20 @@ int bypass_object_cache(struct request *req)
 		uint32_t vid = oid_to_vid(oid);
 		struct object_cache *cache;
 
-		cache = find_object_cache(vid, 0);
+		cache = find_object_cache(vid, false);
 		if (!cache)
-			return 1;
+			return true;
 		if (req->rq.flags & SD_FLAG_CMD_WRITE) {
 			object_cache_flush_and_delete(cache);
-			return 1;
+			return true;
 		} else  {
 			/* For read requet, we can read cache if any */
 			uint32_t idx = object_cache_oid_to_idx(oid);
 
-			if (object_cache_lookup(cache, idx, 0, false) == 0)
-				return 0;
+			if (object_cache_lookup(cache, idx, false, false) == 0)
+				return false;
 			else
-				return 1;
+				return true;
 		}
 	}
 
@@ -981,8 +981,8 @@ int bypass_object_cache(struct request *req)
 	 */
 	if (is_vmstate_obj(oid) || is_vdi_attr_obj(oid) ||
 	    req->rq.flags & SD_FLAG_CMD_COW)
-		return 1;
-	return 0;
+		return true;
+	return false;
 }
 
 int object_cache_handle_request(struct request *req)
@@ -993,15 +993,16 @@ int object_cache_handle_request(struct request *req)
 	uint32_t idx = object_cache_oid_to_idx(oid);
 	struct object_cache *cache;
 	struct object_cache_entry *entry;
-	int ret, create = 0;
+	int ret;
+	bool create = false;
 
 	dprintf("%08"PRIx32", len %"PRIu32", off %"PRIu64"\n", idx,
 		hdr->data_length, hdr->obj.offset);
 
-	cache = find_object_cache(vid, 1);
+	cache = find_object_cache(vid, true);
 
 	if (req->rq.opcode == SD_OP_CREATE_AND_WRITE_OBJ)
-		create = 1;
+		create = true;
 
 retry:
 	ret = object_cache_lookup(cache, idx, create,
@@ -1044,7 +1045,7 @@ err:
 }
 
 int object_cache_write(uint64_t oid, char *data, unsigned int datalen,
-		       uint64_t offset, uint16_t flags, int create)
+		       uint64_t offset, uint16_t flags, bool create)
 {
 	uint32_t vid = oid_to_vid(oid);
 	uint32_t idx = object_cache_oid_to_idx(oid);
@@ -1052,7 +1053,7 @@ int object_cache_write(uint64_t oid, char *data, unsigned int datalen,
 	struct object_cache_entry *entry;
 	int ret;
 
-	cache = find_object_cache(vid, 0);
+	cache = find_object_cache(vid, false);
 
 	dprintf("%" PRIx64 "\n", oid);
 
@@ -1078,7 +1079,7 @@ int object_cache_read(uint64_t oid, char *data, unsigned int datalen,
 	struct object_cache_entry *entry;
 	int ret;
 
-	cache = find_object_cache(vid, 0);
+	cache = find_object_cache(vid, false);
 
 	dprintf("%" PRIx64 "\n", oid);
 
@@ -1100,7 +1101,7 @@ int object_cache_flush_vdi(struct request *req)
 	uint32_t vid = oid_to_vid(req->rq.obj.oid);
 	struct object_cache *cache;
 
-	cache = find_object_cache(vid, 0);
+	cache = find_object_cache(vid, false);
 	if (!cache) {
 		dprintf("%"PRIX32" not found\n", vid);
 		return SD_RES_SUCCESS;
@@ -1114,7 +1115,7 @@ int object_cache_flush_and_del(struct request *req)
 	uint32_t vid = oid_to_vid(req->rq.obj.oid);
 	struct object_cache *cache;
 
-	cache = find_object_cache(vid, 0);
+	cache = find_object_cache(vid, false);
 
 	if (cache && object_cache_flush_and_delete(cache) < 0)
 		return SD_RES_EIO;
@@ -1129,7 +1130,7 @@ void object_cache_remove(uint64_t oid)
 	struct object_cache *oc;
 	struct object_cache_entry *entry;
 
-	oc = find_object_cache(vid, 0);
+	oc = find_object_cache(vid, false);
 	if (!oc)
 		return;
 
@@ -1172,7 +1173,7 @@ static int load_existing_cache_object(struct object_cache *cache)
 		if (idx == ULLONG_MAX)
 			continue;
 
-		add_to_object_cache(cache, idx, 0);
+		add_to_object_cache(cache, idx, false);
 		dprintf("load cache %06" PRIx32 "/%08" PRIx32 "\n",
 			cache->vid, idx);
 	}
@@ -1208,7 +1209,7 @@ static int load_existing_cache(void)
 		if (vid == ULLONG_MAX)
 			continue;
 
-		cache = find_object_cache(vid, 1);
+		cache = find_object_cache(vid, true);
 		load_existing_cache_object(cache);
 	}
 
diff --git a/sheep/ops.c b/sheep/ops.c
index 3c8aa4d..a2a795e 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -39,7 +39,7 @@ struct sd_op_template {
 	enum sd_op_type type;
 
 	/* process request even when cluster is not working */
-	int force;
+	bool force;
 
 	/*
 	 * process_work() will be called in a worker thread, and process_main()
@@ -317,7 +317,7 @@ static int cluster_shutdown(const struct sd_req *req, struct sd_rsp *rsp,
 static int cluster_enable_recover(const struct sd_req *req,
 				    struct sd_rsp *rsp, void *data)
 {
-	sys->disable_recovery = 0;
+	sys->disable_recovery = false;
 	resume_suspended_recovery();
 	return SD_RES_SUCCESS;
 }
@@ -325,7 +325,7 @@ static int cluster_enable_recover(const struct sd_req *req,
 static int cluster_disable_recover(const struct sd_req *req,
 				   struct sd_rsp *rsp, void *data)
 {
-	sys->disable_recovery = 1;
+	sys->disable_recovery = true;
 	return SD_RES_SUCCESS;
 }
 
@@ -350,9 +350,9 @@ static int cluster_get_vdi_attr(struct request *req)
 	vid &= SD_NR_VDIS - 1;
 	ret = get_vdi_attr(req->data, hdr->data_length,
 			   vid, &attrid, created_time,
-			   hdr->flags & SD_FLAG_CMD_CREAT,
-			   hdr->flags & SD_FLAG_CMD_EXCL,
-			   hdr->flags & SD_FLAG_CMD_DEL);
+			   !!(hdr->flags & SD_FLAG_CMD_CREAT),
+			   !!(hdr->flags & SD_FLAG_CMD_EXCL),
+			   !!(hdr->flags & SD_FLAG_CMD_DEL));
 
 	rsp->vdi.vdi_id = vid;
 	rsp->vdi.attr_id = attrid;
@@ -933,7 +933,7 @@ static struct sd_op_template sd_ops[] = {
 	[SD_OP_MAKE_FS] = {
 		.name = "MAKE_FS",
 		.type = SD_OP_TYPE_CLUSTER,
-		.force = 1,
+		.force = true,
 		.process_main = cluster_make_fs,
 	},
 
@@ -957,42 +957,42 @@ static struct sd_op_template sd_ops[] = {
 	[SD_OP_FORCE_RECOVER] = {
 		.name = "FORCE_RECOVER",
 		.type = SD_OP_TYPE_CLUSTER,
-		.force = 1,
+		.force = true,
 		.process_main = cluster_force_recover,
 	},
 
 	[SD_OP_SNAPSHOT] = {
 		.name = "SNAPSHOT",
 		.type = SD_OP_TYPE_CLUSTER,
-		.force = 1,
+		.force = true,
 		.process_main = cluster_snapshot,
 	},
 
 	[SD_OP_RESTORE] = {
 		.name = "RESTORE",
 		.type = SD_OP_TYPE_CLUSTER,
-		.force = 1,
+		.force = true,
 		.process_main = cluster_restore,
 	},
 
 	[SD_OP_CLEANUP] = {
 		.name = "CLEANUP",
 		.type = SD_OP_TYPE_CLUSTER,
-		.force = 1,
+		.force = true,
 		.process_main = cluster_cleanup,
 	},
 
 	[SD_OP_NOTIFY_VDI_DEL] = {
 		.name = "NOTIFY_VDI_DEL",
 		.type = SD_OP_TYPE_CLUSTER,
-		.force = 1,
+		.force = true,
 		.process_main = cluster_notify_vdi_del,
 	},
 
 	[SD_OP_COMPLETE_RECOVERY] = {
 		.name = "COMPLETE_RECOVERY",
 		.type = SD_OP_TYPE_CLUSTER,
-		.force = 1,
+		.force = true,
 		.process_main = cluster_recovery_completion,
 	},
 
@@ -1000,28 +1000,28 @@ static struct sd_op_template sd_ops[] = {
 	[SD_OP_GET_STORE_LIST] = {
 		.name = "GET_STORE_LIST",
 		.type = SD_OP_TYPE_LOCAL,
-		.force = 1,
+		.force = true,
 		.process_work = local_get_store_list,
 	},
 
 	[SD_OP_READ_VDIS] = {
 		.name = "READ_VDIS",
 		.type = SD_OP_TYPE_LOCAL,
-		.force = 1,
+		.force = true,
 		.process_main = local_read_vdis,
 	},
 
 	[SD_OP_GET_VDI_COPIES] = {
 		.name = "GET_VDI_COPIES",
 		.type = SD_OP_TYPE_LOCAL,
-		.force = 1,
+		.force = true,
 		.process_main = local_get_vdi_copies,
 	},
 
 	[SD_OP_GET_NODE_LIST] = {
 		.name = "GET_NODE_LIST",
 		.type = SD_OP_TYPE_LOCAL,
-		.force = 1,
+		.force = true,
 		.process_main = local_get_node_list,
 	},
 
@@ -1040,7 +1040,7 @@ static struct sd_op_template sd_ops[] = {
 	[SD_OP_STAT_CLUSTER] = {
 		.name = "STAT_CLUSTER",
 		.type = SD_OP_TYPE_LOCAL,
-		.force = 1,
+		.force = true,
 		.process_work = local_stat_cluster,
 	},
 
@@ -1059,7 +1059,7 @@ static struct sd_op_template sd_ops[] = {
 	[SD_OP_GET_SNAP_FILE] = {
 		.name = "GET_SNAP_FILE",
 		.type = SD_OP_TYPE_LOCAL,
-		.force = 1,
+		.force = true,
 		.process_work = local_get_snap_file,
 	},
 
@@ -1078,21 +1078,21 @@ static struct sd_op_template sd_ops[] = {
 	[SD_OP_TRACE] = {
 		.name = "TRACE",
 		.type = SD_OP_TYPE_LOCAL,
-		.force = 1,
+		.force = true,
 		.process_main = local_trace_ops,
 	},
 
 	[SD_OP_TRACE_READ_BUF] = {
 		.name = "TRACE_READ_BUF",
 		.type = SD_OP_TYPE_LOCAL,
-		.force = 1,
+		.force = true,
 		.process_work = local_trace_read_buf,
 	},
 
 	[SD_OP_KILL_NODE] = {
 		.name = "KILL_NODE",
 		.type = SD_OP_TYPE_LOCAL,
-		.force = 1,
+		.force = true,
 		.process_main = local_kill_node,
 	},
 
@@ -1189,37 +1189,37 @@ const char *op_name(struct sd_op_template *op)
 	return op->name;
 }
 
-int is_cluster_op(struct sd_op_template *op)
+bool is_cluster_op(struct sd_op_template *op)
 {
 	return op->type == SD_OP_TYPE_CLUSTER;
 }
 
-int is_local_op(struct sd_op_template *op)
+bool is_local_op(struct sd_op_template *op)
 {
 	return op->type == SD_OP_TYPE_LOCAL;
 }
 
-int is_peer_op(struct sd_op_template *op)
+bool is_peer_op(struct sd_op_template *op)
 {
 	return op->type == SD_OP_TYPE_PEER;
 }
 
-int is_gateway_op(struct sd_op_template *op)
+bool is_gateway_op(struct sd_op_template *op)
 {
 	return op->type == SD_OP_TYPE_GATEWAY;
 }
 
-int is_force_op(struct sd_op_template *op)
+bool is_force_op(struct sd_op_template *op)
 {
 	return !!op->force;
 }
 
-int has_process_work(struct sd_op_template *op)
+bool has_process_work(struct sd_op_template *op)
 {
 	return !!op->process_work;
 }
 
-int has_process_main(struct sd_op_template *op)
+bool has_process_main(struct sd_op_template *op)
 {
 	return !!op->process_main;
 }
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 9e59a80..6c9b123 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -91,7 +91,7 @@ int for_each_object_in_wd(int (*func)(uint64_t oid, void *arg), bool cleanup,
 	return ret;
 }
 
-int default_exist(uint64_t oid)
+bool default_exist(uint64_t oid)
 {
 	char path[PATH_MAX];
 
@@ -99,10 +99,10 @@ int default_exist(uint64_t oid)
 	if (access(path, R_OK | W_OK) < 0) {
 		if (errno != ENOENT)
 			eprintf("failed to check object %"PRIx64", %m\n", oid);
-		return 0;
+		return false;
 	}
 
-	return 1;
+	return true;
 }
 
 static int err_to_sderr(uint64_t oid, int err)
diff --git a/sheep/recovery.c b/sheep/recovery.c
index 17dbbbb..f455a2b 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -28,7 +28,7 @@ struct recovery_work {
 	uint32_t epoch;
 	uint32_t done;
 
-	int stop;
+	bool stop;
 	struct work work;
 	bool suspended; /* true when automatic recovery is disabled
 			 * and recovery process is suspended */
@@ -113,13 +113,13 @@ out:
  * A virtual node that does not match any node in current node list
  * means the node has left the cluster, then it's an invalid virtual node.
  */
-static int is_invalid_vnode(struct sd_vnode *entry, struct sd_node *nodes,
-				int nr_nodes)
+static bool is_invalid_vnode(struct sd_vnode *entry, struct sd_node *nodes,
+			     int nr_nodes)
 {
 	if (bsearch(entry, nodes, nr_nodes, sizeof(struct sd_node),
 		    node_id_cmp))
-		return 0;
-	return 1;
+		return false;
+	return true;
 }
 
 /*
@@ -156,7 +156,7 @@ again:
 			/* Succeed */
 			break;
 		} else if (SD_RES_OLD_NODE_VER == ret) {
-			rw->stop = 1;
+			rw->stop = true;
 			goto err;
 		} else
 			ret = -1;
@@ -208,12 +208,12 @@ static void recover_object_work(struct work *work)
 		eprintf("failed to recover object %"PRIx64"\n", oid);
 }
 
-int node_in_recovery(void)
+bool node_in_recovery(void)
 {
 	return !!recovering_work;
 }
 
-int is_recovery_init(void)
+bool is_recovery_init(void)
 {
 	struct recovery_work *rw = recovering_work;
 
@@ -574,12 +574,12 @@ again:
 	qsort(rw->oids, rw->count, sizeof(uint64_t), obj_cmp);
 }
 
-static int newly_joined(struct sd_node *node, struct recovery_work *rw)
+static bool newly_joined(struct sd_node *node, struct recovery_work *rw)
 {
 	if (bsearch(node, rw->old_vinfo->nodes, rw->old_vinfo->nr_nodes,
 		    sizeof(struct sd_node), node_id_cmp))
-		return 0;
-	return 1;
+		return false;
+	return true;
 }
 
 /* Prepare the object list that belongs to this node */
diff --git a/sheep/request.c b/sheep/request.c
index 2a76547..5922bed 100644
--- a/sheep/request.c
+++ b/sheep/request.c
@@ -24,7 +24,7 @@
 
 static void requeue_request(struct request *req);
 
-static int is_access_local(struct request *req, uint64_t oid)
+static bool is_access_local(struct request *req, uint64_t oid)
 {
 	struct sd_vnode *obj_vnodes[SD_MAX_COPIES];
 	int nr_copies;
@@ -36,10 +36,10 @@ static int is_access_local(struct request *req, uint64_t oid)
 
 	for (i = 0; i < nr_copies; i++) {
 		if (vnode_is_local(obj_vnodes[i]))
-			return 1;
+			return true;
 	}
 
-	return 0;
+	return false;
 }
 
 static void io_op_done(struct work *work)
@@ -433,7 +433,7 @@ static struct request *alloc_local_request(void *data, int data_length)
 		req->data = data;
 	}
 
-	req->local = 1;
+	req->local = true;
 
 	INIT_LIST_HEAD(&req->request_list);
 
@@ -531,10 +531,9 @@ void put_request(struct request *req)
 	if (uatomic_sub_return(&req->refcnt, 1) > 0)
 		return;
 
-	if (req->local) {
-		req->done = 1;
+	if (req->local)
 		eventfd_write(req->wait_efd, value);
-	} else {
+	else {
 		if (conn_tx_on(&ci->conn)) {
 			clear_client_info(ci);
 			free_request(req);
diff --git a/sheep/sheep.c b/sheep/sheep.c
index daa4e93..a5567eb 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -228,7 +228,7 @@ static void object_cache_directio_set(char *s)
 static void _object_cache_set(char *s)
 {
 	int i;
-	static int first = 1;
+	static bool first = true;
 
 	struct object_cache_arg {
 		const char *name;
@@ -243,7 +243,7 @@ static void _object_cache_set(char *s)
 
 	if (first) {
 		assert(!strcmp(s, "object"));
-		first = 0;
+		first = false;
 		return;
 	}
 
@@ -316,8 +316,8 @@ int main(int argc, char **argv)
 	int ch, longindex;
 	int ret, port = SD_LISTEN_PORT;
 	const char *dir = DEFAULT_OBJECT_DIR;
-	int is_daemon = 1;
-	int to_stdout = 0;
+	bool is_daemon = true;
+	bool to_stdout = false;
 	int log_level = SDOG_INFO;
 	char path[PATH_MAX];
 	int64_t zone = -1;
@@ -350,7 +350,7 @@ int main(int argc, char **argv)
 			pid_file = optarg;
 			break;
 		case 'f':
-			is_daemon = 0;
+			is_daemon = false;
 			break;
 		case 'l':
 			log_level = strtol(optarg, &p, 10);
@@ -382,7 +382,7 @@ int main(int argc, char **argv)
 			nr_vnodes = 0;
 			break;
 		case 'o':
-			to_stdout = 1;
+			to_stdout = true;
 			break;
 		case 'z':
 			zone = strtol(optarg, &p, 10);
@@ -449,7 +449,7 @@ int main(int argc, char **argv)
 		}
 	}
 	if (nr_vnodes == 0) {
-		sys->gateway_only = 1;
+		sys->gateway_only = true;
 		sys->disk_space = 0;
 	}
 
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index ecfeb5f..9a72f78 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -51,8 +51,7 @@ struct request {
 	struct list_head pending_list;
 
 	int refcnt;
-	int local;
-	int done;
+	bool local;
 	int wait_efd;
 
 	uint64_t local_oid;
@@ -67,7 +66,7 @@ struct cluster_info {
 	const char *cdrv_option;
 
 	/* set after finishing the JOIN procedure */
-	int join_finished;
+	bool join_finished;
 	struct sd_node this_node;
 
 	uint32_t epoch;
@@ -104,8 +103,8 @@ struct cluster_info {
 
 	uint32_t recovered_epoch;
 
-	uint8_t gateway_only;
-	uint8_t disable_recovery;
+	bool gateway_only;
+	bool disable_recovery;
 
 	struct work_queue *gateway_wqueue;
 	struct work_queue *io_wqueue;
@@ -149,7 +148,7 @@ struct store_driver {
 	struct list_head list;
 	const char *name;
 	int (*init)(char *path);
-	int (*exist)(uint64_t oid);
+	bool (*exist)(uint64_t oid);
 	/* create_and_write must be an atomic operation*/
 	int (*create_and_write)(uint64_t oid, struct siocb *);
 	int (*write)(uint64_t oid, struct siocb *);
@@ -170,7 +169,7 @@ struct store_driver {
 };
 
 int default_init(char *p);
-int default_exist(uint64_t oid);
+bool default_exist(uint64_t oid);
 int default_create_and_write(uint64_t oid, struct siocb *iocb);
 int default_write(uint64_t oid, struct siocb *iocb);
 int default_read(uint64_t oid, struct siocb *iocb);
@@ -238,8 +237,8 @@ int lookup_vdi(char *name, char *tag, uint32_t *vid, uint32_t snapid,
 int read_vdis(char *data, int len, unsigned int *rsp_len);
 
 int get_vdi_attr(struct sheepdog_vdi_attr *vattr, int data_len, uint32_t vid,
-		uint32_t *attrid, uint64_t ctime, int write,
-		int excl, int delete);
+		uint32_t *attrid, uint64_t ctime, bool write,
+		bool excl, bool delete);
 
 int local_get_node_list(const struct sd_req *req, struct sd_rsp *rsp,
 		void *data);
@@ -294,13 +293,13 @@ int objlist_cache_cleanup(uint32_t vid);
 int start_recovery(struct vnode_info *cur_vinfo, struct vnode_info *old_vinfo);
 void resume_recovery_work(void);
 bool oid_in_recovery(uint64_t oid);
-int is_recovery_init(void);
-int node_in_recovery(void);
+bool is_recovery_init(void);
+bool node_in_recovery(void);
 
 int read_backend_object(uint64_t oid, char *data, unsigned int datalen,
 		       uint64_t offset, int nr_copies);
 int write_object(uint64_t oid, char *data, unsigned int datalen,
-		 uint64_t offset, uint16_t flags, int create, int nr_copies);
+		 uint64_t offset, uint16_t flags, bool create, int nr_copies);
 int read_object(uint64_t oid, char *data, unsigned int datalen,
 		uint64_t offset, int nr_copies);
 int remove_object(uint64_t oid, int nr_copies);
@@ -319,13 +318,13 @@ void put_request(struct request *req);
 
 struct sd_op_template *get_sd_op(uint8_t opcode);
 const char *op_name(struct sd_op_template *op);
-int is_cluster_op(struct sd_op_template *op);
-int is_local_op(struct sd_op_template *op);
-int is_peer_op(struct sd_op_template *op);
-int is_gateway_op(struct sd_op_template *op);
-int is_force_op(struct sd_op_template *op);
-int has_process_work(struct sd_op_template *op);
-int has_process_main(struct sd_op_template *op);
+bool is_cluster_op(struct sd_op_template *op);
+bool is_local_op(struct sd_op_template *op);
+bool is_peer_op(struct sd_op_template *op);
+bool is_gateway_op(struct sd_op_template *op);
+bool is_force_op(struct sd_op_template *op);
+bool has_process_work(struct sd_op_template *op);
+bool has_process_main(struct sd_op_template *op);
 void do_process_work(struct work *work);
 int do_process_main(struct sd_op_template *op, const struct sd_req *req,
 		    struct sd_rsp *rsp, void *data);
@@ -338,19 +337,19 @@ struct jrnl_descriptor *jrnl_begin(const void *buf, size_t count, off_t offset,
 int jrnl_end(struct jrnl_descriptor * jd);
 int jrnl_recover(const char *jrnl_dir);
 
-static inline int is_myself(uint8_t *addr, uint16_t port)
+static inline bool is_myself(uint8_t *addr, uint16_t port)
 {
 	return (memcmp(addr, sys->this_node.nid.addr,
 		       sizeof(sys->this_node.nid.addr)) == 0) &&
 		port == sys->this_node.nid.port;
 }
 
-static inline int vnode_is_local(struct sd_vnode *v)
+static inline bool vnode_is_local(struct sd_vnode *v)
 {
 	return is_myself(v->nid.addr, v->nid.port);
 }
 
-static inline int node_is_local(struct sd_node *n)
+static inline bool node_is_local(struct sd_node *n)
 {
 	return is_myself(n->nid.addr, n->nid.port);
 }
@@ -373,13 +372,13 @@ int default_flush(void);
 
 /* object_cache */
 
-int bypass_object_cache(struct request *req);
-int object_is_cached(uint64_t oid);
+bool bypass_object_cache(struct request *req);
+bool object_is_cached(uint64_t oid);
 
 void object_cache_try_to_reclaim(void);
 int object_cache_handle_request(struct request *req);
 int object_cache_write(uint64_t oid, char *data, unsigned int datalen,
-		       uint64_t offset, uint16_t flags, int create);
+		       uint64_t offset, uint16_t flags, bool create);
 int object_cache_read(uint64_t oid, char *data, unsigned int datalen,
 		      uint64_t offset);
 int object_cache_flush_vdi(struct request *req);
diff --git a/sheep/store.c b/sheep/store.c
index fa2d5dc..e3c95bd 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -168,12 +168,13 @@ uint32_t get_latest_epoch(void)
 	return epoch;
 }
 
-static int init_path(const char *d, int *new)
+static int init_path(const char *d, bool *new)
 {
 	int ret, retry = 0;
 	struct stat s;
 
-	*new = 0;
+	if (new)
+		*new = false;
 again:
 	ret = stat(d, &s);
 	if (ret) {
@@ -187,7 +188,8 @@ again:
 			eprintf("cannot create the directory %s: %m\n", d);
 			return 1;
 		} else {
-			*new = 1;
+			if (new)
+				*new = true;
 			retry++;
 			goto again;
 		}
@@ -238,10 +240,9 @@ out:
 
 int init_base_path(const char *d)
 {
-	int new = 0;
 	int ret;
 
-	ret = init_path(d, &new);
+	ret = init_path(d, NULL);
 	if (ret)
 		return ret;
 	return lock_base_dir(d);
@@ -251,7 +252,7 @@ int init_base_path(const char *d)
 
 static int init_obj_path(const char *base_path)
 {
-	int new, len;
+	int len;
 
 	len = strlen(base_path);
 	/* farm needs extra HEX_LEN + 3 chars to store snapshot objects.
@@ -265,19 +266,17 @@ static int init_obj_path(const char *base_path)
 	obj_path = zalloc(strlen(base_path) + strlen(OBJ_PATH) + 1);
 	sprintf(obj_path, "%s" OBJ_PATH, base_path);
 
-	return init_path(obj_path, &new);
+	return init_path(obj_path, NULL);
 }
 
 #define EPOCH_PATH "/epoch/"
 
 static int init_epoch_path(const char *base_path)
 {
-	int new;
-
 	epoch_path = zalloc(strlen(base_path) + strlen(EPOCH_PATH) + 1);
 	sprintf(epoch_path, "%s" EPOCH_PATH, base_path);
 
-	return init_path(epoch_path, &new);
+	return init_path(epoch_path, NULL);
 }
 
 static int init_mnt_path(const char *base_path)
@@ -315,7 +314,8 @@ static int init_mnt_path(const char *base_path)
 
 static int init_jrnl_path(const char *base_path)
 {
-	int new, ret;
+	int ret;
+	bool new;
 
 	/* Create journal directory */
 	jrnl_path = zalloc(strlen(base_path) + strlen(JRNL_PATH) + 1);
@@ -452,7 +452,7 @@ int init_store(const char *d)
  * Write data to both local object cache (if enabled) and backends
  */
 int write_object(uint64_t oid, char *data, unsigned int datalen,
-		 uint64_t offset, uint16_t flags, int create, int nr_copies)
+		 uint64_t offset, uint16_t flags, bool create, int nr_copies)
 {
 	struct sd_req hdr;
 	int ret;
diff --git a/sheep/trace/graph.c b/sheep/trace/graph.c
index c6b6833..c9c58a8 100644
--- a/sheep/trace/graph.c
+++ b/sheep/trace/graph.c
@@ -94,7 +94,7 @@ static notrace void graph_tracer(unsigned long ip, unsigned long *ret_addr)
 
 	memset(&trace, 0, sizeof(trace));
 
-	cr = trace_lookup_ip(ip, 0);
+	cr = trace_lookup_ip(ip, false);
 	assert(cr->namelen + 1 < TRACE_FNAME_LEN);
 	memcpy(trace.fname, cr->name, cr->namelen);
 	memset(trace.fname + cr->namelen, '\0', 1);
diff --git a/sheep/trace/stabs.c b/sheep/trace/stabs.c
index 3e68cc4..4aa8a70 100644
--- a/sheep/trace/stabs.c
+++ b/sheep/trace/stabs.c
@@ -66,7 +66,8 @@ extern const char __STABSTR_END__[];
 static notrace void stab_bsearch(const struct stab *stabs, int *region_left, int *region_right,
 		int type, uintptr_t addr)
 {
-	int l = *region_left, r = *region_right, any_matches = 0;
+	int l = *region_left, r = *region_right;
+	bool any_matches = false;
 
 	while (l <= r) {
 		int true_m = (l + r) / 2, m = true_m;
@@ -80,7 +81,7 @@ static notrace void stab_bsearch(const struct stab *stabs, int *region_left, int
 		}
 
 		/* actual binary search */
-		any_matches = 1;
+		any_matches = true;
 		if (stabs[m].value < addr) {
 			*region_left = m;
 			l = true_m + 1;
diff --git a/sheep/trace/trace.c b/sheep/trace/trace.c
index f27ea39..326340e 100644
--- a/sheep/trace/trace.c
+++ b/sheep/trace/trace.c
@@ -37,7 +37,7 @@ static trace_func_t trace_func = trace_call;
 
 static int trace_efd;
 static int nr_short_thread;
-static int trace_in_patch;
+static bool trace_in_patch;
 
 static pthread_mutex_t suspend_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t suspend_cond = PTHREAD_COND_INITIALIZER;
@@ -106,7 +106,7 @@ static notrace int make_text_writable(unsigned long ip)
 	return mprotect((void *)start, getpagesize() + INSN_SIZE, PROT_READ | PROT_EXEC | PROT_WRITE);
 }
 
-notrace struct caller *trace_lookup_ip(unsigned long ip, int create)
+notrace struct caller *trace_lookup_ip(unsigned long ip, bool create)
 {
 	int h = trace_hash(ip);
 	struct hlist_head *head = trace_hashtable + h;
@@ -165,7 +165,7 @@ static notrace void do_trace_init(unsigned long ip)
 		return;
 
 	memcpy((void *)ip, NOP5, INSN_SIZE);
-	trace_lookup_ip(ip, 1);
+	trace_lookup_ip(ip, true);
 }
 
 notrace int register_trace_function(trace_func_t func)
@@ -258,7 +258,7 @@ static notrace void enable_tracer(int fd, int events, void *data)
 	patch_all_sites((unsigned long)trace_caller);
 	resume_worker_threads();
 	unregister_event(trace_efd);
-	trace_in_patch = 0;
+	trace_in_patch = false;
 	dprintf("tracer enabled\n");
 }
 
@@ -280,7 +280,7 @@ static notrace void disable_tracer(int fd, int events, void *data)
 	nop_all_sites();
 	resume_worker_threads();
 	unregister_event(trace_efd);
-	trace_in_patch = 0;
+	trace_in_patch = false;
 	dprintf("tracer disabled\n");
 }
 
@@ -292,7 +292,7 @@ notrace int trace_enable(void)
 	}
 
 	register_event(trace_efd, enable_tracer, NULL);
-	trace_in_patch = 1;
+	trace_in_patch = true;
 
 	return SD_RES_SUCCESS;
 }
@@ -300,7 +300,7 @@ notrace int trace_enable(void)
 notrace int trace_disable(void)
 {
 	register_event(trace_efd, disable_tracer, NULL);
-	trace_in_patch = 1;
+	trace_in_patch = true;
 
 	return SD_RES_SUCCESS;
 }
diff --git a/sheep/trace/trace.h b/sheep/trace/trace.h
index cdeb2a1..730af97 100644
--- a/sheep/trace/trace.h
+++ b/sheep/trace/trace.h
@@ -54,7 +54,7 @@ extern unsigned long trace_return_call(void);
   extern int register_trace_function(trace_func_t func);
   extern int trace_enable(void);
   extern int trace_disable(void);
-  extern struct caller *trace_lookup_ip(unsigned long ip, int create);
+  extern struct caller *trace_lookup_ip(unsigned long ip, bool create);
   extern int trace_buffer_pop(void *buf, uint32_t len);
   extern void trace_buffer_push(int cpuid, struct trace_graph_item *item);
   extern void short_thread_begin(void);
diff --git a/sheep/vdi.c b/sheep/vdi.c
index ecfcd40..c02ec4f 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -284,7 +284,7 @@ static int create_vdi_obj(struct vdi_iocb *iocb, uint32_t new_vid,
 
 	if (iocb->snapid && cur_vid != iocb->base_vid) {
 		ret = write_object(vid_to_vdi_oid(cur_vid), (char *)cur,
-				   SD_INODE_HEADER_SIZE, 0, 0, 0, 0);
+				   SD_INODE_HEADER_SIZE, 0, 0, false, 0);
 		if (ret != 0) {
 			vprintf(SDOG_ERR, "failed\n");
 			ret = SD_RES_BASE_VDI_READ;
@@ -294,7 +294,7 @@ static int create_vdi_obj(struct vdi_iocb *iocb, uint32_t new_vid,
 
 	if (iocb->base_vid) {
 		ret = write_object(vid_to_vdi_oid(iocb->base_vid), (char *)base,
-				   SD_INODE_HEADER_SIZE, 0, 0, 0, 0);
+				   SD_INODE_HEADER_SIZE, 0, 0, false, 0);
 		if (ret != 0) {
 			vprintf(SDOG_ERR, "failed\n");
 			ret = SD_RES_BASE_VDI_WRITE;
@@ -303,7 +303,7 @@ static int create_vdi_obj(struct vdi_iocb *iocb, uint32_t new_vid,
 	}
 
 	ret = write_object(vid_to_vdi_oid(new_vid), (char *)new, sizeof(*new),
-			   0, 0, 1, iocb->nr_copies);
+			   0, 0, true, iocb->nr_copies);
 	if (ret != 0)
 		ret = SD_RES_VDI_WRITE;
 
@@ -322,7 +322,7 @@ static int find_first_vdi(unsigned long start, unsigned long end, char *name,
 	struct sheepdog_inode *inode = NULL;
 	unsigned long i;
 	int ret = SD_RES_NO_MEM;
-	int vdi_found = 0;
+	bool vdi_found = false;
 	int nr_copies;
 
 	inode = malloc(SD_INODE_HEADER_SIZE);
@@ -346,7 +346,7 @@ static int find_first_vdi(unsigned long start, unsigned long end, char *name,
 		}
 
 		if (!strncmp(inode->name, name, strlen(inode->name))) {
-			vdi_found = 1;
+			vdi_found = true;
 			if (tag && tag[0] &&
 			    strncmp(inode->tag, tag, sizeof(inode->tag)) != 0)
 				continue;
@@ -561,7 +561,7 @@ static int delete_inode(struct deletion_work *dw)
 	memset(inode->name, 0, sizeof(inode->name));
 
 	ret = write_object(vid_to_vdi_oid(dw->vid), (char *)inode,
-			   SD_INODE_HEADER_SIZE, 0, 0, 0, dw->nr_copies);
+			   SD_INODE_HEADER_SIZE, 0, 0, false, dw->nr_copies);
 	if (ret != 0) {
 		ret = SD_RES_EIO;
 		goto out;
@@ -648,7 +648,7 @@ static void delete_one(struct work *work)
 	memset(inode->name, 0, sizeof(inode->name));
 
 	write_object(vid_to_vdi_oid(vdi_id), (void *)inode,
-		     sizeof(*inode), 0, 0, 0, nr_copies);
+		     sizeof(*inode), 0, 0, false, nr_copies);
 out:
 	free(inode);
 }
@@ -725,12 +725,12 @@ out:
 	return 1;
 }
 
-static uint64_t get_vdi_root(uint32_t vid, int *cloned)
+static uint64_t get_vdi_root(uint32_t vid, bool *cloned)
 {
 	int ret, nr_copies;
 	struct sheepdog_inode *inode = NULL;
 
-	*cloned = 0;
+	*cloned = false;
 
 	inode = malloc(SD_INODE_HEADER_SIZE);
 	if (!inode) {
@@ -748,7 +748,7 @@ next:
 			&& !inode->snap_ctime) {
 		dprintf("vdi %" PRIx32 " is a cloned vdi.\n", vid);
 		/* current vdi is a cloned vdi */
-		*cloned = 1;
+		*cloned = true;
 	}
 
 	if (ret != SD_RES_SUCCESS) {
@@ -772,7 +772,8 @@ out:
 static int start_deletion(struct request *req, uint32_t vid)
 {
 	struct deletion_work *dw = NULL;
-	int ret = SD_RES_NO_MEM, cloned;
+	int ret = SD_RES_NO_MEM;
+	bool cloned;
 	uint32_t root_vid;
 
 	dw = zalloc(sizeof(struct deletion_work));
@@ -838,7 +839,7 @@ err:
 
 int get_vdi_attr(struct sheepdog_vdi_attr *vattr, int data_len,
 		 uint32_t vid, uint32_t *attrid, uint64_t create_time,
-		 int wr, int excl, int delete)
+		 bool wr, bool excl, bool delete)
 {
 	struct sheepdog_vdi_attr tmp_attr;
 	uint64_t oid, hval;
@@ -863,7 +864,7 @@ int get_vdi_attr(struct sheepdog_vdi_attr *vattr, int data_len,
 
 		if (ret == SD_RES_NO_OBJ && wr) {
 			ret = write_object(oid, (char *)vattr,
-					   data_len, 0, 0, 1, nr_copies);
+					   data_len, 0, 0, true, nr_copies);
 			if (ret)
 				ret = SD_RES_EIO;
 			else
@@ -884,15 +885,15 @@ int get_vdi_attr(struct sheepdog_vdi_attr *vattr, int data_len,
 			else if (delete) {
 				ret = write_object(oid, (char *)"", 1,
 						   offsetof(struct sheepdog_vdi_attr, name),
-						   0, 0, nr_copies);
+						   0, false, nr_copies);
 				if (ret)
 					ret = SD_RES_EIO;
 				else
 					ret = SD_RES_SUCCESS;
 			} else if (wr) {
 				ret = write_object(oid, (char *)vattr,
-						   SD_ATTR_OBJ_SIZE, 0, 0, 0,
-						   nr_copies);
+						   SD_ATTR_OBJ_SIZE, 0, 0,
+						   false, nr_copies);
 
 				if (ret)
 					ret = SD_RES_EIO;
diff --git a/sheep/work.c b/sheep/work.c
index 4240db9..d32e7ad 100644
--- a/sheep/work.c
+++ b/sheep/work.c
@@ -187,9 +187,9 @@ retest:
 static int init_eventfd(void)
 {
 	int ret;
-	static int done = 0;
+	static bool done = false;
 
-	if (done++)
+	if (done)
 		return 0;
 
 	efd = eventfd(0, EFD_NONBLOCK);
@@ -205,6 +205,8 @@ static int init_eventfd(void)
 		return 1;
 	}
 
+	done = true;
+
 	return 0;
 }
 
diff --git a/sheepfs/core.c b/sheepfs/core.c
index e46b3b8..f9a0f76 100644
--- a/sheepfs/core.c
+++ b/sheepfs/core.c
@@ -34,8 +34,8 @@ char sheepfs_shadow[PATH_MAX];
 
 static int sheepfs_debug;
 static int sheepfs_fg;
-int sheepfs_page_cache = 0;
-int sheepfs_object_cache = 1;
+int sheepfs_page_cache = false;
+int sheepfs_object_cache = true;
 char sdhost[32] = "localhost";
 int sdport = SD_LISTEN_PORT;
 
@@ -323,20 +323,20 @@ int main(int argc, char **argv)
 			memcpy(sdhost, optarg, strlen(optarg));
 			break;
 		case 'd':
-			sheepfs_debug = 1;
+			sheepfs_debug = true;
 			break;
 		case 'h':
 			usage(0);
 			break;
 		case 'f':
-			sheepfs_fg = 1;
+			sheepfs_fg = true;
 			fs_printf = fg_printf;
 			break;
 		case 'k':
-			sheepfs_page_cache = 1;
+			sheepfs_page_cache = true;
 			break;
 		case 'n':
-			sheepfs_object_cache = 0;
+			sheepfs_object_cache = false;
 			break;
 		case 'p':
 			sdport = strtol(optarg, NULL, 10);
diff --git a/sheepfs/shadow_file.c b/sheepfs/shadow_file.c
index 4037e65..3c6b0c0 100644
--- a/sheepfs/shadow_file.c
+++ b/sheepfs/shadow_file.c
@@ -134,7 +134,7 @@ int shadow_file_delete(const char *path)
 	return 0;
 }
 
-int shadow_file_exsit(const char *path)
+bool shadow_file_exsit(const char *path)
 {
 	char p[PATH_MAX];
 
@@ -142,8 +142,8 @@ int shadow_file_exsit(const char *path)
 	if (access(p, R_OK | W_OK) < 0) {
 		if (errno != ENOENT)
 			sheepfs_pr("%m\n");
-		return 0;
+		return false;
 	}
 
-	return 1;
+	return true;
 }
diff --git a/sheepfs/sheepfs.h b/sheepfs/sheepfs.h
index da59a92..bda109a 100644
--- a/sheepfs/sheepfs.h
+++ b/sheepfs/sheepfs.h
@@ -48,7 +48,7 @@ extern int shadow_file_setxattr(const char *path, const char *name,
 extern int shadow_file_getxattr(const char *path, const char *name,
 				void *value, size_t size);
 extern int shadow_file_delete(const char *path);
-extern int shadow_file_exsit(const char *path);
+extern bool shadow_file_exsit(const char *path);
 
 /* volume.c */
 extern int create_volume_layout(void);
diff --git a/sheepfs/volume.c b/sheepfs/volume.c
index d39f705..20cf029 100644
--- a/sheepfs/volume.c
+++ b/sheepfs/volume.c
@@ -141,7 +141,7 @@ static int volume_rw_object(char *buf, uint64_t oid, size_t size,
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 	int ret, fd, sock_idx;
 	unsigned wlen = 0, rlen = 0;
-	int create = 0;
+	bool create = false;
 	uint32_t vid = oid_to_vid(oid);
 	struct vdi_inode *vdi;
 	unsigned long idx = 0;
@@ -165,7 +165,7 @@ static int volume_rw_object(char *buf, uint64_t oid, size_t size,
 				memset(buf, 0, size);
 				goto done;
 			}
-			create = 1;
+			create = true;
 		} else {
 			if (rw == VOLUME_READ) {
 				oid = vid_to_data_oid(
@@ -177,7 +177,7 @@ static int volume_rw_object(char *buf, uint64_t oid, size_t size,
 						vdi->inode->data_vdi_id[idx],
 						idx);
 				hdr.flags |= SD_FLAG_CMD_COW;
-				create = 1;
+				create = true;
 			}
 		}
 	}
-- 
1.7.2.5




More information about the sheepdog mailing list