Revision 01e61e2d
b/block-migration.c | ||
---|---|---|
23 | 23 |
|
24 | 24 |
#define BLK_MIG_FLAG_DEVICE_BLOCK 0x01 |
25 | 25 |
#define BLK_MIG_FLAG_EOS 0x02 |
26 |
#define BLK_MIG_FLAG_PROGRESS 0x04 |
|
26 | 27 |
|
27 | 28 |
#define MAX_IS_ALLOCATED_SEARCH 65536 |
28 | 29 |
#define MAX_BLOCKS_READ 10000 |
... | ... | |
70 | 71 |
int read_done; |
71 | 72 |
int transferred; |
72 | 73 |
int64_t total_sector_sum; |
73 |
int64_t print_completion;
|
|
74 |
int prev_progress;
|
|
74 | 75 |
} BlkMigState; |
75 | 76 |
|
76 | 77 |
static BlkMigState block_mig_state; |
... | ... | |
226 | 227 |
block_mig_state.read_done = 0; |
227 | 228 |
block_mig_state.transferred = 0; |
228 | 229 |
block_mig_state.total_sector_sum = 0; |
229 |
block_mig_state.print_completion = 0;
|
|
230 |
block_mig_state.prev_progress = -1;
|
|
230 | 231 |
|
231 | 232 |
for (bs = bdrv_first; bs != NULL; bs = bs->next) { |
232 | 233 |
if (bs->type == BDRV_TYPE_HD) { |
... | ... | |
257 | 258 |
{ |
258 | 259 |
int64_t completed_sector_sum = 0; |
259 | 260 |
BlkMigDevState *bmds; |
261 |
int progress; |
|
260 | 262 |
int ret = 0; |
261 | 263 |
|
262 | 264 |
QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) { |
... | ... | |
273 | 275 |
} |
274 | 276 |
} |
275 | 277 |
|
276 |
if (completed_sector_sum >= block_mig_state.print_completion) { |
|
277 |
monitor_printf(mon, "Completed %" PRId64 " %%\r", |
|
278 |
completed_sector_sum * 100 / |
|
279 |
block_mig_state.total_sector_sum); |
|
278 |
progress = completed_sector_sum * 100 / block_mig_state.total_sector_sum; |
|
279 |
if (progress != block_mig_state.prev_progress) { |
|
280 |
block_mig_state.prev_progress = progress; |
|
281 |
qemu_put_be64(f, (progress << BDRV_SECTOR_BITS) |
|
282 |
| BLK_MIG_FLAG_PROGRESS); |
|
283 |
monitor_printf(mon, "Completed %d %%\r", progress); |
|
280 | 284 |
monitor_flush(mon); |
281 |
block_mig_state.print_completion += |
|
282 |
(BDRV_SECTORS_PER_DIRTY_CHUNK * 10000); |
|
283 | 285 |
} |
284 | 286 |
|
285 | 287 |
return ret; |
... | ... | |
445 | 447 |
blk_mig_save_dirty_blocks(mon, f); |
446 | 448 |
blk_mig_cleanup(mon); |
447 | 449 |
|
450 |
/* report completion */ |
|
451 |
qemu_put_be64(f, (100 << BDRV_SECTOR_BITS) | BLK_MIG_FLAG_PROGRESS); |
|
452 |
|
|
448 | 453 |
if (qemu_file_has_error(f)) { |
449 | 454 |
return 0; |
450 | 455 |
} |
... | ... | |
459 | 464 |
|
460 | 465 |
static int block_load(QEMUFile *f, void *opaque, int version_id) |
461 | 466 |
{ |
467 |
static int banner_printed; |
|
462 | 468 |
int len, flags; |
463 | 469 |
char device_name[256]; |
464 | 470 |
int64_t addr; |
... | ... | |
490 | 496 |
bdrv_write(bs, addr, buf, BDRV_SECTORS_PER_DIRTY_CHUNK); |
491 | 497 |
|
492 | 498 |
qemu_free(buf); |
499 |
} else if (flags & BLK_MIG_FLAG_PROGRESS) { |
|
500 |
if (!banner_printed) { |
|
501 |
printf("Receiving block device images\n"); |
|
502 |
banner_printed = 1; |
|
503 |
} |
|
504 |
printf("Completed %d %%%c", (int)addr, |
|
505 |
(addr == 100) ? '\n' : '\r'); |
|
506 |
fflush(stdout); |
|
493 | 507 |
} else if (!(flags & BLK_MIG_FLAG_EOS)) { |
494 | 508 |
fprintf(stderr, "Unknown flags\n"); |
495 | 509 |
return -EINVAL; |
Also available in: Unified diff