[sheepdog] [PATCH 2/8] sheep: add cmd argument -W to specify a max cache size

levin li levin108 at gmail.com
Mon Jul 9 08:29:16 CEST 2012


From: levin li <xingke.lwp at taobao.com>


Signed-off-by: levin li <xingke.lwp at taobao.com>
---
 sheep/sheep.c      |   16 +++++++++++++++-
 sheep/sheep_priv.h |    2 ++
 2 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/sheep/sheep.c b/sheep/sheep.c
index 7d1e853..56a432e 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -43,11 +43,12 @@ static struct option const long_options[] = {
 	{"port", required_argument, NULL, 'p'},
 	{"vnodes", required_argument, NULL, 'v'},
 	{"enable-cache", no_argument, NULL, 'w'},
+	{"cache-size", optional_argument, NULL, 'W'},
 	{"zone", required_argument, NULL, 'z'},
 	{NULL, 0, NULL, 0},
 };
 
-static const char *short_options = "c:dDfghl:op:v:wy:z:";
+static const char *short_options = "c:dDfghl:op:v:wW:y:z:";
 
 static void usage(int status)
 {
@@ -70,6 +71,7 @@ Options:\n\
   -p, --port              specify the TCP port on which to listen\n\
   -v, --vnodes            specify the number of virtual nodes\n\
   -w, --enable-cache      enable object cache\n\
+  -W, --cache-size        specify the max cache size\n\
   -y, --myaddr            specify the address advertised to other sheep\n\
   -z, --zone              specify the zone id\n\
 ", PACKAGE_VERSION, program_name);
@@ -104,6 +106,7 @@ int main(int argc, char **argv)
 	int log_level = SDOG_INFO;
 	char path[PATH_MAX];
 	int64_t zone = -1;
+	int64_t cache_size = 0;
 	int nr_vnodes = SD_DEFAULT_VNODES;
 	bool explicit_addr = false;
 	int af;
@@ -177,6 +180,17 @@ int main(int argc, char **argv)
 			vprintf(SDOG_INFO, "enable write cache\n");
 			enable_write_cache = 1;
 			break;
+		case 'W':
+			cache_size = strtol(optarg, &p, 10);
+			if (optarg == p || cache_size < 0 ||
+			    UINT32_MAX < cache_size) {
+				fprintf(stderr, "Invalid cache size '%s': "
+					"must be an integer between 0 and %u\n",
+					optarg, UINT32_MAX);
+				exit(1);
+			}
+			sys->cache_size = cache_size;
+			break;
 		case 'v':
 			nr_vnodes = strtol(optarg, &p, 10);
 			if (optarg == p || nr_vnodes < 0 || SD_MAX_VNODES < nr_vnodes) {
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index afbc361..de06417 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -89,6 +89,8 @@ struct cluster_info {
 	uint32_t status;
 	uint16_t flags;
 
+	uint64_t cache_size;
+
 	/*
 	 * List of nodes that were past of the last epoch before a shutdown,
 	 * but failed to join.
-- 
1.7.1




More information about the sheepdog mailing list