RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1250331 - Change-media cannot insert if disk source element with startupPolicy
Summary: Change-media cannot insert if disk source element with startupPolicy
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.2
Hardware: x86_64
OS: Unspecified
medium
medium
Target Milestone: rc
: ---
Assignee: Michal Privoznik
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-08-05 07:47 UTC by Pei Zhang
Modified: 2016-11-03 18:22 UTC (History)
7 users (show)

Fixed In Version: libvirt-1.3.2-1.el7
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-11-03 18:22:24 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2016:2577 0 normal SHIPPED_LIVE Moderate: libvirt security, bug fix, and enhancement update 2016-11-03 12:07:06 UTC

Description Pei Zhang 2015-08-05 07:47:05 UTC
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 16:08:50 UTC
Patch proposed upstream:

https://www.redhat.com/archives/libvir-list/2015-September/msg00912.html

Comment 2 Michal Privoznik 2015-09-29 12:01:07 UTC
I've just pushed the patch upstream:

commit d72a8f7465896572b38521d1d3e82e7d36eb3f4e
Author:     Michal Privoznik <mprivozn>
AuthorDate: Thu Sep 24 18:00:06 2015 +0200
Commit:     Michal Privoznik <mprivozn>
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>

v1.2.20-rc1-3-gd72a8f7

Comment 3 Han Han 2016-01-05 08:52:04 UTC
I test it on upstream latest version with the steps in Comment1.Bug reproduced.

Comment 4 Han Han 2016-01-13 08:14:09 UTC
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 16:44:54 UTC
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 16:09:07 UTC
Pushed upstream:

commit 9cbd1ecc3ec4d6079327b6a24a518a454276aafe
Author:     Michal Privoznik <mprivozn>
AuthorDate: Wed Jan 13 17:32:05 2016 +0100
Commit:     Michal Privoznik <mprivozn>
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>

Comment 8 Pei Zhang 2016-03-04 09:38:36 UTC
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 18:22:24 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://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.