From edadd46c05b1eb93479a88017783bae648709bfa Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Wed, 27 Apr 2016 14:58:32 +0200 Subject: [PATCH] qemu: process: Fix failure semantics for perf events For strange reasons if a perf event type was not supported or failed to be enabled at VM start libvirt would ignore the failure. On the other hand on restart if the event could not be re-enabled libvirt would fail to reconnect to the VM and kill it. Both don't make really sense. Fix it by failing to start the VM if the event is not supported and change the event to disabled if it can't be reconnected (unlikely). Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1329045 --- src/qemu/qemu_process.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 4dd0fc37f9..8ca9841fe5 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3501,17 +3501,14 @@ qemuDomainPerfRestart(virDomainObjPtr vm) for (i = 0; i < VIR_PERF_EVENT_LAST; i++) { if (def->perf->events[i] && def->perf->events[i] == VIR_TRISTATE_BOOL_YES) { - if (virPerfEventEnable(priv->perf, i, vm->pid)) - goto cleanup; + + /* Failure to re-enable the perf event should not be fatal */ + if (virPerfEventEnable(priv->perf, i, vm->pid) < 0) + def->perf->events[i] = VIR_TRISTATE_BOOL_NO; } } return 0; - - cleanup: - virPerfFree(priv->perf); - priv->perf = NULL; - return -1; } struct qemuProcessReconnectData { @@ -5414,8 +5411,9 @@ qemuProcessLaunch(virConnectPtr conn, goto cleanup; for (i = 0; i < VIR_PERF_EVENT_LAST; i++) { - if (vm->def->perf->events[i] == VIR_TRISTATE_BOOL_YES) - virPerfEventEnable(priv->perf, i, vm->pid); + if (vm->def->perf->events[i] == VIR_TRISTATE_BOOL_YES && + virPerfEventEnable(priv->perf, i, vm->pid) < 0) + goto cleanup; } /* This must be done after cgroup placement to avoid resetting CPU