Commit ec36ba14748e140dda237ba22ad3135e360b0d9f
1 parent
3ae43202
vmdk compatibility level 6 images, by Soren Hansen.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3175 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
6 changed files
with
43 additions
and
26 deletions
block-qcow.c
... | ... | @@ -769,7 +769,7 @@ static int qcow_create(const char *filename, int64_t total_size, |
769 | 769 | l1_size = ((total_size * 512) + (1LL << shift) - 1) >> shift; |
770 | 770 | |
771 | 771 | header.l1_table_offset = cpu_to_be64(header_size); |
772 | - if (flags) { | |
772 | + if (flags & BLOCK_FLAG_ENCRYPT) { | |
773 | 773 | header.crypt_method = cpu_to_be32(QCOW_CRYPT_AES); |
774 | 774 | } else { |
775 | 775 | header.crypt_method = cpu_to_be32(QCOW_CRYPT_NONE); | ... | ... |
block-qcow2.c
... | ... | @@ -1076,7 +1076,7 @@ static int qcow_create(const char *filename, int64_t total_size, |
1076 | 1076 | s->cluster_size = 1 << s->cluster_bits; |
1077 | 1077 | header.cluster_bits = cpu_to_be32(s->cluster_bits); |
1078 | 1078 | header_size = (header_size + 7) & ~7; |
1079 | - if (flags) { | |
1079 | + if (flags & BLOCK_FLAG_ENCRYPT) { | |
1080 | 1080 | header.crypt_method = cpu_to_be32(QCOW_CRYPT_AES); |
1081 | 1081 | } else { |
1082 | 1082 | header.crypt_method = cpu_to_be32(QCOW_CRYPT_NONE); | ... | ... |
block-vmdk.c
... | ... | @@ -712,7 +712,7 @@ static int vmdk_create(const char *filename, int64_t total_size, |
712 | 712 | "# The Disk Data Base \n" |
713 | 713 | "#DDB\n" |
714 | 714 | "\n" |
715 | - "ddb.virtualHWVersion = \"4\"\n" | |
715 | + "ddb.virtualHWVersion = \"%d\"\n" | |
716 | 716 | "ddb.geometry.cylinders = \"%lu\"\n" |
717 | 717 | "ddb.geometry.heads = \"16\"\n" |
718 | 718 | "ddb.geometry.sectors = \"63\"\n" |
... | ... | @@ -789,7 +789,7 @@ static int vmdk_create(const char *filename, int64_t total_size, |
789 | 789 | if ((temp_str = strrchr(real_filename, ':')) != NULL) |
790 | 790 | real_filename = temp_str + 1; |
791 | 791 | sprintf(desc, desc_template, time(NULL), (unsigned long)total_size, |
792 | - real_filename, total_size / (63 * 16)); | |
792 | + real_filename, (flags & BLOCK_FLAG_COMPAT6 ? 6 : 4), total_size / (63 * 16)); | |
793 | 793 | |
794 | 794 | /* write the descriptor */ |
795 | 795 | lseek(fd, le64_to_cpu(header.desc_offset) << 9, SEEK_SET); | ... | ... |
block_int.h
qemu-img.c
... | ... | @@ -22,6 +22,7 @@ |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | 24 | #include "vl.h" |
25 | +#include "block_int.h" | |
25 | 26 | |
26 | 27 | #ifdef _WIN32 |
27 | 28 | #include <windows.h> |
... | ... | @@ -98,9 +99,9 @@ void help(void) |
98 | 99 | "QEMU disk image utility\n" |
99 | 100 | "\n" |
100 | 101 | "Command syntax:\n" |
101 | - " create [-e] [-b base_image] [-f fmt] filename [size]\n" | |
102 | + " create [-e] [-6] [-b base_image] [-f fmt] filename [size]\n" | |
102 | 103 | " commit [-f fmt] filename\n" |
103 | - " convert [-c] [-e] [-f fmt] filename [-O output_fmt] output_filename\n" | |
104 | + " convert [-c] [-e] [-6] [-f fmt] filename [-O output_fmt] output_filename\n" | |
104 | 105 | " info [-f fmt] filename\n" |
105 | 106 | "\n" |
106 | 107 | "Command parameters:\n" |
... | ... | @@ -114,6 +115,7 @@ void help(void) |
114 | 115 | " 'output_fmt' is the destination format\n" |
115 | 116 | " '-c' indicates that target image must be compressed (qcow format only)\n" |
116 | 117 | " '-e' indicates that the target image must be encrypted (qcow format only)\n" |
118 | + " '-6' indicates that the target image must use compatibility level 6 (vmdk format only)\n" | |
117 | 119 | ); |
118 | 120 | printf("\nSupported format:"); |
119 | 121 | bdrv_iterate_format(format_print, NULL); |
... | ... | @@ -241,7 +243,7 @@ static BlockDriverState *bdrv_new_open(const char *filename, |
241 | 243 | |
242 | 244 | static int img_create(int argc, char **argv) |
243 | 245 | { |
244 | - int c, ret, encrypted; | |
246 | + int c, ret, flags; | |
245 | 247 | const char *fmt = "raw"; |
246 | 248 | const char *filename; |
247 | 249 | const char *base_filename = NULL; |
... | ... | @@ -249,9 +251,9 @@ static int img_create(int argc, char **argv) |
249 | 251 | const char *p; |
250 | 252 | BlockDriver *drv; |
251 | 253 | |
252 | - encrypted = 0; | |
254 | + flags = 0; | |
253 | 255 | for(;;) { |
254 | - c = getopt(argc, argv, "b:f:he"); | |
256 | + c = getopt(argc, argv, "b:f:he6"); | |
255 | 257 | if (c == -1) |
256 | 258 | break; |
257 | 259 | switch(c) { |
... | ... | @@ -265,8 +267,11 @@ static int img_create(int argc, char **argv) |
265 | 267 | fmt = optarg; |
266 | 268 | break; |
267 | 269 | case 'e': |
268 | - encrypted = 1; | |
270 | + flags |= BLOCK_FLAG_ENCRYPT; | |
269 | 271 | break; |
272 | + case '6': | |
273 | + flags |= BLOCK_FLAG_COMPAT6; | |
274 | + break; | |
270 | 275 | } |
271 | 276 | } |
272 | 277 | if (optind >= argc) |
... | ... | @@ -299,14 +304,16 @@ static int img_create(int argc, char **argv) |
299 | 304 | error("Unknown file format '%s'", fmt); |
300 | 305 | printf("Formatting '%s', fmt=%s", |
301 | 306 | filename, fmt); |
302 | - if (encrypted) | |
307 | + if (flags & BLOCK_FLAG_ENCRYPT) | |
303 | 308 | printf(", encrypted"); |
309 | + if (flags & BLOCK_FLAG_COMPAT6) | |
310 | + printf(", compatibility level=6"); | |
304 | 311 | if (base_filename) { |
305 | 312 | printf(", backing_file=%s", |
306 | 313 | base_filename); |
307 | 314 | } |
308 | 315 | printf(", size=%" PRId64 " kB\n", (int64_t) (size / 1024)); |
309 | - ret = bdrv_create(drv, filename, size / 512, base_filename, encrypted); | |
316 | + ret = bdrv_create(drv, filename, size / 512, base_filename, flags); | |
310 | 317 | if (ret < 0) { |
311 | 318 | if (ret == -ENOTSUP) { |
312 | 319 | error("Formatting or formatting option not supported for file format '%s'", fmt); |
... | ... | @@ -411,7 +418,7 @@ static int is_allocated_sectors(const uint8_t *buf, int n, int *pnum) |
411 | 418 | |
412 | 419 | static int img_convert(int argc, char **argv) |
413 | 420 | { |
414 | - int c, ret, n, n1, compress, cluster_size, cluster_sectors, encrypt; | |
421 | + int c, ret, n, n1, flags, cluster_size, cluster_sectors; | |
415 | 422 | const char *filename, *fmt, *out_fmt, *out_filename; |
416 | 423 | BlockDriver *drv; |
417 | 424 | BlockDriverState *bs, *out_bs; |
... | ... | @@ -422,10 +429,9 @@ static int img_convert(int argc, char **argv) |
422 | 429 | |
423 | 430 | fmt = NULL; |
424 | 431 | out_fmt = "raw"; |
425 | - compress = 0; | |
426 | - encrypt = 0; | |
432 | + flags = 0; | |
427 | 433 | for(;;) { |
428 | - c = getopt(argc, argv, "f:O:hce"); | |
434 | + c = getopt(argc, argv, "f:O:hce6"); | |
429 | 435 | if (c == -1) |
430 | 436 | break; |
431 | 437 | switch(c) { |
... | ... | @@ -439,10 +445,13 @@ static int img_convert(int argc, char **argv) |
439 | 445 | out_fmt = optarg; |
440 | 446 | break; |
441 | 447 | case 'c': |
442 | - compress = 1; | |
448 | + flags |= BLOCK_FLAG_COMPRESS; | |
443 | 449 | break; |
444 | 450 | case 'e': |
445 | - encrypt = 1; | |
451 | + flags |= BLOCK_FLAG_ENCRYPT; | |
452 | + break; | |
453 | + case '6': | |
454 | + flags |= BLOCK_FLAG_COMPAT6; | |
446 | 455 | break; |
447 | 456 | } |
448 | 457 | } |
... | ... | @@ -458,14 +467,16 @@ static int img_convert(int argc, char **argv) |
458 | 467 | drv = bdrv_find_format(out_fmt); |
459 | 468 | if (!drv) |
460 | 469 | error("Unknown file format '%s'", out_fmt); |
461 | - if (compress && drv != &bdrv_qcow && drv != &bdrv_qcow2) | |
470 | + if (flags & BLOCK_FLAG_COMPRESS && drv != &bdrv_qcow && drv != &bdrv_qcow2) | |
462 | 471 | error("Compression not supported for this file format"); |
463 | - if (encrypt && drv != &bdrv_qcow && drv != &bdrv_qcow2) | |
472 | + if (flags & BLOCK_FLAG_ENCRYPT && drv != &bdrv_qcow && drv != &bdrv_qcow2) | |
464 | 473 | error("Encryption not supported for this file format"); |
465 | - if (compress && encrypt) | |
474 | + if (flags & BLOCK_FLAG_COMPRESS && drv != &bdrv_vmdk) | |
475 | + error("Alternative compatibility level not supported for this file format"); | |
476 | + if (flags & BLOCK_FLAG_ENCRYPT && flags & BLOCK_FLAG_COMPRESS) | |
466 | 477 | error("Compression and encryption not supported at the same time"); |
467 | 478 | bdrv_get_geometry(bs, &total_sectors); |
468 | - ret = bdrv_create(drv, out_filename, total_sectors, NULL, encrypt); | |
479 | + ret = bdrv_create(drv, out_filename, total_sectors, NULL, flags); | |
469 | 480 | if (ret < 0) { |
470 | 481 | if (ret == -ENOTSUP) { |
471 | 482 | error("Formatting not supported for file format '%s'", fmt); |
... | ... | @@ -476,7 +487,7 @@ static int img_convert(int argc, char **argv) |
476 | 487 | |
477 | 488 | out_bs = bdrv_new_open(out_filename, out_fmt); |
478 | 489 | |
479 | - if (compress) { | |
490 | + if (flags && BLOCK_FLAG_COMPRESS) { | |
480 | 491 | if (bdrv_get_info(out_bs, &bdi) < 0) |
481 | 492 | error("could not get block driver info"); |
482 | 493 | cluster_size = bdi.cluster_size; | ... | ... |
qemu-img.texi
... | ... | @@ -8,9 +8,9 @@ usage: qemu-img command [command options] |
8 | 8 | |
9 | 9 | The following commands are supported: |
10 | 10 | @table @option |
11 | -@item create [-e] [-b @var{base_image}] [-f @var{fmt}] @var{filename} [@var{size}] | |
11 | +@item create [-e] [-6] [-b @var{base_image}] [-f @var{fmt}] @var{filename} [@var{size}] | |
12 | 12 | @item commit [-f @var{fmt}] @var{filename} |
13 | -@item convert [-c] [-e] [-f @var{fmt}] @var{filename} [-O @var{output_fmt}] @var{output_filename} | |
13 | +@item convert [-c] [-e] [-6] [-f @var{fmt}] @var{filename} [-O @var{output_fmt}] @var{output_filename} | |
14 | 14 | @item info [-f @var{fmt}] @var{filename} |
15 | 15 | @end table |
16 | 16 | |
... | ... | @@ -67,12 +67,14 @@ is the destination disk image filename |
67 | 67 | indicates that target image must be compressed (qcow format only) |
68 | 68 | @item -e |
69 | 69 | indicates that the target image must be encrypted (qcow format only) |
70 | +@item -6 | |
71 | +indicates that the target image must use compatibility level 6 (vmdk format only) | |
70 | 72 | @end table |
71 | 73 | |
72 | 74 | Command description: |
73 | 75 | |
74 | 76 | @table @option |
75 | -@item create [-e] [-b @var{base_image}] [-f @var{fmt}] @var{filename} [@var{size}] | |
77 | +@item create [-6] [-e] [-b @var{base_image}] [-f @var{fmt}] @var{filename} [@var{size}] | |
76 | 78 | |
77 | 79 | Create the new disk image @var{filename} of size @var{size} and format |
78 | 80 | @var{fmt}. | ... | ... |