提交 fb8fa77c 编写于 作者: K Kevin Wolf 提交者: Anthony Liguori

qcow2: Fix error handling in qcow2_grow_l1_table

Return the appropriate error value instead of always using EIO. Don't free the
L1 table on errors, we still need it.
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 81a1b45a
...@@ -67,9 +67,10 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size) ...@@ -67,9 +67,10 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size)
/* set new table */ /* set new table */
cpu_to_be32w((uint32_t*)data, new_l1_size); cpu_to_be32w((uint32_t*)data, new_l1_size);
cpu_to_be64w((uint64_t*)(data + 4), new_l1_table_offset); cpu_to_be64w((uint64_t*)(data + 4), new_l1_table_offset);
if (bdrv_pwrite(s->hd, offsetof(QCowHeader, l1_size), data, ret = bdrv_pwrite(s->hd, offsetof(QCowHeader, l1_size), data,sizeof(data));
sizeof(data)) != sizeof(data)) if (ret != sizeof(data)) {
goto fail; goto fail;
}
qemu_free(s->l1_table); qemu_free(s->l1_table);
qcow2_free_clusters(bs, s->l1_table_offset, s->l1_size * sizeof(uint64_t)); qcow2_free_clusters(bs, s->l1_table_offset, s->l1_size * sizeof(uint64_t));
s->l1_table_offset = new_l1_table_offset; s->l1_table_offset = new_l1_table_offset;
...@@ -77,8 +78,9 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size) ...@@ -77,8 +78,9 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size)
s->l1_size = new_l1_size; s->l1_size = new_l1_size;
return 0; return 0;
fail: fail:
qemu_free(s->l1_table); qemu_free(new_l1_table);
return -EIO; qcow2_free_clusters(bs, new_l1_table_offset, new_l1_size2);
return ret < 0 ? ret : -EIO;
} }
void qcow2_l2_cache_reset(BlockDriverState *bs) void qcow2_l2_cache_reset(BlockDriverState *bs)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册