Revision 82801d8f
b/block-migration.c | ||
---|---|---|
43 | 43 |
int bulk_completed; |
44 | 44 |
int shared_base; |
45 | 45 |
int64_t cur_sector; |
46 |
int64_t completed_sectors; |
|
46 | 47 |
int64_t total_sectors; |
47 | 48 |
int64_t dirty; |
48 | 49 |
QSIMPLEQ_ENTRY(BlkMigDevState) entry; |
... | ... | |
67 | 68 |
int submitted; |
68 | 69 |
int read_done; |
69 | 70 |
int transferred; |
71 |
int64_t total_sector_sum; |
|
70 | 72 |
int64_t print_completion; |
71 | 73 |
} BlkMigState; |
72 | 74 |
|
... | ... | |
118 | 120 |
} |
119 | 121 |
|
120 | 122 |
if (cur_sector >= total_sectors) { |
121 |
bmds->cur_sector = total_sectors; |
|
123 |
bmds->cur_sector = bmds->completed_sectors = total_sectors;
|
|
122 | 124 |
return 1; |
123 | 125 |
} |
124 | 126 |
|
125 |
if (cur_sector >= block_mig_state.print_completion) { |
|
126 |
printf("Completed %" PRId64 " %%\r", cur_sector * 100 / total_sectors); |
|
127 |
fflush(stdout); |
|
128 |
block_mig_state.print_completion += |
|
129 |
(BDRV_SECTORS_PER_DIRTY_CHUNK * 10000); |
|
130 |
} |
|
127 |
bmds->completed_sectors = cur_sector; |
|
131 | 128 |
|
132 | 129 |
cur_sector &= ~((int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK - 1); |
133 | 130 |
|
... | ... | |
194 | 191 |
block_mig_state.submitted = 0; |
195 | 192 |
block_mig_state.read_done = 0; |
196 | 193 |
block_mig_state.transferred = 0; |
194 |
block_mig_state.total_sector_sum = 0; |
|
197 | 195 |
block_mig_state.print_completion = 0; |
198 | 196 |
|
199 | 197 |
for (bs = bdrv_first; bs != NULL; bs = bs->next) { |
... | ... | |
202 | 200 |
bmds->bs = bs; |
203 | 201 |
bmds->bulk_completed = 0; |
204 | 202 |
bmds->total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; |
203 |
bmds->completed_sectors = 0; |
|
205 | 204 |
bmds->shared_base = block_mig_state.shared_base; |
206 | 205 |
|
206 |
block_mig_state.total_sector_sum += bmds->total_sectors; |
|
207 |
|
|
207 | 208 |
if (bmds->shared_base) { |
208 | 209 |
printf("Start migration for %s with shared base image\n", |
209 | 210 |
bs->device_name); |
... | ... | |
218 | 219 |
|
219 | 220 |
static int blk_mig_save_bulked_block(QEMUFile *f, int is_async) |
220 | 221 |
{ |
222 |
int64_t completed_sector_sum = 0; |
|
221 | 223 |
BlkMigDevState *bmds; |
224 |
int ret = 0; |
|
222 | 225 |
|
223 | 226 |
QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) { |
224 | 227 |
if (bmds->bulk_completed == 0) { |
... | ... | |
226 | 229 |
/* completed bulk section for this device */ |
227 | 230 |
bmds->bulk_completed = 1; |
228 | 231 |
} |
229 |
return 1; |
|
232 |
completed_sector_sum += bmds->completed_sectors; |
|
233 |
ret = 1; |
|
234 |
break; |
|
235 |
} else { |
|
236 |
completed_sector_sum += bmds->completed_sectors; |
|
230 | 237 |
} |
231 | 238 |
} |
232 | 239 |
|
233 |
/* we reached here means bulk is completed */ |
|
234 |
return 0; |
|
240 |
if (completed_sector_sum >= block_mig_state.print_completion) { |
|
241 |
printf("Completed %" PRId64 " %%\r", |
|
242 |
completed_sector_sum * 100 / block_mig_state.total_sector_sum); |
|
243 |
fflush(stdout); |
|
244 |
block_mig_state.print_completion += |
|
245 |
(BDRV_SECTORS_PER_DIRTY_CHUNK * 10000); |
|
246 |
} |
|
247 |
|
|
248 |
return ret; |
|
235 | 249 |
} |
236 | 250 |
|
237 | 251 |
#define MAX_NUM_BLOCKS 4 |
... | ... | |
319 | 333 |
|
320 | 334 |
static void blk_mig_cleanup(void) |
321 | 335 |
{ |
322 |
BlkMigDevState *bmds, *next_bmds;
|
|
323 |
BlkMigBlock *blk, *next_blk;
|
|
336 |
BlkMigDevState *bmds; |
|
337 |
BlkMigBlock *blk; |
|
324 | 338 |
|
325 |
QTAILQ_FOREACH_SAFE(bmds, &block_mig_state.dev_list, entry, next_bmds) {
|
|
326 |
QTAILQ_REMOVE(&block_mig_state.dev_list, bmds, entry);
|
|
339 |
while ((bmds = QSIMPLEQ_FIRST(&block_mig_state.bmds_list)) != NULL) {
|
|
340 |
QSIMPLEQ_REMOVE_HEAD(&block_mig_state.bmds_list, entry);
|
|
327 | 341 |
qemu_free(bmds); |
328 | 342 |
} |
329 | 343 |
|
330 |
QTAILQ_FOREACH_SAFE(blk, &block_mig_state.blk_list, entry, next_blk) {
|
|
331 |
QTAILQ_REMOVE(&block_mig_state.blk_list, blk, entry);
|
|
344 |
while ((blk = QSIMPLEQ_FIRST(&block_mig_state.blk_list)) != NULL) {
|
|
345 |
QSIMPLEQ_REMOVE_HEAD(&block_mig_state.blk_list, entry);
|
|
332 | 346 |
qemu_free(blk->buf); |
333 | 347 |
qemu_free(blk); |
334 | 348 |
} |
Also available in: Unified diff