Bug 1461301

Summary: unknown error occurred when attach a disk with a pci address already occupied in guest while virtlockd is enabled
Product: Red Hat Enterprise Linux 7 Reporter: yafu <yafu>
Component: libvirtAssignee: Peter Krempa <pkrempa>
Status: CLOSED ERRATA QA Contact: Han Han <hhan>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.4CC: dyuan, eskultet, hhan, lmen, pkrempa, rbalakri, xuzhang, zpeng
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-3.8.0-1.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-04-10 10:48:37 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:

Description yafu 2017-06-14 07:25:07 UTC
Description of problem:
unknown error occurred when attach a disk with a pci address already occupied in guest while virtlockd is enabled

Version-Release number of selected component (if applicable):
libvirt-3.2.0-9.virtcov.el7.x86_64
qemu-kvm-rhev-2.9.0-10.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1.Set lock_manageer as 'lockd' and restart libvirtd service:
#cat /etc/libvirt/qemu.conf
lock_manager = 'lockd'
#systemctl restart libvirtd

2.Start a guest:
#virsh start full-73

3.Prepare a disk with pci address aleardy occupied in guest:
#cat disk.xml
  <disk type='file' device='disk'>
       <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/test.qcow2'/>
      <target dev='vdb' bus='virtio'/>
      ****<address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>***
    </disk>

4.Hotplug the disk to the guest:
#virsh attach-device full-73 disk.xml
error: Failed to attach device from disk.xml
error: An error occurred, but the cause is unknown

Actual results:
unknown error occurred when attach a disk with a pci address already occupied in guest while virtlockd is enabled

Expected results:
Should report clear error as follows:
# virsh attach-device full-73 disk.xml
error: Failed to attach device from disk.xml
error: XML error: Attempted double use of PCI Address 0000:00:0a.0

Comment 2 Han Han 2017-06-14 08:01:58 UTC
Confirmed regression:
It works on libvirt-2.0.0-10.el7_3.9.x86_64 of RHEL7.3.z

1. Set lock_manager = "lockd" in /etc/libvirt/qemu.conf
2. Restart virtlockd and libvirtd
3. Start a VM:
# virsh list 
 Id    Name                           State
----------------------------------------------------
 1     avocado-vt-vm1                 running

4. Attach a disk with pci address then detach it:
# virsh attach-disk avocado-vt-vm1 /tmp/raw vdb  --address pci:0000.00.a.0
Disk attached successfully

# virsh detach-disk avocado-vt-vm1 vdb                                    
Disk detached successfully

Comment 3 Han Han 2017-06-14 08:39:57 UTC
Sorry for the mistake in comment2. Actually it is not a regression, in other words, it can be reproduced on libvirt-2.0.0-10.el7_3.9.x86_64

One more scenario:
It can be reproduce when attach to an unreachable pci address:
# virsh attach-disk avocado-vt-vm1 /tmp/raw vdb  --address pci:000a.00.6.0
error: Failed to attach disk
error: An error occurred, but the cause is unknown

Comment 4 Peter Krempa 2017-09-15 03:40:19 UTC
Fixed upstream:

commit a823d0a62e858a62a585a78599b6d859c5b4dcac 
Author: Peter Krempa <pkrempa>
Date:   Mon Sep 11 15:28:15 2017 +0200

    qemu: Restore errors when rolling back disk image state
    
    Some operations done to rollback disk image labelling and locking might
    overwrite (or clear) the actual error. Remember the original error when
    tearing down disk access so that it's not obscured.

Comment 6 Han Han 2017-11-07 02:38:53 UTC
Verified on libvirt-3.9.0-1.el7.x86_64:
1. Setup virtlockd env:
In qemu.conf:
lock_manager = "lockd"

# systemctl restart virtlockd
# systemctl restart libvirtd

2. Start an VM. Attach two disks to the same pci address
# virsh attach-disk V /tmp/a vdb --address pci:0000.00.a.0
Disk attached successfully

# virsh attach-disk V /tmp/b vdc --address pci:0000.00.a.0
error: Failed to attach disk
error: XML error: Attempted double use of PCI Address 0000:00:0a.0

Libvirt gives clear error message when attaching to duplicate pci address.
Bug fixed.

Comment 10 errata-xmlrpc 2018-04-10 10:48:37 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/RHEA-2018:0704