[sheepdog] [PATCH] dog/vdi: stop preallocation for no share option in vdi cloning

Liu Yuan namei.unix at gmail.com
Tue May 27 09:38:40 CEST 2014


On Tue, May 27, 2014 at 02:45:27PM +0800, Ruoyu wrote:
> Previous patch add a -n (--no-share) option in dog vdi clone.
> Preallocation is also enabled by this option. However, it is
> unnecessary to preallocate data object. In fact, we only need to
> copy parent's data objects into its own.
> 
> This patch fix this problem to carry out thin-provision.
> 
> Signed-off-by: Ruoyu <liangry at ucweb.com>
> ---
>  dog/vdi.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/dog/vdi.c b/dog/vdi.c
> index a8491c3..3daec21 100644
> --- a/dog/vdi.c
> +++ b/dog/vdi.c
> @@ -23,8 +23,7 @@
>  
>  static struct sd_option vdi_options[] = {
>  	{'P', "prealloc", false, "preallocate all the data objects"},
> -	{'n', "no-share", false, "share nothing with its parent, "
> -				"prealloc also enabled"},
> +	{'n', "no-share", false, "share nothing with its parent"},
>  	{'i', "index", true, "specify the index of data objects"},
>  	{'s', "snapshot", true, "specify a snapshot id or tag name"},
>  	{'x', "exclusive", false, "write in an exclusive mode"},
> @@ -575,7 +574,8 @@ static int vdi_clone(int argc, char **argv)
>  	ret = do_vdi_create(dst_vdi, inode->vdi_size, base_vid, &new_vid, false,
>  			    inode->nr_copies, inode->copy_policy,
>  			    inode->store_policy);
> -	if (ret != EXIT_SUCCESS || !vdi_cmd_data.prealloc)
> +	if (ret != EXIT_SUCCESS ||
> +			(!vdi_cmd_data.prealloc && !vdi_cmd_data.no_share))
>  		goto out;
>  
>  	new_inode = xmalloc(sizeof(*inode));
> @@ -601,8 +601,11 @@ static int vdi_clone(int argc, char **argv)
>  				goto out;
>  			}
>  			size = SD_DATA_OBJ_SIZE;
> -		} else
> +		} else {
> +			if (vdi_cmd_data.no_share)
> +				continue;
>  			size = 0;
> +		}
>  
>  		oid = vid_to_data_oid(new_vid, idx);
>  		ret = dog_write_object(oid, 0, buf, size, 0, 0,
> @@ -2424,7 +2427,6 @@ static int vdi_parser(int ch, const char *opt)
>  		break;
>  	case 'n':
>  		vdi_cmd_data.no_share = true;
> -		vdi_cmd_data.prealloc = true;
>  		break;
>  	case 'i':
>  		vdi_cmd_data.index = strtol(opt, &p, 10);

This patch won't work with the following example:

dog vdi clone -n -P xxx, which users do want both no-share and preallocation.

Thanks
Yuan



More information about the sheepdog mailing list