[Sheepdog] [PATCH 2/3] set the number of copies in the response of vdi operations

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Tue Feb 15 18:28:41 CET 2011


We need to know the number of replications to read/write objects
directly.  This patch sets the number in the response of vdi
operations, and avoid redundant accesses to the vdi objects.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 include/sheepdog_proto.h |    3 ++-
 sheep/group.c            |   11 +++++++----
 sheep/sheep_priv.h       |    8 +++++---
 sheep/vdi.c              |   26 ++++++++++++++++----------
 4 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 6385c9a..5c37618 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -154,7 +154,8 @@ struct sd_vdi_rsp {
 	uint32_t        result;
 	uint32_t        rsvd;
 	uint32_t        vdi_id;
-	uint32_t        pad[5];
+	uint32_t        copies;
+	uint32_t        pad[4];
 };
 
 struct sheepdog_inode {
diff --git a/sheep/group.c b/sheep/group.c
index 527144b..1731a97 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -632,16 +632,17 @@ static void vdi_op(struct vdi_op_message *msg)
 	struct sd_vdi_rsp *rsp = &msg->rsp;
 	void *data = msg->data;
 	int ret = SD_RES_SUCCESS;
-	uint32_t vid = 0;
+	uint32_t vid = 0, nr_copies = sys->nr_sobjs;
 
 	switch (hdr->opcode) {
 	case SD_OP_NEW_VDI:
 		ret = add_vdi(hdr->epoch, data, hdr->data_length, hdr->vdi_size, &vid,
 			      hdr->base_vdi_id, hdr->copies,
-			      hdr->snapid);
+			      hdr->snapid, &nr_copies);
 		break;
 	case SD_OP_DEL_VDI:
-		ret = del_vdi(hdr->epoch, data, hdr->data_length, &vid, hdr->snapid);
+		ret = del_vdi(hdr->epoch, data, hdr->data_length, &vid,
+			      hdr->snapid, &nr_copies);
 		break;
 	case SD_OP_LOCK_VDI:
 	case SD_OP_GET_VDI_INFO:
@@ -649,7 +650,8 @@ static void vdi_op(struct vdi_op_message *msg)
 			ret = SD_RES_VER_MISMATCH;
 			break;
 		}
-		ret = lookup_vdi(hdr->epoch, data, hdr->data_length, &vid, hdr->snapid);
+		ret = lookup_vdi(hdr->epoch, data, hdr->data_length, &vid,
+				 hdr->snapid, &nr_copies);
 		if (ret != SD_RES_SUCCESS)
 			break;
 		break;
@@ -667,6 +669,7 @@ static void vdi_op(struct vdi_op_message *msg)
 	}
 
 	rsp->vdi_id = vid;
+	rsp->copies = nr_copies;
 	rsp->result = ret;
 }
 
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 9b21e0f..00e0c34 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -144,11 +144,13 @@ int init_store(const char *dir);
 
 int add_vdi(uint32_t epoch, char *data, int data_len, uint64_t size,
 	    uint32_t *new_vid, uint32_t base_vid, uint32_t copies,
-	    int is_snapshot);
+	    int is_snapshot, unsigned int *nr_copies);
 
-int del_vdi(uint32_t epoch, char *data, int data_len, uint32_t *vid, uint32_t snapid);
+int del_vdi(uint32_t epoch, char *data, int data_len, uint32_t *vid,
+	    uint32_t snapid, unsigned int *nr_copies);
 
-int lookup_vdi(uint32_t epoch, char *data, int data_len, uint32_t *vid, uint32_t snapid);
+int lookup_vdi(uint32_t epoch, char *data, int data_len, uint32_t *vid,
+	       uint32_t snapid, unsigned int *nr_copies);
 
 int read_vdis(char *data, int len, unsigned int *rsp_len);
 
diff --git a/sheep/vdi.c b/sheep/vdi.c
index cbc0fff..7cc0114 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -118,7 +118,8 @@ static int create_vdi_obj(uint32_t epoch, char *name, uint32_t new_vid, uint64_t
 
 static int find_first_vdi(uint32_t epoch, unsigned long start, unsigned long end,
 			  char *name, char *tag, uint32_t snapid, uint32_t *vid,
-			  unsigned long *deleted_nr, uint32_t *next_snap)
+			  unsigned long *deleted_nr, uint32_t *next_snap,
+			  unsigned int *nr_copies)
 {
 	struct sheepdog_node_list_entry entries[SD_MAX_NODES];
 	static struct sheepdog_inode inode;
@@ -154,6 +155,7 @@ static int find_first_vdi(uint32_t epoch, unsigned long start, unsigned long end
 
 			*next_snap = inode.snap_id + 1;
 			*vid = inode.vdi_id;
+			*nr_copies = inode.nr_copies;
 			return SD_RES_SUCCESS;
 		}
 	}
