On 5/24/2010 6:24 AM, Daniel P. Berrange wrote:
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.
You are saying there is, and can only ever be, one possible way that the
operation could ever be considered invalid?
Even within the limited scope of virDomainDestroy() and the particular
values it was called with, I find that hard to believe on general principle.
I can see that, say, it may not make any sense to try to tell the
difference between "never was created" and "created but now
destroyed".
Such distinctions probably belong in front end distro init scripts and
other admin utils. IE: your script or util tracks whether or not it has
tried to start a domain and whether or not the fact that it's not
currently running is expected or an error.
--
bkw