Each connection have its own domains so we must make the domain path
as a sub-path of the specific connection.
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
src/connect.c | 12 +++++++----
src/connect.h | 1 +
src/domain.c | 64 ++++++++++++++++++++++++++++++++++++++++-------------------
src/events.c | 10 +++++-----
src/util.c | 10 ++++++----
src/util.h | 6 ++++--
6 files changed, 68 insertions(+), 35 deletions(-)
diff --git a/src/connect.c b/src/connect.c
index 3aec99e..5249eba 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -100,7 +100,8 @@ virtDBusConnectEnumarateDomains(sd_bus *bus VIR_ATTR_UNUSED,
paths = calloc(n_domains + 1, sizeof(char *));
for (int i = 0; i < n_domains; i += 1)
- paths[i] = virtDBusUtilBusPathForVirDomain(domains[i]);
+ paths[i] = virtDBusUtilBusPathForVirDomain(domains[i],
+ connect->domainPath);
*nodes = paths;
paths = NULL;
@@ -142,7 +143,8 @@ virtDBusConnectListDomains(sd_bus_message *message,
for (int i = 0; domains[i] != NULL; i += 1) {
_cleanup_(virtDBusUtilFreep) char *path = NULL;
- path = virtDBusUtilBusPathForVirDomain(domains[i]);
+ path = virtDBusUtilBusPathForVirDomain(domains[i],
+ connect->domainPath);
r = sd_bus_message_append(reply, "o", path);
if (r < 0)
@@ -180,7 +182,7 @@ virtDBusConnectCreateXML(sd_bus_message *message,
if (!domain)
return virtDBusUtilSetLastVirtError(error);
- path = virtDBusUtilBusPathForVirDomain(domain);
+ path = virtDBusUtilBusPathForVirDomain(domain, connect->domainPath);
return sd_bus_reply_method_return(message, "o", path);
}
@@ -208,7 +210,7 @@ virtDBusConnectDefineXML(sd_bus_message *message,
if (!domain)
return virtDBusUtilSetLastVirtError(error);
- path = virtDBusUtilBusPathForVirDomain(domain);
+ path = virtDBusUtilBusPathForVirDomain(domain, connect->domainPath);
return sd_bus_reply_method_return(message, "o", path);
}
@@ -278,6 +280,8 @@ virtDBusConnectFree(virtDBusConnect *connect)
if (connect->connection)
virtDBusConnectClose(connect, true);
+ free(connect->domainPath);
+
free(connect);
return NULL;
diff --git a/src/connect.h b/src/connect.h
index 489ce84..bed2c7e 100644
--- a/src/connect.h
+++ b/src/connect.h
@@ -9,6 +9,7 @@ struct virtDBusConnect {
sd_bus *bus;
const char *uri;
const char *connectPath;
+ char *domainPath;
virConnectPtr connection;
sd_bus_node_enumerator_t enumerateDomains;
diff --git a/src/domain.c b/src/domain.c
index bc465b0..33ed2b3 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -1,6 +1,9 @@
+#define _GNU_SOURCE
#include "domain.h"
#include "util.h"
+#include <stdio.h>
+
static int
virtDBusDomainGetName(sd_bus *bus VIR_ATTR_UNUSED,
const char *path,
@@ -14,7 +17,8 @@ virtDBusDomainGetName(sd_bus *bus VIR_ATTR_UNUSED,
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
const char *name = "";
- domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path);
+ domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
+ connect->domainPath);
if (domain == NULL)
return sd_bus_message_append(reply, "s", "");
@@ -38,7 +42,8 @@ virtDBusDomainGetUUID(sd_bus *bus VIR_ATTR_UNUSED,
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
char uuid[VIR_UUID_STRING_BUFLEN] = "";
- domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path);
+ domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
+ connect->domainPath);
if (domain == NULL)
return sd_bus_message_append(reply, "s", "");
@@ -59,7 +64,8 @@ virtDBusDomainGetId(sd_bus *bus VIR_ATTR_UNUSED,
virtDBusConnect *connect = userdata;
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
- domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path);
+ domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
+ connect->domainPath);
if (domain == NULL)
return sd_bus_message_append(reply, "u", 0);
@@ -78,7 +84,8 @@ virtDBusDomainGetVcpus(sd_bus *bus VIR_ATTR_UNUSED,
virtDBusConnect *connect = userdata;
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
- domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path);
+ domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
+ connect->domainPath);
if (domain == NULL)
return sd_bus_message_append(reply, "u", 0);
@@ -98,7 +105,8 @@ virtDBusDomainGetOsType(sd_bus *bus VIR_ATTR_UNUSED,
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
_cleanup_(virtDBusUtilFreep) char *os_type = NULL;
- domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path);
+ domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
+ connect->domainPath);
if (domain == NULL)
return sd_bus_message_append(reply, "s", "");
@@ -122,7 +130,8 @@ virtDBusDomainGetActive(sd_bus *bus VIR_ATTR_UNUSED,
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
int active;
- domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path);
+ domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
+ connect->domainPath);
if (domain == NULL)
return sd_bus_message_append(reply, "b", 0);
@@ -146,7 +155,8 @@ virtDBusDomainGetPersistent(sd_bus *bus VIR_ATTR_UNUSED,
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
int persistent;
- domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path);
+ domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
+ connect->domainPath);
if (domain == NULL)
return sd_bus_message_append(reply, "b", 0);
@@ -171,7 +181,8 @@ virtDBusDomainGetState(sd_bus *bus VIR_ATTR_UNUSED,
int state = 0;
const char *string;
- domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path);
+ domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
+ connect->domainPath);
if (domain == NULL)
return sd_bus_message_append(reply, "s", "");
@@ -221,7 +232,8 @@ virtDBusDomainGetAutostart(sd_bus *bus VIR_ATTR_UNUSED,
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
int autostart = 0;
- domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path);
+ domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
+ connect->domainPath);
if (domain == NULL)
return sd_bus_message_append(reply, "b", 0);
@@ -242,7 +254,8 @@ virtDBusDomainGetXMLDesc(sd_bus_message *message,
int r;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection,
- sd_bus_message_get_path(message));
+ sd_bus_message_get_path(message),
+ connect->domainPath);
if (domain == NULL) {
return sd_bus_reply_method_errorf(message,
SD_BUS_ERROR_UNKNOWN_OBJECT,
@@ -286,7 +299,8 @@ virtDBusDomainGetStats(sd_bus_message *message,
return r;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection,
- sd_bus_message_get_path(message));
+ sd_bus_message_get_path(message),
+ connect->domainPath);
if (domain == NULL) {
return sd_bus_reply_method_errorf(message,
SD_BUS_ERROR_UNKNOWN_OBJECT,
@@ -321,7 +335,8 @@ virtDBusDomainShutdown(sd_bus_message *message,
int r;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection,
- sd_bus_message_get_path(message));
+ sd_bus_message_get_path(message),
+ connect->domainPath);
if (domain == NULL) {
return sd_bus_reply_method_errorf(message,
SD_BUS_ERROR_UNKNOWN_OBJECT,
@@ -346,7 +361,8 @@ virtDBusDomainDestroy(sd_bus_message *message,
int r;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection,
- sd_bus_message_get_path(message));
+ sd_bus_message_get_path(message),
+ connect->domainPath);
if (domain == NULL) {
return sd_bus_reply_method_errorf(message,
SD_BUS_ERROR_UNKNOWN_OBJECT,
@@ -376,7 +392,8 @@ virtDBusDomainReboot(sd_bus_message *message,
return r;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection,
- sd_bus_message_get_path(message));
+ sd_bus_message_get_path(message),
+ connect->domainPath);
if (domain == NULL) {
return sd_bus_reply_method_errorf(message,
SD_BUS_ERROR_UNKNOWN_OBJECT,
@@ -406,7 +423,8 @@ virtDBusDomainReset(sd_bus_message *message,
return r;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection,
- sd_bus_message_get_path(message));
+ sd_bus_message_get_path(message),
+ connect->domainPath);
if (domain == NULL) {
return sd_bus_reply_method_errorf(message,
SD_BUS_ERROR_UNKNOWN_OBJECT,
@@ -431,7 +449,8 @@ virtDBusDomainCreate(sd_bus_message *message,
int r;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection,
- sd_bus_message_get_path(message));
+ sd_bus_message_get_path(message),
+ connect->domainPath);
if (domain == NULL) {
return sd_bus_reply_method_errorf(message,
SD_BUS_ERROR_UNKNOWN_OBJECT,
@@ -456,7 +475,8 @@ virtDBusDomainUndefine(sd_bus_message *message,
int r;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection,
- sd_bus_message_get_path(message));
+ sd_bus_message_get_path(message),
+ connect->domainPath);
if (domain == NULL) {
return sd_bus_reply_method_errorf(message,
SD_BUS_ERROR_UNKNOWN_OBJECT,
@@ -514,7 +534,7 @@ virtDBusDomainLookup(sd_bus *bus VIR_ATTR_UNUSED,
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
int r;
- r = sd_bus_path_decode(path, "/org/libvirt/domain", &name);
+ r = sd_bus_path_decode(path, connect->domainPath, &name);
if (r < 0)
return r;
@@ -541,14 +561,18 @@ virtDBusDomainRegister(virtDBusConnect *connect,
{
int r;
- r = sd_bus_add_node_enumerator(bus, NULL, "/org/libvirt/domain",
+ r = asprintf(&connect->domainPath, "%s/domain",
connect->connectPath);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_add_node_enumerator(bus, NULL, connect->domainPath,
connect->enumerateDomains, connect);
if (r < 0)
return r;
return sd_bus_add_fallback_vtable(bus,
NULL,
- "/org/libvirt/domain",
+ connect->domainPath,
"org.libvirt.Domain",
virt_domain_vtable,
virtDBusDomainLookup,
diff --git a/src/events.c b/src/events.c
index d2d7f6b..05d5940 100644
--- a/src/events.c
+++ b/src/events.c
@@ -60,7 +60,7 @@ virtDBusEventsDomainLifecycle(virConnectPtr connection VIR_ATTR_UNUSED,
return r;
name = virDomainGetName(domain);
- path = virtDBusUtilBusPathForVirDomain(domain);
+ path = virtDBusUtilBusPathForVirDomain(domain, connect->domainPath);
r = sd_bus_message_append(message, "so", name ? : "", path);
if (r < 0)
@@ -80,7 +80,7 @@ virtDBusEventsDomainDeviceAdded(virConnectPtr connection
VIR_ATTR_UNUSED,
_cleanup_(virtDBusUtilFreep) char *path = NULL;
int r;
- path = virtDBusUtilBusPathForVirDomain(domain);
+ path = virtDBusUtilBusPathForVirDomain(domain, connect->domainPath);
r = sd_bus_message_new_signal(connect->bus,
&message,
@@ -108,7 +108,7 @@ virtDBusEventsDomainDeviceRemoved(virConnectPtr connection
VIR_ATTR_UNUSED,
_cleanup_(virtDBusUtilFreep) char *path = NULL;
int r;
- path = virtDBusUtilBusPathForVirDomain(domain);
+ path = virtDBusUtilBusPathForVirDomain(domain, connect->domainPath);
r = sd_bus_message_new_signal(connect->bus,
&message,
@@ -138,7 +138,7 @@ virtDBusEventsDomainDiskChange(virConnectPtr connection
VIR_ATTR_UNUSED,
const char *reasonstr;
int r;
- path = virtDBusUtilBusPathForVirDomain(domain);
+ path = virtDBusUtilBusPathForVirDomain(domain, connect->domainPath);
r = sd_bus_message_new_signal(connect->bus,
&message,
@@ -182,7 +182,7 @@ virtDBusEventsDomainTrayChange(virConnectPtr connection
VIR_ATTR_UNUSED,
const char *reasonstr;
int r;
- path = virtDBusUtilBusPathForVirDomain(domain);
+ path = virtDBusUtilBusPathForVirDomain(domain, connect->domainPath);
r = sd_bus_message_new_signal(connect->bus,
&message,
diff --git a/src/util.c b/src/util.c
index 6636d0a..d0649fa 100644
--- a/src/util.c
+++ b/src/util.c
@@ -77,25 +77,27 @@ virtDBusUtilSetError(sd_bus_error *error,
}
char *
-virtDBusUtilBusPathForVirDomain(virDomainPtr domain)
+virtDBusUtilBusPathForVirDomain(virDomainPtr domain,
+ const char *domainPath)
{
char *path = NULL;
char uuid[VIR_UUID_STRING_BUFLEN] = "";
virDomainGetUUIDString(domain, uuid);
- sd_bus_path_encode("/org/libvirt/domain", uuid, &path);
+ sd_bus_path_encode(domainPath, uuid, &path);
return path;
}
virDomainPtr
virtDBusUtilVirDomainFromBusPath(virConnectPtr connection,
- const char *path)
+ const char *path,
+ const char *domainPath)
{
_cleanup_(virtDBusUtilFreep) char *name = NULL;
int r;
- r = sd_bus_path_decode(path, "/org/libvirt/domain", &name);
+ r = sd_bus_path_decode(path, domainPath, &name);
if (r < 0)
return NULL;
diff --git a/src/util.h b/src/util.h
index cb8447d..14b1e9a 100644
--- a/src/util.h
+++ b/src/util.h
@@ -24,11 +24,13 @@ virtDBusUtilSetError(sd_bus_error *error,
const char *message);
char *
-virtDBusUtilBusPathForVirDomain(virDomainPtr domain);
+virtDBusUtilBusPathForVirDomain(virDomainPtr domain,
+ const char *domainPath);
virDomainPtr
virtDBusUtilVirDomainFromBusPath(virConnectPtr connection,
- const char *path);
+ const char *path,
+ const char *domainPath);
static inline void
virtDBusUtilFreep(void *p)
--
2.14.3