Skip to content

Commit

Permalink
ch_monitor: Minor refactor of the cloud-hypervisor crash detection
Browse files Browse the repository at this point in the history
Signed-off-by: Vineeth Pillai <[email protected]>
  • Loading branch information
Vineeth Pillai authored and bryteise committed Apr 2, 2021
1 parent 77e469c commit b02d862
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions src/ch/ch_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,26 @@ static int virCHMonitorValidateEventsJSON(virCHMonitorPtr mon,
return events;
}

/*
* Caller should have locked the Domain
*/
static inline int virCHMonitorShutdownVm(virDomainObjPtr vm,
virDomainShutoffReason reason)
{
virCHDriverPtr driver = CH_DOMAIN_PRIVATE(vm)->driver;
g_autoptr(virCHDriverConfig) cfg = virCHDriverGetConfig(driver);

if (virCHDomainObjBeginJob(vm, CH_JOB_MODIFY))
return -1;

virCHProcessStop(driver, vm, reason);
if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir))
VIR_WARN("Failed to persist the domain after shutdown!");
virCHDomainObjEndJob(vm);

return 0;
}

/*
* Caller should have reference on Monitor and Domain
*/
Expand Down Expand Up @@ -750,21 +770,15 @@ static int virCHMonitorProcessEvent(virCHMonitorPtr mon,
case virCHMonitorVmmEventShutdown: // shutdown inside vmm
case virCHMonitorVmEventShutdown:
{
g_autoptr(virCHDriverConfig) cfg = virCHDriverGetConfig(driver);
virDomainState state;

virObjectLock(vm);
state = virDomainObjGetState(vm, NULL);
if ((ev == virCHMonitorVmmEventShutdown ||
state == VIR_DOMAIN_SHUTDOWN) &&
(virCHDomainObjBeginJob(vm, CH_JOB_MODIFY) == 0)) {

if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir))
VIR_WARN("Failed to persist the domain after shutdown!");

virCHProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN);

virCHDomainObjEndJob(vm);
state == VIR_DOMAIN_SHUTDOWN)) {
if (virCHMonitorShutdownVm(vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN))
VIR_WARN("Failed to mark the VM(%s) as SHUTDOWN!",
vm->def->name);
}
virObjectUnlock(vm);
break;
Expand Down Expand Up @@ -936,10 +950,16 @@ static int virCHMonitorReadProcessEvents(virCHMonitorPtr mon,

ret = read(monitor_fd, buf + sz, max_sz - sz);
if (ret == 0 || (ret < 0 && errno == EINTR)) {
if ((virPidFileReadPathIfAlive(priv->pidfile, &pid, priv->ch_path)) < 0 || (pid < 0)) {
virCHProcessStop(CH_DOMAIN_PRIVATE(vm)->driver, vm, VIR_DOMAIN_SHUTOFF_CRASHED);
return -1;
if (virPidFileReadPathIfAlive(priv->pidfile, &pid, priv->ch_path) < 0 ||
(pid < 0)) {
virObjectLock(vm);
if (virCHMonitorShutdownVm(vm, VIR_DOMAIN_SHUTOFF_CRASHED))
VIR_WARN("Failed to mark the VM(%s) as SHUTDOWN!",
vm->def->name);
virObjectUnlock(vm);
return 0;
}

g_usleep(G_USEC_PER_SEC);
continue;
} else if (ret < 0) {
Expand Down

0 comments on commit b02d862

Please sign in to comment.