[sheepdog] [PATCH 05/10] sheep: fix 'md info'

Liu Yuan namei.unix at gmail.com
Sun May 26 15:40:41 CEST 2013


Show the output format as 'node info'

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 collie/node.c            |   13 ++++++++-----
 include/internal_proto.h |    2 +-
 sheep/md.c               |    2 +-
 tests/057.out            |   48 +++++++++++++++++++++++-----------------------
 tests/common.filter      |    2 +-
 5 files changed, 35 insertions(+), 32 deletions(-)

diff --git a/collie/node.c b/collie/node.c
index 3fe1108..38dc94b 100644
--- a/collie/node.c
+++ b/collie/node.c
@@ -211,7 +211,7 @@ static int node_kill(int argc, char **argv)
 static int node_md_info(struct node_id *nid)
 {
 	struct sd_md_info info = {};
-	char free_str[UINT64_DECIMAL_SIZE], used_str[UINT64_DECIMAL_SIZE];
+	char size_str[UINT64_DECIMAL_SIZE], used_str[UINT64_DECIMAL_SIZE];
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 	int ret, i;
@@ -232,10 +232,13 @@ static int node_md_info(struct node_id *nid)
 	}
 
 	for (i = 0; i < info.nr; i++) {
-		size_to_str(info.disk[i].size, free_str, sizeof(free_str));
+		uint64_t size = info.disk[i].free + info.disk[i].used;
+		int ratio = (int)(((double)info.disk[i].used / size) * 100);
+
+		size_to_str(size, size_str, sizeof(size_str));
 		size_to_str(info.disk[i].used, used_str, sizeof(used_str));
-		fprintf(stdout, "%2d\t%s\t%s\t%s\n", info.disk[i].idx, used_str,
-			free_str, info.disk[i].path);
+		fprintf(stdout, "%2d\t%s\t%s\t%3d%%\t%s\n", info.disk[i].idx,
+			size_str, used_str, ratio, info.disk[i].path);
 	}
 	return EXIT_SUCCESS;
 }
