From: Marc-André Lureau <marcandre.lureau(a)redhat.com>
The following changes are going to communicate with the qemu-rdp server
through the VM D-Bus bus, keep a connection for that and further usage.
Signed-off-by: Marc-André Lureau <marcandre.lureau(a)redhat.com>
Reviewed-by: Martin Kletzander <mkletzan(a)redhat.com>
---
src/qemu/qemu_dbus.c | 35 +++++++++++++++++++++++++++++++++++
src/qemu/qemu_dbus.h | 3 +++
src/qemu/qemu_domain.h | 2 ++
src/qemu/qemu_process.c | 3 +++
4 files changed, 43 insertions(+)
diff --git a/src/qemu/qemu_dbus.c b/src/qemu/qemu_dbus.c
index 06b655d870..c9e99ea27b 100644
--- a/src/qemu/qemu_dbus.c
+++ b/src/qemu/qemu_dbus.c
@@ -84,6 +84,36 @@ qemuDBusGetAddress(virQEMUDriver *driver,
}
+bool
+qemuDBusConnect(virQEMUDriver *driver,
+ virDomainObj *vm)
+{
+ qemuDomainObjPrivate *priv = vm->privateData;
+ g_autoptr(GError) gerr = NULL;
+ g_autofree char *address = NULL;
+
+ if (priv->dbusConnection)
+ return true;
+
+ address = qemuDBusGetAddress(driver, vm);
+ if (!address)
+ return false;
+
+ priv->dbusConnection =
+ g_dbus_connection_new_for_address_sync(address,
+
G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT|
+
G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
+ NULL, NULL, &gerr);
+ if (!priv->dbusConnection) {
+ virReportError(VIR_ERR_OPERATION_FAILED,
+ _("Failed to connect to dbus-daemon: %1$s"),
gerr->message);
+ return false;
+ }
+
+ return true;
+}
+
+
static int
qemuDBusWriteConfig(const char *filename, const char *path)
{
@@ -140,6 +170,8 @@ qemuDBusStop(virQEMUDriver *driver,
} else {
priv->dbusDaemonRunning = false;
}
+
+ g_clear_object(&priv->dbusConnection);
}
@@ -264,6 +296,9 @@ qemuDBusStart(virQEMUDriver *driver,
if (qemuSecurityDomainSetPathLabel(driver, vm, sockpath, false) < 0)
goto cleanup;
+ if (!qemuDBusConnect(driver, vm))
+ goto cleanup;
+
priv->dbusDaemonRunning = true;
ret = 0;
cleanup:
diff --git a/src/qemu/qemu_dbus.h b/src/qemu/qemu_dbus.h
index b27f38a591..2d97c6df2d 100644
--- a/src/qemu/qemu_dbus.h
+++ b/src/qemu/qemu_dbus.h
@@ -24,6 +24,9 @@
char *qemuDBusGetAddress(virQEMUDriver *driver,
virDomainObj *vm);
+bool qemuDBusConnect(virQEMUDriver *driver,
+ virDomainObj *vm);
+
int qemuDBusStart(virQEMUDriver *driver,
virDomainObj *vm);
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 8e53a270a7..a70617f3c0 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -39,6 +39,7 @@
#include "qemu_fd.h"
#include "virchrdev.h"
#include "virobject.h"
+#include "virgdbus.h"
#include "virdomainmomentobjlist.h"
#include "virenum.h"
#include "vireventthread.h"
@@ -240,6 +241,7 @@ struct _qemuDomainObjPrivate {
/* running backup job */
virDomainBackupDef *backup;
+ GDBusConnection *dbusConnection;
bool dbusDaemonRunning;
/* list of Ids to migrate */
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 0173fbe3be..1eb670e6ba 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -9405,6 +9405,9 @@ qemuProcessReconnect(void *opaque)
if (qemuDomainObjStartWorker(obj) < 0)
goto error;
+ if (priv->dbusDaemonRunning && !qemuDBusConnect(driver, obj))
+ goto error;
+
VIR_DEBUG("Reconnect monitor to def=%p name='%s'", obj,
obj->def->name);
tryMonReconn = true;
--
2.47.0