[sheepdog] [PATCH 1/2] collie: add node cache command to set max cache size

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Mon Jul 30 06:59:45 CEST 2012


At Mon, 30 Jul 2012 12:21:19 +0800,
levin li wrote:
> 
> From: levin li <xingke.lwp at taobao.com>
> 
> 
> Signed-off-by: levin li <xingke.lwp at taobao.com>
> ---
>  collie/node.c            |   44 ++++++++++++++++++++++++++++++++++++++++++++
>  include/internal_proto.h |    1 +
>  2 files changed, 45 insertions(+), 0 deletions(-)
> 
> diff --git a/collie/node.c b/collie/node.c
> index df841a0..e6bcab8 100644
> --- a/collie/node.c
> +++ b/collie/node.c
> @@ -139,6 +139,48 @@ static int node_recovery(int argc, char **argv)
>  	return EXIT_SUCCESS;
>  }
>  
> +static int node_cache(int argc, char **argv)
> +{
> +	int fd, ret, cache_size;
> +	unsigned int wlen, rlen = 0;
> +	struct sd_req hdr;
> +	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
> +
> +	cache_size = strtol(argv[optind++], NULL, 10);
> +	if (cache_size < 0) {
> +		fprintf(stderr, "Invalid cache size %d\n", cache_size);
> +		return EXIT_FAILURE;
> +	}

We should check the cache size more strictly.  For example,

	char *p;
	cache_size = strtol(argv[optind], &p, 10);
	if (argv[optind] == p || cache_size < 0) {
		fprintf(stderr, "Invalid cache size %s\n", argv[optind]);
		return EXIT_FAILURE;
	}
	optind++;

Thanks,

Kazutaka


> +
> +	fd = connect_to(sdhost, sdport);
> +	if (fd < 0)
> +		return EXIT_FAILURE;
> +
> +	wlen = sizeof(cache_size);
> +
> +	sd_init_req(&hdr, SD_OP_SET_CACHE_SIZE);
> +	hdr.flags = SD_FLAG_CMD_WRITE;
> +	hdr.data_length = wlen;
> +
> +	ret = exec_req(fd, &hdr, (void *)&cache_size, &wlen, &rlen);
> +	close(fd);
> +
> +	if (ret) {
> +		fprintf(stderr, "Failed to connect\n");
> +		return EXIT_FAILURE;
> +	}
> +
> +	if (rsp->result != SD_RES_SUCCESS) {
> +		fprintf(stderr, "specify max cache size failed: %s\n",
> +				sd_strerror(rsp->result));
> +		return EXIT_FAILURE;
> +	}
> +
> +	printf("Max cache size set to %dM\n", cache_size);
> +
> +	return EXIT_SUCCESS;
> +}
> +
>  static int node_kill(int argc, char **argv)
>  {
>  	char host[128];
> @@ -174,6 +216,8 @@ static struct subcommand node_cmd[] = {
>  	 SUBCMD_FLAG_NEED_NODELIST, node_info},
>  	{"recovery", NULL, "aprh", "show nodes in recovery",
>  	 SUBCMD_FLAG_NEED_NODELIST, node_recovery},
> +	{"cache", "<cache size>", "aprh", "specify max cache size",
> +	SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG, node_cache},
>  	{NULL,},
>  };
>  
> diff --git a/include/internal_proto.h b/include/internal_proto.h
> index a296217..3e22124 100644
> --- a/include/internal_proto.h
> +++ b/include/internal_proto.h
> @@ -60,6 +60,7 @@
>  #define SD_OP_READ_PEER      0xA4
>  #define SD_OP_WRITE_PEER     0xA5
>  #define SD_OP_REMOVE_PEER    0xA6
> +#define SD_OP_SET_CACHE_SIZE 0xA7
>  
>  /* internal flags for hdr.flags, must be above 0x80 */
>  #define SD_FLAG_CMD_RECOVERY 0x0080
> -- 
> 1.7.1
> 
> -- 
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> http://lists.wpkg.org/mailman/listinfo/sheepdog



More information about the sheepdog mailing list