Guido Winkelmann
2010-May-21 12:11 UTC
[libvirt-users] Better error codes when stopping a VM that is already stopped
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. 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()? Can't we have a more obvious/precise error code in that case, like VIR_ERR_DOMAIN_NOT_RUNNING or something like that? Guido Winkelmann
Cole Robinson
2010-May-21 15:50 UTC
[libvirt-users] Better error codes when stopping a VM that is already stopped
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.> 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.> Can't we have a more obvious/precise error code in that case, like > VIR_ERR_DOMAIN_NOT_RUNNING or something like that? >Sounds like a reasonable idea, won't help you though if your app needs to support older versions. - Cole
Daniel P. Berrange
2010-May-24 10:24 UTC
[libvirt-users] Better error codes when stopping a VM that is already stopped
On Fri, May 21, 2010 at 02:11:47PM +0200, 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. > > 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()?The VIR_ERR_OPERATION_INVALID is a precise code that says the request operation is not valid wrt the current state of the guest. So for the virDomainDestroy() method, the only cause of this message is requesting destroy of a guest that is not running. Similarly you'll get it if you try to start a guest that is already running.> Can't we have a more obvious/precise error code in that case, like > VIR_ERR_DOMAIN_NOT_RUNNING or something like that?The VIR_ERR_OPERATION_INVALID is already very precisely defined as you need. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Possibly Parallel Threads
- Bug? virGetLastError() returns NULL after virDomainCreate() if Domain running already
- Re: VIR_ERR_OPERATION_INVALID from virDomainDestroyFlags call
- VIR_ERR_OPERATION_INVALID from virDomainDestroyFlags call
- [PATCH libguestfs v3] lib: Handle slow USB devices more gracefully.
- Cannot create qcow2 images with libvirt 0.8.1