Commit 8a7c7ee9 authored by Katerina Koukiou's avatar Katerina Koukiou

Introduce StorageVol Interface

Signed-off-by: default avatarKaterina Koukiou <kkoukiou@redhat.com>
Reviewed-by: Pavel Hrdina's avatarPavel Hrdina <phrdina@redhat.com>
parent 63b95f0a
......@@ -24,7 +24,9 @@ interfaces_files = \
org.libvirt.Network.xml \
org.libvirt.NWFilter.xml \
org.libvirt.Secret.xml \
org.libvirt.StoragePool.xml
org.libvirt.StoragePool.xml \
org.libvirt.StorageVol.xml \
$(NULL)
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/storagevol">
<interface name="org.libvirt.StorageVol">
</interface>
</node>
......@@ -12,7 +12,9 @@ DAEMON_SOURCES = \
network.c network.h \
nwfilter.c nwfilter.h \
secret.c secret.h \
storagepool.c storagepool.h
storagepool.c storagepool.h \
storagevol.c storagevol.h \
$(NULL)
EXTRA_DIST = \
$(DAEMON_SOURCES)
......
......@@ -5,6 +5,7 @@
#include "nwfilter.h"
#include "secret.h"
#include "storagepool.h"
#include "storagevol.h"
#include "util.h"
#include <gio/gunixfdlist.h>
......@@ -1612,6 +1613,7 @@ virtDBusConnectFree(virtDBusConnect *connect)
g_free(connect->nwfilterPath);
g_free(connect->secretPath);
g_free(connect->storagePoolPath);
g_free(connect->storageVolPath);
g_free(connect);
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virtDBusConnect, virtDBusConnectFree);
......@@ -1679,6 +1681,10 @@ virtDBusConnectNew(virtDBusConnect **connectp,
if (error && *error)
return;
virtDBusStorageVolRegister(connect, error);
if (error && *error)
return;
*connectp = connect;
connect = NULL;
}
......
......@@ -17,6 +17,7 @@ struct virtDBusConnect {
gchar *nwfilterPath;
gchar *secretPath;
gchar *storagePoolPath;
gchar *storageVolPath;
virConnectPtr connection;
GMutex lock;
......
#include "storagevol.h"
#include "util.h"
#include <libvirt/libvirt.h>
static virtDBusGDBusPropertyTable virtDBusStorageVolPropertyTable[] = {
{ 0 }
};
static virtDBusGDBusMethodTable virtDBusStorageVolMethodTable[] = {
{ 0 }
};
static gchar **
virtDBusStorageVolEnumerate(gpointer userData)
{
virtDBusConnect *connect = userData;
g_autoptr(virStoragePoolPtr) storagePools = NULL;
gint numPools = 0;
GPtrArray *list = NULL;
if (!virtDBusConnectOpen(connect, NULL))
return NULL;
numPools = virConnectListAllStoragePools(connect->connection,
&storagePools, 0);
if (numPools <= 0)
return NULL;
list = g_ptr_array_new();
for (gint i = 0; i < numPools; i++) {
g_autoptr(virStorageVolPtr) storageVols = NULL;
gint numVols;
numVols = virStoragePoolListAllVolumes(storagePools[i],
&storageVols, 0);
if (numVols <= 0)
continue;
for (gint j = 0; j < numVols; j++) {
gchar *volPath = virtDBusUtilBusPathForVirStorageVol(storageVols[j],
connect->storageVolPath);
g_ptr_array_add(list, volPath);
}
}
if (list->len > 0)
g_ptr_array_add(list, NULL);
return (gchar **)g_ptr_array_free(list, FALSE);
}
static GDBusInterfaceInfo *interfaceInfo;
void
virtDBusStorageVolRegister(virtDBusConnect *connect,
GError **error)
{
connect->storageVolPath = g_strdup_printf("%s/storagevol",
connect->connectPath);
if (!interfaceInfo) {
interfaceInfo = virtDBusGDBusLoadIntrospectData(VIRT_DBUS_STORAGEVOL_INTERFACE,
error);
if (!interfaceInfo)
return;
}
virtDBusGDBusRegisterSubtree(connect->bus,
connect->storageVolPath,
interfaceInfo,
virtDBusStorageVolEnumerate,
virtDBusStorageVolMethodTable,
virtDBusStorageVolPropertyTable,
connect);
}
#pragma once
#include "connect.h"
#define VIRT_DBUS_STORAGEVOL_INTERFACE "org.libvirt.StorageVol"
void
virtDBusStorageVolRegister(virtDBusConnect *connect,
GError **error);
......@@ -417,3 +417,38 @@ virtDBusUtilVirStoragePoolListFree(virStoragePoolPtr *storagePools)
g_free(storagePools);
}
virStorageVolPtr
virtDBusUtilVirStorageVolFromBusPath(virConnectPtr connection,
const gchar *path,
const gchar *storageVolPath)
{
g_autofree gchar *key = NULL;
gsize prefixLen = strlen(storageVolPath) + 1;
key = virtDBusUtilDecodeStr(path + prefixLen);
return virStorageVolLookupByKey(connection, key);
}
gchar *
virtDBusUtilBusPathForVirStorageVol(virStorageVolPtr storageVol,
const gchar *storageVolPath)
{
const gchar *key = NULL;
g_autofree const gchar *encodedKey = NULL;
key = virStorageVolGetKey(storageVol);
encodedKey = virtDBusUtilEncodeStr(key);
return g_strdup_printf("%s/%s", storageVolPath, encodedKey);
}
void
virtDBusUtilVirStorageVolListFree(virStorageVolPtr *storageVols)
{
for (gint i = 0; storageVols[i] != NULL; i++)
virStorageVolFree(storageVols[i]);
g_free(storageVols);
}
......@@ -133,3 +133,19 @@ virtDBusUtilVirStoragePoolListFree(virStoragePoolPtr *storagePools);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePool, virStoragePoolFree);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePoolPtr,
virtDBusUtilVirStoragePoolListFree);
virStorageVolPtr
virtDBusUtilVirStorageVolFromBusPath(virConnectPtr connection,
const gchar *path,
const gchar *storageVolPath);
gchar *
virtDBusUtilBusPathForVirStorageVol(virStorageVolPtr storageVol,
const gchar *storageVolPath);
void
virtDBusUtilVirStorageVolListFree(virStorageVolPtr *storageVols);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageVol, virStorageVolFree);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageVolPtr,
virtDBusUtilVirStorageVolListFree);
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