1

Description of problem:

On Centos machine, if we try to delete the SCSI disk image for running vm (which is added via virt-manager) through virsh vol-delete command, getting "cannot unlink file 'XXX': Success" error.

This error occurs intermittently and occurs only if we try to delete disk image when vm is running.

Version-Release number of selected component (if applicable):

OS:CentOS Linux release 7.2.1511

Libvirt: [root@CV-HJ-CentOS7-02 images]# virsh version Compiled against library: libvirt 1.2.17 Using library: libvirt 1.2.17 Using API: QEMU 1.2.17 Running hypervisor: QEMU 1.5.3

Steps to Reproduce:

  1. Add SCSI disk from virt manager to VM
  2. Start VM from virt-manager and confirm disk is attached as SCSI.
  3. Try to delete the newly added SCSI disk using virsh vol-delete command: virsh # vol-delete /var/lib/libvirt/images/.img

Actual results:

It is giving Following error: error: Failed to delete vol /var/lib/libvirt/images/.img error: cannot unlink file '/var/lib/libvirt/images/.img': Success

2 Answers2

2

It looks like you're trying to delete the disk image before detaching it from the running VM which isn't allowed. You'll need to detach the disk first, then do a pool refresh and then you'll be able to delete it.

Here's an example using "f23-tst_default" as the name of my VM (domain) and a disk named "f23-test_default.qcow2" which I want to remove:

# virsh domblklist f23-tst_default
Target     Source
------------------------------------------------
vda        /var/lib/libvirt/images/f23-tst_default.img
sda        /var/lib/libvirt/images/f23-tst_default.qcow2

# virsh detach-disk f23-tst_default --target sda
Disk detached successfully

# virsh domblklist f23-tst_default                                 
Target     Source
------------------------------------------------
vda        /var/lib/libvirt/images/f23-tst_default.img

# virsh pool-refresh default
Pool default refreshed

# virsh vol-delete --pool default f23-tst_default.qcow2            
Vol f23-tst_default.qcow2 deleted

If you don't do a 'pool-refresh' then virsh doesn't realize that the domain is no longer using the volume and, therefore, won't allow you to remove it.

foobrew
  • 1,766
  • 1
  • 11
  • 3
2

I faced the same issue and it was a file permissions problem. I too faced it after upgrading from Centos 7.1 to 7.2.

To resolve make sure that the owner of the directory where the image is stored (default pool is /var/lib/libvirt/images) is the one defined in "user" option in /etc/libvirt/qemu.conf (default user is qemu).

If you haven't touched the defaults then:

# chown qemu:qemu /var/lib/libvirt/images

Then create a new image and try to delete it. It should succeed.

Babis
  • 21
  • 1
  • 4
  • 1
    This also fixes the permission error in ```vagrant destroy``` when using ```vagrant-libvirt```. see https://github.com/vagrant-libvirt/vagrant-libvirt/issues/641 – Sebastian Wagner Aug 11 '16 at 07:53
  • great solution but on Ubuntu 16.04.1 I get `chown: invalid user: 'qemu:qemu'`. Instead I had to `sudo chown libvirt-qemu:libvirtd /var/lib/libvirt/images` and it worked. – Chaim Eliyah Sep 16 '16 at 01:37