vmdk: Fix creating big description file
PATCH 1/1 vmdk: Fix creating big description file
The buffer for description file was 4096 which only covers a few hundred of extents. This changes the buffer to dynamic allocated with g_strdup_printf in order to support bigger cases.
--- block/vmdk.c | 65 +- tests/qemu-iotests/059 | 5 + tests/qemu-iotests/059.out | 2012 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 2058 insertions(+), 24 deletions(-)
block/vmdk.c +41 -24
@@ -1588,7 +1588,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, Error **errp) {int fd, idx =0 ; -char desc[BUF_SIZE ]; +char *desc =NULL ;int64_t total_size =0 , filesize;const char *adapter_type =NULL ;const char *backing_file =NULL ;
@@ -1596,7 +1596,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,int flags =0 ;int ret =0 ;bool flat, split, compress; -char ext_desc_lines[BUF_SIZE ] ="" ; +char *ext_desc_lines =NULL ;char path[PATH_MAX ], prefix[PATH_MAX ], postfix[PATH_MAX ];const int64_t split_size =0x80000000 ;/* VMDK has constant split size */ const char *desc_extent_line;
@@ -1625,7 +1625,8 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,"ddb.adapterType = \"%s\"\n" ;if (filename_decompose (filename, path, prefix, postfix,PATH_MAX , errp)) { -return -EINVAL ; + ret = -EINVAL ; + goto exit; }/* Read out options */ while (options && options->name) {
@@ -1651,7 +1652,8 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, strcmp(adapter_type, "lsilogic") && strcmp(adapter_type, "legacyESX")) {error_setg (errp,"Unknown adapter type: '%s'" , adapter_type); -return -EINVAL ; + ret = -EINVAL ; + goto exit; }if (strcmp (adapter_type,"ide" ) !=0 ) {/* that's the number of heads with which vmware operates when
@@ -1667,7 +1669,8 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, strcmp(fmt, "twoGbMaxExtentFlat") && strcmp(fmt, "streamOptimized")) {error_setg (errp,"Unknown subformat: '%s'" , fmt); -return -EINVAL ; + ret = -EINVAL ; + goto exit; } split = !(strcmp (fmt,"twoGbMaxExtentFlat" ) &&strcmp (fmt,"twoGbMaxExtentSparse" ));
@@ -1681,22 +1684,25 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, }if (flat && backing_file) {error_setg (errp,"Flat image can't have backing file" ); -return -ENOTSUP ; + ret = -ENOTSUP ; + goto exit; }if (flat && zeroed_grain) {error_setg (errp,"Flat image can't enable zeroed grain" ); -return -ENOTSUP ; + ret = -ENOTSUP ; + goto exit; }if (backing_file) {BlockDriverState *bs =bdrv_new ("" ); ret =bdrv_open (bs, backing_file,NULL ,0 ,NULL , errp);if (ret !=0 ) {bdrv_unref (bs); -return ret; + goto exit; }if (strcmp (bs->drv->format_name,"vmdk" )) {bdrv_unref (bs); -return -EINVAL ; + ret = -EINVAL ; + goto exit; } parent_cid =vmdk_read_cid (bs,0 );bdrv_unref (bs);
@@ -1711,6 +1717,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,char ext_filename[PATH_MAX ];char desc_filename[PATH_MAX ];int64_t size = filesize; +char *new_desc_lines =NULL ;if (split && size > split_size) { size = split_size;
@@ -1730,25 +1737,31 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,if (vmdk_create_extent (ext_filename, size, flat, compress, zeroed_grain)) { -return -EINVAL ; + ret = -EINVAL ; + goto exit; } filesize -= size;/* Format description line */ snprintf (desc_line,sizeof (desc_line), desc_extent_line, size /512 , desc_filename); -pstrcat (ext_desc_lines,sizeof (ext_desc_lines), desc_line); + new_desc_lines =g_strdup_printf ("%s%s" , + ext_desc_lines ? :"" , + desc_line); +g_free (ext_desc_lines); + ext_desc_lines = new_desc_lines; }/* generate descriptor file */ -snprintf (desc,sizeof (desc), desc_template, - (unsigned int )time (NULL ), - parent_cid, - fmt, - parent_desc_line, - ext_desc_lines, - (flags &BLOCK_FLAG_COMPAT6 ?6 :4 ), - total_size / (int64_t )(63 * number_heads *512 ), number_heads, - adapter_type); + desc =g_strdup_printf (desc_template, + (unsigned int )time (NULL ), + parent_cid, + fmt, + parent_desc_line, + ext_desc_lines, + (flags &BLOCK_FLAG_COMPAT6 ?6 :4 ), + total_size / (int64_t )(63 * number_heads *512 ), + number_heads, + adapter_type);if (split || flat) { fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
@@ -1759,21 +1772,25 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, 0644); }if (fd <0 ) { -return -errno; + ret = -errno; + goto exit; }/* the descriptor offset = 0x200 */ if (!split && !flat &&0x200 !=lseek (fd,0x200 ,SEEK_SET )) { ret = -errno; - goto exit; + goto close_exit; } ret =qemu_write_full (fd, desc,strlen (desc));if (ret !=strlen (desc)) { ret = -errno; - goto exit; + goto close_exit; } ret =0 ; -exit: +close_exit:qemu_close (fd); +exit: +g_free (desc); +g_free (ext_desc_lines);return ret; }
tests/qemu-iotests/059 +5 -0
@@ -75,6 +75,11 @@ echo echo "=== Testing monolithicFlat with zeroed_grain ===" IMGOPTS="subformat=monolithicFlat,zeroed_grain=on" _make_test_img 2G +echo +echo "=== Testing big twoGbMaxExtentFlat ===" +IMGOPTS="subformat=twoGbMaxExtentFlat" _make_test_img 1000G +$QEMU_IMG info $TEST_IMG | _filter_testdir + # success, all done echo "*** done" rm -f $seq.full
tests/qemu-iotests/059.out +2012 -0
2,016 lines not on this page · raw message
Signature · 1 line
1.8.4.2
Quoted 10 lines · Fam Zheng
The buffer for description file was 4096 which only covers a few hundred of extents. This changes the buffer to dynamic allocated with
g_strdup_printfin order to support bigger cases.Signed-off-by Fam Zheng <[email protected]>--- block/vmdk.c | 65 +- tests/qemu-iotests/059 | 5 + tests/qemu-iotests/059.out | 2012 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 2058 insertions(+), 24 deletions(-)
Does VMware have a hard limit? For example, does it open the 1000 GB twoGbMaxExtentFlat file from your test case?
Minor comments below but feel free to keep the code as-is if you wish:
Quoted 50 lines
block/vmdk.c +10
-6@@ -1625,7 +1625,8 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,"ddb.adapterType = \"%s\"\n" ;if (filename_decompose (filename, path, prefix, postfix,PATH_MAX , errp)) { -return -EINVAL ; + ret = -EINVAL ; + goto exit; }/* Read out options */ while (options && options->name) {@@ -1651,7 +1652,8 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, strcmp(adapter_type, "lsilogic") && strcmp(adapter_type, "legacyESX")) {error_setg (errp,"Unknown adapter type: '%s'" , adapter_type); -return -EINVAL ; + ret = -EINVAL ; + goto exit; }if (strcmp (adapter_type,"ide" ) !=0 ) {/* that's the number of heads with which vmware operates when @@ -1667,7 +1669,8 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, strcmp(fmt, "twoGbMaxExtentFlat") && strcmp(fmt, "streamOptimized")) {error_setg (errp,"Unknown subformat: '%s'" , fmt); -return -EINVAL ; + ret = -EINVAL ; + goto exit; } split = !(strcmp (fmt,"twoGbMaxExtentFlat" ) &&strcmp (fmt,"twoGbMaxExtentSparse" ));@@ -1681,22 +1684,25 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, }if (flat && backing_file) {error_setg (errp,"Flat image can't have backing file" ); -return -ENOTSUP ; + ret = -ENOTSUP ; + goto exit; }if (flat && zeroed_grain) {error_setg (errp,"Flat image can't enable zeroed grain" ); -return -ENOTSUP ; + ret = -ENOTSUP ; + goto exit; }if (backing_file) {BlockDriverState *bs =bdrv_new ("" ); ret =bdrv_open (bs, backing_file,NULL ,0 ,NULL , errp);if (ret !=0 ) {bdrv_unref (bs); -return ret;
block/vmdk.c static int vmdk_create(const char *filename, QEMUOptionParameter *options, · line 1708
Quoted 10 lines
block/vmdk.c +3
-1+ goto exit; }if (strcmp (bs->drv->format_name,"vmdk" )) {bdrv_unref (bs); -return -EINVAL ; + ret = -EINVAL ; + goto exit; } parent_cid =vmdk_read_cid (bs,0 );bdrv_unref (bs);
Changing these to goto isn't really necessary.
Quoted 9 lines
block/vmdk.c +2
-1@@ -1730,25 +1737,31 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,if (vmdk_create_extent (ext_filename, size, flat, compress, zeroed_grain)) { -return -EINVAL ; + ret = -EINVAL ; + goto exit; } filesize -= size;
block/vmdk.c static int vmdk_create(const char *filename, QEMUOptionParameter *options, · line 1752
Quoted 10 lines
block/vmdk.c +5
-1/* Format description line */ snprintf (desc_line,sizeof (desc_line), desc_extent_line, size /512 , desc_filename); -pstrcat (ext_desc_lines,sizeof (ext_desc_lines), desc_line); + new_desc_lines =g_strdup_printf ("%s%s" , + ext_desc_lines ? :"" , + desc_line); +g_free (ext_desc_lines); + ext_desc_lines = new_desc_lines;
These lines can be eliminated if you use GString:
/* Format description line */
g_string_append_printf(ext_desc_lines,
desc_extent_line, size / 512, desc_filename);
Quoted 12 lines · Stefan Hajnoczi
Quoted 10 lines · Fam Zheng
The buffer for description file was 4096 which only covers a few hundred of extents. This changes the buffer to dynamic allocated with
g_strdup_printfin order to support bigger cases.Signed-off-by Fam Zheng <[email protected]>--- block/vmdk.c | 65 +- tests/qemu-iotests/059 | 5 + tests/qemu-iotests/059.out | 2012 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 2058 insertions(+), 24 deletions(-)
Quoted 3 lines
Does VMware have a hard limit? For example, does it open the 1000 GB twoGbMaxExtentFlat file from your test case?
Yes it does. The limit is far above this, there is a statement in VMDK spec: "Maximum VMDK file size is 2TB." It opens this file from the test case, however I can't generate such a twoGbMaxExtentFlat from Workstation, because it will be automatically forced to monolithicFlat (if the size is above certain threshold).
Quoted 56 lines
Minor comments below but feel free to keep the code as-is if you wish:
Quoted 54 lines
block/vmdk.c +11
-6@@ -1625,7 +1625,8 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,"ddb.adapterType = \"%s\"\n" ;if (filename_decompose (filename, path, prefix, postfix,PATH_MAX , errp)) { -return -EINVAL ; + ret = -EINVAL ; + goto exit; }/* Read out options */ while (options && options->name) {@@ -1651,7 +1652,8 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, strcmp(adapter_type, "lsilogic") && strcmp(adapter_type, "legacyESX")) {error_setg (errp,"Unknown adapter type: '%s'" , adapter_type); -return -EINVAL ; + ret = -EINVAL ; + goto exit; }if (strcmp (adapter_type,"ide" ) !=0 ) {/* that's the number of heads with which vmware operates when @@ -1667,7 +1669,8 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, strcmp(fmt, "twoGbMaxExtentFlat") && strcmp(fmt, "streamOptimized")) {error_setg (errp,"Unknown subformat: '%s'" , fmt); -return -EINVAL ; + ret = -EINVAL ; + goto exit; } split = !(strcmp (fmt,"twoGbMaxExtentFlat" ) &&strcmp (fmt,"twoGbMaxExtentSparse" ));@@ -1681,22 +1684,25 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, }if (flat && backing_file) {error_setg (errp,"Flat image can't have backing file" ); -return -ENOTSUP ; + ret = -ENOTSUP ; + goto exit; }if (flat && zeroed_grain) {error_setg (errp,"Flat image can't enable zeroed grain" ); -return -ENOTSUP ; + ret = -ENOTSUP ; + goto exit; }if (backing_file) {BlockDriverState *bs =bdrv_new ("" ); ret =bdrv_open (bs, backing_file,NULL ,0 ,NULL , errp);if (ret !=0 ) {bdrv_unref (bs); -return ret; + goto exit; }if (strcmp (bs->drv->format_name,"vmdk" )) {bdrv_unref (bs);
Quoted 9 lines
block/vmdk.c static int vmdk_create(const char *filename, QEMUOptionParameter *options, · line 1708
Quoted 6 lines
block/vmdk.c +2
-1-return -EINVAL ; + ret = -EINVAL ; + goto exit; } parent_cid =vmdk_read_cid (bs,0 );bdrv_unref (bs);Changing these to goto isn't really necessary.
Just that I'd like to keep it consistent that exit point is either direct return statement or goto jump, in one function, so it will be easy to reason the code path.
Quoted 22 lines
Quoted 9 lines
block/vmdk.c +2
-1@@ -1730,25 +1737,31 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,if (vmdk_create_extent (ext_filename, size, flat, compress, zeroed_grain)) { -return -EINVAL ; + ret = -EINVAL ; + goto exit; } filesize -= size;block/vmdk.c static int vmdk_create(const char *filename, QEMUOptionParameter *options, · line 1752
Quoted 10 lines
block/vmdk.c +5
-1/* Format description line */ snprintf (desc_line,sizeof (desc_line), desc_extent_line, size /512 , desc_filename); -pstrcat (ext_desc_lines,sizeof (ext_desc_lines), desc_line); + new_desc_lines =g_strdup_printf ("%s%s" , + ext_desc_lines ? :"" , + desc_line); +g_free (ext_desc_lines); + ext_desc_lines = new_desc_lines;These lines can be eliminated if you use GString:
Quoted 6 lines
/* Format description line */
g_string_append_printf(ext_desc_lines,desc_extent_line, size / 512, desc_filename);
OK, good idea. Thanks
Fam
Quoted 17 lines · Fam Zheng
Quoted 12 lines · Stefan Hajnoczi
Quoted 10 lines · Fam Zheng
The buffer for description file was 4096 which only covers a few hundred of extents. This changes the buffer to dynamic allocated with
g_strdup_printfin order to support bigger cases.Signed-off-by Fam Zheng <[email protected]>--- block/vmdk.c | 65 +- tests/qemu-iotests/059 | 5 + tests/qemu-iotests/059.out | 2012 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 2058 insertions(+), 24 deletions(-)Quoted 3 lines
Does VMware have a hard limit? For example, does it open the 1000 GB twoGbMaxExtentFlat file from your test case?
Quoted 5 lines
Yes it does. The limit is far above this, there is a statement in VMDK spec: "Maximum VMDK file size is 2TB." It opens this file from the test case, however I can't generate such a twoGbMaxExtentFlat from Workstation, because it will be automatically forced to monolithicFlat (if the size is above certain threshold).
Okay, good. Thanks for explaining.
Stefan