@@ -244,7 +247,7 @@ static int md_info(int argc, char **argv)
 {
 	int i, ret;
 
-	fprintf(stdout, "Id\tUsed\tFree\tPath\n");
+	fprintf(stdout, "Id\tSize\tUsed\tUse%%\tPath\n");
 
 	if (!node_cmd_data.all_nodes) {
 		struct node_id nid = {.port = sdport};
diff --git a/include/internal_proto.h b/include/internal_proto.h
index 2057f9b..b5dc910 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -168,7 +168,7 @@ struct vdi_op_message {
 
 struct md_info {
 	int idx;
-	uint64_t size;
+	uint64_t free;
 	uint64_t used;
 	char path[PATH_MAX];
 };
diff --git a/sheep/md.c b/sheep/md.c
index 33f7ab3..64463d9 100644
--- a/sheep/md.c
+++ b/sheep/md.c
@@ -606,7 +606,7 @@ uint32_t md_get_info(struct sd_md_info *info)
 		info->disk[i].idx = i;
 		pstrcpy(info->disk[i].path, PATH_MAX, md_disks[i].path);
 		/* FIXME: better handling failure case. */
-		info->disk[i].size = get_path_free_size(info->disk[i].path,
+		info->disk[i].free = get_path_free_size(info->disk[i].path,
 							&info->disk[i].used);
 	}
 	info->nr = md_nr_disks;
diff --git a/tests/057.out b/tests/057.out
index 27c70ce..466af8a 100644
--- a/tests/057.out
+++ b/tests/057.out
@@ -1,15 +1,15 @@
 QA output created by 057
 using backend plain store
-Id	Used	Free	Path
-0 32 MB MASKED GB STORE/0/d0
-1 32 MB MASKED GB STORE/0/d1
-2 40 MB MASKED GB STORE/0/d2
-Id	Used	Free	Path
-0 4.0 MB MASKED GB STORE/0/d0
-1 20 MB MASKED GB STORE/0/d1
-2 28 MB MASKED GB STORE/0/d2
-3 20 MB MASKED GB STORE/0/d3
-4 24 MB MASKED GB STORE/0/d4
+Id	Size	Used	Use%	Path
+0 MASKED GB 32 MB MASKED STORE/0/d0
+1 MASKED GB 32 MB MASKED STORE/0/d1
+2 MASKED GB 40 MB MASKED STORE/0/d2
+Id	Size	Used	Use%	Path
+0 MASKED GB 4.0 MB MASKED STORE/0/d0
+1 MASKED GB 20 MB MASKED STORE/0/d1
+2 MASKED GB 28 MB MASKED STORE/0/d2
+3 MASKED GB 20 MB MASKED STORE/0/d3
+4 MASKED GB 24 MB MASKED STORE/0/d4
 finish check&repair test
 Cluster status: running, auto-recovery enabled
 
@@ -21,16 +21,16 @@ DATE      1 [127.0.0.1:7000, 127.0.0.1:7001, 127.0.0.1:7002]
 Failed to execute request, look for sheep.log for more information
 Nodes In Recovery:
   Id   Host:Port         V-Nodes       Zone
-Id	Used	Free	Path
-0 4.0 MB MASKED GB STORE/0/d0
-1 20 MB MASKED GB STORE/0/d1
-2 28 MB MASKED GB STORE/0/d2
-3 20 MB MASKED GB STORE/0/d3
-4 24 MB MASKED GB STORE/0/d4
-Id	Used	Free	Path
-0 28 MB MASKED GB STORE/0/d2
-1 32 MB MASKED GB STORE/0/d3
-2 36 MB MASKED GB STORE/0/d4
+Id	Size	Used	Use%	Path
+0 MASKED GB 4.0 MB MASKED STORE/0/d0
+1 MASKED GB 20 MB MASKED STORE/0/d1
+2 MASKED GB 28 MB MASKED STORE/0/d2
+3 MASKED GB 20 MB MASKED STORE/0/d3
+4 MASKED GB 24 MB MASKED STORE/0/d4
+Id	Size	Used	Use%	Path
+0 MASKED GB 28 MB MASKED STORE/0/d2
+1 MASKED GB 32 MB MASKED STORE/0/d3
+2 MASKED GB 36 MB MASKED STORE/0/d4
 finish check&repair test
 Cluster status: running, auto-recovery enabled
 
@@ -42,10 +42,10 @@ DATE      1 [127.0.0.1:7000, 127.0.0.1:7001, 127.0.0.1:7002]
 Failed to execute request, look for sheep.log for more information
 Nodes In Recovery:
   Id   Host:Port         V-Nodes       Zone
-Id	Used	Free	Path
-0 28 MB MASKED GB STORE/0/d2
-1 32 MB MASKED GB STORE/0/d3
-2 36 MB MASKED GB STORE/0/d4
+Id	Size	Used	Use%	Path
+0 MASKED GB 28 MB MASKED STORE/0/d2
+1 MASKED GB 32 MB MASKED STORE/0/d3
+2 MASKED GB 36 MB MASKED STORE/0/d4
 Cluster status: running, auto-recovery enabled
 
 Cluster created at DATE
diff --git a/tests/common.filter b/tests/common.filter
index 13ceb9e..bf6bc94 100644
--- a/tests/common.filter
+++ b/tests/common.filter
@@ -165,7 +165,7 @@ _filter_store()
 
 _filter_md_info()
 {
-	awk '{if ($4 ~ /^[0-9.]+$/) $4="MASKED";print $0}' | _filter_store
+	awk '{if ($2 ~ /^[0-9.]+$/) {$2="MASKED";$6="MASKED"};print $0}' | _filter_store
 }
 
 _filter_node_info()
-- 
1.7.9.5




More information about the sheepdog mailing list