@@ -300,7 +300,8 @@ int qcow2_dirty_bitmap_store(BlockDriverState *bs,
uint8_t *buf,
}
}
if (dirty_bitmap_index < 0) {
- qcow2_dirty_bitmap_create(bs, name, size, granularity);
+ ret = qcow2_dirty_bitmap_create(bs, name, size, granularity);
+ if (ret < 0) { return ret; }
dirty_bitmap_index = s->nb_dirty_bitmaps - 1;
}
bm = s->dirty_bitmaps + dirty_bitmap_index;
@@ -384,7 +385,7 @@ int qcow2_dirty_bitmap_create(BlockDriverState *bs,
const char *name,
bm->l1_size =
size_to_clusters(s, (((size - 1) / sector_granularity) >> 3) + 1);
l1_table_offset =
- qcow2_alloc_clusters(bs, s->l1_size * sizeof(uint64_t));
+ qcow2_alloc_clusters(bs, bm->l1_size * sizeof(uint64_t));
if (l1_table_offset < 0) {
ret = l1_table_offset;
goto fail;
@@ -398,18 +399,18 @@ int qcow2_dirty_bitmap_create(BlockDriverState
*bs, const char *name,
}
/* initialize with zero clusters */
- for (i = 0; i < s->l1_size; i++) {
+ for (i = 0; i < bm->l1_size; i++) {
l1_table[i] = cpu_to_be64(1);
}
ret = qcow2_pre_write_overlap_check(bs, 0, bm->l1_table_offset,
- s->l1_size * sizeof(uint64_t));
+ bm->l1_size * sizeof(uint64_t));
if (ret < 0) {
goto fail;
}
ret = bdrv_pwrite(bs->file, bm->l1_table_offset, l1_table,
- s->l1_size * sizeof(uint64_t));
+ bm->l1_size * sizeof(uint64_t));
if (ret < 0) {
goto fail;
}
@@ -1146,7 +1146,7 @@ static int dirty_bitmap_func(void *opaque,
QemuOpts *opts, Error **errp)
qdict_put(options, "node-name", qstring_from_str(file_id));
}
- bdrv_open(&file_bs, file, NULL, options, 0, NULL, errp);
+ bdrv_open(&file_bs, file, NULL, options, BDRV_O_RDWR, NULL, errp);
if (options) {
QDECREF(options);