tools: qemu: Add patches to support adapter_type and monolithicFlat
[openwrt/staging/mkresin.git] / tools / qemu / patches / 0012-vmdk-Allow-selecting-SCSI-adapter-in-image-creation.patch
1 From 5483df4df2729a5d1e4888a48039b1cd90438480 Mon Sep 17 00:00:00 2001
2 From: Othmar Pasteka <pasteka@kabsi.at>
3 Date: Wed, 30 Jan 2013 00:26:52 +0100
4 Subject: [PATCH 12/12] vmdk: Allow selecting SCSI adapter in image creation
5
6 Introduce a new option "adapter_type" when converting to vmdk images.
7 It can be one of the following: ide (default), buslogic, lsilogic
8 or legacyESX (according to the vmdk spec from vmware).
9
10 In case of a non-ide adapter, heads is set to 255 instead of the 16.
11 The latter is used for "ide".
12
13 Also see LP#545089
14
15 Signed-off-by: Othmar Pasteka <pasteka@kabsi.at>
16 Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
17 ---
18 block/vmdk.c | 31 ++++++++++++++++++++++++++++---
19 block_int.h | 1 +
20 2 files changed, 29 insertions(+), 3 deletions(-)
21
22 --- a/block/vmdk.c
23 +++ b/block/vmdk.c
24 @@ -1089,6 +1089,7 @@ static int vmdk_create(const char *filen
25 int fd, idx = 0;
26 char desc[BUF_SIZE];
27 int64_t total_size = 0, filesize;
28 + const char *adapter_type = NULL;
29 const char *backing_file = NULL;
30 const char *fmt = NULL;
31 int flags = 0;
32 @@ -1100,6 +1101,7 @@ static int vmdk_create(const char *filen
33 const char *desc_extent_line;
34 char parent_desc_line[BUF_SIZE] = "";
35 uint32_t parent_cid = 0xffffffff;
36 + uint32_t number_heads = 16;
37 const char desc_template[] =
38 "# Disk DescriptorFile\n"
39 "version=1\n"
40 @@ -1116,9 +1118,9 @@ static int vmdk_create(const char *filen
41 "\n"
42 "ddb.virtualHWVersion = \"%d\"\n"
43 "ddb.geometry.cylinders = \"%" PRId64 "\"\n"
44 - "ddb.geometry.heads = \"16\"\n"
45 + "ddb.geometry.heads = \"%d\"\n"
46 "ddb.geometry.sectors = \"63\"\n"
47 - "ddb.adapterType = \"ide\"\n";
48 + "ddb.adapterType = \"%s\"\n";
49
50 if (filename_decompose(filename, path, prefix, postfix, PATH_MAX)) {
51 return -EINVAL;
52 @@ -1127,6 +1129,8 @@ static int vmdk_create(const char *filen
53 while (options && options->name) {
54 if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
55 total_size = options->value.n;
56 + } else if (!strcmp(options->name, BLOCK_OPT_ADAPTER_TYPE)) {
57 + adapter_type = options->value.s;
58 } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
59 backing_file = options->value.s;
60 } else if (!strcmp(options->name, BLOCK_OPT_COMPAT6)) {
61 @@ -1136,6 +1140,20 @@ static int vmdk_create(const char *filen
62 }
63 options++;
64 }
65 + if (!adapter_type) {
66 + adapter_type = "ide";
67 + } else if (strcmp(adapter_type, "ide") &&
68 + strcmp(adapter_type, "buslogic") &&
69 + strcmp(adapter_type, "lsilogic") &&
70 + strcmp(adapter_type, "legacyESX")) {
71 + fprintf(stderr, "VMDK: Unknown adapter type: '%s'.\n", adapter_type);
72 + return -EINVAL;
73 + }
74 + if (strcmp(adapter_type, "ide") != 0) {
75 + /* that's the number of heads with which vmware operates when
76 + creating, exporting, etc. vmdk files with a non-ide adapter type */
77 + number_heads = 255;
78 + }
79 if (!fmt) {
80 /* Default format to monolithicSparse */
81 fmt = "monolithicSparse";
82 @@ -1222,7 +1240,8 @@ static int vmdk_create(const char *filen
83 parent_desc_line,
84 ext_desc_lines,
85 (flags & BLOCK_FLAG_COMPAT6 ? 6 : 4),
86 - total_size / (int64_t)(63 * 16 * 512));
87 + total_size / (int64_t)(63 * number_heads * 512), number_heads,
88 + adapter_type);
89 if (split || flat) {
90 fd = open(
91 filename,
92 @@ -1281,6 +1300,12 @@ static QEMUOptionParameter vmdk_create_o
93 .help = "Virtual disk size"
94 },
95 {
96 + .name = BLOCK_OPT_ADAPTER_TYPE,
97 + .type = OPT_STRING,
98 + .help = "Virtual adapter type, can be one of "
99 + "ide (default), lsilogic, buslogic or legacyESX"
100 + },
101 + {
102 .name = BLOCK_OPT_BACKING_FILE,
103 .type = OPT_STRING,
104 .help = "File name of a base image"
105 --- a/block_int.h
106 +++ b/block_int.h
107 @@ -40,6 +40,7 @@
108 #define BLOCK_OPT_TABLE_SIZE "table_size"
109 #define BLOCK_OPT_PREALLOC "preallocation"
110 #define BLOCK_OPT_SUBFMT "subformat"
111 +#define BLOCK_OPT_ADAPTER_TYPE "adapter_type"
112
113 typedef struct AIOPool {
114 void (*cancel)(BlockDriverAIOCB *acb);