[sheepdog] [PATCH v2 2/4] sheep: add user-defined free disk space size
levin li
levin108 at gmail.com
Fri Aug 3 14:50:09 CEST 2012
From: levin li <xingke.lwp at taobao.com>
Sometimes user doesn't want sheep to use all the disk space,
maybe some space in the same disk is for other use, such as
object cache, or something else, so we can't only get the free
space by syscall, we also should provide a way for users to
specify the free disk space
Signed-off-by: levin li <xingke.lwp at taobao.com>
---
sheep/sheep.c | 15 ++++++++++++++-
sheep/store.c | 5 +++++
2 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/sheep/sheep.c b/sheep/sheep.c
index 52a294b..1c11d86 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -47,13 +47,14 @@ static struct option const long_options[] = {
{"stdout", no_argument, NULL, 'o'},
{"port", required_argument, NULL, 'p'},
{"vnodes", required_argument, NULL, 'v'},
+ {"disk-space", required_argument, NULL, 's'},
{"enable-cache", required_argument, NULL, 'w'},
{"zone", required_argument, NULL, 'z'},
{"pidfile", required_argument, NULL, 'P'},
{NULL, 0, NULL, 0},
};
-static const char *short_options = "c:dDfghl:op:P:v:w:y:z:";
+static const char *short_options = "c:dDfghl:op:P:v:s:w:y:z:";
static void usage(int status)
{
@@ -76,6 +77,7 @@ Options:\n\
-p, --port specify the TCP port on which to listen\n\
-P, --pidfile create a pid file\n\
-v, --vnodes specify the number of virtual nodes\n\
+ -s, --disk-space specify the free disk space in megabytes\n\
-w, --enable-cache enable object cache and specify the max cache size in megabytes\n\
-y, --myaddr specify the address advertised to other sheep\n\
-z, --zone specify the zone id\n\
@@ -187,6 +189,7 @@ int main(int argc, char **argv)
char path[PATH_MAX];
int64_t zone = -1;
int64_t cache_size = 0;
+ int32_t free_space = 0;
int nr_vnodes = SD_DEFAULT_VNODES;
bool explicit_addr = false;
int af;
@@ -283,6 +286,16 @@ int main(int argc, char **argv)
exit(1);
}
break;
+ case 's':
+ free_space = strtol(optarg, &p, 10);
+ if (optarg == p || free_space < 0 || UINT32_MAX < free_space) {
+ fprintf(stderr, "Invalid free space size '%s': "
+ "must be an integer between 0 and %u\n",
+ optarg, UINT32_MAX);
+ exit(1);
+ }
+ sys->disk_space = free_space;
+ break;
case 'c':
sys->cdrv = find_cdrv(optarg);
if (!sys->cdrv) {
diff --git a/sheep/store.c b/sheep/store.c
index 2c2f94b..e320072 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -457,6 +457,11 @@ static int init_disk_space(const char *base_path)
goto out;
}
+ if (sys->disk_space) {
+ ret = set_cluster_space(sys->disk_space);
+ goto out;
+ }
+
ret = statfs(base_path, &sf);
if (ret < 0) {
dprintf("get disk space failed %m\n");
--
1.7.1
More information about the sheepdog
mailing list