static int virLXCProcessAutostartDomain(virDomainObjPtr vm, void *opaque) { const struct virLXCProcessAutostartData *data = opaque; int ret = 0; virObjectLock(vm); if (vm->autostart && !virDomainObjIsActive(vm)) { ret = virLXCProcessStart(data->conn, data->driver, vm, 0, NULL, false, VIR_DOMAIN_RUNNING_BOOTED); virDomainAuditStart(vm, "booted", ret >= 0); if (ret < 0) { virErrorPtr err = virGetLastError(); VIR_ERROR(_("Failed to autostart VM '%s': %s"), vm->def->name, err ? err->message : ""); } else { virObjectEventPtr event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STARTED, VIR_DOMAIN_EVENT_STARTED_BOOTED); if (event) virObjectEventStateQueue(data->driver->domainEventState, event); } } virObjectUnlock(vm); return ret; }
static int virLXCProcessReboot(virLXCDriverPtr driver, virDomainObjPtr vm) { virConnectPtr conn = virLXCProcessAutoDestroyGetConn(driver, vm); int reason = vm->state.reason; bool autodestroy = false; int ret = -1; virDomainDefPtr savedDef; VIR_DEBUG("Faking reboot"); if (conn) { virConnectRef(conn); autodestroy = true; } else { conn = virConnectOpen("lxc:///"); /* Ignoring NULL conn which is mostly harmless here */ } /* In a reboot scenario, we need to make sure we continue * to use the current 'def', and not switch to 'newDef'. * So temporarily hide the newDef and then reinstate it */ savedDef = vm->newDef; vm->newDef = NULL; virLXCProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN); vm->newDef = savedDef; if (virLXCProcessStart(conn, driver, vm, autodestroy, reason) < 0) { VIR_WARN("Unable to handle reboot of vm %s", vm->def->name); goto cleanup; } if (conn) virConnectClose(conn); ret = 0; cleanup: return ret; }