提交 d191d12d 编写于 作者: S Stefan Weil 提交者: Anthony Liguori

qcow2: Allow qcow2 disk images with size zero

Images with disk size 0 may be used for
VM snapshots, but not to save normal block data.

It is possible to create such images using
qemu-img, but opening them later fails.

So even "qemu-img info image.qcow2" is not
possible for an image created with
"qemu-img create -f qcow2 image.qcow2 0".

This is fixed here.
Signed-off-by: NStefan Weil <weil@mail.berlios.de>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 b4558d74
...@@ -39,6 +39,9 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size) ...@@ -39,6 +39,9 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size)
new_l1_size = s->l1_size; new_l1_size = s->l1_size;
if (min_size <= new_l1_size) if (min_size <= new_l1_size)
return 0; return 0;
if (new_l1_size == 0) {
new_l1_size = 1;
}
while (min_size > new_l1_size) { while (min_size > new_l1_size) {
new_l1_size = (new_l1_size * 3 + 1) / 2; new_l1_size = (new_l1_size * 3 + 1) / 2;
} }
......
...@@ -166,8 +166,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags) ...@@ -166,8 +166,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
if (header.magic != QCOW_MAGIC || header.version != QCOW_VERSION) if (header.magic != QCOW_MAGIC || header.version != QCOW_VERSION)
goto fail; goto fail;
if (header.size <= 1 || if (header.cluster_bits < MIN_CLUSTER_BITS ||
header.cluster_bits < MIN_CLUSTER_BITS ||
header.cluster_bits > MAX_CLUSTER_BITS) header.cluster_bits > MAX_CLUSTER_BITS)
goto fail; goto fail;
if (header.crypt_method > QCOW_CRYPT_AES) if (header.crypt_method > QCOW_CRYPT_AES)
...@@ -200,13 +199,15 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags) ...@@ -200,13 +199,15 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
if (s->l1_size < s->l1_vm_state_index) if (s->l1_size < s->l1_vm_state_index)
goto fail; goto fail;
s->l1_table_offset = header.l1_table_offset; s->l1_table_offset = header.l1_table_offset;
s->l1_table = qemu_mallocz( if (s->l1_size > 0) {
align_offset(s->l1_size * sizeof(uint64_t), 512)); s->l1_table = qemu_mallocz(
if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) != align_offset(s->l1_size * sizeof(uint64_t), 512));
s->l1_size * sizeof(uint64_t)) if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) !=
goto fail; s->l1_size * sizeof(uint64_t))
for(i = 0;i < s->l1_size; i++) { goto fail;
be64_to_cpus(&s->l1_table[i]); for(i = 0;i < s->l1_size; i++) {
be64_to_cpus(&s->l1_table[i]);
}
} }
/* alloc L2 cache */ /* alloc L2 cache */
s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t)); s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册