Bug 1088667

Summary: [storage] some volume related virsh commands work when the passed volume is not one volume of the passed pool
Product: Red Hat Enterprise Linux 7 Reporter: Yang Yang <yanyang>
Component: libvirtAssignee: Peter Krempa <pkrempa>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1CC: dyuan, mzhan, pkrempa, pzhang, rbalakri, shyu, xuzhang
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-1.2.7-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-03-05 07:34:13 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 Yang Yang 2014-04-17 01:10:49 UTC
Description:
Tried to resize volume by running virsh cmd vol-resize by passing an pool and passing the full volume path. But the volume passed is not one of the volumes of the passed pool. Finally, resize successfully.

Product Version:
libvirt-1.1.1-29.el7.x86_64
qemu-kvm-rhev-1.5.3-60.el7ev.x86_64

How producible:
Always

Steps:
1. Create a qcow3 format volume in default pool
# cat qcow3-vol2.xml
<volume>
  <name>qcow3-vol2</name>
  <source>
  </source>
  <capacity unit='bytes'>1024000000</capacity>
  <allocation unit='bytes'>204000</allocation>
  <target>
    <format type='qcow2'/>
    <compat>1.1</compat>
    <features>
    <lazy_refcounts/>
    </features>
  </target>
</volume>

# virsh vol-create default qcow3-vol2.xml
Vol qcow3-vol2 created from qcow3-vol2.xml

# ll /var/lib/libvirt/images/qcow3-vol2
-rw-------. 1 qemu qemu 17826304 Mar 28 15:12 /var/lib/libvirt/images/qcow3-vol2

2.# virsh pool-list --all
Name                 State      Autostart
-----------------------------------------
default              active     yes       
fs                   active     no

# virsh pool-dumpxml fs | grep path
    <path>/mnt</path>


# virsh vol-list fs
Name                 Path                                    
-----------------------------------------
lost+found           /mnt/lost+found                        
qcow3-vol            /mnt/qcow3-vol                          
qcow3-vol3           /mnt/qcow3-vol3

Make sure there is no volume named qcow3-vol2 in fs pool.

3. Resize the volume by passing pool fs and path of volume qcow3-vol2 which is in default pool
# virsh vol-resize --pool fs /var/lib/libvirt/images/qcow3-vol2 6G
Size of volume 'qcow3-vol2' successfully changed to 6G


Actual results:
in step 3: As above shows.

Expected results:
in step 3:
Should check if the passed volume exists in the passed pool. The command should quit and return with error like this:
error: Storage vol not found: no storage vol with matching name 'qcow3-vol2' in pool fs

Additional info:
The same issue was hit by virsh cmd vol-upload, vol-download, vol-clone, vol-wipe, vol-delete, vol-dumpxml, vol-info, vol-key, vol-path.

Comment 1 Peter Krempa 2014-06-02 09:03:57 UTC
Fixed upstream:

commit 6ef0b03483281659f2e1e321da9c56c97e05a305
Author: Peter Krempa <pkrempa>
Date:   Fri May 30 14:44:55 2014 +0200

    virsh: Check whether found volume is member of the specified storage pool
    
    When looking up storage volumes virsh uses multiple lookup steps. Some
    of the steps don't require a pool name specified. This resulted into a
    possibility that a volume would be part of a different pool than the
    user specified:
    
    Let's have a /var/lib/libvirt/images/test.qcow image in the 'default'
    pool and a second pool 'emptypool':
    
    Currently we'd return:
      $ virsh vol-info --pool emptypool /var/lib/libvirt/images/test.qcow
      Name:           test.qcow
      Type:           file
      Capacity:       100.00 MiB
      Allocation:     212.00 KiB
    
    After the fix:
     $ tools/virsh vol-info --pool emptypool /var/lib/libvirt/images/test.qcow
     error: Requested volume '/var/lib/libvirt/images/test.qcow' is not in pool 'emptypool'

Comment 3 Pei Zhang 2014-12-01 09:31:03 UTC
verify version:
libvirt-1.2.8-9.el7.x86_64
qemu-kvm-rhev-2.1.2-13.el7.x86_64
kernel-3.10.0-211.el7.x86_64

steps:

prepare a pool of  other type and create volumes in the pool.

1.check the volume in pool
# virsh vol-list default --details| grep test.img 
 test.img          /var/lib/libvirt/images/test.img          file    1.00 GiB    1.00 GiB

# virsh vol-list fs-pool1 --details| grep test.img 
 test.img    /var/lib/libvirt/images/fs-pool/test.img    file  1.00 GiB    1.00 GiB

# virsh vol-list dir-pool --details | grep vol1.xml
 vol1.xml     /tmp/dir-pool/vol1.xml     file    358.00 B    4.00 KiB

2.test commands vol-X using mismatching pool and volume.

# virsh vol-info --pool fs-pool1 /var/lib/libvirt/images/test.img
error: Requested volume '/var/lib/libvirt/images/test.img' is not in pool 'fs-pool1'

# virsh vol-resize --pool fs-pool1 /var/lib/libvirt/images/test.img 2G
error: Requested volume '/var/lib/libvirt/images/test.img' is not in pool 'fs-pool1'

# virsh vol-upload --pool default /tmp/dir-pool/vol1.xml disk-volume.xml 
error: Requested volume '/tmp/dir-pool/vol1.xml' is not in pool 'default'

# virsh vol-download /tmp/dir-pool/vol1.xml test-pool.xml --pool default
error: Requested volume '/tmp/dir-pool/vol1.xml' is not in pool 'default'

# virsh vol-key --pool fs-pool1 /var/lib/libvirt/images/test.img 
error: Requested volume '/var/lib/libvirt/images/test.img' is not in pool 'fs-pool1'

Tt will give a clear error message if the volume does not match the pool when using other vol-X commands . 

3.test commands vol-X using matched pool and volume.

# virsh vol-key /var/lib/libvirt/images/fs-pool/test.img --pool fs-pool1
/var/lib/libvirt/images/fs-pool/test.img

# virsh vol-key --pool fs-pool1 /var/lib/libvirt/images/fs-pool/test.img 
/var/lib/libvirt/images/fs-pool/test.img

# virsh vol-resize --pool fs-pool1 /var/lib/libvirt/images/fs-pool/test.img 2G
Size of volume 'test.img' successfully changed to 2G

# ll /var/lib/libvirt/images/fs-pool/test.img -h
-rw-------. 1 root root 2.0G Dec  1 14:31 /var/lib/libvirt/images/fs-pool/test.img

4. test command vol-X  just using volume name and matched pool name instead of absolute path when the two volume has a same name. 

# virsh vol-info test.img default
Name:           test.img
Type:           file
Capacity:       1.00 GiB
Allocation:     1.00 GiB

# virsh vol-info test.img fs-pool1
Name:           test.img
Type:           file
Capacity:       2.00 GiB
Allocation:     1.00 GiB

# virsh vol-key test.img fs-pool1
/var/lib/libvirt/images/fs-pool/test.img

# virsh vol-key test.img default
/var/lib/libvirt/images/test.img

it will check the specified storage pool .move to verified.

Comment 5 errata-xmlrpc 2015-03-05 07:34:13 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-2015-0323.html