[libvirt] [PATCH 5/6] qemu: process: Fix failure semantics for perf events

Peter Krempa pkrempa at redhat.com
Wed Apr 27 13:32:33 UTC 2016


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 f8d13aa..af06aa6 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
-- 
2.8.1




More information about the libvir-list mailing list