mirror of https://gitee.com/openkylin/libvirt.git
conf: Rename life cycle actions to event actions
While current on_{poweroff,reboot,crash} action configuration is about configuring life cycle actions, they can all be considered events and actions that need to be done on a particular event. Let's generalize the code by renaming life cycle actions to event actions so that it can be reused later for non-lifecycle events.
This commit is contained in:
parent
0ec6aebb64
commit
d0ea530b00
|
@ -907,15 +907,11 @@
|
||||||
This guest NUMA specification is currently available only for QEMU/KVM.
|
This guest NUMA specification is currently available only for QEMU/KVM.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h3><a name="elementsLifecycle">Lifecycle control</a></h3>
|
<h3><a name="elementsEvents">Events configuration</a></h3>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
It is sometimes necessary to override the default actions taken
|
It is sometimes necessary to override the default actions taken
|
||||||
when a guest OS triggers a lifecycle operation. The following
|
on various events.
|
||||||
collections of elements allow the actions to be specified. A
|
|
||||||
common use case is to force a reboot to be treated as a poweroff
|
|
||||||
when doing the initial OS installation. This allows the VM to be
|
|
||||||
re-configured for the first post-install bootup.
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
|
@ -925,6 +921,13 @@
|
||||||
<on_crash>restart</on_crash>
|
<on_crash>restart</on_crash>
|
||||||
...</pre>
|
...</pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The following collections of elements allow the actions to be
|
||||||
|
specified when a guest OS triggers a lifecycle operation. A
|
||||||
|
common use case is to force a reboot to be treated as a poweroff
|
||||||
|
when doing the initial OS installation. This allows the VM to be
|
||||||
|
re-configured for the first post-install bootup.
|
||||||
|
</p>
|
||||||
<dl>
|
<dl>
|
||||||
<dt><code>on_poweroff</code></dt>
|
<dt><code>on_poweroff</code></dt>
|
||||||
<dd>The content of this element specifies the action to take when
|
<dd>The content of this element specifies the action to take when
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
<ref name="clock"/>
|
<ref name="clock"/>
|
||||||
<ref name="resources"/>
|
<ref name="resources"/>
|
||||||
<ref name="features"/>
|
<ref name="features"/>
|
||||||
<ref name="termination"/>
|
<ref name="events"/>
|
||||||
<optional>
|
<optional>
|
||||||
<ref name="pm"/>
|
<ref name="pm"/>
|
||||||
</optional>
|
</optional>
|
||||||
|
@ -2226,10 +2226,10 @@
|
||||||
</element>
|
</element>
|
||||||
</define>
|
</define>
|
||||||
<!--
|
<!--
|
||||||
When a domain terminates multiple policies can be applied depending
|
When a certain event happens, multiple policies can be applied
|
||||||
on how it ended:
|
depends on what happened:
|
||||||
-->
|
-->
|
||||||
<define name="termination">
|
<define name="events">
|
||||||
<interleave>
|
<interleave>
|
||||||
<optional>
|
<optional>
|
||||||
<element name="on_reboot">
|
<element name="on_reboot">
|
||||||
|
|
|
@ -7518,11 +7518,12 @@ error:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int virDomainLifecycleParseXML(xmlXPathContextPtr ctxt,
|
static int virDomainEventActionParseXML(xmlXPathContextPtr ctxt,
|
||||||
const char *xpath,
|
const char *name,
|
||||||
int *val,
|
const char *xpath,
|
||||||
int defaultVal,
|
int *val,
|
||||||
virLifecycleFromStringFunc convFunc)
|
int defaultVal,
|
||||||
|
virEventActionFromStringFunc convFunc)
|
||||||
{
|
{
|
||||||
char *tmp = virXPathString(xpath, ctxt);
|
char *tmp = virXPathString(xpath, ctxt);
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
|
@ -7531,7 +7532,7 @@ static int virDomainLifecycleParseXML(xmlXPathContextPtr ctxt,
|
||||||
*val = convFunc(tmp);
|
*val = convFunc(tmp);
|
||||||
if (*val < 0) {
|
if (*val < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unknown lifecycle action %s"), tmp);
|
_("unknown %s action: %s"), name, tmp);
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -8941,20 +8942,25 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
|
||||||
VIR_FREE(nodes);
|
VIR_FREE(nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virDomainLifecycleParseXML(ctxt, "string(./on_reboot[1])",
|
if (virDomainEventActionParseXML(ctxt, "on_reboot",
|
||||||
&def->onReboot, VIR_DOMAIN_LIFECYCLE_RESTART,
|
"string(./on_reboot[1])",
|
||||||
virDomainLifecycleTypeFromString) < 0)
|
&def->onReboot,
|
||||||
|
VIR_DOMAIN_LIFECYCLE_RESTART,
|
||||||
|
virDomainLifecycleTypeFromString) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virDomainLifecycleParseXML(ctxt, "string(./on_poweroff[1])",
|
if (virDomainEventActionParseXML(ctxt, "on_poweroff",
|
||||||
&def->onPoweroff, VIR_DOMAIN_LIFECYCLE_DESTROY,
|
"string(./on_poweroff[1])",
|
||||||
virDomainLifecycleTypeFromString) < 0)
|
&def->onPoweroff,
|
||||||
|
VIR_DOMAIN_LIFECYCLE_DESTROY,
|
||||||
|
virDomainLifecycleTypeFromString) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virDomainLifecycleParseXML(ctxt, "string(./on_crash[1])",
|
if (virDomainEventActionParseXML(ctxt, "on_crash",
|
||||||
&def->onCrash,
|
"string(./on_crash[1])",
|
||||||
VIR_DOMAIN_LIFECYCLE_CRASH_DESTROY,
|
&def->onCrash,
|
||||||
virDomainLifecycleCrashTypeFromString) < 0)
|
VIR_DOMAIN_LIFECYCLE_CRASH_DESTROY,
|
||||||
|
virDomainLifecycleCrashTypeFromString) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virDomainPMStateParseXML(ctxt,
|
if (virDomainPMStateParseXML(ctxt,
|
||||||
|
@ -11452,15 +11458,15 @@ virDomainEmulatorPinDel(virDomainDefPtr def)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virDomainLifecycleDefFormat(virBufferPtr buf,
|
virDomainEventActionDefFormat(virBufferPtr buf,
|
||||||
int type,
|
int type,
|
||||||
const char *name,
|
const char *name,
|
||||||
virLifecycleToStringFunc convFunc)
|
virEventActionToStringFunc convFunc)
|
||||||
{
|
{
|
||||||
const char *typeStr = convFunc(type);
|
const char *typeStr = convFunc(type);
|
||||||
if (!typeStr) {
|
if (!typeStr) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unexpected lifecycle type %d"), type);
|
_("unexpected %s action: %d"), name, type);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13674,17 +13680,17 @@ virDomainDefFormatInternal(virDomainDefPtr def,
|
||||||
virBufferAddLit(buf, " </clock>\n");
|
virBufferAddLit(buf, " </clock>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virDomainLifecycleDefFormat(buf, def->onPoweroff,
|
if (virDomainEventActionDefFormat(buf, def->onPoweroff,
|
||||||
"on_poweroff",
|
"on_poweroff",
|
||||||
virDomainLifecycleTypeToString) < 0)
|
virDomainLifecycleTypeToString) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (virDomainLifecycleDefFormat(buf, def->onReboot,
|
if (virDomainEventActionDefFormat(buf, def->onReboot,
|
||||||
"on_reboot",
|
"on_reboot",
|
||||||
virDomainLifecycleTypeToString) < 0)
|
virDomainLifecycleTypeToString) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (virDomainLifecycleDefFormat(buf, def->onCrash,
|
if (virDomainEventActionDefFormat(buf, def->onCrash,
|
||||||
"on_crash",
|
"on_crash",
|
||||||
virDomainLifecycleCrashTypeToString) < 0)
|
virDomainLifecycleCrashTypeToString) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (def->pm.s3 || def->pm.s4) {
|
if (def->pm.s3 || def->pm.s4) {
|
||||||
|
|
|
@ -2144,8 +2144,8 @@ virDomainChrDefGetSecurityLabelDef(virDomainChrDefPtr def, const char *model);
|
||||||
virSecurityLabelDefPtr
|
virSecurityLabelDefPtr
|
||||||
virDomainDefAddSecurityLabelDef(virDomainDefPtr def, const char *model);
|
virDomainDefAddSecurityLabelDef(virDomainDefPtr def, const char *model);
|
||||||
|
|
||||||
typedef const char* (*virLifecycleToStringFunc)(int type);
|
typedef const char* (*virEventActionToStringFunc)(int type);
|
||||||
typedef int (*virLifecycleFromStringFunc)(const char *type);
|
typedef int (*virEventActionFromStringFunc)(const char *type);
|
||||||
|
|
||||||
VIR_ENUM_DECL(virDomainTaint)
|
VIR_ENUM_DECL(virDomainTaint)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue