Commit 15e6690aca348a7dc8772b8f1197cf13c8764335

Authored by bellard
1 parent c47c33b0

fixed disk image creation


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2089 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 9 additions and 5 deletions
block-qcow2.c
... ... @@ -1081,7 +1081,7 @@ static int qcow_create(const char *filename, int64_t total_size,
1081 1081 s->l1_table_offset = offset;
1082 1082 header.l1_table_offset = cpu_to_be64(s->l1_table_offset);
1083 1083 header.l1_size = cpu_to_be32(l1_size);
1084   - offset += align_offset(l1_size, s->cluster_size);
  1084 + offset += align_offset(l1_size * sizeof(uint64_t), s->cluster_size);
1085 1085  
1086 1086 s->refcount_table = qemu_mallocz(s->cluster_size);
1087 1087 if (!s->refcount_table)
... ... @@ -1089,7 +1089,7 @@ static int qcow_create(const char *filename, int64_t total_size,
1089 1089 s->refcount_block = qemu_mallocz(s->cluster_size);
1090 1090 if (!s->refcount_block)
1091 1091 goto fail;
1092   -
  1092 +
1093 1093 s->refcount_table_offset = offset;
1094 1094 header.refcount_table_offset = cpu_to_be64(offset);
1095 1095 header.refcount_table_clusters = cpu_to_be32(1);
... ... @@ -1101,7 +1101,7 @@ static int qcow_create(const char *filename, int64_t total_size,
1101 1101  
1102 1102 /* update refcounts */
1103 1103 create_refcount_update(s, 0, header_size);
1104   - create_refcount_update(s, s->l1_table_offset, l1_size);
  1104 + create_refcount_update(s, s->l1_table_offset, l1_size * sizeof(uint64_t));
1105 1105 create_refcount_update(s, s->refcount_table_offset, s->cluster_size);
1106 1106 create_refcount_update(s, s->refcount_block_offset, s->cluster_size);
1107 1107  
... ... @@ -1894,7 +1894,11 @@ static int grow_refcount_table(BlockDriverState *bs, int min_size)
1894 1894 if (min_size <= new_table_size)
1895 1895 break;
1896 1896 }
1897   -
  1897 +#ifdef DEBUG_ALLOC2
  1898 + printf("grow_refcount_table from %d to %d\n",
  1899 + s->refcount_table_size,
  1900 + new_table_size);
  1901 +#endif
1898 1902 new_table_size2 = new_table_size * sizeof(uint64_t);
1899 1903 new_table = qemu_mallocz(new_table_size2);
1900 1904 if (!new_table)
... ... @@ -2144,7 +2148,7 @@ static void check_refcounts(BlockDriverState *bs)
2144 2148 size = bdrv_getlength(s->hd);
2145 2149 nb_clusters = (size + s->cluster_size - 1) >> s->cluster_bits;
2146 2150 refcount_table = qemu_mallocz(nb_clusters * sizeof(uint16_t));
2147   -
  2151 +
2148 2152 /* header */
2149 2153 inc_refcounts(bs, refcount_table, nb_clusters,
2150 2154 0, s->cluster_size);
... ...