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

MORITA Kazutaka morita.kazutaka at gmail.com
Mon Apr 29 14:13:43 CEST 2013


At Mon, 29 Apr 2013 19:00:06 +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 |   21 +++++++++++----------
>  1 file changed, 11 insertions(+), 10 deletions(-)
> 
> diff --git a/sheep/vdi.c b/sheep/vdi.c
> index 8b7a11f..b3bd0cb 100644
> --- a/sheep/vdi.c
> +++ b/sheep/vdi.c
> @@ -498,17 +498,18 @@ 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:
> +		sd_dprintf("%s", sd_strerror(ret));
> +		return ret;

sd_eprintf() is better for error cases.

Applied the other patches, thanks!

Kazutaka



More information about the sheepdog mailing list