[Sheepdog] [PATCH v2] sheep: cleanup epoch type

Liu Yuan namei.unix at gmail.com
Wed May 2 05:59:33 CEST 2012


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

We have defined 'epoch' as uint32_t, but many code use it as int,
so fix this inconsistency.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 v2:
 - fix farm_init(), don't wrap around for epoch
 - update tgt_epoch type.

 collie/cluster.c         |    4 ++--
 collie/collie.c          |    4 ++--
 collie/collie.h          |    2 +-
 doc/farm-internal.txt    |    2 +-
 include/sheepdog_proto.h |    2 +-
 sheep/farm/farm.c        |   18 +++++++++---------
 sheep/farm/farm.h        |    4 ++--
 sheep/farm/snap.c        |    4 ++--
 sheep/group.c            |    6 +++---
 sheep/ops.c              |    6 +++---
 sheep/recovery.c         |    8 ++++----
 sheep/sheep_priv.h       |    4 ++--
 sheep/simple_store.c     |    9 +++++----
 sheep/store.c            |    2 +-
 14 files changed, 38 insertions(+), 37 deletions(-)

diff --git a/collie/cluster.c b/collie/cluster.c
index 8d872f1..66bd03e 100644
--- a/collie/cluster.c
+++ b/collie/cluster.c
@@ -17,7 +17,7 @@
 #include "collie.h"
 
 struct cluster_cmd_data {
-	int epoch;
+	uint32_t epoch;
 	int list;
 	int copies;
 	int nohalt;
@@ -244,7 +244,7 @@ static int cluster_shutdown(int argc, char **argv)
 	return EXIT_SUCCESS;
 }
 
