#include "monitor.h"
#include "block-migration.h"
#include "migration.h"
+#include "blockdev.h"
#include <assert.h>
#define BLOCK_SIZE (BDRV_SECTORS_PER_DIRTY_CHUNK << BDRV_SECTOR_BITS)
{
int64_t chunk = sector / (int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK;
- if (bmds->aio_bitmap &&
- (sector << BDRV_SECTOR_BITS) < bdrv_getlength(bmds->bs)) {
+ if ((sector << BDRV_SECTOR_BITS) < bdrv_getlength(bmds->bs)) {
return !!(bmds->aio_bitmap[chunk / (sizeof(unsigned long) * 8)] &
(1UL << (chunk % (sizeof(unsigned long) * 8))));
} else {
bit = start % (sizeof(unsigned long) * 8);
val = bmds->aio_bitmap[idx];
if (set) {
- if (!(val & (1UL << bit))) {
- val |= 1UL << bit;
- }
+ val |= 1UL << bit;
} else {
- if (val & (1UL << bit)) {
- val &= ~(1UL << bit);
- }
+ val &= ~(1UL << bit);
}
bmds->aio_bitmap[idx] = val;
}
bmds->completed_sectors = 0;
bmds->shared_base = block_mig_state.shared_base;
alloc_aio_bitmap(bmds);
+ drive_get_ref(drive_get_by_blockdev(bs));
+ bdrv_set_in_use(bs, 1);
block_mig_state.total_sector_sum += sectors;
}
}
- progress = completed_sector_sum * 100 / block_mig_state.total_sector_sum;
+ if (block_mig_state.total_sector_sum != 0) {
+ progress = completed_sector_sum * 100 /
+ block_mig_state.total_sector_sum;
+ } else {
+ progress = 100;
+ }
if (progress != block_mig_state.prev_progress) {
block_mig_state.prev_progress = progress;
qemu_put_be64(f, (progress << BDRV_SECTOR_BITS)
int nr_sectors;
for (sector = bmds->cur_dirty; sector < bmds->total_sectors;) {
- if (bmds_aio_inflight(bmds, sector))
+ if (bmds_aio_inflight(bmds, sector)) {
qemu_aio_flush();
+ }
if (bdrv_get_dirty(bmds->bs, sector)) {
if (total_sectors - sector < BDRV_SECTORS_PER_DIRTY_CHUNK) {
BlkMigDevState *bmds;
BlkMigBlock *blk;
+ set_dirty_tracking(0);
+
while ((bmds = QSIMPLEQ_FIRST(&block_mig_state.bmds_list)) != NULL) {
QSIMPLEQ_REMOVE_HEAD(&block_mig_state.bmds_list, entry);
+ bdrv_set_in_use(bmds->bs, 0);
+ drive_put_ref(drive_get_by_blockdev(bmds->bs));
qemu_free(bmds->aio_bitmap);
qemu_free(bmds);
}
qemu_free(blk);
}
- set_dirty_tracking(0);
-
monitor_printf(mon, "\n");
}
int len, flags;
char device_name[256];
int64_t addr;
- BlockDriverState *bs;
+ BlockDriverState *bs, *bs_prev = NULL;
uint8_t *buf;
+ int64_t total_sectors = 0;
+ int nr_sectors;
do {
addr = qemu_get_be64(f);
return -EINVAL;
}
+ if (bs != bs_prev) {
+ bs_prev = bs;
+ total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS;
+ if (total_sectors <= 0) {
+ error_report("Error getting length of block device %s\n",
+ device_name);
+ return -EINVAL;
+ }
+ }
+
+ if (total_sectors - addr < BDRV_SECTORS_PER_DIRTY_CHUNK) {
+ nr_sectors = total_sectors - addr;
+ } else {
+ nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK;
+ }
+
buf = qemu_malloc(BLOCK_SIZE);
qemu_get_buffer(f, buf, BLOCK_SIZE);
- ret = bdrv_write(bs, addr, buf, BDRV_SECTORS_PER_DIRTY_CHUNK);
+ ret = bdrv_write(bs, addr, buf, nr_sectors);
qemu_free(buf);
if (ret < 0) {