KVM how to determine which virtual disk files are in use by VMs

kvm-virtualizationlibvirtlsofqemu

I tried lsof|grep *.qcow2 and got no results back (why is that? I definitely have VMs running using that disk format).

I also considered grepping qcow2 on *.xml within the config directory, but this wouldn't tell me which were in use necessarily.

Is there an easy way to determine which disk images are in use and by which domains/VMs?

Also, since lsof doesn't seem to do what I want, what is the method you all use to determine which files are accessed by which process?

Running Cent 6.3 with libvirt/kvm/qemu virsh 0.10.2

EDIT: See my comment, it was grep that was failing me, not lsof.. What is going on that I need to enable Extended regex to match '*.qcow2' ?

Best Answer

Since the file format and extension quite often differ (libvirt's defauls is .img usually - for both qcow2 and raw), and sometimes you're using LVs and not files, I'd start looking into the currently used storage directly:
ps -ef |grep qcow2|awk -F'-drive' '{ print $2 }'|cut -d',' -f1
This will only show the first disk, you can extend the script to show more