[sheepdog] [PATCH v1 2/5] write inode at one time in vdi_create() and vdi_clone()

Robin Dong robin.k.dong at gmail.com
Fri Oct 11 08:20:44 CEST 2013


It will improve performance for writing whole inode once after change all vid
instead of write vid many times.

Signed-off-by: Robin Dong <sanbai at taobao.com>
---
 dog/vdi.c |   50 ++++++++++++++++++++++++++++++++------------------
 1 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/dog/vdi.c b/dog/vdi.c
index 28509e2..02267ab 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -536,15 +536,18 @@ static int vdi_create(int argc, char **argv)
 		}
 
 		sd_inode_set_vdi(inode, idx, vid);
-		ret = sd_write_object(vid_to_vdi_oid(vid), 0, &vid, sizeof(vid),
-				      SD_INODE_HEADER_SIZE + sizeof(vid) * idx,
-				      0, inode->nr_copies, inode->copy_policy,
-				      false, true);
-		if (ret) {
-			ret = EXIT_FAILURE;
-			goto out;
-		}
 	}
+
+	ret = sd_write_object(vid_to_vdi_oid(vid), 0, inode,
+			      sizeof(uint32_t) * MAX_DATA_OBJS,
+			      SD_INODE_HEADER_SIZE, 0,
+			      inode->nr_copies, inode->copy_policy,
+			      false, true);
+	if (ret) {
+		ret = EXIT_FAILURE;
+		goto out;
+	}
+
 	vdi_show_progress(idx * SD_DATA_OBJ_SIZE, inode->vdi_size);
 	ret = EXIT_SUCCESS;
 
@@ -605,7 +608,7 @@ static int vdi_clone(int argc, char **argv)
 	uint32_t base_vid, new_vid, vdi_id;
 	uint64_t oid;
 	int idx, max_idx, ret;
-	struct sd_inode *inode = NULL;
+	struct sd_inode *inode = NULL, *new_inode = NULL;
 	char *buf = NULL;
 
 	dst_vdi = argv[optind];
@@ -635,6 +638,13 @@ static int vdi_clone(int argc, char **argv)
 	if (ret != EXIT_SUCCESS || !vdi_cmd_data.prealloc)
 		goto out;
 
+	new_inode = xmalloc(sizeof(*inode));
+
+	ret = read_vdi_obj(dst_vdi, 0, "", NULL, new_inode,
+				SD_INODE_HEADER_SIZE);
+	if (ret != EXIT_SUCCESS)
+		goto out;
+
 	buf = xzalloc(SD_DATA_OBJ_SIZE);
 	max_idx = count_data_objs(inode);
 
@@ -661,17 +671,19 @@ static int vdi_clone(int argc, char **argv)
 			ret = EXIT_FAILURE;
 			goto out;
 		}
+		sd_inode_set_vdi(new_inode,  idx, new_vid);
+	}
 
-		ret = sd_write_object(vid_to_vdi_oid(new_vid), 0, &new_vid,
-				      sizeof(new_vid),
-				SD_INODE_HEADER_SIZE + sizeof(new_vid) * idx, 0,
-				      inode->nr_copies, inode->copy_policy,
-				      false, true);
-		if (ret) {
-			ret = EXIT_FAILURE;
-			goto out;
-		}
+	ret = sd_write_object(vid_to_vdi_oid(new_vid), 0, new_inode,
+			      sizeof(uint32_t) * MAX_DATA_OBJS,
+			      SD_INODE_HEADER_SIZE, 0,
+			      inode->nr_copies, inode->copy_policy,
+			      false, true);
+	if (ret) {
+		ret = EXIT_FAILURE;
+		goto out;
 	}
+
 	vdi_show_progress(idx * SD_DATA_OBJ_SIZE, inode->vdi_size);
 	ret = EXIT_SUCCESS;
 
@@ -683,6 +695,8 @@ static int vdi_clone(int argc, char **argv)
 	}
 out:
 	free(inode);
+	if (new_inode)
+		free(new_inode);
 	free(buf);
 	return ret;
 }
-- 
1.7.1




More information about the sheepdog mailing list