[sheepdog] [PATCH 2/2] collie: clean up sheep's state variables

Liu Yuan namei.unix at gmail.com
Wed Jun 20 13:21:15 CEST 2012


From: Liu Yuan <tailai.ly at taobao.com>

- prefix them all with SD_

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 collie/cluster.c |   10 +++++-----
 collie/collie.c  |   20 ++++++++++----------
 collie/collie.h  |    8 ++++----
 collie/common.c  |    6 +++---
 collie/debug.c   |    4 ++--
 collie/node.c    |   34 +++++++++++++++++-----------------
 collie/vdi.c     |   30 +++++++++++++++---------------
 7 files changed, 56 insertions(+), 56 deletions(-)

diff --git a/collie/cluster.c b/collie/cluster.c
index c991096..23fa2b0 100644
--- a/collie/cluster.c
+++ b/collie/cluster.c
@@ -93,7 +93,7 @@ static int cluster_format(int argc, char **argv)
 	hdr.copies = cluster_cmd_data.copies;
 	if (cluster_cmd_data.nohalt)
 		set_nohalt(&hdr.flags);
-	hdr.epoch = node_list_version;
+	hdr.epoch = sd_epoch;
 	hdr.ctime = (uint64_t) tv.tv_sec << 32 | tv.tv_usec * 1000;
 
 	if (strlen(cluster_cmd_data.name))
@@ -133,7 +133,7 @@ static int cluster_info(int argc, char **argv)
 	struct tm tm;
 	char time_str[128];
 
