[sheepdog] [PATCH v3 5/5] extend MAX number of objects

Robin Dong robin.k.dong at gmail.com
Thu Oct 24 11:46:22 CEST 2013


Add the max number of objects and add new MACRO for index of inode.

Signed-off-by: Robin Dong <sanbai at taobao.com>
---
 include/sheepdog_proto.h |   10 ++++++----
 lib/option.c             |    3 +++
 lib/sd_inode.c           |   38 ++++++++++++++++++++------------------
 3 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 8c9be31..0f26c5f 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -96,7 +96,7 @@
 #define VMSTATE_BIT (UINT64_C(1) << 62)
 #define VDI_ATTR_BIT (UINT64_C(1) << 61)
 #define VDI_BTREE_BIT (UINT64_C(1) << 60)
-#define MAX_DATA_OBJS (1ULL << 20)
+#define MAX_DATA_OBJS (1ULL << 32)
 #define MAX_CHILDREN (1024U - 1) /* we use the last uint32_t as btree_counter */
 #define SD_MAX_VDI_LEN 256U
 #define SD_MAX_VDI_TAG_LEN 256U
@@ -108,8 +108,10 @@
 #define SD_MAX_VDI_SIZE (SD_DATA_OBJ_SIZE * MAX_DATA_OBJS)
 
 #define SD_INODE_SIZE (sizeof(struct sd_inode))
-#define SD_INODE_INDEX_SIZE (sizeof(uint32_t) * MAX_DATA_OBJS)
-#define SD_INODE_HEADER_SIZE (sizeof(struct sd_inode) - SD_INODE_INDEX_SIZE)
+#define SD_INODE_DATA_INDEX (1ULL << 20)
+#define SD_INODE_DATA_INDEX_SIZE (sizeof(uint32_t) * SD_INODE_DATA_INDEX)
+#define SD_INODE_HEADER_SIZE (sizeof(struct sd_inode) - \
+		SD_INODE_DATA_INDEX_SIZE)
 #define SD_ATTR_OBJ_SIZE (sizeof(struct sheepdog_vdi_attr))
 #define CURRENT_VDI_ID 0
 
