Bug 1250331 - Change-media cannot insert if disk source element with startupPolicy
Change-media cannot insert if disk source element with startupPolicy
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt (Show other bugs)
7.2
x86_64 Unspecified
medium Severity medium
: rc
: ---
Assigned To: Michal Privoznik
Virtualization Bugs
: Upstream
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2015-08-05 03:47 EDT by Pei Zhang
Modified: 2016-11-03 14:22 EDT (History)
7 users (show)

See Also:
Fixed In Version: libvirt-1.3.2-1.el7
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2016-11-03 14:22:24 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Pei Zhang 2015-08-05 03:47:05 EDT
Description of problem:
Change-media cannot insert if source element with startupPolicy

Version-Release number of selected component (if applicable):
libvirt-1.2.17-3.el7.x86_64

How reproducible:
100%

1.Define and start a guest like following :

# virsh dumpxml r7-vm1 | grep disk -A 9
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source startupPolicy='optional'/>
      <backingStore/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <alias name='ide0-1-0'/>
      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
    </disk>


# virsh domblklist r7-vm1
Target     Source
------------------------------------------------
hdc        -
vda        /var/lib/libvirt/images/r7.1-rls-q2.img
sdb        iqn.2008-09.5.165.3ffe.104:server.target3/1


2. insert a media
# virsh change-media r7-vm1 hdc --insert /var/lib/libvirt/images/b.iso
error: The disk device 'hdc' already has media


3.insert a media via --update
# virsh change-media r7-vm1 hdc --update /var/lib/libvirt/images/b.iso
Successfully updated media.

Actual results :
As step2, fail to insert a media

Expexted results :
the media can be inserted .

Additional info :
It can also be reproduced with RHEL7.1 released libvirt.
Perhaps the issue is long lasting.
Comment 1 Michal Privoznik 2015-09-24 12:08:50 EDT
Patch proposed upstream:

https://www.redhat.com/archives/libvir-list/2015-September/msg00912.html
Comment 2 Michal Privoznik 2015-09-29 08:01:07 EDT
I've just pushed the patch upstream:

commit d72a8f7465896572b38521d1d3e82e7d36eb3f4e
Author:     Michal Privoznik <mprivozn@redhat.com>
AuthorDate: Thu Sep 24 18:00:06 2015 +0200
Commit:     Michal Privoznik <mprivozn@redhat.com>
CommitDate: Tue Sep 29 13:29:29 2015 +0200

    virsh: Preserve startupPolicy in change-media command
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1250331
    
    Even after my rework of startupPolicy handling, one command
    slipped my attention. The change-media command has a very unique
    approach to constructing disk XML. However, it will not preserve
    startupPolicy attribute.
    
    Signed-off-by: Michal Privoznik <mprivozn@redhat.com>

v1.2.20-rc1-3-gd72a8f7
Comment 3 Han Han 2016-01-05 03:52:04 EST
I test it on upstream latest version with the steps in Comment1.Bug reproduced.
Comment 4 Han Han 2016-01-13 03:14:09 EST
Test it on the upstream version v1.3.1-rc1-15-g71daae9 as comment1 does. Bug reproduced. Pls check it.
Comment 5 Michal Privoznik 2016-01-13 11:44:54 EST
Ah. Thanks for the notice. I've proposed this fix upstream:

https://www.redhat.com/archives/libvir-list/2016-January/msg00530.html
Comment 6 Michal Privoznik 2016-01-25 11:09:07 EST
Pushed upstream:

commit 9cbd1ecc3ec4d6079327b6a24a518a454276aafe
Author:     Michal Privoznik <mprivozn@redhat.com>
AuthorDate: Wed Jan 13 17:32:05 2016 +0100
Commit:     Michal Privoznik <mprivozn@redhat.com>
CommitDate: Mon Jan 25 15:57:23 2016 +0100

    virsh: Correctly detect inserted media in change-media command
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1250331
    
    It all works like this. The change-media command dumps domain
    XML, finds the corresponding cdrom device we want to change media
    in and returns it in the xmlNodePtr form. This way we don't have
    to bother with keeping all the subelements or attributes that we
    don't care about in the XML that is fed back to libvirt for the
    update API.
    
    Now, the problem is we try to be clever here and detect if disk
    already has a source (indicated by <source/> subelement).
    However, bare fact that the element is there does not mean disk
    has source. Make our clever check better.
    
    Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Comment 8 Pei Zhang 2016-03-04 04:38:36 EST
Verified Version :
libvirt-1.3.2-1.el7.x86_64
qemu-kvm-rhev-2.3.0-31.el7_2.8.x86_64 

steps : 
1.Define and start a guest like following 

# virsh dumpxml r72|grep disk -A 9
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source startupPolicy='optional'/>
      <backingStore/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <alias name='ide0-1-0'/>
      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
    </disk>

2. change-media insert a cdrom 

# virsh change-media r72 --insert hdc /mnt/at-dt/change-media/a.iso 
Successfully inserted media.

2.1 check doamin xml again

# virsh dumpxml r72|grep cdrom -A 9
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/mnt/at-dt/change-media/a.iso' startupPolicy='optional'>
        <seclabel model='selinux' labelskip='yes'/>
      </source>
      <backingStore/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <alias name='ide0-1-0'/>
      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
2.2 login guest to check, the cdrom is useful.

3. change-media update cdrom source.

# virsh change-media r72 --update hdc /mnt/at-dt/change-media/b.iso 
Successfully updated media.

# virsh domblklist r72
Target     Source
------------------------------------------------
hdc        /mnt/at-dt/change-media/b.iso
vda        /mnt/r73_test/r72rls.qcow2

4. change-media insert cdrom which already has a source 

# virsh domblklist r72 --details
Type       Device     Target     Source
------------------------------------------------
file       cdrom      hdc        /mnt/at-dt/change-media/a.iso
volume     cdrom      hde        r7.2-boot.iso
file       disk       vda        /mnt/r73_test/r72rls.qcow2


# virsh change-media --insert r72 hde /mnt/at-dt/change-media/b.iso 
error: The disk device 'hde' already has media

As above, move this bug to verified.
Comment 10 errata-xmlrpc 2016-11-03 14:22:24 EDT
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://rhn.redhat.com/errata/RHSA-2016-2577.html

Note You need to log in before you can comment on or make changes to this bug.