-	log_length = node_list_version * sizeof(struct epoch_log);
+	log_length = sd_epoch * sizeof(struct epoch_log);
 again:
 	logs = malloc(log_length);
 	if (!logs) {
@@ -152,7 +152,7 @@ again:
 	memset(&hdr, 0, sizeof(hdr));
 
 	hdr.opcode = SD_OP_STAT_CLUSTER;
-	hdr.epoch = node_list_version;
+	hdr.epoch = sd_epoch;
 	hdr.data_length = log_length;
 
 	rlen = hdr.data_length;
@@ -223,7 +223,7 @@ static int cluster_shutdown(int argc, char **argv)
 	memset(&hdr, 0, sizeof(hdr));
 
 	hdr.opcode = SD_OP_SHUTDOWN;
-	hdr.epoch = node_list_version;
+	hdr.epoch = sd_epoch;
 
 	rlen = 0;
 	wlen = 0;
@@ -453,7 +453,7 @@ static int cluster_recover(int argc, char **argv)
 	memset(&hdr, 0, sizeof(hdr));
 
 	hdr.opcode = SD_OP_RECOVER;
-	hdr.epoch = node_list_version;
+	hdr.epoch = sd_epoch;
 
 	rlen = 0;
 	wlen = 0;
diff --git a/collie/collie.c b/collie/collie.c
index eb10fe5..34f49b3 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -53,11 +53,11 @@ static const struct sd_option collie_options[] = {
 
 static void usage(struct command *commands, int status);
 
-uint32_t node_list_version;
+uint32_t sd_epoch;
 
-struct sd_node node_list_entries[SD_MAX_NODES];
-struct sd_vnode vnode_list_entries[SD_MAX_VNODES];
-int nr_nodes, nr_vnodes;
+struct sd_node sd_nodes[SD_MAX_NODES];
+struct sd_vnode sd_vnodes[SD_MAX_VNODES];
+int sd_nodes_nr, sd_vnodes_nr;
 unsigned master_idx;
 
 static int update_node_list(int max_nodes, uint32_t epoch)
@@ -101,21 +101,21 @@ static int update_node_list(int max_nodes, uint32_t epoch)
 		goto out;
 	}
 
-	nr_nodes = size / sizeof(*ent);
-	if (nr_nodes == 0) {
+	sd_nodes_nr = size / sizeof(*ent);
+	if (sd_nodes_nr == 0) {
 		fprintf(stderr, "There are no active sheep daemons\n");
 		exit(EXIT_FAILURE);
 	}
 
 	/* FIXME */
-	if (nr_nodes > max_nodes) {
+	if (sd_nodes_nr > max_nodes) {
 		ret = -1;
 		goto out;
 	}
 
-	memcpy(node_list_entries, buf, size);
-	nr_vnodes = nodes_to_vnodes(node_list_entries, nr_nodes, vnode_list_entries);
-	node_list_version = hdr.epoch;
+	memcpy(sd_nodes, buf, size);
+	sd_vnodes_nr = nodes_to_vnodes(sd_nodes, sd_nodes_nr, sd_vnodes);
+	sd_epoch = hdr.epoch;
 	master_idx = rsp->master_idx;
 out:
 	if (buf)
diff --git a/collie/collie.h b/collie/collie.h
index c698e36..3657232 100644
--- a/collie/collie.h
+++ b/collie/collie.h
@@ -55,10 +55,10 @@ extern int sdport;
 extern int highlight;
 extern int raw_output;
 
-extern uint32_t node_list_version;
-extern struct sd_node node_list_entries[SD_MAX_NODES];
-extern struct sd_vnode vnode_list_entries[SD_MAX_VNODES];
-extern int nr_nodes, nr_vnodes;
+extern uint32_t sd_epoch;
+extern struct sd_node sd_nodes[SD_MAX_NODES];
+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);
diff --git a/collie/common.c b/collie/common.c
index dd78efa..d87afee 100644
--- a/collie/common.c
+++ b/collie/common.c
@@ -57,7 +57,7 @@ int sd_read_object(uint64_t oid, void *data, unsigned int datalen,
 	}
 
 	memset(&hdr, 0, sizeof(hdr));
-	hdr.epoch = node_list_version;
+	hdr.epoch = sd_epoch;
 	hdr.opcode = SD_OP_READ_OBJ;
 	hdr.flags = SD_FLAG_CMD_WEAK_CONSISTENCY;
 	hdr.data_length = rlen;
@@ -97,7 +97,7 @@ int sd_write_object(uint64_t oid, uint64_t cow_oid, void *data, unsigned int dat
 	}
 
 	memset(&hdr, 0, sizeof(hdr));
-	hdr.epoch = node_list_version;
+	hdr.epoch = sd_epoch;
 	if (create)
 		hdr.opcode = SD_OP_CREATE_AND_WRITE_OBJ;
 	else
@@ -145,7 +145,7 @@ int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
 
 	req.opcode = SD_OP_READ_VDIS;
 	req.data_length = sizeof(vdi_inuse);
-	req.epoch = node_list_version;
+	req.epoch = sd_epoch;
 
 	rlen = sizeof(vdi_inuse);
 	ret = exec_req(fd, &req, vdi_inuse, &wlen, &rlen);
diff --git a/collie/debug.c b/collie/debug.c
index 14f963f..40c89bd 100644
--- a/collie/debug.c
+++ b/collie/debug.c
@@ -48,7 +48,7 @@ static int do_trace_cat(void)
 	memset(&hdr, 0, sizeof(hdr));
 	hdr.opcode = SD_OP_TRACE_CAT;
 	hdr.data_length = rlen = TRACE_BUF_LEN;
-	hdr.epoch = node_list_version;
+	hdr.epoch = sd_epoch;
 
 	wlen = 0;
 	ret = exec_req(fd, &hdr, buf, &wlen, &rlen);
@@ -105,7 +105,7 @@ static int debug_trace(int argc, char **argv)
 	memset(&hdr, 0, sizeof(hdr));
 
 	hdr.opcode = SD_OP_TRACE;
-	hdr.epoch = node_list_version;
+	hdr.epoch = sd_epoch;
 	hdr.data_length = enabled;
 
 	rlen = 0;
diff --git a/collie/node.c b/collie/node.c
index 4fc0f72..2449b16 100644
--- a/collie/node.c
+++ b/collie/node.c
@@ -27,24 +27,24 @@ static int node_list(int argc, char **argv)
 
 	if (!raw_output)
 		printf("M   Id   Host:Port         V-Nodes       Zone\n");
-	for (i = 0; i < nr_nodes; i++) {
+	for (i = 0; i < sd_nodes_nr; i++) {
 		char data[128];
 
-		addr_to_str(data, sizeof(data), node_list_entries[i].addr,
-			    node_list_entries[i].port);
+		addr_to_str(data, sizeof(data), sd_nodes[i].addr,
+			    sd_nodes[i].port);
 
 		if (i == master_idx) {
 			if (highlight)
 				printf(TEXT_BOLD);
 			printf(raw_output ? "* %d %s %d %d\n" : "* %4d   %-20s\t%2d%11d\n",
-			       i, data, node_list_entries[i].nr_vnodes,
-			       node_list_entries[i].zone);
+			       i, data, sd_nodes[i].nr_vnodes,
+			       sd_nodes[i].zone);
 			if (highlight)
 				printf(TEXT_NORMAL);
 		} else
 			printf(raw_output ? "- %d %s %d %d\n" : "- %4d   %-20s\t%2d%11d\n",
-			       i, data, node_list_entries[i].nr_vnodes,
-			       node_list_entries[i].zone);
+			       i, data, sd_nodes[i].nr_vnodes,
+			       sd_nodes[i].zone);
 	}
 
 	return EXIT_SUCCESS;
@@ -59,7 +59,7 @@ static int node_info(int argc, char **argv)
 	if (!raw_output)
 		printf("Id\tSize\tUsed\tUse%%\n");
 
-	for (i = 0; i < nr_nodes; i++) {
+	for (i = 0; i < sd_nodes_nr; i++) {
 		char name[128];
 		int fd;
 		unsigned wlen, rlen;
@@ -67,16 +67,16 @@ static int node_info(int argc, char **argv)
 		struct sd_node_rsp *rsp = (struct sd_node_rsp *)&req;
 		char store_str[UINT64_DECIMAL_SIZE], free_str[UINT64_DECIMAL_SIZE];
 
-		addr_to_str(name, sizeof(name), node_list_entries[i].addr, 0);
+		addr_to_str(name, sizeof(name), sd_nodes[i].addr, 0);
 
-		fd = connect_to(name, node_list_entries[i].port);
+		fd = connect_to(name, sd_nodes[i].port);
 		if (fd < 0)
 			return 1;
 
 		memset(&req, 0, sizeof(req));
 
 		req.opcode = SD_OP_STAT_SHEEP;
-		req.epoch = node_list_version;
+		req.epoch = sd_epoch;
 
 		wlen = 0;
 		rlen = 0;
@@ -127,16 +127,16 @@ static int node_recovery(int argc, char **argv)
 		printf("  Id   Host:Port         V-Nodes       Zone\n");
 	}
 
-	for (i = 0; i < nr_nodes; i++) {
+	for (i = 0; i < sd_nodes_nr; i++) {
 		char host[128];
 		int fd;
 		unsigned wlen, rlen;
 		struct sd_node_req req;
 		struct sd_node_rsp *rsp = (struct sd_node_rsp *)&req;
 
-		addr_to_str(host, sizeof(host), node_list_entries[i].addr, 0);
+		addr_to_str(host, sizeof(host), sd_nodes[i].addr, 0);
 
-		fd = connect_to(host, node_list_entries[i].port);
+		fd = connect_to(host, sd_nodes[i].port);
 		if (fd < 0)
 			return EXIT_FAILURE;
 
@@ -151,10 +151,10 @@ static int node_recovery(int argc, char **argv)
 
 		if (!ret && rsp->result == SD_RES_SUCCESS) {
 			addr_to_str(host, sizeof(host),
-					node_list_entries[i].addr, node_list_entries[i].port);
+					sd_nodes[i].addr, sd_nodes[i].port);
 			printf(raw_output ? "%d %s %d %d\n" : "%4d   %-20s%5d%11d\n",
-				   i, host, node_list_entries[i].nr_vnodes,
-				   node_list_entries[i].zone);
+				   i, host, sd_nodes[i].nr_vnodes,
+				   sd_nodes[i].zone);
 		}
 	}
 
diff --git a/collie/vdi.c b/collie/vdi.c
index f21d3e9..6c0a238 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -270,14 +270,14 @@ static void parse_objs(uint64_t oid, obj_parser_func_t func, void *data, unsigne
 		return;
 	}
 
-	for (i = 0; i < nr_nodes; i++) {
+	for (i = 0; i < sd_nodes_nr; i++) {
 		unsigned wlen = 0, rlen = size;
 		struct sd_req hdr;
 		struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 
-		addr_to_str(name, sizeof(name), node_list_entries[i].addr, 0);
+		addr_to_str(name, sizeof(name), sd_nodes[i].addr, 0);
 
-		fd = connect_to(name, node_list_entries[i].port);
+		fd = connect_to(name, sd_nodes[i].port);
 		if (fd < 0)
 			break;
 
@@ -286,14 +286,14 @@ static void parse_objs(uint64_t oid, obj_parser_func_t func, void *data, unsigne
 		hdr.opcode = SD_OP_READ_OBJ;
 		hdr.data_length = rlen;
 		hdr.flags = SD_FLAG_CMD_IO_LOCAL;
-		hdr.epoch = node_list_version;
+		hdr.epoch = sd_epoch;
 
 		hdr.obj.oid = oid;
 
 		ret = exec_req(fd, &hdr, buf, &wlen, &rlen);
 		close(fd);
 
-		sprintf(name + strlen(name), ":%d", node_list_entries[i].port);
+		sprintf(name + strlen(name), ":%d", sd_nodes[i].port);
 
 		if (ret)
 			fprintf(stderr, "Failed to connect to %s\n", name);
@@ -716,7 +716,7 @@ static int vdi_delete(int argc, char **argv)
 	wlen = sizeof(vdiname);
 
 	hdr.opcode = SD_OP_DEL_VDI;
-	hdr.epoch = node_list_version;
+	hdr.epoch = sd_epoch;
 	hdr.flags = SD_FLAG_CMD_WRITE;
 	hdr.data_length = wlen;
 	hdr.vdi.snapid = vdi_cmd_data.snapshot_id;
@@ -769,7 +769,7 @@ static int vdi_object(int argc, char **argv)
 
 	if (idx == ~0) {
 		printf("Looking for the inode object 0x%" PRIx32 " with %d nodes\n\n",
-		       vid, nr_nodes);
+		       vid, sd_nodes_nr);
 		parse_objs(vid_to_vdi_oid(vid), do_print_obj, NULL, SD_INODE_SIZE);
 	} else {
 		struct get_data_oid_info old_info;
@@ -788,7 +788,7 @@ static int vdi_object(int argc, char **argv)
 			if (old_info.data_oid) {
 				printf("Looking for the object 0x%" PRIx64
 				       " (the inode vid 0x%" PRIx32 " idx %u) with %d nodes\n\n",
-				       old_info.data_oid, vid, idx, nr_nodes);
+				       old_info.data_oid, vid, idx, sd_nodes_nr);
 
 				parse_objs(old_info.data_oid, do_print_obj, NULL, SD_DATA_OBJ_SIZE);
 			} else
@@ -813,7 +813,7 @@ static int print_obj_epoch(uint64_t oid)
 	int vnodes_nr, nr_logs, log_length;
 	char host[128];
 
-	log_length = node_list_version * sizeof(struct epoch_log);
+	log_length = sd_epoch * sizeof(struct epoch_log);
 again:
 	logs = malloc(log_length);
 	if (!logs) {
@@ -832,7 +832,7 @@ again:
 	memset(&hdr, 0, sizeof(hdr));
 
 	hdr.opcode = SD_OP_STAT_CLUSTER;
-	hdr.epoch = node_list_version;
+	hdr.epoch = sd_epoch;
 	hdr.data_length = log_length;
 
 	rlen = hdr.data_length;
@@ -893,7 +893,7 @@ static int vdi_track(int argc, char **argv)
 
 	if (idx == ~0) {
 		printf("Tracking the inode object 0x%" PRIx32 " with %d nodes\n",
-		       vid, nr_nodes);
+		       vid, sd_nodes_nr);
 		print_obj_epoch(vid_to_vdi_oid(vid));
 	} else {
 		struct get_data_oid_info oid_info;
@@ -914,7 +914,7 @@ static int vdi_track(int argc, char **argv)
 				printf("Tracking the object 0x%" PRIx64
 				       " (the inode vid 0x%" PRIx32 " idx %u)"
 					   " with %d nodes\n",
-				       oid_info.data_oid, vid, idx, nr_nodes);
+				       oid_info.data_oid, vid, idx, sd_nodes_nr);
 				print_obj_epoch(oid_info.data_oid);
 
 			} else
@@ -1341,7 +1341,7 @@ static void *read_object_from(struct sd_vnode *vnode, uint64_t oid)
 	}
 
 	hdr.opcode = SD_OP_READ_OBJ;
-	hdr.epoch = node_list_version;
+	hdr.epoch = sd_epoch;
 	hdr.flags = SD_FLAG_CMD_IO_LOCAL;
 	hdr.data_length = rlen;
 
@@ -1380,7 +1380,7 @@ static void write_object_to(struct sd_vnode *vnode, uint64_t oid, void *buf)
 	}
 
 	hdr.opcode = SD_OP_WRITE_OBJ;
-	hdr.epoch = node_list_version;
+	hdr.epoch = sd_epoch;
 	hdr.flags = SD_FLAG_CMD_IO_LOCAL | SD_FLAG_CMD_WRITE;
 	hdr.data_length = wlen;
 
@@ -1422,7 +1422,7 @@ static void do_check_repair(uint64_t oid, int nr_copies)
 	void *buf;
 	int i;
 
-	collie_oid_to_vnodes(vnode_list_entries, nr_vnodes,
+	collie_oid_to_vnodes(sd_vnodes, sd_vnodes_nr,
 			     oid, nr_copies, tgt_vnodes);
 	for (i = 0; i < nr_copies; i++) {
 		buf = read_object_from(tgt_vnodes[i], oid);
-- 
1.7.10.2




More information about the sheepdog mailing list