qemu: Preserve fakeReboot flag in domain status

Thus, when libvirtd is restarted, it will know if a domain is supposed
to be killed or reset when it shuts down.
This commit is contained in:
Jiri Denemark 2011-09-28 12:10:13 +02:00
parent cc0e4e8ddb
commit bd83b2a371
4 changed files with 32 additions and 8 deletions

View File

@ -302,6 +302,9 @@ static int qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void *data)
virBufferAddLit(buf, "/>\n");
}
if (priv->fakeReboot)
virBufferAsprintf(buf, " <fakereboot/>\n");
return 0;
}
@ -445,6 +448,8 @@ static int qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void *data)
}
}
priv->fakeReboot = virXPathBoolean("boolean(./fakereboot)", ctxt) == 1;
return 0;
error:
@ -1566,3 +1571,19 @@ qemuDomainRemoveInactive(struct qemud_driver *driver,
}
virDomainRemoveInactive(&driver->domains, vm);
}
void
qemuDomainSetFakeReboot(struct qemud_driver *driver,
virDomainObjPtr vm,
bool value)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
if (priv->fakeReboot == value)
return;
priv->fakeReboot = value;
if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0)
VIR_WARN("Failed to save status on vm %s", vm->def->name);
}

View File

@ -273,4 +273,8 @@ int qemuDomainSnapshotDiscardAllMetadata(struct qemud_driver *driver,
void qemuDomainRemoveInactive(struct qemud_driver *driver,
virDomainObjPtr vm);
void qemuDomainSetFakeReboot(struct qemud_driver *driver,
virDomainObjPtr vm,
bool value);
#endif /* __QEMU_DOMAIN_H__ */

View File

@ -1512,13 +1512,13 @@ static int qemuDomainShutdown(virDomainPtr dom) {
goto endjob;
}
qemuDomainSetFakeReboot(driver, vm, false);
priv = vm->privateData;
qemuDomainObjEnterMonitor(driver, vm);
ret = qemuMonitorSystemPowerdown(priv->mon);
qemuDomainObjExitMonitor(driver, vm);
priv->fakeReboot = false;
endjob:
if (qemuDomainObjEndJob(driver, vm) == 0)
vm = NULL;
@ -1575,7 +1575,8 @@ static int qemuDomainReboot(virDomainPtr dom, unsigned int flags) {
ret = qemuMonitorSystemPowerdown(priv->mon);
qemuDomainObjExitMonitor(driver, vm);
priv->fakeReboot = true;
if (ret == 0)
qemuDomainSetFakeReboot(driver, vm, true);
endjob:
if (qemuDomainObjEndJob(driver, vm) == 0)
@ -1616,7 +1617,6 @@ qemuDomainDestroyFlags(virDomainPtr dom,
virDomainObjPtr vm;
int ret = -1;
virDomainEventPtr event = NULL;
qemuDomainObjPrivatePtr priv;
virCheckFlags(0, -1);
@ -1630,8 +1630,7 @@ qemuDomainDestroyFlags(virDomainPtr dom,
goto cleanup;
}
priv = vm->privateData;
priv->fakeReboot = false;
qemuDomainSetFakeReboot(driver, vm, false);
/* Although qemuProcessStop does this already, there may
* be an outstanding job active. We want to make sure we

View File

@ -442,7 +442,7 @@ qemuProcessShutdownOrReboot(virDomainObjPtr vm)
priv->gotShutdown = true;
if (priv->fakeReboot) {
priv->fakeReboot = false;
qemuDomainSetFakeReboot(qemu_driver, vm, false);
virDomainObjRef(vm);
virThread th;
if (virThreadCreate(&th,
@ -2846,7 +2846,7 @@ int qemuProcessStart(virConnectPtr conn,
goto cleanup;
vm->def->id = driver->nextvmid++;
priv->fakeReboot = false;
qemuDomainSetFakeReboot(driver, vm, false);
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_UNKNOWN);
/* Run an early hook to set-up missing devices */