1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-04-01 20:05:19 +00:00

qemu/dbus: keep a connection to the VM D-Bus

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@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Marc-André Lureau 2025-03-16 12:18:34 +04:00 committed by Martin Kletzander
parent 3af8f135e9
commit dbfb96d18c
4 changed files with 43 additions and 0 deletions

View File

@ -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:

View File

@ -24,6 +24,9 @@
char *qemuDBusGetAddress(virQEMUDriver *driver,
virDomainObj *vm);
bool qemuDBusConnect(virQEMUDriver *driver,
virDomainObj *vm);
int qemuDBusStart(virQEMUDriver *driver,
virDomainObj *vm);

View File

@ -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 */

View File

@ -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;