[sheepdog] [PATCH 1/6] sheep: use switch case inside vdi_create()

MORITA Kazutaka morita.kazutaka at gmail.com
Mon Apr 29 00:15:20 CEST 2013


At Sat, 27 Apr 2013 13:44:17 +0800,
Liu Yuan wrote:
> 
> From: Liu Yuan <tailai.ly at taobao.com>
> 
> Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
> ---
>  sheep/vdi.c |   20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/sheep/vdi.c b/sheep/vdi.c
> index 8b7a11f..8abc23c 100644
> --- a/sheep/vdi.c
> +++ b/sheep/vdi.c
> @@ -498,17 +498,17 @@ int vdi_create(struct vdi_iocb *iocb, uint32_t *new_vid)
>  	int ret;
>  
>  	ret = vdi_lookup(iocb, &info);
> -	if (iocb->create_snapshot) {
> -		/* We should have base vdi, otherwise error happens */
> -		if (ret != SD_RES_SUCCESS)
> -			return ret;
> -	} else {
> -		/* If we already have the same VDI or met other errors. */
> -		if (ret != SD_RES_NO_VDI) {
> -			if (ret == SD_RES_SUCCESS)
> -				ret = SD_RES_VDI_EXIST;
> +	switch (ret) {
> +	case SD_RES_SUCCESS:
> +		if (!iocb->create_snapshot)
> +			return SD_RES_VDI_EXIST;
> +		break;
> +	case SD_RES_NO_VDI:
> +		if (iocb->create_snapshot)
>  			return ret;
> -		}
> +		break;
> +	default:
> +		return ret;

I'd suggest printing sd_strerror(ret) since something unexpected
happens in the default case.

Thanks,

Kazutaka



More information about the sheepdog mailing list