[Sheepdog] [PATCH 13/18] collie: support SD_OP_STAT_CLUSTER

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


This is used to get cluster information and current epoch.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 collie/group.c           |   53 ++++++++++++++++++++++++++++++++++++++++++++++
 collie/net.c             |    2 +
 include/sheepdog_proto.h |    1 +
 3 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/collie/group.c b/collie/group.c
index 7dbbe9e..676ddbb 100644
--- a/collie/group.c
+++ b/collie/group.c
@@ -352,6 +352,51 @@ static struct epoch_tree *find_start_epoch(struct tree_vertex *root)
 	return tree;
 }
 
+struct start_epoch_info {
+	int nr_logs;
+	struct epoch_log *logs;
+};
+
+static int __get_start_epochs(struct tree_vertex *vertex, int depth,
+			      struct start_epoch_info *sei)
+{
+	struct epoch_tree *tree;
+	struct tree_vertex *v;
+	int i;
+
+	tree = container_of(vertex, struct epoch_tree, vertex);
+	if (tree->updated) {
+		for (i = 0; i < sei->nr_logs; i++) {
+			v = vertex;
+			while (v->id) {
+				if (v->id == sei->logs[i].hval)
+					goto out;
+				v = tree_parent(v);
+			}
+		}
+		sei->nr_logs++;
+	out:
+		sei->logs[i].ctime = tree->ctime;
+		sei->logs[i].hval = vertex->id;
+		sei->logs[i].epoch = tree->epoch;
+		sei->logs[i].nr_nodes = tree->nr_nodes;
+		memcpy(sei->logs[i].nodes, tree->nodes, sizeof(tree->nodes[0]) * tree->nr_nodes);
+	}
+	return 0;
+}
+
+static int get_start_epochs(struct tree_vertex *root, struct epoch_log *logs)
+{
+	struct start_epoch_info sei;
+
+	sei.nr_logs = 0;
+	sei.logs = logs;
+
+	tree_walk(root, (tree_vertex_func_t)__get_start_epochs, &sei);
+
+	return sei.nr_logs;
+}
+
 static int __check_enough_epochs(struct tree_vertex *vertex, int depth, void *data)
 {
 	struct epoch_tree *tree;
@@ -806,6 +851,12 @@ static void vdi_op(struct vdi_op_message *msg)
 		break;
 	case SD_OP_SHUTDOWN:
 		break;
+	case SD_OP_STAT_CLUSTER:
+		rsp->rsvd = sys->status;
+		rsp->data_length = get_start_epochs(&sys->epoch_tree_root, (struct epoch_log *)msg->data);
+		rsp->data_length *= sizeof(struct epoch_log);
+		rsp->result = SD_RES_SUCCESS;
+		break;
 	default:
 		ret = SD_RES_SYSTEM_ERROR;
 		eprintf("opcode %d is not implemented\n", hdr->opcode);
@@ -867,6 +918,8 @@ static void vdi_op_done(struct vdi_op_message *msg)
 	case SD_OP_SHUTDOWN:
 		sys->status = SD_STATUS_SHUTDOWN;
 		break;
+	case SD_OP_STAT_CLUSTER:
+		break;
 	default:
 		eprintf("unknown operation %d\n", hdr->opcode);
 		ret = SD_RES_UNKNOWN;
diff --git a/collie/net.c b/collie/net.c
index 6e2fe67..9a942c4 100644
--- a/collie/net.c
+++ b/collie/net.c
@@ -29,6 +29,7 @@ static void __done(struct work *work, int idx)
 	case SD_OP_GET_VDI_INFO:
 	case SD_OP_MAKE_FS:
 	case SD_OP_SHUTDOWN:
+	case SD_OP_STAT_CLUSTER:
 		/* request is forwarded to cpg group */
 		return;
 	}
@@ -62,6 +63,7 @@ static void queue_request(struct request *req)
 	case SD_OP_GET_VDI_INFO:
 	case SD_OP_MAKE_FS:
 	case SD_OP_SHUTDOWN:
+	case SD_OP_STAT_CLUSTER:
 		req->work.fn = cluster_queue_request;
 		break;
 	case SD_OP_SO:
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index e835f68..540bbdb 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -58,6 +58,7 @@
 #define SD_OP_SO_STAT        0x65
 
 #define SD_OP_STAT_SHEEP     0xB0
+#define SD_OP_STAT_CLUSTER   0xB1
 
 #define SD_FLAG_CMD_WRITE    0x01
 #define SD_FLAG_CMD_COW      0x02
-- 
1.5.6.5




More information about the sheepdog mailing list