Bug 1244080

Summary: Fail to create dir pool from virt-manager when the target path already exist
Product: Red Hat Enterprise Linux 7 Reporter: tingting zheng <tzheng>
Component: libvirtAssignee: John Ferlan <jferlan>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.2CC: cfergeau, dyuan, jferlan, juzhou, mzhan, rbalakri, xiaodwan, xuzhang, yanyang, yisun
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-1.2.17-3.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-11-19 06:48:05 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 tingting zheng 2015-07-17 03:35:22 UTC
Description:
Fail to create dir pool from virt-manager when the target path already exist

Version:
libvirt-python-1.2.17-1.el7.x86_64
libvirt-1.2.17-2.el7.x86_64
virt-manager-1.2.1-2.el7.noarch

How reproducible:
100%

Steps to Reproduce:
1.Create a directory,eg:/var/lib/libvirt/images/test

2.Launch virt-manager,create a dir pool named test,set the "Target Path" as an already existing directory,eg:the directory created in step 1.
Error shows:
Error creating pool: Could not build storage pool: failed to create directory '/var/lib/libvirt/images/test': File exists

Traceback (most recent call last):
  File "/usr/share/virt-manager/virtManager/asyncjob.py", line 89, in cb_wrapper
    callback(asyncjob, *args, **kwargs)
  File "/usr/share/virt-manager/virtManager/createpool.py", line 446, in _async_pool_create
    poolobj = self._pool.install(create=True, meter=meter, build=build)
  File "/usr/share/virt-manager/virtinst/storage.py", line 533, in install
    raise RuntimeError(errmsg)
RuntimeError: Could not build storage pool: failed to create directory '/var/lib/libvirt/images/test': File exists

3.The same error shows when I use pool-build to build a pool with already exist directory.
# cat test.xml
<pool type='dir'>
  <name>test</name>
  <source>
  </source>
  <target>
    <path>/var/lib/libvirt/images/test</path>
    <permissions>
      <mode>0711</mode>
      <owner>0</owner>
      <group>0</group>
    </permissions>
  </target>
</pool>

# virsh pool-define test.xml
Pool test defined from test.xml

# virsh pool-build test
error: Failed to build pool test
error: internal error: child failed to create '/var/lib/libvirt/images/test': exit status 17

Actual results:
As description.

Expected results:
Virt-manager can create pool with existing target path.

Additional info:
https://www.redhat.com/archives/libvir-list/2015-July/msg00602.html

Comment 2 Christophe Fergeau 2015-07-17 08:29:29 UTC
https://www.redhat.com/archives/libvir-list/2015-July/msg00627.html should hopefully fix that.

Comment 3 John Ferlan 2015-07-21 13:25:00 UTC
A patch was pushed upstream:

$ git show 60d5ed8c520462fd8fbc2d8dfac7b7c16ae5eb51
commit 60d5ed8c520462fd8fbc2d8dfac7b7c16ae5eb51
Author: Christophe Fergeau <cfergeau>
Date:   Fri Jul 17 10:02:20 2015 +0200

    storage: Fix pool building when directory already exists
    
    Currently, when trying to virsh pool-define/virsh pool-build a new
    'dir' pool, if the target directory already exists, virsh
    pool-build/virStoragePoolBuild will error out. This is a change of
    behaviour compared to eg libvirt 1.2.13
    
    This is caused by the wrong type being used for the dir_create_flags
    variable in virStorageBackendFileSystemBuild , it's defined as a bool
    but is used as a flag bit field so should be unsigned int (this matches
    the type virDirCreate expects for this variable).
    
    This should fix https://bugzilla.gnome.org/show_bug.cgi?id=752417 (GNOME
    Boxes) and https://bugzilla.redhat.com/show_bug.cgi?id=1244080
    (downstream virt-manager).
$ git describe 60d5ed8c520462fd8fbc2d8dfac7b7c16ae5eb51
v1.2.17-124-g60d5ed8
$

Comment 6 yisun 2015-08-25 06:29:30 UTC
test on:
libvirt-1.2.17-6.el7.x86_64
virt-manager-1.2.1-6.el7

VERIFIED. 


Steps:
pure libvirt:
1. # cat dir.pool 
<pool type='dir'>
  <name>test</name>
  <source>
  </source>
  <target>
    <path>/var/lib/libvirt/images/</path>
    <permissions>
      <mode>0711</mode>
      <owner>0</owner>
      <group>0</group>
    </permissions>
  </target>
</pool>

2. # ll /var/lib/libvirt/images
total 3649748
-rw-r--r--. 1 qemu qemu     197120 Aug  5 16:14 1.qcow2
-rw-r--r--. 1 root root    1048576 Aug 19 21:25 cdrom.img

3. # virsh pool-define dir.pool 
Pool test defined from dir.pool

4. # virsh pool-build test
Pool test built

5. # virsh pool-start test
Pool test started

6. # virsh vol-list test
 Name                 Path                                    
------------------------------------------------------------------------------
 1.qcow2              /var/lib/libvirt/images/1.qcow2         
 cdrom.img            /var/lib/libvirt/images/cdrom.img    


virt-manager:
1.Create a directory,/mnt
2.Click "Add Pool" button during creating new VM
3.Target path set to "/mnt"
4.Click OK and pool successfully created.

Comment 8 errata-xmlrpc 2015-11-19 06:48:05 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