[sheepdog] [PATCH v2 2/4] sheep: add user-defined free disk space size

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Sat Aug 4 08:20:38 CEST 2012


At Sat, 04 Aug 2012 15:06:02 +0900,
MORITA Kazutaka wrote:
> 
> At Fri,  3 Aug 2012 20:50:09 +0800,
> levin li wrote:
> > 
> > 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;
> 
> Should be int64_t?
> 
> >  	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);
> 
> Should use strtoll()?
> 
> > +			if (optarg == p || free_space < 0 || UINT32_MAX < free_space) {
> 
> INT64_MAX instead of UINT32_MAX?

And we should exit when free_space == 0, because sheep calculates the
free space when sys->disk_space is zero.

Thanks,

Kazutaka



More information about the sheepdog mailing list