[sheepdog] [PATCH] dog/vdi: enable to unlock a vdi locked by tgtd

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Wed Nov 26 10:14:32 CET 2014


At Wed, 26 Nov 2014 17:45:15 +0900,
YAMADA Hideki wrote:
> 
> Explicitly add vdi.type parameter in RELEASE_VDI request.
> 
> Signed-off-by: YAMADA Hideki <yamada.hideki at lab.ntt.co.jp>
> ---
>  dog/vdi.c |   43 ++++++++++++++++++++++++++++++++++++++-----
>  1 files changed, 38 insertions(+), 5 deletions(-)

Applied, thanks.
Hitoshi

> 
> diff --git a/dog/vdi.c b/dog/vdi.c
> index c541706..8bb0501 100644
> --- a/dog/vdi.c
> +++ b/dog/vdi.c
> @@ -2888,22 +2888,55 @@ static int lock_unlock(int argc, char **argv)
>  	struct sd_req hdr;
>  	const char *vdiname = argv[optind];
>  	struct vdi_tree *vdi;
> +	struct vdi_state *vs = NULL;
> +	int ret = EXIT_SYSFAIL, vs_count = 0;
> +	uint32_t type;
>  
>  	init_tree();
>  	if (parse_vdi(construct_vdi_tree, SD_INODE_HEADER_SIZE,
>  			NULL, true) < 0)
> -		return EXIT_SYSFAIL;
> +		goto out;
>  
>  	vdi = find_vdi_from_root_by_name(vdiname);
>  	if (!vdi) {
>  		sd_err("VDI: %s not found", vdiname);
> -		return EXIT_SYSFAIL;
> +		goto out;
>  	}
>  
> -	sd_init_req(&hdr, SD_OP_RELEASE_VDI);
> -	hdr.vdi.base_vdi_id = vdi->vid;
> +	vs = get_vdi_state(&vs_count);
> +	if (!vs)
> +		goto out;
> +
> +	for (int i = 0; i < vs_count; i++) {
> +		if (vs[i].vid != vdi->vid) 
> +			continue;
>  
> -	return dog_exec_req(&sd_nid, &hdr, NULL);
> +		switch (vs[i].lock_state) {
> +		case LOCK_STATE_UNLOCKED:
> +			sd_err("VDI: %s is not locked", vdiname);
> +			goto out;
> +		case LOCK_STATE_LOCKED:
> +			type = LOCK_TYPE_NORMAL;
> +			break;
> +		case LOCK_STATE_SHARED:
> +			type = LOCK_TYPE_SHARED;
> +			break;
> +		default:
> +			sd_err("VDI: %s unknown lock state", vdiname);
> +			goto out;
> +		}
> +
> +		sd_init_req(&hdr, SD_OP_RELEASE_VDI);
> +		hdr.vdi.base_vdi_id = vdi->vid;
> +		hdr.vdi.type = type;
> +		ret = dog_exec_req(&sd_nid, &hdr, NULL);
> +		goto out;
> +	}
> +
> +out:
> +	if (vs)
> +		free(vs);
> +	return ret;
>  }
>  
>  static struct subcommand vdi_lock_cmd[] = {
> -- 
> 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