Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx> --- data/Makefile.am | 3 +- data/org.libvirt.StoragePool.xml | 7 +++++ src/Makefile.am | 3 +- src/connect.c | 6 ++++ src/connect.h | 1 + src/storagepool.c | 65 ++++++++++++++++++++++++++++++++++++++++ src/storagepool.h | 9 ++++++ src/util.c | 33 ++++++++++++++++++++ src/util.h | 16 ++++++++++ 9 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 data/org.libvirt.StoragePool.xml create mode 100644 src/storagepool.c create mode 100644 src/storagepool.h diff --git a/data/Makefile.am b/data/Makefile.am index 61702df..4d2af45 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -21,7 +21,8 @@ polkit_DATA = $(polkit_files:.rules.in=.rules) interfaces_files = \ org.libvirt.Connect.xml \ org.libvirt.Domain.xml \ - org.libvirt.Network.xml + org.libvirt.Network.xml \ + org.libvirt.StoragePool.xml interfacesdir = $(DBUS_INTERFACES_DIR) interfaces_DATA = $(interfaces_files) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml new file mode 100644 index 0000000..504a166 --- /dev/null +++ b/data/org.libvirt.StoragePool.xml @@ -0,0 +1,7 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" +"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> + +<node name="/org/libvirt/storagepool"> + <interface name="org.libvirt.StoragePool"> + </interface> +</node> diff --git a/src/Makefile.am b/src/Makefile.am index 158398a..5e082da 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,7 +9,8 @@ DAEMON_SOURCES = \ domain.c domain.h \ events.c events.h \ gdbus.c gdbus.h \ - network.c network.h + network.c network.h \ + storagepool.c storagepool.h EXTRA_DIST = \ $(DAEMON_SOURCES) diff --git a/src/connect.c b/src/connect.c index fd335e3..e838e98 100644 --- a/src/connect.c +++ b/src/connect.c @@ -2,6 +2,7 @@ #include "domain.h" #include "events.h" #include "network.h" +#include "storagepool.h" #include "util.h" #include <glib/gprintf.h> @@ -1105,6 +1106,7 @@ virtDBusConnectFree(virtDBusConnect *connect) g_free(connect->domainPath); g_free(connect->networkPath); + g_free(connect->storagePoolPath); g_free(connect); } G_DEFINE_AUTOPTR_CLEANUP_FUNC(virtDBusConnect, virtDBusConnectFree); @@ -1154,6 +1156,10 @@ virtDBusConnectNew(virtDBusConnect **connectp, if (error && *error) return; + virtDBusStoragePoolRegister(connect, error); + if (error && *error) + return; + *connectp = connect; connect = NULL; } diff --git a/src/connect.h b/src/connect.h index f89bc9d..d6c3830 100644 --- a/src/connect.h +++ b/src/connect.h @@ -14,6 +14,7 @@ struct virtDBusConnect { const gchar *connectPath; gchar *domainPath; gchar *networkPath; + gchar *storagePoolPath; virConnectPtr connection; GMutex lock; diff --git a/src/storagepool.c b/src/storagepool.c new file mode 100644 index 0000000..f1421ef --- /dev/null +++ b/src/storagepool.c @@ -0,0 +1,65 @@ +#include "storagepool.h" +#include "util.h" + +#include <libvirt/libvirt.h> + +static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] = { + { 0 } +}; + +static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = { + { 0 } +}; + +static gchar ** +virtDBusStoragePoolEnumerate(gpointer userData) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePoolPtr) storagePools = NULL; + gint num = 0; + gchar **ret = NULL; + + if (!virtDBusConnectOpen(connect, NULL)) + return NULL; + + num = virConnectListAllStoragePools(connect->connection, &storagePools, 0); + if (num < 0) + return NULL; + + if (num == 0) + return NULL; + + ret = g_new0(gchar *, num + 1); + + for (gint i = 0; i < num; i++) { + ret[i] = virtDBusUtilBusPathForVirStoragePool(storagePools[i], + connect->storagePoolPath); + } + + return ret; +} + +static GDBusInterfaceInfo *interfaceInfo; + +void +virtDBusStoragePoolRegister(virtDBusConnect *connect, + GError **error) +{ + connect->storagePoolPath = g_strdup_printf("%s/storagepool", + connect->connectPath); + + if (!interfaceInfo) { + interfaceInfo = virtDBusGDBusLoadIntrospectData(VIRT_DBUS_STORAGEPOOL_INTERFACE, + error); + if (!interfaceInfo) + return; + } + + virtDBusGDBusRegisterSubtree(connect->bus, + connect->storagePoolPath, + interfaceInfo, + virtDBusStoragePoolEnumerate, + virtDBusStoragePoolMethodTable, + virtDBusStoragePoolPropertyTable, + connect); +} diff --git a/src/storagepool.h b/src/storagepool.h new file mode 100644 index 0000000..fb2bffb --- /dev/null +++ b/src/storagepool.h @@ -0,0 +1,9 @@ +#pragma once + +#include "connect.h" + +#define VIRT_DBUS_STORAGEPOOL_INTERFACE "org.libvirt.StoragePool" + +void +virtDBusStoragePoolRegister(virtDBusConnect *connect, + GError **error); diff --git a/src/util.c b/src/util.c index 548fac8..e90be3b 100644 --- a/src/util.c +++ b/src/util.c @@ -255,3 +255,36 @@ virtDBusUtilStringListFree(virtDBusCharArray *item) g_free(item); } + +virStoragePoolPtr +virtDBusUtilVirStoragePoolFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *storagePoolPath) +{ + g_autofree gchar *name = NULL; + gsize prefixLen = strlen(storagePoolPath) + 1; + + name = virtDBusUtilDecodeUUID(path + prefixLen); + + return virStoragePoolLookupByUUIDString(connection, name); +} + +gchar * +virtDBusUtilBusPathForVirStoragePool(virStoragePoolPtr storagePool, + const gchar *storagePoolPath) +{ + gchar uuid[VIR_UUID_STRING_BUFLEN] = ""; + g_autofree gchar *newUuid = NULL; + virStoragePoolGetUUIDString(storagePool, uuid); + newUuid = virtDBusUtilEncodeUUID(uuid); + return g_strdup_printf("%s/%s", storagePoolPath, newUuid); +} + +void +virtDBusUtilVirStoragePoolListFree(virStoragePoolPtr *storagePools) +{ + for (gint i = 0; storagePools[i] != NULL; i++) + virStoragePoolFree(storagePools[i]); + + g_free(storagePools); +} diff --git a/src/util.h b/src/util.h index 3309803..d932b66 100644 --- a/src/util.h +++ b/src/util.h @@ -78,3 +78,19 @@ void virtDBusUtilStringListFree(virtDBusCharArray *item); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virtDBusCharArray, virtDBusUtilStringListFree); + +virStoragePoolPtr +virtDBusUtilVirStoragePoolFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *storagePoolPath); + +gchar * +virtDBusUtilBusPathForVirStoragePool(virStoragePoolPtr storagePool, + const gchar *storagePoolPath); + +void +virtDBusUtilVirStoragePoolListFree(virStoragePoolPtr *storagePools); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePool, virStoragePoolFree); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePoolPtr, + virtDBusUtilVirStoragePoolListFree); -- 2.15.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list