@@ -227,7 +229,7 @@ struct sd_inode {
 	uint32_t parent_vdi_id;
 	uint32_t child_vdi_id[MAX_CHILDREN];
 	uint32_t btree_counter;
-	uint32_t data_vdi_id[MAX_DATA_OBJS];
+	uint32_t data_vdi_id[SD_INODE_DATA_INDEX];
 };
 
 struct sd_extent {
diff --git a/lib/option.c b/lib/option.c
index d12c205..a74049b 100644
--- a/lib/option.c
+++ b/lib/option.c
@@ -71,6 +71,9 @@ int option_parse_size(const char *value, uint64_t *ret)
 		goto err;
 
 	switch (*postfix) {
+	case 'P':
+	case 'p':
+		sizef *= 1024;
 	case 'T':
 	case 't':
 		sizef *= 1024;
diff --git a/lib/sd_inode.c b/lib/sd_inode.c
index 60976d6..2d94471 100644
--- a/lib/sd_inode.c
+++ b/lib/sd_inode.c
@@ -76,7 +76,8 @@
 #include "util.h"
 #include "sheepdog_proto.h"
 
-#define EXT_MAX_SPACE (SD_INODE_INDEX_SIZE - sizeof(struct sd_extent_header))
+#define EXT_MAX_SPACE (SD_INODE_DATA_INDEX_SIZE - \
+		sizeof(struct sd_extent_header))
 #define EXT_MAX_ENTRIES (EXT_MAX_SPACE / sizeof(struct sd_extent))
 #define EXT_IDX_MAX_ENTRIES (EXT_MAX_SPACE / sizeof(struct sd_extent_idx))
 
@@ -142,11 +143,12 @@ static void dump_btree(read_node_fn reader, struct sd_inode *inode)
 	} else if (header->depth == 2) {
 		last_idx = LAST_IDX(inode->data_vdi_id);
 		itor_idx = FIRST_IDX(inode->data_vdi_id);
-		leaf_node = xmalloc(SD_INODE_INDEX_SIZE);
+		leaf_node = xmalloc(SD_INODE_DATA_INDEX_SIZE);
 		tmp = (void *)leaf_node;
 
 		while (itor_idx != last_idx) {
-			reader(itor_idx->oid, &tmp, SD_INODE_INDEX_SIZE, 0);
+			reader(itor_idx->oid, &tmp,
+					SD_INODE_DATA_INDEX_SIZE, 0);
 
 			sd_info("btree> %p idx: %d, %lu, %u",
 					itor_idx, itor_idx->idx, itor_idx->oid,
@@ -297,8 +299,8 @@ static void transfer_to_idx_root(write_node_fn writer, struct sd_inode *inode)
 	uint32_t num = root->entries / 2;
 
 	/* create two leaf-node and copy the entries from root-node */
-	left = xmalloc(SD_INODE_INDEX_SIZE);
-	right = xmalloc(SD_INODE_INDEX_SIZE);
+	left = xmalloc(SD_INODE_DATA_INDEX_SIZE);
+	right = xmalloc(SD_INODE_DATA_INDEX_SIZE);
 
 	split_to_nodes(root, left, right, num);
 
@@ -306,9 +308,9 @@ static void transfer_to_idx_root(write_node_fn writer, struct sd_inode *inode)
 	left_oid = vid_to_btree_oid(inode->vdi_id, inode->btree_counter++);
 	right_oid = vid_to_btree_oid(inode->vdi_id, inode->btree_counter++);
 
-	writer(left_oid, left, SD_INODE_INDEX_SIZE, 0, inode->nr_copies,
+	writer(left_oid, left, SD_INODE_DATA_INDEX_SIZE, 0, inode->nr_copies,
 			inode->copy_policy, 1);
-	writer(right_oid, right, SD_INODE_INDEX_SIZE, 0, inode->nr_copies,
+	writer(right_oid, right, SD_INODE_DATA_INDEX_SIZE, 0, inode->nr_copies,
 			inode->copy_policy, 1);
 
 	/* change root from ext-node to idx-node */
@@ -335,12 +337,12 @@ static int search_whole_btree(read_node_fn reader, const struct sd_inode *inode,
 	if (header->depth == 2) {
 		path->depth = 2;
 		path->p_idx = search_idx_entry(header, idx);
-		leaf_node = xmalloc(SD_INODE_INDEX_SIZE);
+		leaf_node = xmalloc(SD_INODE_DATA_INDEX_SIZE);
 		tmp = (void *)leaf_node;
 
 		if (idx_in_range(header, path->p_idx)) {
 			oid = path->p_idx->oid;
-			ret = reader(oid, &tmp, SD_INODE_INDEX_SIZE, 0);
+			ret = reader(oid, &tmp, SD_INODE_DATA_INDEX_SIZE, 0);
 			if (ret != SD_RES_SUCCESS)
 				goto out;
 			path->p_ext = search_ext_entry(leaf_node, idx);
@@ -351,7 +353,7 @@ static int search_whole_btree(read_node_fn reader, const struct sd_inode *inode,
 		} else {
 			/* check if last idx-node has space */
 			oid = (path->p_idx - 1)->oid;
-			ret = reader(oid, &tmp, SD_INODE_INDEX_SIZE, 0);
+			ret = reader(oid, &tmp, SD_INODE_DATA_INDEX_SIZE, 0);
 			if (ret != SD_RES_SUCCESS)
 				goto out;
 			if (leaf_node->entries < EXT_MAX_ENTRIES) {
@@ -403,15 +405,15 @@ static void split_ext_node(write_node_fn writer, struct sd_inode *inode,
 	uint32_t num = old->entries / 2;
 	uint64_t new_oid;
 
-	new_ext = xmalloc(SD_INODE_INDEX_SIZE);
+	new_ext = xmalloc(SD_INODE_DATA_INDEX_SIZE);
 
 	split_to_nodes(old, new_ext, old, num);
 
 	new_oid = vid_to_btree_oid(inode->vdi_id, inode->btree_counter++);
-	writer(new_oid, new_ext, SD_INODE_INDEX_SIZE, 0, inode->nr_copies,
+	writer(new_oid, new_ext, SD_INODE_DATA_INDEX_SIZE, 0, inode->nr_copies,
 			inode->copy_policy, 1);
-	writer(path->p_idx->oid, old, SD_INODE_INDEX_SIZE, 0, inode->nr_copies,
-			inode->copy_policy, 0);
+	writer(path->p_idx->oid, old, SD_INODE_DATA_INDEX_SIZE, 0,
+			inode->nr_copies, inode->copy_policy, 0);
 
 	/* write new index */
 	insert_idx_entry(EXT_HEADER(inode->data_vdi_id),
@@ -451,7 +453,7 @@ static int insert_new_node(write_node_fn writer, read_node_fn reader,
 			insert_ext_entry_nosearch(path->p_ext_header,
 					path->p_ext, idx, vdi_id);
 			writer(path->p_idx->oid, path->p_ext_header,
-				SD_INODE_INDEX_SIZE, 0, inode->nr_copies,
+				SD_INODE_DATA_INDEX_SIZE, 0, inode->nr_copies,
 				inode->copy_policy, 1);
 		} else if (path->p_ext_header) {
 			/* the last idx-node */
@@ -461,17 +463,17 @@ static int insert_new_node(write_node_fn writer, read_node_fn reader,
 			path->p_idx->idx =
 				(LAST_EXT(path->p_ext_header) - 1)->idx;
 			writer(path->p_idx->oid, path->p_ext_header,
-				SD_INODE_INDEX_SIZE, 0, inode->nr_copies,
+				SD_INODE_DATA_INDEX_SIZE, 0, inode->nr_copies,
 				inode->copy_policy, 1);
 		} else {
 			/* create a new ext-node */
-			leaf_node = xmalloc(SD_INODE_INDEX_SIZE);
+			leaf_node = xmalloc(SD_INODE_DATA_INDEX_SIZE);
 			sd_inode_init(leaf_node, 2);
 			oid = vid_to_btree_oid(inode->vdi_id,
 					inode->btree_counter++);
 			insert_ext_entry_nosearch(leaf_node,
 					FIRST_EXT(leaf_node), idx, vdi_id);
-			writer(oid, leaf_node, SD_INODE_INDEX_SIZE,
+			writer(oid, leaf_node, SD_INODE_DATA_INDEX_SIZE,
 					0, inode->nr_copies,
 					inode->copy_policy, 1);
 			insert_idx_entry_nosearch(header, path->p_idx,
-- 
1.7.1




More information about the sheepdog mailing list