]> git.proxmox.com Git - qemu.git/blob - block-migration.c
d62a8b80bac428bb9a13780991db3f4196fda435
[qemu.git] / block-migration.c
1 /*
2 * QEMU live block migration
3 *
4 * Copyright IBM, Corp. 2009
5 *
6 * Authors:
7 * Liran Schour <lirans@il.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
14 */
15
16 #include "qemu-common.h"
17 #include "block/block_int.h"
18 #include "hw/hw.h"
19 #include "qemu/queue.h"
20 #include "qemu/timer.h"
21 #include "migration/block.h"
22 #include "migration/migration.h"
23 #include "sysemu/blockdev.h"
24 #include <assert.h>
25
26 #define BLOCK_SIZE (1 << 20)
27 #define BDRV_SECTORS_PER_DIRTY_CHUNK (BLOCK_SIZE >> BDRV_SECTOR_BITS)
28
29 #define BLK_MIG_FLAG_DEVICE_BLOCK 0x01
30 #define BLK_MIG_FLAG_EOS 0x02
31 #define BLK_MIG_FLAG_PROGRESS 0x04
32
33 #define MAX_IS_ALLOCATED_SEARCH 65536
34
35 //#define DEBUG_BLK_MIGRATION
36
37 #ifdef DEBUG_BLK_MIGRATION
38 #define DPRINTF(fmt, ...) \
39 do { printf("blk_migration: " fmt, ## __VA_ARGS__); } while (0)
40 #else
41 #define DPRINTF(fmt, ...) \
42 do { } while (0)
43 #endif
44
45 typedef struct BlkMigDevState {
46 /* Written during setup phase. Can be read without a lock. */
47 BlockDriverState *bs;
48 int shared_base;
49 int64_t total_sectors;
50 QSIMPLEQ_ENTRY(BlkMigDevState) entry;
51
52 /* Only used by migration thread. Does not need a lock. */
53 int bulk_completed;
54 int64_t cur_sector;
55 int64_t cur_dirty;
56
57 /* Protected by iothread lock. */
58 unsigned long *aio_bitmap;
59 int64_t completed_sectors;
60 } BlkMigDevState;
61
62 typedef struct BlkMigBlock {
63 /* Only used by migration thread. */
64 uint8_t *buf;
65 BlkMigDevState *bmds;
66 int64_t sector;
67 int nr_sectors;
68 struct iovec iov;
69 QEMUIOVector qiov;
70 BlockDriverAIOCB *aiocb;
71
72 /* Protected by iothread lock. */
73 int ret;
74 QSIMPLEQ_ENTRY(BlkMigBlock) entry;
75 } BlkMigBlock;
76
77 typedef struct BlkMigState {
78 /* Written during setup phase. Can be read without a lock. */
79 int blk_enable;
80 int shared_base;
81 QSIMPLEQ_HEAD(bmds_list, BlkMigDevState) bmds_list;
82 int64_t total_sector_sum;
83
84 /* Protected by iothread lock. */
85 QSIMPLEQ_HEAD(blk_list, BlkMigBlock) blk_list;
86 int submitted;
87 int read_done;
88
89 /* Only used by migration thread. Does not need a lock. */
90 int transferred;
91 int prev_progress;
92 int bulk_completed;
93 } BlkMigState;
94
95 static BlkMigState block_mig_state;
96
97 static void blk_send(QEMUFile *f, BlkMigBlock * blk)
98 {
99 int len;
100
101 /* sector number and flags */
102 qemu_put_be64(f, (blk->sector << BDRV_SECTOR_BITS)
103 | BLK_MIG_FLAG_DEVICE_BLOCK);
104
105 /* device name */
106 len = strlen(blk->bmds->bs->device_name);
107 qemu_put_byte(f, len);
108 qemu_put_buffer(f, (uint8_t *)blk->bmds->bs->device_name, len);
109
110 qemu_put_buffer(f, blk->buf, BLOCK_SIZE);
111 }
112
113 int blk_mig_active(void)
114 {
115 return !QSIMPLEQ_EMPTY(&block_mig_state.bmds_list);
116 }
117
118 uint64_t blk_mig_bytes_transferred(void)
119 {
120 BlkMigDevState *bmds;
121 uint64_t sum = 0;
122
123 QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
124 sum += bmds->completed_sectors;
125 }
126 return sum << BDRV_SECTOR_BITS;
127 }
128
129 uint64_t blk_mig_bytes_remaining(void)
130 {
131 return blk_mig_bytes_total() - blk_mig_bytes_transferred();
132 }
133
134 uint64_t blk_mig_bytes_total(void)
135 {
136 BlkMigDevState *bmds;
137 uint64_t sum = 0;
138
139 QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
140 sum += bmds->total_sectors;
141 }
142 return sum << BDRV_SECTOR_BITS;
143 }
144
145 static int bmds_aio_inflight(BlkMigDevState *bmds, int64_t sector)
146 {
147 int64_t chunk = sector / (int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK;
148
149 if ((sector << BDRV_SECTOR_BITS) < bdrv_getlength(bmds->bs)) {
150 return !!(bmds->aio_bitmap[chunk / (sizeof(unsigned long) * 8)] &
151 (1UL << (chunk % (sizeof(unsigned long) * 8))));
152 } else {
153 return 0;
154 }
155 }
156
157 static void bmds_set_aio_inflight(BlkMigDevState *bmds, int64_t sector_num,
158 int nb_sectors, int set)
159 {
160 int64_t start, end;
161 unsigned long val, idx, bit;
162
163 start = sector_num / BDRV_SECTORS_PER_DIRTY_CHUNK;
164 end = (sector_num + nb_sectors - 1) / BDRV_SECTORS_PER_DIRTY_CHUNK;
165
166 for (; start <= end; start++) {
167 idx = start / (sizeof(unsigned long) * 8);
168 bit = start % (sizeof(unsigned long) * 8);
169 val = bmds->aio_bitmap[idx];
170 if (set) {
171 val |= 1UL << bit;
172 } else {
173 val &= ~(1UL << bit);
174 }
175 bmds->aio_bitmap[idx] = val;
176 }
177 }
178
179 static void alloc_aio_bitmap(BlkMigDevState *bmds)
180 {
181 BlockDriverState *bs = bmds->bs;
182 int64_t bitmap_size;
183
184 bitmap_size = (bdrv_getlength(bs) >> BDRV_SECTOR_BITS) +
185 BDRV_SECTORS_PER_DIRTY_CHUNK * 8 - 1;
186 bitmap_size /= BDRV_SECTORS_PER_DIRTY_CHUNK * 8;
187
188 bmds->aio_bitmap = g_malloc0(bitmap_size);
189 }
190
191 static void blk_mig_read_cb(void *opaque, int ret)
192 {
193 BlkMigBlock *blk = opaque;
194
195 blk->ret = ret;
196
197 QSIMPLEQ_INSERT_TAIL(&block_mig_state.blk_list, blk, entry);
198 bmds_set_aio_inflight(blk->bmds, blk->sector, blk->nr_sectors, 0);
199
200 block_mig_state.submitted--;
201 block_mig_state.read_done++;
202 assert(block_mig_state.submitted >= 0);
203 }
204
205 static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds)
206 {
207 int64_t total_sectors = bmds->total_sectors;
208 int64_t cur_sector = bmds->cur_sector;
209 BlockDriverState *bs = bmds->bs;
210 BlkMigBlock *blk;
211 int nr_sectors;
212
213 if (bmds->shared_base) {
214 while (cur_sector < total_sectors &&
215 !bdrv_is_allocated(bs, cur_sector, MAX_IS_ALLOCATED_SEARCH,
216 &nr_sectors)) {
217 cur_sector += nr_sectors;
218 }
219 }
220
221 if (cur_sector >= total_sectors) {
222 bmds->cur_sector = bmds->completed_sectors = total_sectors;
223 return 1;
224 }
225
226 bmds->completed_sectors = cur_sector;
227
228 cur_sector &= ~((int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK - 1);
229
230 /* we are going to transfer a full block even if it is not allocated */
231 nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK;
232
233 if (total_sectors - cur_sector < BDRV_SECTORS_PER_DIRTY_CHUNK) {
234 nr_sectors = total_sectors - cur_sector;
235 }
236
237 blk = g_malloc(sizeof(BlkMigBlock));
238 blk->buf = g_malloc(BLOCK_SIZE);
239 blk->bmds = bmds;
240 blk->sector = cur_sector;
241 blk->nr_sectors = nr_sectors;
242
243 blk->iov.iov_base = blk->buf;
244 blk->iov.iov_len = nr_sectors * BDRV_SECTOR_SIZE;
245 qemu_iovec_init_external(&blk->qiov, &blk->iov, 1);
246
247 block_mig_state.submitted++;
248
249 blk->aiocb = bdrv_aio_readv(bs, cur_sector, &blk->qiov,
250 nr_sectors, blk_mig_read_cb, blk);
251
252 bdrv_reset_dirty(bs, cur_sector, nr_sectors);
253 bmds->cur_sector = cur_sector + nr_sectors;
254
255 return (bmds->cur_sector >= total_sectors);
256 }
257
258 static void set_dirty_tracking(int enable)
259 {
260 BlkMigDevState *bmds;
261
262 QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
263 bdrv_set_dirty_tracking(bmds->bs, enable ? BLOCK_SIZE : 0);
264 }
265 }
266
267 static void init_blk_migration_it(void *opaque, BlockDriverState *bs)
268 {
269 BlkMigDevState *bmds;
270 int64_t sectors;
271
272 if (!bdrv_is_read_only(bs)) {
273 sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS;
274 if (sectors <= 0) {
275 return;
276 }
277
278 bmds = g_malloc0(sizeof(BlkMigDevState));
279 bmds->bs = bs;
280 bmds->bulk_completed = 0;
281 bmds->total_sectors = sectors;
282 bmds->completed_sectors = 0;
283 bmds->shared_base = block_mig_state.shared_base;
284 alloc_aio_bitmap(bmds);
285 drive_get_ref(drive_get_by_blockdev(bs));
286 bdrv_set_in_use(bs, 1);
287
288 block_mig_state.total_sector_sum += sectors;
289
290 if (bmds->shared_base) {
291 DPRINTF("Start migration for %s with shared base image\n",
292 bs->device_name);
293 } else {
294 DPRINTF("Start full migration for %s\n", bs->device_name);
295 }
296
297 QSIMPLEQ_INSERT_TAIL(&block_mig_state.bmds_list, bmds, entry);
298 }
299 }
300
301 static void init_blk_migration(QEMUFile *f)
302 {
303 block_mig_state.submitted = 0;
304 block_mig_state.read_done = 0;
305 block_mig_state.transferred = 0;
306 block_mig_state.total_sector_sum = 0;
307 block_mig_state.prev_progress = -1;
308 block_mig_state.bulk_completed = 0;
309
310 bdrv_iterate(init_blk_migration_it, NULL);
311 }
312
313 static int blk_mig_save_bulked_block(QEMUFile *f)
314 {
315 int64_t completed_sector_sum = 0;
316 BlkMigDevState *bmds;
317 int progress;
318 int ret = 0;
319
320 QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
321 if (bmds->bulk_completed == 0) {
322 if (mig_save_device_bulk(f, bmds) == 1) {
323 /* completed bulk section for this device */
324 bmds->bulk_completed = 1;
325 }
326 completed_sector_sum += bmds->completed_sectors;
327 ret = 1;
328 break;
329 } else {
330 completed_sector_sum += bmds->completed_sectors;
331 }
332 }
333
334 if (block_mig_state.total_sector_sum != 0) {
335 progress = completed_sector_sum * 100 /
336 block_mig_state.total_sector_sum;
337 } else {
338 progress = 100;
339 }
340 if (progress != block_mig_state.prev_progress) {
341 block_mig_state.prev_progress = progress;
342 qemu_put_be64(f, (progress << BDRV_SECTOR_BITS)
343 | BLK_MIG_FLAG_PROGRESS);
344 DPRINTF("Completed %d %%\r", progress);
345 }
346
347 return ret;
348 }
349
350 static void blk_mig_reset_dirty_cursor(void)
351 {
352 BlkMigDevState *bmds;
353
354 QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
355 bmds->cur_dirty = 0;
356 }
357 }
358
359 static int mig_save_device_dirty(QEMUFile *f, BlkMigDevState *bmds,
360 int is_async)
361 {
362 BlkMigBlock *blk;
363 int64_t total_sectors = bmds->total_sectors;
364 int64_t sector;
365 int nr_sectors;
366 int ret = -EIO;
367
368 for (sector = bmds->cur_dirty; sector < bmds->total_sectors;) {
369 if (bmds_aio_inflight(bmds, sector)) {
370 bdrv_drain_all();
371 }
372 if (bdrv_get_dirty(bmds->bs, sector)) {
373
374 if (total_sectors - sector < BDRV_SECTORS_PER_DIRTY_CHUNK) {
375 nr_sectors = total_sectors - sector;
376 } else {
377 nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK;
378 }
379 blk = g_malloc(sizeof(BlkMigBlock));
380 blk->buf = g_malloc(BLOCK_SIZE);
381 blk->bmds = bmds;
382 blk->sector = sector;
383 blk->nr_sectors = nr_sectors;
384
385 if (is_async) {
386 blk->iov.iov_base = blk->buf;
387 blk->iov.iov_len = nr_sectors * BDRV_SECTOR_SIZE;
388 qemu_iovec_init_external(&blk->qiov, &blk->iov, 1);
389
390 blk->aiocb = bdrv_aio_readv(bmds->bs, sector, &blk->qiov,
391 nr_sectors, blk_mig_read_cb, blk);
392 block_mig_state.submitted++;
393 bmds_set_aio_inflight(bmds, sector, nr_sectors, 1);
394 } else {
395 ret = bdrv_read(bmds->bs, sector, blk->buf, nr_sectors);
396 if (ret < 0) {
397 goto error;
398 }
399 blk_send(f, blk);
400
401 g_free(blk->buf);
402 g_free(blk);
403 }
404
405 bdrv_reset_dirty(bmds->bs, sector, nr_sectors);
406 break;
407 }
408 sector += BDRV_SECTORS_PER_DIRTY_CHUNK;
409 bmds->cur_dirty = sector;
410 }
411
412 return (bmds->cur_dirty >= bmds->total_sectors);
413
414 error:
415 DPRINTF("Error reading sector %" PRId64 "\n", sector);
416 g_free(blk->buf);
417 g_free(blk);
418 return ret;
419 }
420
421 /* return value:
422 * 0: too much data for max_downtime
423 * 1: few enough data for max_downtime
424 */
425 static int blk_mig_save_dirty_block(QEMUFile *f, int is_async)
426 {
427 BlkMigDevState *bmds;
428 int ret = 1;
429
430 QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
431 ret = mig_save_device_dirty(f, bmds, is_async);
432 if (ret <= 0) {
433 break;
434 }
435 }
436
437 return ret;
438 }
439
440 static int flush_blks(QEMUFile *f)
441 {
442 BlkMigBlock *blk;
443 int ret = 0;
444
445 DPRINTF("%s Enter submitted %d read_done %d transferred %d\n",
446 __FUNCTION__, block_mig_state.submitted, block_mig_state.read_done,
447 block_mig_state.transferred);
448
449 while ((blk = QSIMPLEQ_FIRST(&block_mig_state.blk_list)) != NULL) {
450 if (qemu_file_rate_limit(f)) {
451 break;
452 }
453 if (blk->ret < 0) {
454 ret = blk->ret;
455 break;
456 }
457
458 QSIMPLEQ_REMOVE_HEAD(&block_mig_state.blk_list, entry);
459 blk_send(f, blk);
460
461 g_free(blk->buf);
462 g_free(blk);
463
464 block_mig_state.read_done--;
465 block_mig_state.transferred++;
466 assert(block_mig_state.read_done >= 0);
467 }
468
469 DPRINTF("%s Exit submitted %d read_done %d transferred %d\n", __FUNCTION__,
470 block_mig_state.submitted, block_mig_state.read_done,
471 block_mig_state.transferred);
472 return ret;
473 }
474
475 static int64_t get_remaining_dirty(void)
476 {
477 BlkMigDevState *bmds;
478 int64_t dirty = 0;
479
480 QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
481 dirty += bdrv_get_dirty_count(bmds->bs);
482 }
483
484 return dirty << BDRV_SECTOR_BITS;
485 }
486
487 static void blk_mig_cleanup(void)
488 {
489 BlkMigDevState *bmds;
490 BlkMigBlock *blk;
491
492 bdrv_drain_all();
493
494 set_dirty_tracking(0);
495
496 while ((bmds = QSIMPLEQ_FIRST(&block_mig_state.bmds_list)) != NULL) {
497 QSIMPLEQ_REMOVE_HEAD(&block_mig_state.bmds_list, entry);
498 bdrv_set_in_use(bmds->bs, 0);
499 drive_put_ref(drive_get_by_blockdev(bmds->bs));
500 g_free(bmds->aio_bitmap);
501 g_free(bmds);
502 }
503
504 while ((blk = QSIMPLEQ_FIRST(&block_mig_state.blk_list)) != NULL) {
505 QSIMPLEQ_REMOVE_HEAD(&block_mig_state.blk_list, entry);
506 g_free(blk->buf);
507 g_free(blk);
508 }
509 }
510
511 static void block_migration_cancel(void *opaque)
512 {
513 blk_mig_cleanup();
514 }
515
516 static int block_save_setup(QEMUFile *f, void *opaque)
517 {
518 int ret;
519
520 DPRINTF("Enter save live setup submitted %d transferred %d\n",
521 block_mig_state.submitted, block_mig_state.transferred);
522
523 init_blk_migration(f);
524
525 /* start track dirty blocks */
526 set_dirty_tracking(1);
527
528 ret = flush_blks(f);
529 blk_mig_reset_dirty_cursor();
530 qemu_put_be64(f, BLK_MIG_FLAG_EOS);
531
532 return ret;
533 }
534
535 static int block_save_iterate(QEMUFile *f, void *opaque)
536 {
537 int ret;
538 int64_t last_ftell = qemu_ftell(f);
539
540 DPRINTF("Enter save live iterate submitted %d transferred %d\n",
541 block_mig_state.submitted, block_mig_state.transferred);
542
543 ret = flush_blks(f);
544 if (ret) {
545 return ret;
546 }
547
548 blk_mig_reset_dirty_cursor();
549
550 /* control the rate of transfer */
551 while ((block_mig_state.submitted +
552 block_mig_state.read_done) * BLOCK_SIZE <
553 qemu_file_get_rate_limit(f)) {
554 if (block_mig_state.bulk_completed == 0) {
555 /* first finish the bulk phase */
556 if (blk_mig_save_bulked_block(f) == 0) {
557 /* finished saving bulk on all devices */
558 block_mig_state.bulk_completed = 1;
559 }
560 ret = 0;
561 } else {
562 ret = blk_mig_save_dirty_block(f, 1);
563 }
564 if (ret < 0) {
565 return ret;
566 }
567 if (ret != 0) {
568 /* no more dirty blocks */
569 break;
570 }
571 }
572
573 ret = flush_blks(f);
574 if (ret) {
575 return ret;
576 }
577
578 qemu_put_be64(f, BLK_MIG_FLAG_EOS);
579 return qemu_ftell(f) - last_ftell;
580 }
581
582 static int block_save_complete(QEMUFile *f, void *opaque)
583 {
584 int ret;
585
586 DPRINTF("Enter save live complete submitted %d transferred %d\n",
587 block_mig_state.submitted, block_mig_state.transferred);
588
589 ret = flush_blks(f);
590 if (ret) {
591 return ret;
592 }
593
594 blk_mig_reset_dirty_cursor();
595
596 /* we know for sure that save bulk is completed and
597 all async read completed */
598 assert(block_mig_state.submitted == 0);
599
600 do {
601 ret = blk_mig_save_dirty_block(f, 0);
602 if (ret < 0) {
603 return ret;
604 }
605 } while (ret == 0);
606
607 /* report completion */
608 qemu_put_be64(f, (100 << BDRV_SECTOR_BITS) | BLK_MIG_FLAG_PROGRESS);
609
610 DPRINTF("Block migration completed\n");
611
612 qemu_put_be64(f, BLK_MIG_FLAG_EOS);
613
614 blk_mig_cleanup();
615 return 0;
616 }
617
618 static uint64_t block_save_pending(QEMUFile *f, void *opaque, uint64_t max_size)
619 {
620 /* Estimate pending number of bytes to send */
621 uint64_t pending;
622
623 pending = get_remaining_dirty() +
624 block_mig_state.submitted * BLOCK_SIZE +
625 block_mig_state.read_done * BLOCK_SIZE;
626
627 /* Report at least one block pending during bulk phase */
628 if (pending == 0 && !block_mig_state.bulk_completed) {
629 pending = BLOCK_SIZE;
630 }
631
632 DPRINTF("Enter save live pending %" PRIu64 "\n", pending);
633 return pending;
634 }
635
636 static int block_load(QEMUFile *f, void *opaque, int version_id)
637 {
638 static int banner_printed;
639 int len, flags;
640 char device_name[256];
641 int64_t addr;
642 BlockDriverState *bs, *bs_prev = NULL;
643 uint8_t *buf;
644 int64_t total_sectors = 0;
645 int nr_sectors;
646 int ret;
647
648 do {
649 addr = qemu_get_be64(f);
650
651 flags = addr & ~BDRV_SECTOR_MASK;
652 addr >>= BDRV_SECTOR_BITS;
653
654 if (flags & BLK_MIG_FLAG_DEVICE_BLOCK) {
655 /* get device name */
656 len = qemu_get_byte(f);
657 qemu_get_buffer(f, (uint8_t *)device_name, len);
658 device_name[len] = '\0';
659
660 bs = bdrv_find(device_name);
661 if (!bs) {
662 fprintf(stderr, "Error unknown block device %s\n",
663 device_name);
664 return -EINVAL;
665 }
666
667 if (bs != bs_prev) {
668 bs_prev = bs;
669 total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS;
670 if (total_sectors <= 0) {
671 error_report("Error getting length of block device %s",
672 device_name);
673 return -EINVAL;
674 }
675 }
676
677 if (total_sectors - addr < BDRV_SECTORS_PER_DIRTY_CHUNK) {
678 nr_sectors = total_sectors - addr;
679 } else {
680 nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK;
681 }
682
683 buf = g_malloc(BLOCK_SIZE);
684
685 qemu_get_buffer(f, buf, BLOCK_SIZE);
686 ret = bdrv_write(bs, addr, buf, nr_sectors);
687
688 g_free(buf);
689 if (ret < 0) {
690 return ret;
691 }
692 } else if (flags & BLK_MIG_FLAG_PROGRESS) {
693 if (!banner_printed) {
694 printf("Receiving block device images\n");
695 banner_printed = 1;
696 }
697 printf("Completed %d %%%c", (int)addr,
698 (addr == 100) ? '\n' : '\r');
699 fflush(stdout);
700 } else if (!(flags & BLK_MIG_FLAG_EOS)) {
701 fprintf(stderr, "Unknown block migration flags: %#x\n", flags);
702 return -EINVAL;
703 }
704 ret = qemu_file_get_error(f);
705 if (ret != 0) {
706 return ret;
707 }
708 } while (!(flags & BLK_MIG_FLAG_EOS));
709
710 return 0;
711 }
712
713 static void block_set_params(const MigrationParams *params, void *opaque)
714 {
715 block_mig_state.blk_enable = params->blk;
716 block_mig_state.shared_base = params->shared;
717
718 /* shared base means that blk_enable = 1 */
719 block_mig_state.blk_enable |= params->shared;
720 }
721
722 static bool block_is_active(void *opaque)
723 {
724 return block_mig_state.blk_enable == 1;
725 }
726
727 SaveVMHandlers savevm_block_handlers = {
728 .set_params = block_set_params,
729 .save_live_setup = block_save_setup,
730 .save_live_iterate = block_save_iterate,
731 .save_live_complete = block_save_complete,
732 .save_live_pending = block_save_pending,
733 .load_state = block_load,
734 .cancel = block_migration_cancel,
735 .is_active = block_is_active,
736 };
737
738 void blk_mig_init(void)
739 {
740 QSIMPLEQ_INIT(&block_mig_state.bmds_list);
741 QSIMPLEQ_INIT(&block_mig_state.blk_list);
742
743 register_savevm_live(NULL, "block", 0, 1, &savevm_block_handlers,
744 &block_mig_state);
745 }