Commit 5b80e55b authored by Katerina Koukiou's avatar Katerina Koukiou

Introduce StoragePool Interface

Signed-off-by: default avatarKaterina Koukiou <kkoukiou@redhat.com>
Reviewed-by: Pavel Hrdina's avatarPavel Hrdina <phrdina@redhat.com>
parent b8975eff
......@@ -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)
......
<!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>
......@@ -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)
......
......@@ -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;
}
......
......@@ -14,6 +14,7 @@ struct virtDBusConnect {
const gchar *connectPath;
gchar *domainPath;
gchar *networkPath;
gchar *storagePoolPath;
virConnectPtr connection;
GMutex lock;
......
#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);
}
#pragma once
#include "connect.h"
#define VIRT_DBUS_STORAGEPOOL_INTERFACE "org.libvirt.StoragePool"
void
virtDBusStoragePoolRegister(virtDBusConnect *connect,
GError **error);
......@@ -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);
}
......@@ -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);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment