#include "block/qdict.h"
#include "sysemu/block-backend.h"
+#include "qemu/main-loop.h"
#include "qemu/module.h"
#include "qcow2.h"
#include "qemu/error-report.h"
unsigned int bytes;
int status = 0;
+ if (!s->metadata_preallocation_checked) {
+ ret = qcow2_detect_metadata_preallocation(bs);
+ s->metadata_preallocation = (ret == 1);
+ s->metadata_preallocation_checked = true;
+ }
+
bytes = MIN(INT_MAX, count);
qemu_co_mutex_lock(&s->lock);
ret = qcow2_get_cluster_offset(bs, offset, &bytes, &cluster_offset);
} else if (ret != QCOW2_CLUSTER_UNALLOCATED) {
status |= BDRV_BLOCK_DATA;
}
+ if (s->metadata_preallocation && (status & BDRV_BLOCK_DATA) &&
+ (status & BDRV_BLOCK_OFFSET_VALID))
+ {
+ status |= BDRV_BLOCK_RECURSE;
+ }
return status;
}
{
int64_t nr;
return !bytes ||
- (!bdrv_is_allocated_above(bs, NULL, offset, bytes, &nr) && nr == bytes);
+ (!bdrv_is_allocated_above(bs, NULL, false, offset, bytes, &nr) &&
+ nr == bytes);
}
static bool is_zero_cow(BlockDriverState *bs, QCowL2Meta *m)
}
/* Create BlockBackend to write to the image */
- blk = blk_new(BLK_PERM_WRITE | BLK_PERM_RESIZE, BLK_PERM_ALL);
+ blk = blk_new(bdrv_get_aio_context(bs),
+ BLK_PERM_WRITE | BLK_PERM_RESIZE, BLK_PERM_ALL);
ret = blk_insert_bs(blk, bs, errp);
if (ret < 0) {
goto out;
compat = qemu_opt_get(opts, BLOCK_OPT_COMPAT_LEVEL);
if (!compat) {
/* preserve default */
- } else if (!strcmp(compat, "0.10")) {
+ } else if (!strcmp(compat, "0.10") || !strcmp(compat, "v2")) {
new_version = 2;
- } else if (!strcmp(compat, "1.1")) {
+ } else if (!strcmp(compat, "1.1") || !strcmp(compat, "v3")) {
new_version = 3;
} else {
error_setg(errp, "Unknown compatibility level %s", compat);
}
if (new_size) {
- BlockBackend *blk = blk_new(BLK_PERM_RESIZE, BLK_PERM_ALL);
+ BlockBackend *blk = blk_new(bdrv_get_aio_context(bs),
+ BLK_PERM_RESIZE, BLK_PERM_ALL);
ret = blk_insert_bs(blk, bs, errp);
if (ret < 0) {
blk_unref(blk);
{
.name = BLOCK_OPT_COMPAT_LEVEL,
.type = QEMU_OPT_STRING,
- .help = "Compatibility level (0.10 or 1.1)"
+ .help = "Compatibility level (v2 [0.10] or v3 [1.1])"
},
{
.name = BLOCK_OPT_BACKING_FILE,