[libvirt-users] Destroy VM failed.

Eric Blake eblake at redhat.com
Mon May 7 18:05:40 UTC 2012

On 05/06/2012 09:12 PM, david_zhu wrote:
> Hi,
> When I destroy a VM, sometimes virsh will report failed.
> So I tried the following shell script:
> -bash-4.1# for ((i=0; i<1000; i++)); do virsh start david_mac; virsh destroy 
> david_mac; if [ $? != 0 ] ; then echo $i; break; fi; done
> Domain david_mac started
> Domain david_mac destroyed
> ......
> Domain david_mac started
> error: Failed to destroy domain david_mac
> error: Requested operation is not valid: domain is not running

Bear in mind that there is an inherent race: a guest could itself
request a shutdown prior to the point that you issue the destroy
command, in which case the destroy will fail because the guest is
already shutdown.  Since the end goal is the same (the guest is shut off
either way), it is a good idea to write your scripts to be robust to
this particular race.

That said, if your guest isn't specifically requesting a shutdown, it
seems odd that you are encountering a race, so there may be something
else at play here.  Does the log of the guest give any particular hints?

Eric Blake   eblake at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20120507/1b0df347/attachment.sig>

More information about the libvirt-users mailing list