blk->aiocb = bdrv_aio_readv(bs, cur_sector, &blk->qiov,
nr_sectors, blk_mig_read_cb, blk);
if (!blk->aiocb) {
- printf("Error reading sector %" PRId64 "\n", cur_sector);
- qemu_free(blk->buf);
- qemu_free(blk);
- return 0;
+ goto error;
}
block_mig_state.submitted++;
} else {
if (bdrv_read(bs, cur_sector, blk->buf, nr_sectors) < 0) {
- printf("Error reading sector %" PRId64 "\n", cur_sector);
- return 0;
+ goto error;
}
blk_send(f, blk);
bmds->cur_sector = cur_sector + nr_sectors;
return (bmds->cur_sector >= total_sectors);
+
+error:
+ printf("Error reading sector %" PRId64 "\n", cur_sector);
+ qemu_file_set_error(f);
+ qemu_free(blk->buf);
+ qemu_free(blk);
+ return 0;
}
static void set_dirty_tracking(int enable)
if (bdrv_read(bmds->bs, sector, blk.buf,
BDRV_SECTORS_PER_DIRTY_CHUNK) < 0) {
printf("Error reading sector %" PRId64 "\n", sector);
- /* FIXME: add error handling */
+ qemu_file_set_error(f);
+ qemu_free(blk.buf);
+ return;
}
blk.bmds = bmds;
blk.sector = sector;
if (qemu_file_rate_limit(f)) {
break;
}
+ if (blk->ret < 0) {
+ qemu_file_set_error(f);
+ break;
+ }
blk_send(f, blk);
QSIMPLEQ_REMOVE_HEAD(&block_mig_state.blk_list, entry);
flush_blks(f);
+ if (qemu_file_has_error(f)) {
+ set_dirty_tracking(0);
+ return 0;
+ }
+
/* control the rate of transfer */
while ((block_mig_state.submitted +
block_mig_state.read_done) * BLOCK_SIZE <
flush_blks(f);
+ if (qemu_file_has_error(f)) {
+ set_dirty_tracking(0);
+ return 0;
+ }
+
if (stage == 3) {
while (blk_mig_save_bulked_block(f, 0) != 0) {
/* empty */
/* stop track dirty blocks */
set_dirty_tracking(0);
+ if (qemu_file_has_error(f)) {
+ return 0;
+ }
+
printf("\nBlock migration completed\n");
}
if (flags & BLK_MIG_FLAG_DEVICE_BLOCK) {
/* get device name */
len = qemu_get_byte(f);
-
qemu_get_buffer(f, (uint8_t *)device_name, len);
device_name[len] = '\0';
bs = bdrv_find(device_name);
+ if (!bs) {
+ fprintf(stderr, "Error unknown block device %s\n",
+ device_name);
+ return -EINVAL;
+ }
buf = qemu_malloc(BLOCK_SIZE);
qemu_get_buffer(f, buf, BLOCK_SIZE);
- if (bs != NULL) {
- bdrv_write(bs, addr, buf, BDRV_SECTORS_PER_DIRTY_CHUNK);
- } else {
- printf("Error unknown block device %s\n", device_name);
- /* FIXME: add error handling */
- }
+ bdrv_write(bs, addr, buf, BDRV_SECTORS_PER_DIRTY_CHUNK);
qemu_free(buf);
} else if (!(flags & BLK_MIG_FLAG_EOS)) {
- printf("Unknown flags\n");
- /* FIXME: add error handling */
+ fprintf(stderr, "Unknown flags\n");
+ return -EINVAL;
+ }
+ if (qemu_file_has_error(f)) {
+ return -EIO;
}
} while (!(flags & BLK_MIG_FLAG_EOS));