vmdk: remove wrong calculation of relative path
PATCH 1/1 vmdk: remove wrong calculation of relative path
When creating image with backing file, the driver tries to calculate the relative path from created image file to backing file, but the path computation is incorrect. e.g.:
$ qemu-img create -f vmdk -b vmdk-data-disk.vmdk vmdk-data-snapshot1
Formatting 'vmdk-data-snapshot1', fmt=vmdk size=10737418240
backing_file='vmdk-data-disk.vmdk' compat6=off zeroed_grain=off $ qemu-img info vmdk-data-snapshot1
image: vmdk-data-snapshot1
file format: vmdk
virtual size: 10G (10737418240 bytes)
disk size: 12K
-> backing file: disk.vmdkThe common part in file names, "vmdk-data-", is incorrectly forgotten by relative_path(). As the VMDK specification has no restriction on parentNameHint to be relative path, we simply remove this by using the backing_file option.
--- block/vmdk.c | 44 +------------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-)
block/vmdk.c +1 -43
@@ -1487,45 +1487,6 @@ static int filename_decompose(const char *filename, char *path, char *prefix,return VMDK_OK ; } -static int relative_path (char *dest,int dest_size, -const char *base,const char *target) -{ -int i =0 ; -int n =0 ; -const char *p, *q; -#ifdef _WIN32 -const char *sep ="\\" ; -#else -const char *sep ="/" ; -#endif - -if (!(dest && base && target)) { -return VMDK_ERROR ; - } -if (path_is_absolute (target)) { -pstrcpy (dest, dest_size, target); -return VMDK_OK ; - } -while (base[i] == target[i]) { - i++; - } - p = &base[i]; - q = &target[i]; -while (*p) { -if (*p == *sep) { - n++; - } - p++; - } - dest[0 ] ='\0' ; -for (; n; n--) { -pstrcat (dest, dest_size,".." ); -pstrcat (dest, dest_size, sep); - } -pstrcat (dest, dest_size, q); -return VMDK_OK ; -} -static int vmdk_create (const char *filename,QEMUOptionParameter *options) {int fd, idx =0 ;
@@ -1625,7 +1586,6 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options)return -ENOTSUP ; }if (backing_file) { -char parent_filename[PATH_MAX ];BlockDriverState *bs =bdrv_new ("" ); ret =bdrv_open (bs, backing_file,NULL ,0 ,NULL );if (ret !=0 ) {
@@ -1638,10 +1598,8 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options) } parent_cid =vmdk_read_cid (bs,0 );bdrv_delete (bs); -relative_path (parent_filename,sizeof (parent_filename), - filename, backing_file);snprintf (parent_desc_line,sizeof (parent_desc_line), -"parentFileNameHint=\"%s\"" , parent_filename); +"parentFileNameHint=\"%s\"" , backing_file); }/* Create extents */
Signature · 1 line
1.8.3.1
Am 26.06.2013 um 11:24 hat Fam Zheng geschrieben:
Quoted 15 lines
When creating image with backing file, the driver tries to calculate the relative path from created image file to backing file, but the path computation is incorrect. e.g.:
$ qemu-img create -f vmdk -b vmdk-data-disk.vmdk vmdk-data-snapshot1 Formatting 'vmdk-data-snapshot1', fmt=vmdk size=10737418240 backing_file='vmdk-data-disk.vmdk' compat6=off zeroed_grain=off$ qemu-img info vmdk-data-snapshot1 image: vmdk-data-snapshot1 file format: vmdk virtual size: 10G (10737418240 bytes) disk size: 12K -> backing file: disk.vmdk
Quoted 6 lines
The common part in file names, "vmdk-data-", is incorrectly forgotten by
relative_path(). As the VMDK specification has no restriction on parentNameHint to be relative path, we simply remove this by using thebacking_fileoption.Signed-off-by Fam Zheng <[email protected]>
Nice one. Thanks, applied to the block branch.
Kevin
Il 26/06/2013 17:05, Kevin Wolf ha scritto:
Quoted 16 lines
Am 26.06.2013 um 11:24 hat Fam Zheng geschrieben:
Quoted 15 lines
Quoted 15 lines
When creating image with backing file, the driver tries to calculate the relative path from created image file to backing file, but the path computation is incorrect. e.g.:
$ qemu-img create -f vmdk -b vmdk-data-disk.vmdk vmdk-data-snapshot1 Formatting 'vmdk-data-snapshot1', fmt=vmdk size=10737418240 backing_file='vmdk-data-disk.vmdk' compat6=off zeroed_grain=off$ qemu-img info vmdk-data-snapshot1 image: vmdk-data-snapshot1 file format: vmdk virtual size: 10G (10737418240 bytes) disk size: 12K -> backing file: disk.vmdk
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
The common part in file names, "vmdk-data-", is incorrectly forgotten by
relative_path(). As the VMDK specification has no restriction on parentNameHint to be relative path, we simply remove this by using thebacking_fileoption.Signed-off-by Fam Zheng <[email protected]>Nice one. Thanks, applied to the block branch.
Am 27.06.2013 um 09:09 hat Paolo Bonzini geschrieben:
Quoted 22 lines
Il 26/06/2013 17:05, Kevin Wolf ha scritto:
Quoted 21 lines
Am 26.06.2013 um 11:24 hat Fam Zheng geschrieben:
Quoted 20 lines
Quoted 20 lines
When creating image with backing file, the driver tries to calculate the relative path from created image file to backing file, but the path computation is incorrect. e.g.:
$ qemu-img create -f vmdk -b vmdk-data-disk.vmdk vmdk-data-snapshot1 Formatting 'vmdk-data-snapshot1', fmt=vmdk size=10737418240 backing_file='vmdk-data-disk.vmdk' compat6=off zeroed_grain=off$ qemu-img info vmdk-data-snapshot1 image: vmdk-data-snapshot1 file format: vmdk virtual size: 10G (10737418240 bytes) disk size: 12K -> backing file: disk.vmdkThe common part in file names, "vmdk-data-", is incorrectly forgotten by
relative_path(). As the VMDK specification has no restriction on parentNameHint to be relative path, we simply remove this by using thebacking_fileoption.
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line
Signed-off-by Fam Zheng <[email protected]>Nice one. Thanks, applied to the block branch.
Yeah, why not. I've added it to the commit message now.
Kevin