I just wander if bdrv_is_allocated_above works as it is considered,
migrate image in format of qcow2 run into such backtrace:
#0 0x00007f9e73822c6d in lseek64 () at ../sysdeps/unix/syscall-template.S:82
#1 0x00007f9e765f08e4 in find_allocation (bs=<value optimized out>,
sector_num=<value optimized out>, nb_sectors=20480, pnum=0x7f9e7bab00fc)
at block/raw-posix.c:1285
#2 raw_co_get_block_status (bs=<value optimized out>,
sector_num=<value optimized out>, nb_sectors=20480, pnum=0x7f9e7bab00fc)
at block/raw-posix.c:1381
#3 0x00007f9e765cfe61 in bdrv_co_get_block_status (bs=0x7f9e790e4300, sector_num=
22470528, nb_sectors=20480, pnum=0x7f9e7bab00fc) at block.c:3593
#4 0x00007f9e765cffa8 in bdrv_co_get_block_status (bs=0x7f9e790e00a0, sector_num=
22466560, nb_sectors=<value optimized out>, pnum=0x7f9e7bab00fc)
at block.c:3620
#5 0x00007f9e765cfff7 in bdrv_get_block_status_co_entry (opaque=0x7f9e7bab0080)
at block.c:3639
#6 0x00007f9e765d0088 in bdrv_get_block_status (bs=<value optimized out>,
sector_num=<value optimized out>, nb_sectors=<value optimized out>,
pnum=<value optimized out>) at block.c:3663
#7 0x00007f9e765d00a9 in bdrv_is_allocated (bs=0x7f9e790e00a0,
sector_num=<value optimized out>, nb_sectors=<value optimized out>,
pnum=<value optimized out>) at block.c:3677
#8 0x00007f9e765d0166 in bdrv_is_allocated_above (top=0x7f9e790e00a0, base=0x0,
sector_num=22466560, nb_sectors=20480, pnum=0x7f9e7bab020c) at block.c:3709
#9 0x00007f9e765dcf9e in mirror_iteration (opaque=0x7f9e79486110)
at block/mirror.c:305
#10 mirror_run (opaque=0x7f9e79486110) at block/mirror.c:430
#11 0x00007f9e766120eb in coroutine_trampoline (i0=<value optimized out>,
i1=<value optimized out>) at coroutine-ucontext.c:118
#12 0x00007f9e734c4b70 in ?? () from /lib64/libc.so.6
#13 0x00007ffffa897850 in ?? ()
#14 0x0000000000000000 in ?? ()
it is too slow to tolerate…...
If guest discards a source cluster during mirror, we would want to discard target side as well.
Signed-off-by: Fam Zheng <f...@redhat.com> --- block/mirror.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 58f391a..37a5b61 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -163,6 +163,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) int64_t end, sector_num, next_chunk, next_sector, hbitmap_next_sector; uint64_t delay_ns = 0; MirrorOp *op; + int pnum; s->sector_num = hbitmap_iter_next(&s->hbi); if (s->sector_num < 0) { @@ -289,8 +290,15 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) s->in_flight++; s->sectors_in_flight += nb_sectors; trace_mirror_one_iteration(s, sector_num, nb_sectors); - bdrv_aio_readv(source, sector_num, &op->qiov, nb_sectors, - mirror_read_complete, op); + + if (!bdrv_is_allocated_above(source, NULL, sector_num, + nb_sectors, &pnum)) { + bdrv_aio_discard(s->target, sector_num, nb_sectors, + mirror_write_complete, op); + } else { + bdrv_aio_readv(source, sector_num, &op->qiov, nb_sectors, + mirror_read_complete, op); + } return delay_ns; } -- 1.9.3