0012-vmdk-Allow-selecting-SCSI-adapter-in-image-creation.patch 4.2 KB

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