Bug 1534491

Summary: Mirror jobs for drives with iothreads make QEMU to abort with "block.c:1895: bdrv_attach_child: Assertion `bdrv_get_aio_context(parent_bs) == bdrv_get_aio_context(child_bs)' failed."
Product: Red Hat Enterprise Linux 7 Reporter: Sergio Lopez <slopezpa>
Component: qemu-kvm-rhevAssignee: Stefan Hajnoczi <stefanha>
Status: CLOSED ERRATA QA Contact: Qianqian Zhu <qizhu>
Severity: high Docs Contact:
Priority: high    
Version: 7.4CC: aliang, amureini, chayang, coli, gwatson, juzhang, knoel, michen, mkalinin, mtessun, qizhu, virt-maint, xfu
Target Milestone: rcKeywords: ZStream
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: QEMU 2.10 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1535125 (view as bug list) Environment:
Last Closed: 2018-04-11 00:58:52 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1535125    

Description Sergio Lopez 2018-01-15 11:17:30 UTC
Description of problem:

 * Preparing the images

# qemu-img create -f raw base.img 1g
# qemu-img create -f qcow2 -o backing_file=base.img top1.qcow2
# qemu-img create -f qcow2 -o backing_file=base.img top2.qcow2


 * Running with iothreads

# /usr/libexec/qemu-kvm -m 1g -drive if=none,file=top1.qcow2,format=qcow2,id=drive0 -object iothread,id=iothread0 -device virtio-blk-pci,iothread=iothread0,drive=drive0 -monitor stdio 
QEMU 2.9.0 monitor - type 'help' for more information
(qemu) drive_mirror -n drive0 top2.qcow2
(qemu) info block-jobs
Type mirror, device drive0: Completed 0 of 0 bytes, speed limit 0 bytes/s
(qemu) block_job_complete drive0
qemu-kvm: block.c:1895: bdrv_attach_child: Assertion `bdrv_get_aio_context(parent_bs) == bdrv_get_aio_context(child_bs)' failed.
Aborted (core dumped)


 * Running without iothreads

# /usr/libexec/qemu-kvm -m 1g -drive if=none,file=top1.qcow2,format=qcow2,id=drive0 -device virtio-blk-pci,drive=drive0 -monitor stdio
QEMU 2.9.0 monitor - type 'help' for more information
(qemu) drive_mirror -n drive0 top2.qcow2
(qemu) info block-jobs
Type mirror, device drive0: Completed 0 of 0 bytes, speed limit 0 bytes/s
(qemu) block_job_complete drive0
(qemu) info block-jobs
No active jobs


Version-Release number of selected component (if applicable):

qemu-kvm-rhev-2.9.0-16.el7_4.13.x86_64


How reproducible:

Always


Additional info:

This has been fixed in upstream by this oneliner:

<snip>
[slopezpa@dritchie qemu]$ git show 5ce6bfe255091d532ec4555d0ede816294cb1703
commit 5ce6bfe255091d532ec4555d0ede816294cb1703
Author: sochin.jiang <sochin.jiang>
Date:   Mon Jun 26 19:04:24 2017 +0800

    mirror: Fix inconsistent backing AioContext for after mirroring
    
    mirror_complete opens the backing chain, which should have the same
    AioContext as the top when using iothreads. Make the code guarantee
    this, which fixes a failed assertion in bdrv_attach_child.
    
    Signed-off-by: sochin.jiang <sochin.jiang>
    Message-id: 1498475064-39816-1-git-send-email-sochin.jiang
    [mreitz: Reworded commit message]
    Signed-off-by: Max Reitz <mreitz>

diff --git a/block.c b/block.c
index edfa6b7a2c..b9e5114a27 100644
--- a/block.c
+++ b/block.c
@@ -2185,6 +2185,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options,
         ret = -EINVAL;
         goto free_exit;
     }
+    bdrv_set_aio_context(backing_hd, bdrv_get_aio_context(bs));
 
     /* Hook up the backing file link; drop our reference, bs owns the
      * backing_hd reference now */
</snip>


Please consider backporting this. Thanks.

Comment 4 Qianqian Zhu 2018-01-16 02:54:46 UTC
Reproduced on qemu-kvm-rhev-10:2.9.0-14.el7.x86_64 with steps in comment 0.

If mirror source file is base, wont trigger the core dump, the source file must be a snapshot for this issue.

Same steps work well on qemu-kvm-rhev-2.10.0-16.el7.x86_64, so the latest version qemu should have already fixed this issue.

Comment 5 Ademar Reis 2018-01-16 11:35:36 UTC
(In reply to Qianqian Zhu from comment #4)
> Reproduced on qemu-kvm-rhev-10:2.9.0-14.el7.x86_64 with steps in comment 0.
> 
> If mirror source file is base, wont trigger the core dump, the source file
> must be a snapshot for this issue.
> 
> Same steps work well on qemu-kvm-rhev-2.10.0-16.el7.x86_64, so the latest
> version qemu should have already fixed this issue.

Indeed, I confirmed the upstream patch pointed in Comment #0 is included in qemu-2.10, changing BZ to MODIFIED.

Comment 8 Qianqian Zhu 2018-01-23 06:23:53 UTC
Move to VERIFIED per comment 4.

Comment 10 errata-xmlrpc 2018-04-11 00:58:52 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2018:1104