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