[dbus PATCH 01/14] Introduce NodeDevice Interface

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx>
---
 data/Makefile.am                |  1 +
 data/org.libvirt.NodeDevice.xml |  7 +++++
 src/Makefile.am                 |  1 +
 src/connect.c                   |  6 ++++
 src/connect.h                   |  1 +
 src/nodedev.c                   | 65 +++++++++++++++++++++++++++++++++++++++++
 src/nodedev.h                   |  9 ++++++
 src/util.c                      | 35 ++++++++++++++++++++++
 src/util.h                      | 15 ++++++++++
 9 files changed, 140 insertions(+)
 create mode 100644 data/org.libvirt.NodeDevice.xml
 create mode 100644 src/nodedev.c
 create mode 100644 src/nodedev.h

diff --git a/data/Makefile.am b/data/Makefile.am
index 721b874..b3fa614 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -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 \
diff --git a/data/org.libvirt.NodeDevice.xml b/data/org.libvirt.NodeDevice.xml
new file mode 100644
index 0000000..7ca26d0
--- /dev/null
+++ b/data/org.libvirt.NodeDevice.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/nodedev">
+  <interface name="org.libvirt.NodeDevice">
+  </interface>
+</node>
diff --git a/src/Makefile.am b/src/Makefile.am
index 53d1a23..3ef3472 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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 \
diff --git a/src/connect.c b/src/connect.c
index 4f2bdb6..08898c8 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -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->devPath);
     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;
diff --git a/src/connect.h b/src/connect.h
index 341dfc4..3b62edd 100644
--- a/src/connect.h
+++ b/src/connect.h
@@ -12,6 +12,7 @@ struct virtDBusConnect {
     GDBusConnection *bus;
     const gchar *uri;
     const gchar *connectPath;
+    gchar *devPath;
     gchar *domainPath;
     gchar *networkPath;
     gchar *nwfilterPath;
diff --git a/src/nodedev.c b/src/nodedev.c
new file mode 100644
index 0000000..188df74
--- /dev/null
+++ b/src/nodedev.c
@@ -0,0 +1,65 @@
+#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->devPath);
+    }
+
+    return ret;
+}
+
+static GDBusInterfaceInfo *interfaceInfo;
+
+void
+virtDBusNodeDeviceRegister(virtDBusConnect *connect,
+                           GError **error)
+{
+    connect->devPath = g_strdup_printf("%s/nodedev",
+                                       connect->connectPath);
+
+    if (!interfaceInfo) {
+        interfaceInfo = virtDBusGDBusLoadIntrospectData(VIRT_DBUS_NODEDEV_INTERFACE,
+                                                        error);
+        if (!interfaceInfo)
+            return;
+    }
+
+    virtDBusGDBusRegisterSubtree(connect->bus,
+                                 connect->devPath,
+                                 interfaceInfo,
+                                 virtDBusNodeDeviceEnumerate,
+                                 virtDBusNodeDeviceMethodTable,
+                                 virtDBusNodeDevicePropertyTable,
+                                 connect);
+}
diff --git a/src/nodedev.h b/src/nodedev.h
new file mode 100644
index 0000000..3cd2bdf
--- /dev/null
+++ b/src/nodedev.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "connect.h"
+
+#define VIRT_DBUS_NODEDEV_INTERFACE "org.libvirt.NodeDevice"
+
+void
+virtDBusNodeDeviceRegister(virtDBusConnect *connect,
+                           GError **error);
diff --git a/src/util.c b/src/util.c
index ac6d11b..e736ac1 100644
--- a/src/util.c
+++ b/src/util.c
@@ -311,6 +311,41 @@ virtDBusUtilVirNetworkListFree(virNetworkPtr *networks)
     g_free(networks);
 }
 
+virNodeDevicePtr
+virtDBusUtilVirNodeDeviceFromBusPath(virConnectPtr connection,
+                                     const gchar *path,
+                                     const gchar *devPath)
+{
+    g_autofree gchar *name = NULL;
+    gsize prefixLen = strlen(devPath) + 1;
+
+    name = virtDBusUtilDecodeStr(path + prefixLen);
+
+    return virNodeDeviceLookupByName(connection, name);
+}
+
+gchar *
+virtDBusUtilBusPathForVirNodeDevice(virNodeDevicePtr dev,
+                                    const gchar *devPath)
+{
+    const gchar *name = NULL;
+    g_autofree const gchar *encodedName = NULL;
+
+    name = virNodeDeviceGetName(dev);
+    encodedName = virtDBusUtilEncodeStr(name);
+
+    return g_strdup_printf("%s/%s", devPath, 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,
diff --git a/src/util.h b/src/util.h
index bf08d5d..81372df 100644
--- a/src/util.h
+++ b/src/util.h
@@ -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 *devPath);
+
+gchar *
+virtDBusUtilBusPathForVirNodeDevice(virNodeDevicePtr NodeDevice,
+                                    const gchar *devPath);
+
+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,
-- 
2.15.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux