Commit 937c0aff authored by Katerina Koukiou's avatar Katerina Koukiou

Introduce NodeDevice Interface

Signed-off-by: 's avatarKaterina Koukiou <kkoukiou@redhat.com>
Reviewed-by: Pavel Hrdina's avatarPavel Hrdina <phrdina@redhat.com>
parent e99fa639
......@@ -22,6 +22,7 @@ interfaces_files = \
org.libvirt.Connect.xml \
org.libvirt.Domain.xml \
org.libvirt.Network.xml \
org.libvirt.NodeDevice.xml \
org.libvirt.NWFilter.xml \
org.libvirt.Secret.xml \
org.libvirt.StoragePool.xml \
......
<!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/nodedev">
<interface name="org.libvirt.NodeDevice">
</interface>
</node>
......@@ -10,6 +10,7 @@ DAEMON_SOURCES = \
events.c events.h \
gdbus.c gdbus.h \
network.c network.h \
nodedev.c nodedev.h \
nwfilter.c nwfilter.h \
secret.c secret.h \
storagepool.c storagepool.h \
......
......@@ -2,6 +2,7 @@
#include "domain.h"
#include "events.h"
#include "network.h"
#include "nodedev.h"
#include "nwfilter.h"
#include "secret.h"
#include "storagepool.h"
......@@ -1668,6 +1669,7 @@ virtDBusConnectFree(virtDBusConnect *connect)
if (connect->connection)
virtDBusConnectClose(connect, TRUE);
g_free(connect->nodeDevPath);
g_free(connect->domainPath);
g_free(connect->networkPath);
g_free(connect->nwfilterPath);
......@@ -1729,6 +1731,10 @@ virtDBusConnectNew(virtDBusConnect **connectp,
if (error && *error)
return;
virtDBusNodeDeviceRegister(connect, error);
if (error && *error)
return;
virtDBusNWFilterRegister(connect, error);
if (error && *error)
return;
......
......@@ -12,6 +12,7 @@ struct virtDBusConnect {
GDBusConnection *bus;
const gchar *uri;
const gchar *connectPath;
gchar *nodeDevPath;
gchar *domainPath;
gchar *networkPath;
gchar *nwfilterPath;
......
#include "nodedev.h"
#include "util.h"
#include <libvirt/libvirt.h>
static virtDBusGDBusPropertyTable virtDBusNodeDevicePropertyTable[] = {
{ 0 }
};
static virtDBusGDBusMethodTable virtDBusNodeDeviceMethodTable[] = {
{ 0 }
};
static gchar **
virtDBusNodeDeviceEnumerate(gpointer userData)
{
virtDBusConnect *connect = userData;
g_autoptr(virNodeDevicePtr) devs = NULL;
gint num = 0;
gchar **ret = NULL;
if (!virtDBusConnectOpen(connect, NULL))
return NULL;
num = virConnectListAllNodeDevices(connect->connection, &devs, 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] = virtDBusUtilBusPathForVirNodeDevice(devs[i],
connect->nodeDevPath);
}
return ret;
}
static GDBusInterfaceInfo *interfaceInfo;
void
virtDBusNodeDeviceRegister(virtDBusConnect *connect,
GError **error)
{
connect->nodeDevPath = g_strdup_printf("%s/nodedev",
connect->connectPath);
if (!interfaceInfo) {
interfaceInfo = virtDBusGDBusLoadIntrospectData(VIRT_DBUS_NODEDEV_INTERFACE,
error);
if (!interfaceInfo)
return;
}
virtDBusGDBusRegisterSubtree(connect->bus,
connect->nodeDevPath,
interfaceInfo,
virtDBusNodeDeviceEnumerate,
virtDBusNodeDeviceMethodTable,
virtDBusNodeDevicePropertyTable,
connect);
}
#pragma once
#include "connect.h"
#define VIRT_DBUS_NODEDEV_INTERFACE "org.libvirt.NodeDevice"
void
virtDBusNodeDeviceRegister(virtDBusConnect *connect,
GError **error);
......@@ -311,6 +311,41 @@ virtDBusUtilVirNetworkListFree(virNetworkPtr *networks)
g_free(networks);
}
virNodeDevicePtr
virtDBusUtilVirNodeDeviceFromBusPath(virConnectPtr connection,
const gchar *path,
const gchar *nodeDevPath)
{
g_autofree gchar *name = NULL;
gsize prefixLen = strlen(nodeDevPath) + 1;
name = virtDBusUtilDecodeStr(path + prefixLen);
return virNodeDeviceLookupByName(connection, name);
}
gchar *
virtDBusUtilBusPathForVirNodeDevice(virNodeDevicePtr dev,
const gchar *nodeDevPath)
{
const gchar *name = NULL;
g_autofree const gchar *encodedName = NULL;
name = virNodeDeviceGetName(dev);
encodedName = virtDBusUtilEncodeStr(name);
return g_strdup_printf("%s/%s", nodeDevPath, encodedName);
}
void
virtDBusUtilVirNodeDeviceListFree(virNodeDevicePtr *devs)
{
for (gint i = 0; devs[i] != NULL; i++)
virNodeDeviceFree(devs[i]);
g_free(devs);
}
virNWFilterPtr
virtDBusUtilVirNWFilterFromBusPath(virConnectPtr connection,
const gchar *path,
......
......@@ -80,6 +80,21 @@ virtDBusUtilVirNetworkListFree(virNetworkPtr *networks);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetwork, virNetworkFree);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetworkPtr, virtDBusUtilVirNetworkListFree);
virNodeDevicePtr
virtDBusUtilVirNodeDeviceFromBusPath(virConnectPtr connection,
const gchar *path,
const gchar *nodeDevPath);
gchar *
virtDBusUtilBusPathForVirNodeDevice(virNodeDevicePtr NodeDevice,
const gchar *nodeDevPath);
void
virtDBusUtilVirNodeDeviceListFree(virNodeDevicePtr *devs);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNodeDevice, virNodeDeviceFree);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNodeDevicePtr, virtDBusUtilVirNodeDeviceListFree);
virNWFilterPtr
virtDBusUtilVirNWFilterFromBusPath(virConnectPtr connection,
const gchar *path,
......
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