[Sheepdog] [PATCH 08/18] collie: support SD_OP_READ_EPOCH

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Thu Mar 11 07:48:07 CET 2010


This supports reading node list information at the requested epoch.
Start up routines use this feature.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 collie/collie.h          |    4 ++++
 collie/net.c             |    1 +
 collie/store.c           |   40 ++++++++++++++++++++++++++++++++++++++++
 include/sheepdog_proto.h |    1 +
 4 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/collie/collie.h b/collie/collie.h
index 88bc8be..968925e 100644
--- a/collie/collie.h
+++ b/collie/collie.h
@@ -98,6 +98,8 @@ void so_queue_request(struct work *work, int idx);
 void store_queue_request(struct work *work, int idx);
 
 int get_epoch_list(uint32_t *epoch_list, int *size);
+int read_epoch(int epoch, uint32_t *is_updated, uint64_t *ctime, uint64_t *hval,
+	       struct sheepdog_node_list_entry *entries, int *nr_entries);
 void epoch_queue_request(struct work *work, int idx);
 
 void cluster_queue_request(struct work *work, int idx);
@@ -113,6 +115,8 @@ int epoch_log_write(uint32_t epoch, char *buf, int len);
 int epoch_log_read(uint32_t epoch, char *buf, int len);
 int set_epoch_updated(uint32_t epoch, uint32_t val);
 uint32_t is_epoch_updated(uint32_t epoch);
+uint64_t epoch_hash_val(uint32_t epoch, uint64_t ctime,
+			struct sheepdog_node_list_entry *entries, int len);
 int set_cluster_ctime(uint64_t ctime);
 uint64_t get_cluster_ctime(void);
 
diff --git a/collie/net.c b/collie/net.c
index 70082ad..6e2fe67 100644
--- a/collie/net.c
+++ b/collie/net.c
@@ -50,6 +50,7 @@ static void queue_request(struct request *req)
 		req->work.fn = store_queue_request;
 		break;
 	case SD_OP_GET_EPOCH_LIST:
+	case SD_OP_READ_EPOCH:
 		req->work.fn = epoch_queue_request;
 		break;
 	case SD_OP_GET_NODE_LIST:
diff --git a/collie/store.c b/collie/store.c
index 6bc3229..59f5476 100644
--- a/collie/store.c
+++ b/collie/store.c
@@ -1108,6 +1108,17 @@ uint32_t is_epoch_updated(uint32_t epoch)
 	return val;
 }
 
+uint64_t epoch_hash_val(uint32_t epoch, uint64_t ctime,
+			struct sheepdog_node_list_entry *entries, int len)
+{
+	int64_t hval;
+	hval = fnv_64a_buf(&epoch, sizeof(epoch), FNV1A_64_INIT);
+	hval = fnv_64a_buf(&ctime, sizeof(ctime), hval);
+	hval = fnv_64a_buf(entries, sizeof(*entries) * len, hval);
+
+	return hval;
+}
+
 int set_cluster_ctime(uint64_t ctime)
 {
 	int fd, ret;
@@ -1667,6 +1678,27 @@ int get_epoch_list(uint32_t *epoch_list, int *size)
 	return SD_RES_SUCCESS;
 }
 
+int read_epoch(int epoch, uint32_t *is_updated, uint64_t *ctime, uint64_t *hval,
+	       struct sheepdog_node_list_entry *entries, int *nr_entries)
+{
+	int ret;
+
+	ret = epoch_log_read(epoch, (char *)entries,
+			     *nr_entries * sizeof(*entries));
+	if (ret == -1) {
+		eprintf("failed to read epoch %d\n", epoch);
+		*nr_entries = 0;
+		return SD_RES_EIO;
+	}
+	*nr_entries = ret / sizeof(*entries);
+
+	*is_updated = is_epoch_updated(epoch);
+	*ctime = get_cluster_ctime();
+	*hval = epoch_hash_val(epoch, *ctime, entries, *nr_entries);
+
+	return SD_RES_SUCCESS;
+}
+
 void epoch_queue_request(struct work *work, int idx)
 {
 	struct request *req = container_of(work, struct request, work);
@@ -1674,6 +1706,7 @@ void epoch_queue_request(struct work *work, int idx)
 	struct sd_epoch_req *hdr = (struct sd_epoch_req *)&req->rq;
 	struct sd_epoch_rsp *rsp = (struct sd_epoch_rsp *)&req->rp;
 	uint32_t opcode = hdr->opcode;
+	struct sheepdog_node_list_entry *entries;
 
 	switch (opcode) {
 	case SD_OP_GET_EPOCH_LIST:
@@ -1681,6 +1714,13 @@ void epoch_queue_request(struct work *work, int idx)
 		ret = get_epoch_list(req->data, &n);
 		rsp->data_length = n * sizeof(uint32_t);
 		break;
+	case SD_OP_READ_EPOCH:
+		entries = req->data;
+		n = hdr->data_length / sizeof(*entries);
+		ret = read_epoch(hdr->request_epoch, &rsp->is_updated, &rsp->ctime,
+				 &rsp->hval, entries, &n);
+		rsp->data_length = n * sizeof(*entries);
+		break;
 	}
 	if (ret != SD_RES_SUCCESS) {
 		dprintf("failed, %d, %x, %x\n", idx, opcode, ret);
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 64d0016..c1197fb 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -37,6 +37,7 @@
 #define SD_OP_SHUTDOWN       0x24
 
 #define SD_OP_GET_EPOCH_LIST 0x25
+#define SD_OP_READ_EPOCH     0x26
 
 #define SD_OP_DEBUG_INC_NVER 0xA0
 #define SD_OP_DEBUG_SET_NODE 0xA1
-- 
1.5.6.5




More information about the sheepdog mailing list