BlockdevOnError on_error;
char *backing_file_str;
bool bs_read_only;
+ bool chain_frozen;
} StreamBlockJob;
static int coroutine_fn stream_populate(BlockBackend *blk,
int64_t offset, uint64_t bytes,
void *buf)
{
- QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
-
assert(bytes < SIZE_MAX);
/* Copy-on-read the unallocated clusters */
- return blk_co_preadv(blk, offset, qiov.size, &qiov, BDRV_REQ_COPY_ON_READ);
+ return blk_co_pread(blk, offset, bytes, buf, BDRV_REQ_COPY_ON_READ);
+}
+
+static void stream_abort(Job *job)
+{
+ StreamBlockJob *s = container_of(job, StreamBlockJob, common.job);
+
+ if (s->chain_frozen) {
+ BlockJob *bjob = &s->common;
+ bdrv_unfreeze_backing_chain(blk_bs(bjob->blk), s->base);
+ }
}
static int stream_prepare(Job *job)
Error *local_err = NULL;
int ret = 0;
+ bdrv_unfreeze_backing_chain(bs, base);
+ s->chain_frozen = false;
+
if (bs->backing) {
const char *base_id = NULL, *base_fmt = NULL;
if (base) {
.free = block_job_free,
.run = stream_run,
.prepare = stream_prepare,
+ .abort = stream_abort,
.clean = stream_clean,
.user_resume = block_job_user_resume,
.drain = block_job_drain,
BlockDriverState *iter;
bool bs_read_only;
+ if (bdrv_freeze_backing_chain(bs, base, errp) < 0) {
+ return;
+ }
+
/* Make sure that the image is opened in read-write mode */
bs_read_only = bdrv_is_read_only(bs);
if (bs_read_only) {
if (bdrv_reopen_set_read_only(bs, false, errp) != 0) {
- return;
+ bs_read_only = false;
+ goto fail;
}
}
s->base = base;
s->backing_file_str = g_strdup(backing_file_str);
s->bs_read_only = bs_read_only;
+ s->chain_frozen = true;
s->on_error = on_error;
trace_stream_start(bs, base, s);
if (bs_read_only) {
bdrv_reopen_set_read_only(bs, true, NULL);
}
+ bdrv_unfreeze_backing_chain(bs, base);
}