On 05/04/2011 08:45 AM, Jiri Denemark wrote:
Only in drivers which use virDomainObj, drivers that query
hypervisor
for domain status need to be updated separately in case their hypervisor
supports this functionality.
The reason is also saved into domain state XML so if a domain is not
running (i.e., no state XML exists) the reason will be lost by libvirtd
restart. I think this is an acceptable limitation.
+void
+virDomainObjSetState(virDomainObjPtr dom, virDomainState state, int reason)
+{
+ int last = -1;
+
+ switch (state) {
+ case VIR_DOMAIN_NOSTATE: last = VIR_DOMAIN_NOSTATE_LAST; break;
+ case VIR_DOMAIN_RUNNING: last = VIR_DOMAIN_RUNNING_LAST; break;
+ case VIR_DOMAIN_BLOCKED: last = VIR_DOMAIN_BLOCKED_LAST; break;
+ case VIR_DOMAIN_PAUSED: last = VIR_DOMAIN_PAUSED_LAST; break;
+ case VIR_DOMAIN_SHUTDOWN: last = VIR_DOMAIN_SHUTDOWN_LAST; break;
+ case VIR_DOMAIN_SHUTOFF: last = VIR_DOMAIN_SHUTOFF_LAST; break;
+ case VIR_DOMAIN_CRASHED: last = VIR_DOMAIN_CRASHED_LAST; break;
+ }
+
+ if (last < 0) {
+ VIR_ERROR(_("invalid domain state: %d"), state);
+ return;
+ }
+
+ dom->state.state = state;
+ if (reason > 0 || reason < last)
&&, not ||
ACK with that nit fixed. virDomainObjSetState does not need a flags
parameter, even though the public API has one (a virCheckFlags at each
of the public API is sufficient to be the end of the line for that
argument, and it does not have to propagate into src/conf/domain_conf.c).
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library
http://libvirt.org