[sheepdog] [PATCH 1/2] collie: add 'collie vdi cache flush' to flush dirty cache

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Mon Dec 17 06:00:56 CET 2012


At Sat, 15 Dec 2012 19:37:41 +0800,
levin li wrote:
> 
> From: levin li <xingke.lwp at taobao.com>
> 
> This command can flush cache of an VDI in specified node, which is
> useful when QEMU terminates accidentally, left the dirty cache data
> unflushed, this command helps us to flush and delete this cache into
> the cluster.
> 
> Signed-off-by: levin li <xingke.lwp at taobao.com>
> ---
>  collie/vdi.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 51 insertions(+)
> 
> diff --git a/collie/vdi.c b/collie/vdi.c
> index 108cb1d..9adb051 100644
> --- a/collie/vdi.c
> +++ b/collie/vdi.c
> @@ -1857,6 +1857,54 @@ out:
>  	return ret;
>  }
>  
> +static int vdi_cache_flush(int argc, char **argv)
> +{
> +	const char *vdiname = argv[optind++];
> +	struct sd_req hdr;
> +	uint32_t vid;
> +	int ret = EXIT_SUCCESS;
> +
> +	ret = find_vdi_name(vdiname, vdi_cmd_data.snapshot_id,
> +			    vdi_cmd_data.snapshot_tag, &vid, 0);
> +	if (ret < 0) {
> +		fprintf(stderr, "Failed to open VDI %s\n", vdiname);
> +		ret = EXIT_FAILURE;
> +		goto out;
> +	}
> +
> +	sd_init_req(&hdr, SD_OP_FLUSH_DEL_CACHE);
> +	hdr.obj.oid = vid_to_vdi_oid(vid);
> +
> +	ret = send_light_req(&hdr, sdhost, sdport);
> +	if (ret) {
> +		fprintf(stderr, "failed to execute request\n");
> +		return EXIT_FAILURE;
> +	}
> +out:
> +	return ret;
> +}
> +
> +static struct subcommand vdi_cache_cmd[] = {
> +	{"flush", NULL, NULL, "flush the cache of the vdi specified.",
> +	 NULL, 0, vdi_cache_flush},
> +	{NULL,},
> +};
> +
> +static int vdi_cache(int argc, char **argv)
> +{
> +	int i;
> +
> +	for (i = 0; vdi_cache_cmd[i].name; i++) {
> +		if (!strcmp(vdi_cache_cmd[i].name, argv[3])) {
> +			optind ++;

Redundant space before '++'.

> +			return vdi_cache_cmd[i].fn(argc, argv);
> +		}
> +	}
> +
> +	subcommand_usage(argv[1], argv[2], EXIT_FAILURE);
> +	return EXIT_FAILURE;
> +}
> +
>  static struct subcommand vdi_cmd[] = {
>  	{"check", "<vdiname>", "saph", "check and repair image's consistency",
>  	 NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG,
> @@ -1912,6 +1960,9 @@ static struct subcommand vdi_cmd[] = {
>  	{"restore", "<vdiname> <backup>", "saph", "restore snapshot images from a backup",
>  	 NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG,
>  	 vdi_restore, vdi_options},
> +	{"cache", NULL, "saph", "See 'collie vdi cache' for more information\n",

"Run 'collie vdi cache' for more information"?

Thanks,

Kazutaka



More information about the sheepdog mailing list