问题
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:
- Add SCSI disk from virt manager to VM
- Start VM from virt-manager and confirm disk is attached as SCSI.
- 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
回答1:
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.
回答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.
来源:https://stackoverflow.com/questions/35339399/centos-libvirt-for-running-vm-virsh-vol-delete-command-fails-while-deleting-sc