[sheepdog] [PATCH 1/3] add helper function to count data objects in vdi

MORITA Kazutaka morita.kazutaka at gmail.com
Tue Sep 3 17:02:59 CEST 2013


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

This also removes redudant object checks in dog, and improves the
performance of 'dog vdi list' when the vdi disk size is not so big.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 dog/cluster.c            |    5 +++--
 dog/common.c             |    3 +--
 dog/vdi.c                |   11 ++++++-----
 include/sheepdog_proto.h |    6 ++++++
 sheep/vdi.c              |    5 +++--
 5 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/dog/cluster.c b/dog/cluster.c
index 3fd87bd..b2ee123 100644
--- a/dog/cluster.c
+++ b/dog/cluster.c
@@ -246,7 +246,7 @@ static void fill_object_tree(uint32_t vid, const char *name, const char *tag,
 			  const struct sd_inode *i, void *data)
 {
 	uint64_t vdi_oid = vid_to_vdi_oid(vid), vmstate_oid;
-	int nr_vmstate_object;
+	int nr_objs, nr_vmstate_object;
 
 	/* ignore active vdi */
 	if (!vdi_is_snapshot(i))
@@ -256,7 +256,8 @@ static void fill_object_tree(uint32_t vid, const char *name, const char *tag,
 	object_tree_insert(vdi_oid, i->nr_copies);
 
 	/* fill data object id */
-	for (uint64_t idx = 0; idx < MAX_DATA_OBJS; idx++) {
+	nr_objs = count_data_objs(i);
+	for (uint64_t idx = 0; idx < nr_objs; idx++) {
 		if (i->data_vdi_id[idx]) {
 			uint64_t oid = vid_to_data_oid(i->data_vdi_id[idx],
 						       idx);
diff --git a/dog/common.c b/dog/common.c
index 84c91f6..6c45056 100644
--- a/dog/common.c
+++ b/dog/common.c
@@ -165,8 +165,7 @@ int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
 			continue;
 
 		if (size > SD_INODE_HEADER_SIZE) {
-			rlen = DIV_ROUND_UP(i.vdi_size, SD_DATA_OBJ_SIZE) *
-				sizeof(i.data_vdi_id[0]);
+			rlen = count_data_objs(&i) * sizeof(i.data_vdi_id[0]);
 			if (rlen > size - SD_INODE_HEADER_SIZE)
 				rlen = size - SD_INODE_HEADER_SIZE;
 
diff --git a/dog/vdi.c b/dog/vdi.c
index 4601140..e8f1ce2 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -64,7 +64,7 @@ static void print_vdi_list(uint32_t vid, const char *name, const char *tag,
 			   uint32_t snapid, uint32_t flags,
 			   const struct sd_inode *i, void *data)
 {
-	int idx;
+	int idx, nr_objs;
 	bool is_clone = false;
 	uint64_t my_objs, cow_objs;
 	time_t ti;
@@ -86,7 +86,8 @@ static void print_vdi_list(uint32_t vid, const char *name, const char *tag,
 
 	my_objs = 0;
 	cow_objs = 0;
-	for (idx = 0; idx < MAX_DATA_OBJS; idx++) {
+	nr_objs = count_data_objs(i);
+	for (idx = 0; idx < nr_objs; idx++) {
 		if (!i->data_vdi_id[idx])
 			continue;
 		if (is_data_obj_writeable(i, idx))
@@ -610,7 +611,7 @@ static int vdi_clone(int argc, char **argv)
 		goto out;
 
 	buf = xzalloc(SD_DATA_OBJ_SIZE);
-	max_idx = DIV_ROUND_UP(inode->vdi_size, SD_DATA_OBJ_SIZE);
+	max_idx = count_data_objs(inode);
 
 	for (idx = 0; idx < max_idx; idx++) {
 		vdi_show_progress(idx * SD_DATA_OBJ_SIZE, inode->vdi_size);
@@ -1522,7 +1523,7 @@ int do_vdi_check(const struct sd_inode *inode)
 
 	queue_vdi_check_work(inode, vid_to_vdi_oid(inode->vdi_id), NULL, wq);
 
-	max_idx = DIV_ROUND_UP(inode->vdi_size, SD_DATA_OBJ_SIZE);
+	max_idx = count_data_objs(inode);
 	vdi_show_progress(done, inode->vdi_size);
 	for (int idx = 0; idx < max_idx; idx++) {
 		vid = inode->data_vdi_id[idx];
@@ -1670,7 +1671,7 @@ static int vdi_backup(int argc, char **argv)
 	if (ret != EXIT_SUCCESS)
 		goto out;
 
-	nr_objs = DIV_ROUND_UP(to_inode->vdi_size, SD_DATA_OBJ_SIZE);
+	nr_objs = count_data_objs(to_inode);
 
 	ret = xwrite(STDOUT_FILENO, &hdr, sizeof(hdr));
 	if (ret < 0) {
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index aa9d6c2..b1a621b 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -18,6 +18,7 @@
 #include <linux/limits.h>
 
 #include "compiler.h"
+#include "bitops.h"
 
 #define SD_PROTO_VER 0x02
 
@@ -337,6 +338,11 @@ static inline bool is_data_obj(uint64_t oid)
 		!is_vdi_attr_obj(oid);
 }
 
+static inline size_t count_data_objs(const struct sd_inode *inode)
+{
+	return DIV_ROUND_UP(inode->vdi_size, SD_DATA_OBJ_SIZE);
+}
+
 static inline size_t get_objsize(uint64_t oid)
 {
 	if (is_vdi_obj(oid))
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 05690c2..0faab62 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -784,7 +784,7 @@ static void delete_one(struct work *work)
 {
 	struct deletion_work *dw = container_of(work, struct deletion_work, work);
 	uint32_t vdi_id = *(dw->buf + dw->count - dw->done - 1);
-	int ret, i, nr_deleted;
+	int ret, i, nr_deleted, nr_objs;
 	struct sd_inode *inode = NULL;
 
 	sd_debug("%d %d, %16x", dw->done, dw->count, vdi_id);
@@ -806,7 +806,8 @@ static void delete_one(struct work *work)
 	if (inode->vdi_size == 0 && vdi_is_deleted(inode))
 		goto out;
 
-	for (nr_deleted = 0, i = 0; i < MAX_DATA_OBJS; i++) {
+	nr_objs = count_data_objs(inode);
+	for (nr_deleted = 0, i = 0; i < nr_objs; i++) {
 		uint64_t oid;
 
 		if (!inode->data_vdi_id[i])
-- 
1.7.9.5




More information about the sheepdog mailing list