From: Michal Privoznik <mpriv...@redhat.com> The domain object already has a member that allows storing hypervisor's PID (vm->pid). There's no need to duplicate it in _virCHMonitor struct. Switch CH code to use the former.
Signed-off-by: Michal Privoznik <mpriv...@redhat.com> --- src/ch/ch_events.c | 2 +- src/ch/ch_monitor.c | 10 ++-------- src/ch/ch_monitor.h | 2 -- src/ch/ch_process.c | 3 +-- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/ch/ch_events.c b/src/ch/ch_events.c index 9cb873d8cd..3d4e3c41e1 100644 --- a/src/ch/ch_events.c +++ b/src/ch/ch_events.c @@ -297,7 +297,7 @@ int virCHStartEventHandler(virCHMonitor *mon) { g_autofree char *name = NULL; - name = g_strdup_printf("ch-evt-%d", mon->pid); + name = g_strdup_printf("ch-evt-%d", mon->vm->pid); virObjectRef(mon); if (virThreadCreateFull(&mon->event_handler_thread, diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index 91899e873b..1c2c1f2858 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -672,14 +672,14 @@ virCHMonitorNew(virDomainObj *vm, virCHDriverConfig *cfg, int logfile) return NULL; } - if ((rv = virPidFileReadPath(priv->pidfile, &mon->pid)) < 0) { + if ((rv = virPidFileReadPath(priv->pidfile, &vm->pid)) < 0) { virReportSystemError(-rv, _("Domain %1$s didn't show up"), vm->def->name); return NULL; } VIR_DEBUG("CH vm=%p name=%s running with pid=%lld", - vm, vm->def->name, (long long)mon->pid); + vm, vm->def->name, (long long)vm->pid); /* open the reader end of fifo before start Event Handler */ while ((event_monitor_fd = open(mon->eventmonitorpath, O_RDONLY)) < 0) { @@ -727,12 +727,6 @@ void virCHMonitorClose(virCHMonitor *mon) if (!mon) return; - if (mon->pid > 0) { - /* try cleaning up the Cloud-Hypervisor process */ - virProcessAbort(mon->pid); - mon->pid = 0; - } - if (mon->handle) curl_easy_cleanup(mon->handle); diff --git a/src/ch/ch_monitor.h b/src/ch/ch_monitor.h index 185de0dbfd..ffac9e938e 100644 --- a/src/ch/ch_monitor.h +++ b/src/ch/ch_monitor.h @@ -108,8 +108,6 @@ struct _virCHMonitor { size_t buf_fill_sz; } event_buffer; - pid_t pid; - virDomainObj *vm; size_t nthreads; diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index 6a59bf756a..a008b52752 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -957,7 +957,6 @@ virCHProcessStart(virCHDriver *driver, } } - vm->pid = priv->monitor->pid; vm->def->id = vm->pid; priv->machineName = virCHDomainGetMachineName(vm); @@ -1024,6 +1023,7 @@ virCHProcessStop(virCHDriver *driver, virErrorPreserveLast(&orig_err); if (priv->monitor) { + virProcessAbort(vm->pid); g_clear_pointer(&priv->monitor, virCHMonitorClose); } @@ -1117,7 +1117,6 @@ virCHProcessStartRestore(virCHDriver *driver, virDomainObj *vm, const char *from } } - vm->pid = priv->monitor->pid; vm->def->id = vm->pid; priv->machineName = virCHDomainGetMachineName(vm); -- 2.49.0