[sheepdog] [PATCH 3/3] sheep: make option set human friendly

Liu Yuan namei.unix at gmail.com
Fri Aug 23 14:24:55 CEST 2013


With this patch, journal size and object cache size should be set with human
friendly value like 200G, 2000M.

This patch breaks compatibility of command line.

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 sheep/journal.c      |    2 +-
 sheep/sheep.c        |   33 +++++++++++++++++----------------
 tests/functional/018 |    2 +-
 tests/functional/019 |    2 +-
 tests/functional/020 |    2 +-
 tests/functional/044 |    2 +-
 tests/functional/047 |    4 ++--
 tests/functional/049 |    4 ++--
 tests/functional/058 |    2 +-
 tests/functional/065 |    4 ++--
 tests/functional/066 |    2 +-
 11 files changed, 30 insertions(+), 29 deletions(-)

diff --git a/sheep/journal.c b/sheep/journal.c
index cd38701..49e2b95 100644
--- a/sheep/journal.c
+++ b/sheep/journal.c
@@ -266,7 +266,7 @@ int journal_file_init(const char *path, size_t size, bool skip)
 	if (!skip)
 		check_recover_journal_file(path);
 
-	jfile_size = (size * 1024 * 1024) / 2;
+	jfile_size = size / 2;
 
 	fd = create_journal_file(path, jfile_name[0]);
 	if (fd < 0)
diff --git a/sheep/sheep.c b/sheep/sheep.c
index e9c7eb5..8394a4a 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -260,21 +260,21 @@ struct system_info *sys = &__sys;
 
 static int cache_size_parser(char *s)
 {
-	const uint32_t max_cache_size = UINT32_MAX;
+	const uint64_t max_cache_size = ((uint64_t)UINT32_MAX + 1)*1024*1024;
 	uint64_t cache_size;
-	char *p;
 
-	cache_size = strtoull(s, &p, 10);
-	if (s == p || max_cache_size < cache_size)
-		goto err;
+	if (option_parse_size(s, &cache_size) < 0)
+		return -1;
+#define MIN_CACHE_SIZE (10*1024*1024) /* 10M */
+	if (cache_size < MIN_CACHE_SIZE || cache_size > max_cache_size) {
+		sd_err("Invalid cache option '%s': size must be between "
+		       "between %uM and %" PRIu64 "G", s,
+		       MIN_CACHE_SIZE/1024/1024, max_cache_size/1024/1024/1024);
+		return -1;
+	}
 
-	sys->object_cache_size = cache_size;
+	sys->object_cache_size = cache_size / 1024 / 1024;
 	return 0;
-
-err:
-	sd_err("Invalid object cache option '%s': size must be an integer "
-	       "between 1 and %" PRIu32 " inclusive", s, max_cache_size);
-	return -1;
 }
 
 static int cache_directio_parser(char *s)