-static int restore_snap(int epoch)
+static int restore_snap(uint32_t epoch)
 {
 	int fd, ret;
 	struct sd_obj_req hdr;
diff --git a/collie/collie.c b/collie/collie.c
index 5a2dc82..eb10fe5 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -53,14 +53,14 @@ static const struct sd_option collie_options[] = {
 
 static void usage(struct command *commands, int status);
 
-uint64_t node_list_version;
+uint32_t node_list_version;
 
 struct sd_node node_list_entries[SD_MAX_NODES];
 struct sd_vnode vnode_list_entries[SD_MAX_VNODES];
 int nr_nodes, nr_vnodes;
 unsigned master_idx;
 
-static int update_node_list(int max_nodes, int epoch)
+static int update_node_list(int max_nodes, uint32_t epoch)
 {
 	int fd, ret;
 	unsigned int size, wlen;
diff --git a/collie/collie.h b/collie/collie.h
index 3a4ba69..829a4ee 100644
--- a/collie/collie.h
+++ b/collie/collie.h
@@ -53,7 +53,7 @@ extern int sdport;
 extern int highlight;
 extern int raw_output;
 
-extern uint64_t node_list_version;
+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;
diff --git a/doc/farm-internal.txt b/doc/farm-internal.txt
index 48d2840..4d1dd28 100644
--- a/doc/farm-internal.txt
+++ b/doc/farm-internal.txt
@@ -71,7 +71,7 @@ As for snap operations, besides snap object, Farm has two log files with the bel
 structure
 
     struct snap_log {
-            int epoch;
+            uint32_t epoch;
             uint64_t time;
             unsigned char sha1[SHA1_LEN];
     };
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 11c2c7c..8d5d901 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -206,7 +206,7 @@ struct sheepdog_vdi_attr {
 #define SHA1_LEN        20
 
 struct snap_log {
-	int epoch;
+	uint32_t epoch;
 	uint64_t time;
 	unsigned char sha1[SHA1_LEN];
 };
diff --git a/sheep/farm/farm.c b/sheep/farm/farm.c
index 838962c..19b8945 100644
--- a/sheep/farm/farm.c
+++ b/sheep/farm/farm.c
@@ -184,7 +184,7 @@ static int farm_close(uint64_t oid, struct siocb *iocb)
 	return SD_RES_SUCCESS;
 }
 
-static int get_trunk_sha1(int epoch, unsigned char *outsha1, int user)
+static int get_trunk_sha1(uint32_t epoch, unsigned char *outsha1, int user)
 {
 	int i, nr_logs = -1, ret = -1;
 	struct snap_log *log_buf, *log_free = NULL;
@@ -212,7 +212,7 @@ out:
 	return ret;
 }
 
-static int cleanup_trunk(int epoch)
+static int cleanup_trunk(uint32_t epoch)
 {
 	struct sha1_file_hdr hdr;
 	struct trunk_entry *trunk_buf, *trunk_free = NULL;
@@ -244,11 +244,11 @@ out:
 static int farm_cleanup_sys_obj(struct siocb *iocb)
 {
 	int i, ret = SD_RES_SUCCESS;
-	int epoch = iocb->epoch;
+	uint32_t epoch = iocb->epoch;
 	struct snap_log *log_pos, *log_free = NULL;
 	int nr_logs;
 
-	if (iocb->epoch <= 0)
+	if (iocb->epoch == 0)
 		return ret;
 
 	for (i = 1; i <= epoch; i++)
@@ -326,7 +326,7 @@ static int farm_init(char *p)
 	if (init_sys_vdi_bitmap(p) < 0)
 		goto err;
 
-	iocb.epoch = sys->epoch - 1;
+	iocb.epoch = sys->epoch ? sys->epoch - 1 : 0;
 	farm_cleanup_sys_obj(&iocb);
 
 	return SD_RES_SUCCESS;
@@ -380,7 +380,7 @@ out:
 	return buf;
 }
 
-static void *retrieve_object_from_snap(uint64_t oid, int epoch)
+static void *retrieve_object_from_snap(uint64_t oid, uint32_t epoch)
 {
 	struct sha1_file_hdr hdr;
 	struct trunk_entry *trunk_buf, *trunk_free = NULL;
@@ -487,7 +487,7 @@ out:
 	return ret;
 }
 
-static int farm_link(uint64_t oid, struct siocb *iocb, int tgt_epoch)
+static int farm_link(uint64_t oid, struct siocb *iocb, uint32_t tgt_epoch)
 {
 	int ret = SD_RES_EIO;
 	void *buf = NULL;
@@ -516,7 +516,7 @@ static int farm_end_recover(struct siocb *iocb)
 {
 	unsigned char snap_sha1[SHA1_LEN];
 	unsigned char trunk_sha1[SHA1_LEN];
-	int epoch = iocb->epoch - 1;
+	uint32_t epoch = iocb->epoch - 1;
 
 	if (epoch == 0)
 		return SD_RES_SUCCESS;
@@ -586,7 +586,7 @@ static int cleanup_working_dir(void)
 	return 0;
 }
 
-static int restore_objects_from_snap(int epoch)
+static int restore_objects_from_snap(uint32_t epoch)
 {
 	struct sha1_file_hdr hdr;
 	struct trunk_entry *trunk_buf, *trunk_free = NULL;
diff --git a/sheep/farm/farm.h b/sheep/farm/farm.h
index e26c179..cc829cd 100644
--- a/sheep/farm/farm.h
+++ b/sheep/farm/farm.h
@@ -72,9 +72,9 @@ extern int trunk_get_working_objlist(uint64_t *list);
 /* snap.c */
 extern int snap_init(void);
 extern void *snap_file_read(unsigned char *sha1, struct sha1_file_hdr *outhdr);
-extern int snap_file_write(int epoch, unsigned char *trunksha1, unsigned char *outsha1, int user);
+extern int snap_file_write(uint32_t epoch, unsigned char *trunksha1, unsigned char *outsha1, int user);
 extern int snap_log_truncate(void);
 extern void *snap_log_read(int *, int user);
-extern int snap_log_write(int epoch, unsigned char *sha1, int user);
+extern int snap_log_write(uint32_t epoch, unsigned char *sha1, int user);
 
 #endif
diff --git a/sheep/farm/snap.c b/sheep/farm/snap.c
index b3d993d..957ea13 100644
--- a/sheep/farm/snap.c
+++ b/sheep/farm/snap.c
@@ -74,7 +74,7 @@ int snap_log_truncate(void)
 	return ret;
 }
 
-int snap_log_write(int epoch, unsigned char *sha1, int user)
+int snap_log_write(uint32_t epoch, unsigned char *sha1, int user)
 {
 	int fd, ret = -1;
 	struct strbuf buf = STRBUF_INIT;
@@ -155,7 +155,7 @@ void *snap_file_read(unsigned char *sha1, struct sha1_file_hdr *outhdr)
 	return buffer;
 }
 
-int snap_file_write(int epoch, unsigned char *trunksha1, unsigned char *outsha1, int user)
+int snap_file_write(uint32_t epoch, unsigned char *trunksha1, unsigned char *outsha1, int user)
 {
 	int ret = 0;
 	struct strbuf buf = STRBUF_INIT;
diff --git a/sheep/group.c b/sheep/group.c
index a98da7f..cc03d55 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -290,7 +290,7 @@ static inline int get_nodes_nr_from(struct list_head *l)
 	return nr;
 }
 
-static int get_nodes_nr_epoch(int epoch)
+static int get_nodes_nr_epoch(uint32_t epoch)
 {
 	struct sd_node nodes[SD_MAX_NODES];
 	int nr;
@@ -301,7 +301,7 @@ static int get_nodes_nr_epoch(int epoch)
 }
 
 static struct sd_node *find_entry_list(struct sd_node *entry,
-							struct list_head *head)
+					struct list_head *head)
 {
 	struct node *n;
 	list_for_each_entry(n, head, list)
@@ -313,7 +313,7 @@ static struct sd_node *find_entry_list(struct sd_node *entry,
 }
 
 static struct sd_node *find_entry_epoch(struct sd_node *entry,
-							 int epoch)
+					uint32_t epoch)
 {
 	struct sd_node nodes[SD_MAX_NODES];
 	int nr, i;
diff --git a/sheep/ops.c b/sheep/ops.c
index 27351af..6b2dec3 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -65,7 +65,7 @@ struct flush_work {
 	struct work work;
 };
 
-static void get_store_dir(struct strbuf *buf, int epoch)
+static void get_store_dir(struct strbuf *buf, uint32_t epoch)
 {
 	if (!strcmp(sd_store->name, "simple"))
 		strbuf_addf(buf, "%s%08u/", obj_path, epoch);
@@ -200,7 +200,7 @@ static int cluster_get_vdi_info(const struct sd_req *req, struct sd_rsp *rsp,
 	return ret;
 }
 
-static int remove_epoch(int epoch)
+static int remove_epoch(uint32_t epoch)
 {
 	int ret;
 	char path[PATH_MAX];
@@ -453,7 +453,7 @@ static int local_get_epoch(const struct sd_req *req, struct sd_rsp *rsp,
 {
 	const struct sd_obj_req *obj_req = (const struct sd_obj_req *)req;
 	struct sd_obj_rsp *obj_rsp = (struct sd_obj_rsp *)rsp;
-	int epoch = obj_req->tgt_epoch;
+	uint32_t epoch = obj_req->tgt_epoch;
 	int len, ret;
 	dprintf("%d\n", epoch);
 	len = epoch_log_read(epoch, (char *)data, obj_req->data_length);
diff --git a/sheep/recovery.c b/sheep/recovery.c
index c6df954..50f7764 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -171,7 +171,7 @@ static int find_tgt_node(struct sd_vnode *old_entry,
 	return -1;
 }
 
-static void *get_vnodes_from_epoch(int epoch, int *nr, int *copies)
+static void *get_vnodes_from_epoch(uint32_t epoch, int *nr, int *copies)
 {
 	int nodes_nr, len = sizeof(struct sd_vnode) * SD_MAX_VNODES;
 	struct sd_node nodes[SD_MAX_NODES];
@@ -194,7 +194,7 @@ static void *get_vnodes_from_epoch(int epoch, int *nr, int *copies)
 
 static int recover_object_from_replica(uint64_t oid,
 				       struct sd_vnode *entry,
-				       int epoch, int tgt_epoch)
+				       uint32_t epoch, uint32_t tgt_epoch)
 {
 	struct sd_obj_req hdr;
 	struct sd_obj_rsp *rsp = (struct sd_obj_rsp *)&hdr;
@@ -311,7 +311,7 @@ static int do_recover_object(struct recovery_work *rw, int copy_idx)
 	struct sd_vnode *old, *cur;
 	uint64_t oid = rw->oids[rw->done];
 	int old_nr = rw->old_nr_vnodes, cur_nr = rw->cur_nr_vnodes;
-	int epoch = rw->epoch, tgt_epoch = rw->epoch - 1;
+	uint32_t epoch = rw->epoch, tgt_epoch = rw->epoch - 1;
 	struct sd_vnode *tgt_entry;
 	int old_idx, cur_idx, tgt_idx, old_copies, cur_copies, ret;
 
@@ -748,7 +748,7 @@ static int fill_obj_list(struct recovery_work *rw)
 /* setup node list and virtual node list */
 static int init_rw(struct recovery_work *rw)
 {
-	int epoch = rw->epoch;
+	uint32_t epoch = rw->epoch;
 
 	rw->cur_nr_nodes = epoch_log_read_nr(epoch, (char *)rw->cur_nodes,
 					     sizeof(rw->cur_nodes));
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index fd36ea4..9cb22d1 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -178,7 +178,7 @@ struct store_driver {
 	int (*format)(struct siocb *);
 	/* Operations in recovery */
 	int (*get_objlist)(struct siocb *);
-	int (*link)(uint64_t oid, struct siocb *, int tgt_epoch);
+	int (*link)(uint64_t oid, struct siocb *, uint32_t tgt_epoch);
 	int (*atomic_put)(uint64_t oid, struct siocb *);
 	int (*begin_recover)(struct siocb *);
 	int (*end_recover)(struct siocb *);
@@ -267,7 +267,7 @@ int read_epoch(uint32_t *epoch, uint64_t *ctime,
 void do_cluster_request(struct work *work);
 
 int update_epoch_store(uint32_t epoch);
-int update_epoch_log(int epoch);
+int update_epoch_log(uint32_t epoch);
 
 int set_cluster_copies(uint8_t copies);
 int get_cluster_copies(uint8_t *copies);
diff --git a/sheep/simple_store.c b/sheep/simple_store.c
index 8e47a3d..d165f28 100644
--- a/sheep/simple_store.c
+++ b/sheep/simple_store.c
@@ -32,7 +32,7 @@ static int simple_store_write(uint64_t oid, struct siocb *iocb);
 
 static int simple_store_init(char *path)
 {
-	int epoch, latest_epoch;
+	uint32_t epoch, latest_epoch;
 	DIR *dir;
 	struct dirent *dent;
 	char p[PATH_MAX];
@@ -181,7 +181,7 @@ static int simple_store_close(uint64_t oid, struct siocb *iocb)
 	return SD_RES_SUCCESS;
 }
 
-static int get_epoch_obj_list(int epoch, uint64_t *objlist, int *nr)
+static int get_epoch_obj_list(uint32_t epoch, uint64_t *objlist, int *nr)
 {
 	struct strbuf buf = STRBUF_INIT;
 	DIR *dir;
@@ -220,7 +220,8 @@ static int simple_store_get_objlist(struct siocb *siocb)
 {
 	uint64_t *objlist = (uint64_t*)siocb->buf;
 	uint64_t *buf;
-	int epoch, nr = 0, obj_nr = 0;
+	uint32_t epoch;
+	int nr = 0, obj_nr = 0;
 	DIR *dir;
 	struct dirent *d;
 	int ret = SD_RES_SUCCESS, r;
@@ -257,7 +258,7 @@ out:
 	return ret;
 }
 
-static int simple_store_link(uint64_t oid, struct siocb *iocb, int tgt_epoch)
+static int simple_store_link(uint64_t oid, struct siocb *iocb, uint32_t tgt_epoch)
 {
        char old[PATH_MAX], new[PATH_MAX];
 
diff --git a/sheep/store.c b/sheep/store.c
index 6412556..7ef72c5 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -254,7 +254,7 @@ int update_epoch_store(uint32_t epoch)
 	return 0;
 }
 
-int update_epoch_log(int epoch)
+int update_epoch_log(uint32_t epoch)
 {
 	int fd, ret, len;
 	time_t t;
-- 
1.7.8.2




More information about the sheepdog mailing list