Bug 1130489

Summary: qemu do not close src image immediately after mirroring done
Product: Red Hat Enterprise Linux 7 Reporter: Xiaoqing Wei <xwei>
Component: qemu-kvm-rhevAssignee: Jeff Cody <jcody>
Status: CLOSED NOTABUG QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1CC: chayang, hhuang, huding, juzhang, qizhu, shyu, virt-maint, xfu, yanyang
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-02-16 00:35:04 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description Xiaoqing Wei 2014-08-15 11:53:24 UTC
Description of problem:

qemu do not close src image immediately after mirroring done

Version-Release number of selected component (if applicable):
qemu-img-rhev-2.1.0-1.el7.x86_64
qemu-kvm-common-rhev-2.1.0-1.el7.x86_64
libcacard-devel-rhev-2.1.0-1.el7.x86_64
libcacard-rhev-2.1.0-1.el7.x86_64
qemu-kvm-rhev-2.1.0-1.el7.x86_64
qemu-kvm-tools-rhev-2.1.0-1.el7.x86_64
qemu-kvm-rhev-debuginfo-2.1.0-1.el7.x86_64


How reproducible:
1 / 1

Steps to Reproduce:
0. Prepare two LVMs, 10G *1, 32G *1, and convert a OS img into the 10G(origin img should has 30G virtual size and < 10G actual size)


1.boot a vm
/bin/qemu-kvm -monitor stdio  \
    -S  \
    -name 'virt-tests-vm1'  \
    -sandbox off  \
    -M pc  \
    -nodefaults  \
    -vga std  \
    -chardev socket,id=qmp_id_qmpmonitor1,path=/tmp/monitor-qmpmonitor1-20140815-110559-kPOHZHpD,server,nowait \
    -mon chardev=qmp_id_qmpmonitor1,mode=control  \
    -chardev socket,id=serial_id_serial0,path=/tmp/serial-serial0-20140815-110559-kPOHZHpD,server,nowait \
    -device isa-serial,chardev=serial_id_serial0  \
    -chardev socket,id=seabioslog_id_20140815-110559-kPOHZHpD,path=/tmp/seabios-20140815-110559-kPOHZHpD,server,nowait \
    -device isa-debugcon,chardev=seabioslog_id_20140815-110559-kPOHZHpD,iobase=0x402 \
    -device ich9-usb-uhci1,id=usb1,bus=pci.0,addr=03 \
    -drive id=drive_image1,if=none,cache=none,snapshot=off,aio=native,file='/dev/rhel/lv10g' \
    -device ide-hd,id=image1,drive=drive_image1,bus=ide.0,unit=0 \
    -device virtio-net-pci,mac=9a:a2:a3:a4:a5:a6,id=id4CoZYU,vectors=4,netdev=idd5Ponr,bus=pci.0,addr=04  \
    -netdev tap,id=idd5Ponr,vhost=on  \
    -m 4096  \
    -smp 4,maxcpus=4,cores=2,threads=1,sockets=2  \
    -cpu 'SandyBridge'  \
    -drive id=drive_cd1,if=none,snapshot=off,aio=native,media=cdrom,file=/root/staf-kvm-devel/autotest-devel/client/tests/virt/shared/data/isos/windows/winutils.iso \
    -device ide-cd,id=cd1,drive=drive_cd1,bus=ide.0,unit=1 \
    -device usb-tablet,id=usb-tablet1,bus=usb1.0,port=1  \
    -vnc :0  \
    -rtc base=localtime,clock=host,driftfix=slew  \
    -boot order=cdn,once=c,menu=off \
    -enable-kvm
# info block
drive_image1: /dev/rhel/lv10g (qcow2)
    I/O status:       nospace

drive_cd1: /root/staf-kvm-devel/autotest-devel/client/tests/virt/shared/data/isos/windows/winutils.iso (raw, read-only)
    Removable device: not locked, tray closed

2. mirror the img
{"execute": "drive-mirror", "arguments": {"device": "drive_image1", "mode": "absolute-paths", "format": "qcow2", "target": "/dev/rhel/raw30g", "sync": "full"}, "id": "rUUcP4XX"}
{"return": {}, "id": "rUUcP4XX"}

3. tell qemu to switch the underlying storage
{"execute": "block-job-complete", "arguments": { "device": "drive_image1"} }
{"return": {}}

4. lsof to check both src and target image
[root@localhost ~]# lsof /dev/rhel/lv10g
COMMAND    PID USER   FD   TYPE DEVICE    SIZE/OFF     NODE NAME
qemu-kvm 30966 root   30u   BLK  253,3 0x280000000 29334404 /dev/rhel/../dm-3
[root@localhost ~]# lsof /dev/rhel/raw30g
COMMAND    PID USER   FD   TYPE DEVICE    SIZE/OFF     NODE NAME
qemu-kvm 30966 root   26u   BLK  253,4 0x800000000 29334414 /dev/rhel/../dm-4

5. reboot the VM, and keep filling it's space(till the data > 10G, so that cant held on the src lvm ),
then it closed the src img
[root@localhost ~]# lsof /dev/rhel/lv10g
[root@localhost ~]# lsof /dev/rhel/raw30g
COMMAND    PID USER   FD   TYPE DEVICE    SIZE/OFF     NODE NAME
qemu-kvm 30966 root   26u   BLK  253,4 0x800000000 29334414 /dev/rhel/../dm-4

Actual results:
as 4 shown
Expected results:
step 4 should got same output as 5 shown.

Additional info:

tested on RHEL.6.6, qemu closed the src immediately.

Comment 5 Jeff Cody 2016-02-16 00:35:04 UTC
I've tried reproducing this bug with LVM images, qcow2 standard files, using scsi, virtio, and ide devices.  I've not been able to reproduce this on any qemu-kvm-rhev version (or upstream master).

I wonder if perhaps in the initial report, although a block-job-complete was issued, if the test essentially had a race condition.  Since the command was just issued once in the shell, if it was done prior to receiving the 'BLOCK_JOB_COMPLETED' from QEMU then the source would not yet be closed.

Given that, the lack of reproduction, and that it isn't clear that it is an issue even if we did not close the source fd immediately, I'm closing this as NOTABUG.