[sheepdog] [PATCH 1/2] dog: add argument for cluster info to display backend store type

Liu Yuan namei.unix at gmail.com
Wed Dec 4 10:45:40 CET 2013


On Wed, Dec 04, 2013 at 05:21:25PM +0800, Robin Dong wrote:
> From: Robin Dong <sanbai at taobao.com>
> 
> 'dog cluster info' does not show backend store information, so we
> add argument '-s' to display it.
> 
> Now, when using 'dog cluster info -s', it will display:
> 
> 	Cluster status: running, auto-recovery enabled
> 	Cluster store: plain with 8:15 redundancy policy
> 
> 	Cluster created at Wed Dec  4 16:39:21 2013
> 
> 	Epoch Time           Version
> 	......
> 
> Signed-off-by: Robin Dong <sanbai at taobao.com>
> ---
>  dog/cluster.c            | 28 ++++++++++++++++++++++++++--
>  include/internal_proto.h |  5 ++++-
>  sheep/ops.c              | 13 +++++++++++--
>  3 files changed, 41 insertions(+), 5 deletions(-)
> 
> diff --git a/dog/cluster.c b/dog/cluster.c
> index f44791c..05e98d2 100644
> --- a/dog/cluster.c
> +++ b/dog/cluster.c
> @@ -21,7 +21,7 @@ static struct sd_option cluster_options[] = {
>  	{'b', "store", true, "specify backend store"},
>  	{'c', "copies", true, "specify the default data redundancy (number of copies)"},
>  	{'f', "force", false, "do not prompt for confirmation"},
> -
> +	{'s', "backend", false, "show backend store information"},
>  	{ 0, NULL, false, NULL },
>  };
>  
> @@ -29,6 +29,7 @@ static struct cluster_cmd_data {
>  	uint8_t copies;
>  	uint8_t copy_policy;
>  	bool force;
> +	bool show_store;
>  	char name[STORE_LEN];
>  } cluster_cmd_data;
>  
> @@ -145,6 +146,7 @@ static int cluster_info(int argc, char **argv)
>  	if (ret < 0)
>  		goto error;
>  
> +	/* show cluster status */
>  	if (!raw_output)
>  		printf("Cluster status: ");
>  	if (rsp->result == SD_RES_SUCCESS)
> @@ -153,6 +155,25 @@ static int cluster_info(int argc, char **argv)
>  	else
>  		printf("%s\n", sd_strerror(rsp->result));
>  
> +	/* show cluster backend store */
> +	if (cluster_cmd_data.show_store) {
> +		if (!raw_output)
> +			printf("Cluster store: ");
> +		if (rsp->result == SD_RES_SUCCESS) {
> +			char copy[10];
> +			if (!logs->copy_policy)
> +				snprintf(copy, sizeof(copy), "%d",
> +					 logs->nr_copies);
> +			else
> +				snprintf(copy, sizeof(copy), "%d:%d",
> +					 (logs->copy_policy >> 4) * 2,
> +					 logs->copy_policy & 0x0f);
> +			printf("%s with %s redundancy policy\n",
> +			       logs->drv_name, copy);

use ec_policy_to_dp() to get data and parity number.

Thanks
Yuan



More information about the sheepdog mailing list