Revision 6ea44308 block-migration.c
b/block-migration.c | ||
---|---|---|
17 | 17 |
#include "block-migration.h" |
18 | 18 |
#include <assert.h> |
19 | 19 |
|
20 |
#define SECTOR_BITS 9 |
|
21 |
#define SECTOR_SIZE (1 << SECTOR_BITS) |
|
22 |
#define SECTOR_MASK ~(SECTOR_SIZE - 1); |
|
23 |
|
|
24 |
#define BLOCK_SIZE (block_mig_state->sectors_per_block << SECTOR_BITS) |
|
20 |
#define BLOCK_SIZE (BDRV_SECTORS_PER_DIRTY_CHUNK << BDRV_SECTOR_BITS) |
|
25 | 21 |
|
26 | 22 |
#define BLK_MIG_FLAG_DEVICE_BLOCK 0x01 |
27 | 23 |
#define BLK_MIG_FLAG_EOS 0x02 |
... | ... | |
69 | 65 |
int no_dirty; |
70 | 66 |
QEMUFile *load_file; |
71 | 67 |
BlkMigDevState *bmds_first; |
72 |
int sectors_per_block; |
|
73 | 68 |
BlkMigBlock *first_blk; |
74 | 69 |
BlkMigBlock *last_blk; |
75 | 70 |
int submitted; |
... | ... | |
111 | 106 |
blk->buf = qemu_malloc(BLOCK_SIZE); |
112 | 107 |
|
113 | 108 |
cur_sector = bms->cur_sector; |
114 |
total_sectors = bdrv_getlength(bs) >> SECTOR_BITS; |
|
109 |
total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS;
|
|
115 | 110 |
|
116 | 111 |
if (bms->shared_base) { |
117 | 112 |
while (cur_sector < bms->total_sectors && |
... | ... | |
132 | 127 |
printf("Completed %" PRId64 " %%\r", cur_sector * 100 / total_sectors); |
133 | 128 |
fflush(stdout); |
134 | 129 |
block_mig_state->print_completion += |
135 |
(block_mig_state->sectors_per_block * 10000);
|
|
130 |
(BDRV_SECTORS_PER_DIRTY_CHUNK * 10000);
|
|
136 | 131 |
} |
137 | 132 |
|
138 |
/* we going to transfder BLOCK_SIZE any way even if it is not allocated */
|
|
139 |
nr_sectors = block_mig_state->sectors_per_block;
|
|
133 |
/* we are going to transfer a full block even if it is not allocated */
|
|
134 |
nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK;
|
|
140 | 135 |
|
141 |
cur_sector &= ~((int64_t)block_mig_state->sectors_per_block -1);
|
|
136 |
cur_sector &= ~((int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK - 1);
|
|
142 | 137 |
|
143 |
if (total_sectors - cur_sector < block_mig_state->sectors_per_block) {
|
|
138 |
if (total_sectors - cur_sector < BDRV_SECTORS_PER_DIRTY_CHUNK) {
|
|
144 | 139 |
nr_sectors = (total_sectors - cur_sector); |
145 | 140 |
} |
146 | 141 |
|
... | ... | |
150 | 145 |
blk->next = NULL; |
151 | 146 |
|
152 | 147 |
blk->iov.iov_base = blk->buf; |
153 |
blk->iov.iov_len = nr_sectors * SECTOR_SIZE; |
|
148 |
blk->iov.iov_len = nr_sectors * BDRV_SECTOR_SIZE;
|
|
154 | 149 |
qemu_iovec_init_external(&blk->qiov, &blk->iov, 1); |
155 | 150 |
|
156 | 151 |
blk->aiocb = bdrv_aio_readv(bs, cur_sector, &blk->qiov, |
... | ... | |
198 | 193 |
printf("Completed %" PRId64 " %%\r", cur_sector * 100 / total_sectors); |
199 | 194 |
fflush(stdout); |
200 | 195 |
block_mig_state->print_completion += |
201 |
(block_mig_state->sectors_per_block * 10000);
|
|
196 |
(BDRV_SECTORS_PER_DIRTY_CHUNK * 10000);
|
|
202 | 197 |
} |
203 | 198 |
|
204 |
cur_sector &= ~((int64_t)block_mig_state->sectors_per_block -1);
|
|
199 |
cur_sector &= ~((int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK - 1);
|
|
205 | 200 |
|
206 |
/* we going to transfer BLOCK_SIZE any way even if it is not allocated */
|
|
207 |
nr_sectors = block_mig_state->sectors_per_block;
|
|
201 |
/* we are going to transfer a full block even if it is not allocated */
|
|
202 |
nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK;
|
|
208 | 203 |
|
209 |
if (total_sectors - cur_sector < block_mig_state->sectors_per_block) {
|
|
204 |
if (total_sectors - cur_sector < BDRV_SECTORS_PER_DIRTY_CHUNK) {
|
|
210 | 205 |
nr_sectors = (total_sectors - cur_sector); |
211 | 206 |
} |
212 | 207 |
|
... | ... | |
217 | 212 |
bdrv_reset_dirty(bs, cur_sector, nr_sectors); |
218 | 213 |
|
219 | 214 |
/* sector number and flags */ |
220 |
qemu_put_be64(f, (cur_sector << SECTOR_BITS) | BLK_MIG_FLAG_DEVICE_BLOCK); |
|
215 |
qemu_put_be64(f, (cur_sector << BDRV_SECTOR_BITS) |
|
216 |
| BLK_MIG_FLAG_DEVICE_BLOCK); |
|
221 | 217 |
|
222 | 218 |
/* device name */ |
223 | 219 |
len = strlen(bs->device_name); |
... | ... | |
226 | 222 |
|
227 | 223 |
qemu_put_buffer(f, tmp_buf, BLOCK_SIZE); |
228 | 224 |
|
229 |
bmds->cur_sector = cur_sector + block_mig_state->sectors_per_block;
|
|
225 |
bmds->cur_sector = cur_sector + BDRV_SECTORS_PER_DIRTY_CHUNK;
|
|
230 | 226 |
|
231 | 227 |
qemu_free(tmp_buf); |
232 | 228 |
|
... | ... | |
238 | 234 |
int len; |
239 | 235 |
|
240 | 236 |
/* sector number and flags */ |
241 |
qemu_put_be64(f, (blk->sector << SECTOR_BITS) | BLK_MIG_FLAG_DEVICE_BLOCK); |
|
237 |
qemu_put_be64(f, (blk->sector << BDRV_SECTOR_BITS) |
|
238 |
| BLK_MIG_FLAG_DEVICE_BLOCK); |
|
242 | 239 |
|
243 | 240 |
/* device name */ |
244 | 241 |
len = strlen(blk->bmds->bs->device_name); |
... | ... | |
270 | 267 |
bmds = qemu_mallocz(sizeof(BlkMigDevState)); |
271 | 268 |
bmds->bs = bs; |
272 | 269 |
bmds->bulk_completed = 0; |
273 |
bmds->total_sectors = bdrv_getlength(bs) >> SECTOR_BITS; |
|
270 |
bmds->total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS;
|
|
274 | 271 |
bmds->shared_base = block_mig_state->shared_base; |
275 | 272 |
|
276 | 273 |
if (bmds->shared_base) { |
... | ... | |
290 | 287 |
blk_mig_save_dev_info(f, bmds); |
291 | 288 |
} |
292 | 289 |
} |
293 |
|
|
294 |
block_mig_state->sectors_per_block = bdrv_get_sectors_per_chunk(); |
|
295 | 290 |
} |
296 | 291 |
|
297 | 292 |
static int blk_mig_save_bulked_block(QEMUFile *f, int is_async) |
... | ... | |
334 | 329 |
for (sector = 0; sector < bmds->cur_sector;) { |
335 | 330 |
if (bdrv_get_dirty(bmds->bs, sector)) { |
336 | 331 |
if (bdrv_read(bmds->bs, sector, buf, |
337 |
block_mig_state->sectors_per_block) < 0) {
|
|
332 |
BDRV_SECTORS_PER_DIRTY_CHUNK) < 0) {
|
|
338 | 333 |
/* FIXME: add error handling */ |
339 | 334 |
} |
340 | 335 |
|
341 | 336 |
/* sector number and flags */ |
342 |
qemu_put_be64(f, (sector << SECTOR_BITS) |
|
337 |
qemu_put_be64(f, (sector << BDRV_SECTOR_BITS)
|
|
343 | 338 |
| BLK_MIG_FLAG_DEVICE_BLOCK); |
344 | 339 |
|
345 | 340 |
/* device name */ |
... | ... | |
347 | 342 |
qemu_put_byte(f, len); |
348 | 343 |
qemu_put_buffer(f, (uint8_t *)bmds->bs->device_name, len); |
349 | 344 |
|
350 |
qemu_put_buffer(f, buf, |
|
351 |
(block_mig_state->sectors_per_block * |
|
352 |
SECTOR_SIZE)); |
|
345 |
qemu_put_buffer(f, buf, BLOCK_SIZE); |
|
353 | 346 |
|
354 | 347 |
bdrv_reset_dirty(bmds->bs, sector, |
355 |
block_mig_state->sectors_per_block);
|
|
348 |
BDRV_SECTORS_PER_DIRTY_CHUNK);
|
|
356 | 349 |
} |
357 |
sector += block_mig_state->sectors_per_block;
|
|
350 |
sector += BDRV_SECTORS_PER_DIRTY_CHUNK;
|
|
358 | 351 |
} |
359 | 352 |
} |
360 | 353 |
} |
... | ... | |
465 | 458 |
BlockDriverState *bs; |
466 | 459 |
uint8_t *buf; |
467 | 460 |
|
468 |
block_mig_state->sectors_per_block = bdrv_get_sectors_per_chunk(); |
|
469 | 461 |
buf = qemu_malloc(BLOCK_SIZE); |
470 | 462 |
|
471 | 463 |
do { |
472 | 464 |
addr = qemu_get_be64(f); |
473 | 465 |
|
474 |
flags = addr & ~SECTOR_MASK; |
|
475 |
addr &= SECTOR_MASK;
|
|
466 |
flags = addr & ~BDRV_SECTOR_MASK;
|
|
467 |
addr >>= BDRV_SECTOR_BITS;
|
|
476 | 468 |
|
477 | 469 |
if (flags & BLK_MIG_FLAG_DEVICE_BLOCK) { |
478 | 470 |
/* get device name */ |
... | ... | |
485 | 477 |
|
486 | 478 |
qemu_get_buffer(f, buf, BLOCK_SIZE); |
487 | 479 |
if (bs != NULL) { |
488 |
bdrv_write(bs, (addr >> SECTOR_BITS), |
|
489 |
buf, block_mig_state->sectors_per_block); |
|
480 |
bdrv_write(bs, addr, buf, BDRV_SECTORS_PER_DIRTY_CHUNK); |
|
490 | 481 |
} else { |
491 | 482 |
printf("Error unknown block device %s\n", device_name); |
492 | 483 |
/* FIXME: add error handling */ |
Also available in: Unified diff