@@ -167,7 +169,8 @@ static int find_first_vdi(uint32_t epoch, unsigned long start, unsigned long end
 
 static int do_lookup_vdi(uint32_t epoch, char *name, int namelen, uint32_t *vid,
 			 char *tag, uint32_t snapid, uint32_t *next_snapid,
-			 unsigned long *right_nr,  unsigned long *deleted_nr)
+			 unsigned long *right_nr,  unsigned long *deleted_nr,
+			 unsigned int *nr_copies)
 {
 	int ret;
 	unsigned long nr, start_nr;
@@ -185,7 +188,7 @@ static int do_lookup_vdi(uint32_t epoch, char *name, int namelen, uint32_t *vid,
 	right_side:
 		/* look up on the right side of the hash point */
 		ret = find_first_vdi(epoch, nr - 1, start_nr, name, tag, snapid, vid,
-				     deleted_nr, next_snapid);
+				     deleted_nr, next_snapid, nr_copies);
 		return ret;
 	} else {
 		/* round up... bitmap search from the head of the bitmap */
@@ -196,7 +199,7 @@ static int do_lookup_vdi(uint32_t epoch, char *name, int namelen, uint32_t *vid,
 		else if (nr) {
 			/* look up on the left side of the hash point */
 			ret = find_first_vdi(epoch, nr - 1, 0, name, tag, snapid, vid,
-					     deleted_nr, next_snapid);
+					     deleted_nr, next_snapid, nr_copies);
 			if (ret == SD_RES_NO_VDI)
 				; /* we need to go to the right side */
 			else
@@ -208,7 +211,8 @@ static int do_lookup_vdi(uint32_t epoch, char *name, int namelen, uint32_t *vid,
 	}
 }
 
-int lookup_vdi(uint32_t epoch, char *data, int data_len, uint32_t *vid, uint32_t snapid)
+int lookup_vdi(uint32_t epoch, char *data, int data_len, uint32_t *vid,
+	       uint32_t snapid, unsigned int *nr_copies)
 {
 	char *name = data, *tag;
 	uint32_t dummy0;
@@ -222,11 +226,12 @@ int lookup_vdi(uint32_t epoch, char *data, int data_len, uint32_t *vid, uint32_t
 		return SD_RES_INVALID_PARMS;
 
 	return do_lookup_vdi(epoch, name, strlen(name), vid, tag, snapid,
-			     &dummy0, &dummy1, &dummy2);
+			     &dummy0, &dummy1, &dummy2, nr_copies);
 }
 
 int add_vdi(uint32_t epoch, char *data, int data_len, uint64_t size,
-	    uint32_t *new_vid, uint32_t base_vid, uint32_t copies, int is_snapshot)
+	    uint32_t *new_vid, uint32_t base_vid, uint32_t copies,
+	    int is_snapshot, unsigned int *nr_copies)
 {
 	uint32_t cur_vid;
 	uint32_t next_snapid;
@@ -240,7 +245,7 @@ int add_vdi(uint32_t epoch, char *data, int data_len, uint64_t size,
 	name = data;
 
 	ret = do_lookup_vdi(epoch, name, strlen(name), &cur_vid, NULL, 0, &next_snapid,
-			    &right_nr, &deleted_nr);
+			    &right_nr, &deleted_nr, nr_copies);
 
 	if (is_snapshot) {
 		if (ret != SD_RES_SUCCESS) {
@@ -285,7 +290,8 @@ int add_vdi(uint32_t epoch, char *data, int data_len, uint64_t size,
 
 int start_deletion(uint32_t vid, uint32_t epoch);
 
-int del_vdi(uint32_t epoch, char *data, int data_len, uint32_t *vid, uint32_t snapid)
+int del_vdi(uint32_t epoch, char *data, int data_len, uint32_t *vid,
+	    uint32_t snapid, unsigned int *nr_copies)
 {
 	char *name = data, *tag;
 	uint32_t dummy0;
@@ -303,7 +309,7 @@ int del_vdi(uint32_t epoch, char *data, int data_len, uint32_t *vid, uint32_t sn
 		return SD_RES_INVALID_PARMS;
 
 	ret = do_lookup_vdi(epoch, name, strlen(name), vid, tag, snapid,
-			     &dummy0, &dummy1, &dummy2);
+			    &dummy0, &dummy1, &dummy2, nr_copies);
 	if (ret != SD_RES_SUCCESS)
 		return ret;
 
-- 
1.5.6.5




More information about the sheepdog mailing list