Bug 1227664

Summary: Wrong type for dir type volume causes a failure when doing vol-delete
Product: Red Hat Enterprise Linux 7 Reporter: Yang Yang <yanyang>
Component: libvirtAssignee: John Ferlan <jferlan>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.2CC: dyuan, jferlan, mzhan, rbalakri, xuzhang, yisun
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-1.2.17-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-11-19 06:40:01 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 2015-06-03 09:08:04 UTC
Description of problem:
Do a vol-create to create a dir type volume in default pool. However,
the type got from both vol-info and vol-dumpxml is file so that deleting it
causes a failure.

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

How reproducible:
100%

Steps to Reproduce:
1. create vol
# cat vol.xml
<volume>
  <name>demo</name>
<capacity unit='bytes'>0</capacity>
  <source>
  </source>
  <target>
    <format type='dir'/>
  </target>
</volume>

# virsh vol-create default vol.xml
Vol demo created from vol.xml

2. check vol-dumpxml, vol-info
# virsh vol-dumpxml demo default
<volume type='file'>
  <name>demo</name>
  <key>/var/lib/libvirt/images/demo</key>
  <source>
  </source>
  <capacity unit='bytes'>0</capacity>
  <allocation unit='bytes'>0</allocation>
  <target>
    <path>/var/lib/libvirt/images/demo</path>
    <format type='dir'/>
    <permissions>
      <mode>0600</mode>
      <owner>0</owner>
      <group>0</group>
      <label>system_u:object_r:virt_image_t:s0</label>
    </permissions>
    <timestamps>
      <atime>1432868902.483414837</atime>
      <mtime>1432868902.483414837</mtime>
      <ctime>1432868902.483414837</ctime>
    </timestamps>
  </target>
</volume>

# virsh vol-info demo default
Name:           demo
Type:           file
Capacity:       0.00 B
Allocation:     0.00 B

# ll /var/lib/libvirt/images/demo/
total 0

3. delete vol
# virsh vol-delete demo default
error: Failed to delete vol demo
error: cannot unlink file '/var/lib/libvirt/images/demo': Is a directory

# virsh vol-list default | grep demo
 demo                 /var/lib/libvirt/images/demo

4. refresh pool
# virsh pool-refresh default
Pool default refreshed

# virsh vol-info demo default
Name:           demo
Type:           dir
Capacity:       0.00 B
Allocation:     0.00 B

# virsh vol-delete demo default
Vol demo deleted

Actual results:
Volume type gets from vol-info and vol-dumpxml is not dir, file instead. Deleting the volume failed. After doing a pool-refresh, volume type change to dir.

Expected results:
If it's supported to create dir type vol via vol-create with xml, fix the type
in the output of vol-dumpxml and vol-info.
If not supported, provide an error when creating volume.

Additional info:

Comment 2 John Ferlan 2015-06-29 18:25:14 UTC
According to bug 727088, having a directory in a fs pool is supported.  Seems that change missed the VolCreate path possibility for having a volume type setting.

Patch sent upstream:

http://www.redhat.com/archives/libvir-list/2015-June/msg01599.html

Comment 3 John Ferlan 2015-06-30 11:03:01 UTC
Patch pushed upstream:

commit e66a4c0b53a7a4a8afcb0d7d10b0569b84aac91c
Author: John Ferlan <jferlan>
Date:   Mon Jun 29 14:18:49 2015 -0400

    storage: Set correct vol->type at VolCreate
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1227664
    
    If the requested format type for the new entry in the file system pool
    is a 'dir', then be sure to set the vol->type correctly as would be done
    when the pool is refreshed.

$ git describe e66a4c0b53a7a4a8afcb0d7d10b0569b84aac91c
v1.2.17-rc1-4-ge66a4c0
$

Comment 5 yisun 2015-07-13 10:19:23 UTC
verified on libvirt-1.2.17-2.el7.x86_64


1. # cat vol.xml 
<volume>
  <name>demo</name>
<capacity unit='bytes'>0</capacity>
  <source>
  </source>
  <target>
    <format type='dir'/>
  </target>
</volume>


2. # virsh vol-create default vol.xml
Vol demo created from vol.xml

3. # virsh vol-dumpxml demo default
<volume type='dir'>    <===== modified as expect.
  <name>demo</name>
  <key>/home/pool/demo</key>
  <source>
  </source>
  <capacity unit='bytes'>0</capacity>
  <allocation unit='bytes'>0</allocation>
  <target>
    <path>/home/pool/demo</path>
    <format type='dir'/>
    <permissions>
      <mode>0600</mode>
      <owner>0</owner>
      <group>0</group>
      <label>system_u:object_r:home_root_t:s0</label>
    </permissions>
    <timestamps>
      <atime>1436782523.935482441</atime>
      <mtime>1436782523.935482441</mtime>
      <ctime>1436782523.935482441</ctime>
    </timestamps>
  </target>
</volume>

4. # virsh vol-info demo default
Name:           demo
Type:           dir    <==== modified as expected. 
Capacity:       0.00 B
Allocation:     0.00 B

5. # virsh vol-delete demo default
Vol demo deleted   <==== can be deleted due to type is corrected. 


6. # virsh pool-refresh default; virsh vol-list default
Pool default refreshed

 Name                 Path                                    
------------------------------------------------------------------------------

Comment 7 errata-xmlrpc 2015-11-19 06:40:01 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/RHBA-2015-2202.html