}
+static void
+qemuDomainModifyLifecycleAction(virDomainDefPtr def,
+ virDomainLifecycle type,
+ virDomainLifecycleAction action)
+{
+ switch (type) {
+ case VIR_DOMAIN_LIFECYCLE_POWEROFF:
+ def->onPoweroff = action;
+ break;
+ case VIR_DOMAIN_LIFECYCLE_REBOOT:
+ def->onReboot = action;
+ break;
+ case VIR_DOMAIN_LIFECYCLE_CRASH:
+ def->onCrash = action;
+ break;
+ case VIR_DOMAIN_LIFECYCLE_LAST:
+ break;
+ }
+}
+
+
+
+static int
+qemuDomainSetLifecycleAction(virDomainPtr dom,
+ unsigned int type,
+ unsigned int action,
+ unsigned int flags)
+{
+ virQEMUDriverPtr driver = dom->conn->privateData;
+ virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ qemuDomainObjPrivatePtr priv;
+ virDomainObjPtr vm = NULL;
+ virDomainDefPtr def = NULL;
+ virDomainDefPtr persistentDef = NULL;
+ int ret = -1;
+
+ virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+ VIR_DOMAIN_AFFECT_CONFIG, -1);
+
+ if (!virDomainDefLifecycleActionAllowed(type, action))
+ goto cleanup;
+
+ if (!(vm = qemuDomObjFromDomain(dom)))
+ goto cleanup;
+
+ priv = vm->privateData;
+
+ if (virDomainSetLifecycleActionEnsureACL(dom->conn, vm->def) < 0)
+ goto cleanup;
+
+ if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
+ goto cleanup;
+
+ if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
+ goto endjob;
+
+ if (def) {
+ if (priv->allowReboot == VIR_TRISTATE_BOOL_NO) {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+ _("cannot update lifecycle action because QEMU "
+ "was started with -no-reboot option"));
+ goto endjob;
+ }
+
+ qemuDomainModifyLifecycleAction(def, type, action);
+
+ if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir,
+ vm, driver->caps) < 0)
+ goto endjob;
+ }
+
+ if (persistentDef) {
+ qemuDomainModifyLifecycleAction(persistentDef, type, action);
+
+ if (virDomainSaveConfig(cfg->configDir, driver->caps,
+ persistentDef) < 0)
+ goto endjob;
+ }
+
+ ret = 0;
+
+ endjob:
+ qemuDomainObjEndJob(driver, vm);
+
+ cleanup:
+ virDomainObjEndAPI(&vm);
+ virObjectUnref(cfg);
+ return ret;
+}
+
+
static virHypervisorDriver qemuHypervisorDriver = {
.name = QEMU_DRIVER_NAME,
.connectOpen = qemuConnectOpen, /* 0.2.0 */
.domainGetGuestVcpus = qemuDomainGetGuestVcpus, /* 2.0.0 */
.domainSetGuestVcpus = qemuDomainSetGuestVcpus, /* 2.0.0 */
.domainSetVcpu = qemuDomainSetVcpu, /* 3.1.0 */
- .domainSetBlockThreshold = qemuDomainSetBlockThreshold /* 3.2.0 */
+ .domainSetBlockThreshold = qemuDomainSetBlockThreshold, /* 3.2.0 */
+ .domainSetLifecycleAction = qemuDomainSetLifecycleAction, /* 3.9.0 */
};