
Am Freitag, 21. Mai 2010 schrieb Cole Robinson:
On 05/21/2010 08:11 AM, Guido Winkelmann wrote:
Hi,
Sometimes when stopping a virtual domain using virDomainDestroy(), I come across a domain that is already stopped. (For example when someone already stopped the domain manually using virsh or because the guest OS issued a shutdown.) This is a special case that I absolutely need to catch and handle.
In virt-manager, we basically do:
def destroy(vm): if vm.is_running(): vm.destroy() return
I'd recommend doing something similar in your app: no reason to run a command if you can check ahead of time if it will fail. You can use virDomainIsActive to check the domain status.
That's not a real solution. It might reduce the frequency with which the problem occurs, but it's still subject to a race condition.
Unfortunately, when this happens, and I call virGetLastError() afterwards, I always just get the error code VIR_ERR_OPERATION_INVALID, which doesn't look very precise to me...
Two questions about this:
Is the domain not running at that moment the only possible condition that can trigger this particular error code when calling virDomainDestroy()?
Yes, there are other errors but none that use OPERATION_INVALID.
After switching from libvirt 0.8.1 to libvirt from git, I'm getting VIR_ERR_RPC when trying to stop a domain that is not running. :( Could this be caused by a mismatch of the libvirt versions between the machine my code is running on (0.8.1) and the version of libvirt on the qemu host (git)? Guido