9c6c51
From 4df55f75bf523e3c1964198299713bdfa85fbad2 Mon Sep 17 00:00:00 2001
9c6c51
Message-Id: <4df55f75bf523e3c1964198299713bdfa85fbad2@dist-git>
9c6c51
From: John Ferlan <jferlan@redhat.com>
9c6c51
Date: Wed, 14 Nov 2018 14:41:31 -0500
9c6c51
Subject: [PATCH] qemu: Set identity for the reconnect all thread
9c6c51
9c6c51
https://bugzilla.redhat.com/show_bug.cgi?id=1648546 (RHEL8)
9c6c51
https://bugzilla.redhat.com/show_bug.cgi?id=1631622 (RHEL7)
9c6c51
9c6c51
If polkit authentication is enabled, an attempt to open
9c6c51
the connection failed during virAccessDriverPolkitGetCaller
9c6c51
when the call to virIdentityGetCurrent returned NULL resulting
9c6c51
in the errors:
9c6c51
9c6c51
  virAccessDriverPolkitGetCaller:87 : access denied:
9c6c51
  Policy kit denied action org.libvirt.api.connect.getattr from <anonymous>
9c6c51
9c6c51
Because qemuProcessReconnect runs in a thread during
9c6c51
daemonRunStateInit processing it doesn't have the thread
9c6c51
local identity. Thus when the virGetConnectNWFilter is
9c6c51
called as part of the qemuProcessFiltersInstantiate when
9c6c51
virDomainConfNWFilterInstantiate is run the attempt to get
9c6c51
the idenity fails and results in the anonymous error above.
9c6c51
9c6c51
To fix this, let's grab/use the virIdenityPtr of the process
9c6c51
that will be creating the thread, e.g. what daemonRunStateInit
9c6c51
has set and use that for our thread. That way any other similar
9c6c51
processing that uses/requires an identity for any other call
9c6c51
that would have previously been successfully run won't fail in
9c6c51
a similar manner.
9c6c51
9c6c51
Signed-off-by: John Ferlan <jferlan@redhat.com>
9c6c51
(cherry picked from commit b04b82f8cb671f067bad2d5e922acf88f13f0934)
9c6c51
Reviewed-by: Erik Skultety <eskultet@redhat.com>
9c6c51
---
9c6c51
 src/qemu/qemu_process.c | 7 +++++++
9c6c51
 1 file changed, 7 insertions(+)
9c6c51
9c6c51
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
9c6c51
index 8ba14abfa4..4b99fbd835 100644
9c6c51
--- a/src/qemu/qemu_process.c
9c6c51
+++ b/src/qemu/qemu_process.c
9c6c51
@@ -81,6 +81,7 @@
9c6c51
 #include "netdev_bandwidth_conf.h"
9c6c51
 #include "virresctrl.h"
9c6c51
 #include "virvsock.h"
9c6c51
+#include "viridentity.h"
9c6c51
 
9c6c51
 #define VIR_FROM_THIS VIR_FROM_QEMU
9c6c51
 
9c6c51
@@ -7609,6 +7610,7 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver,
9c6c51
 struct qemuProcessReconnectData {
9c6c51
     virQEMUDriverPtr driver;
9c6c51
     virDomainObjPtr obj;
9c6c51
+    virIdentityPtr identity;
9c6c51
 };
9c6c51
 /*
9c6c51
  * Open an existing VM's monitor, re-detect VCPU threads
9c6c51
@@ -7645,6 +7647,8 @@ qemuProcessReconnect(void *opaque)
9c6c51
     virCapsPtr caps = NULL;
9c6c51
     bool retry = true;
9c6c51
 
9c6c51
+    virIdentitySetCurrent(data->identity);
9c6c51
+    virObjectUnref(data->identity);
9c6c51
     VIR_FREE(data);
9c6c51
 
9c6c51
     qemuDomainObjRestoreJob(obj, &oldjob);
9c6c51
@@ -7865,6 +7869,7 @@ qemuProcessReconnect(void *opaque)
9c6c51
     virObjectUnref(cfg);
9c6c51
     virObjectUnref(caps);
9c6c51
     virNWFilterUnlockFilterUpdates();
9c6c51
+    virIdentitySetCurrent(NULL);
9c6c51
     return;
9c6c51
 
9c6c51
  error:
9c6c51
@@ -7902,6 +7907,7 @@ qemuProcessReconnectHelper(virDomainObjPtr obj,
9c6c51
 
9c6c51
     memcpy(data, src, sizeof(*data));
9c6c51
     data->obj = obj;
9c6c51
+    data->identity = virIdentityGetCurrent();
9c6c51
 
9c6c51
     virNWFilterReadLockFilterUpdates();
9c6c51
 
9c6c51
@@ -7925,6 +7931,7 @@ qemuProcessReconnectHelper(virDomainObjPtr obj,
9c6c51
 
9c6c51
         virDomainObjEndAPI(&obj);
9c6c51
         virNWFilterUnlockFilterUpdates();
9c6c51
+        virObjectUnref(data->identity);
9c6c51
         VIR_FREE(data);
9c6c51
         return -1;
9c6c51
     }
9c6c51
-- 
9c6c51
2.19.2
9c6c51