@@ -319,8 +319,7 @@ static struct option_parser ionic_parsers[] = {
 
 static char jpath[PATH_MAX];
 static bool jskip;
-static ssize_t jsize;
-#define MIN_JOURNAL_SIZE (64) /* 64M */
+static uint64_t jsize;
 
 static int journal_dir_parser(char *s)
 {
@@ -330,10 +329,12 @@ static int journal_dir_parser(char *s)
 
 static int journal_size_parser(char *s)
 {
-	jsize = strtoll(s, NULL, 10);
-	if (jsize < MIN_JOURNAL_SIZE || jsize == LLONG_MAX) {
+	if (option_parse_size(s, &jsize) < 0)
+		return -1;
+#define MIN_JOURNAL_SIZE (64*1024*1024) /* 64M */
+	if (jsize < MIN_JOURNAL_SIZE) {
 		sd_err("invalid size %s, must be bigger than %u(M)",
-		       s, MIN_JOURNAL_SIZE);
+		       s, MIN_JOURNAL_SIZE/1024/1024);
 		return -1;
 	}
 	return 0;
diff --git a/tests/functional/018 b/tests/functional/018
index c0ab9ee..bcec541 100755
--- a/tests/functional/018
+++ b/tests/functional/018
@@ -5,7 +5,7 @@
 . ./common
 
 for i in `seq 0 2`; do
-    _start_sheep $i "-w size=100"
+    _start_sheep $i "-w size=100M"
 done
 
 _wait_for_sheep "3"
diff --git a/tests/functional/019 b/tests/functional/019
index efe8cb8..136fb6e 100755
--- a/tests/functional/019
+++ b/tests/functional/019
@@ -5,7 +5,7 @@
 . ./common
 
 for i in `seq 0 2`; do
-    _start_sheep $i "-w size=100"
+    _start_sheep $i "-w size=100M"
 done
 
 _wait_for_sheep "3"
diff --git a/tests/functional/020 b/tests/functional/020
index 77066bf..a2a6d04 100755
--- a/tests/functional/020
+++ b/tests/functional/020
@@ -5,7 +5,7 @@
 . ./common
 
 for i in `seq 0 2`; do
-    _start_sheep $i "-w size=20"
+    _start_sheep $i "-w size=20M"
 done
 
 _wait_for_sheep "3"
diff --git a/tests/functional/044 b/tests/functional/044
index fc5d8be..0db70f9 100755
--- a/tests/functional/044
+++ b/tests/functional/044
@@ -5,7 +5,7 @@
 . ./common
 
 for i in 0 1 2; do
-    _start_sheep $i "-w size=1000"
+    _start_sheep $i "-w size=1000M"
 done
 
 _wait_for_sheep 3
diff --git a/tests/functional/047 b/tests/functional/047
index 675f74e..df527e5 100755
--- a/tests/functional/047
+++ b/tests/functional/047
@@ -4,7 +4,7 @@
 
 . ./common
 
-_start_sheep 0 "-j size=64"
+_start_sheep 0 "-j size=64M"
 
 _wait_for_sheep 1
 
@@ -26,7 +26,7 @@ else
 fi
 
 # do the journal replay
-_start_sheep 0 "-j size=64"
+_start_sheep 0 "-j size=64M"
 _wait_for_sheep 1
 
 sleep 3
diff --git a/tests/functional/049 b/tests/functional/049
index d466130..ae3ebc8 100755
--- a/tests/functional/049
+++ b/tests/functional/049
@@ -5,7 +5,7 @@
 . ./common
 
 for i in `seq 0 2`; do
-    _start_sheep $i "-w size=30"
+    _start_sheep $i "-w size=30M"
 done
 
 _wait_for_sheep 3
@@ -20,7 +20,7 @@ _wait_for_sheep_stop
 
 #trigger an object reclaim at startup
 for i in `seq 0 2`; do
-    _start_sheep $i "-w size=10"
+    _start_sheep $i "-w size=10M"
 done
 
 _wait_for_sheep 3
diff --git a/tests/functional/058 b/tests/functional/058
index ea584de..ebd61db 100755
--- a/tests/functional/058
+++ b/tests/functional/058
@@ -4,7 +4,7 @@
 . ./common
 
 for i in 0 1 2; do
-	_start_sheep $i "-w size=200"
+	_start_sheep $i "-w size=200M"
 done
 _wait_for_sheep 3
 _cluster_format
diff --git a/tests/functional/065 b/tests/functional/065
index e0ee1ae..7e5e03b 100755
--- a/tests/functional/065
+++ b/tests/functional/065
@@ -5,7 +5,7 @@
 . ./common
 
 for i in `seq 0 1`; do
-    _start_sheep $i "-w size=400"
+    _start_sheep $i "-w size=400M"
 done
 
 _wait_for_sheep 2
@@ -15,7 +15,7 @@ $DOG vdi create t 1G -P
 
 # move objects into stale directory
 _kill_sheep 0
-_start_sheep 0 "-w size=400"
+_start_sheep 0 "-w size=400M"
 _wait_for_sheep 2
 
 dd if=/dev/zero | $DOG vdi write -w t &
diff --git a/tests/functional/066 b/tests/functional/066
index 97f0b9f..84dedee 100755
--- a/tests/functional/066
+++ b/tests/functional/066
@@ -5,7 +5,7 @@
 . ./common
 
 for i in `seq 0 1 2`; do
-    _start_sheep $i "-w size=200"
+    _start_sheep $i "-w size=200M"
 done
 
 _wait_for_sheep 3
-- 
1.7.9.5




More information about the sheepdog mailing list