[sheepdog] [PATCH v5 12/16] sheep: add a flag to let notify_vdi_add set bitmap if needed

Kai Zhang kyle at zelin.io
Mon May 20 09:50:42 CEST 2013


Add a uint8_t flag "set_bitmap" to sd_req.vdi_state.
Function notify_vdi_add will set bitmap if "set_bitmap" is not 0.

This feature will be used for recovering vdi state and vdi bitmap
on all nodes after loading snapshot to a new cluster.

Currenly, post_cluster_new_vdi() is called only after a SD_OP_NEW_VDI request.
And we won't send SD_OP_NEW_VDI, because it will do a lot things that we don't need.
We use SD_OP_NOTIFY_VDI_ADD request for setting both bitmap and vdi_state.

Signed-off-by: Kai Zhang <kyle at zelin.io>
---
 include/sheepdog_proto.h |    2 ++
 sheep/ops.c              |    3 +++
 sheep/vdi.c              |    1 +
 3 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 5440721..af4ec32 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -144,6 +144,8 @@ struct sd_req {
 			uint32_t	old_vid;
 			uint32_t	new_vid;
 			uint32_t	copies;
+			uint8_t		set_bitmap; /* 0 means false */
+						    /* others mean true */
 		} vdi_state;
 
 		uint32_t		__pad[8];
diff --git a/sheep/ops.c b/sheep/ops.c
index 6dc9b09..25641d7 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -619,6 +619,9 @@ static int cluster_notify_vdi_add(const struct sd_req *req, struct sd_rsp *rsp,
 			      get_vdi_copy_number(req->vdi_state.old_vid),
 			      true);
 
+	if (req->vdi_state.set_bitmap)
+		set_bit(req->vdi_state.new_vid, sys->vdi_inuse);
+
 	add_vdi_state(req->vdi_state.new_vid, req->vdi_state.copies, false);
 
 	return SD_RES_SUCCESS;
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 98abe10..6120068 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -482,6 +482,7 @@ static int notify_vdi_add(uint32_t vdi_id, uint32_t nr_copies, uint32_t old_vid)
 	hdr.vdi_state.old_vid = old_vid;
 	hdr.vdi_state.new_vid = vdi_id;
 	hdr.vdi_state.copies = nr_copies;
+	hdr.vdi_state.set_bitmap = false;
 
 	ret = exec_local_req(&hdr, NULL);
 	if (ret != SD_RES_SUCCESS)
-- 
1.7.1



More information about the sheepdog mailing list