[libvirt] [dbus PATCH 00/14] Introduce NodeDevice APIs

Katerina Koukiou (14): Introduce NodeDevice Interface Implement ListNodeDevices method for Connect Interface Register NodeDevice Lifecycle Events Implement NodeDeviceCreateXML method for Connect Interface Implement Destroy method for NodeDevice Interface Implement Detach method for NodeDevice Interface Implement Name property for NodeDevice Interface Implement Parent property for NodeDevice Interface Implement GetXMLDesc property for NodeDevice Interface Implement ListCaps method for NodeDevicesInterface Implement NodeDeviceLookupByName method for Connect Interface Implement NodeDeviceLookupSCSIHostByWWN method for Connect Interface Implement ReAttach method for NodeDevice Interface Implement Reset method for NodeDevice Interface data/Makefile.am | 1 + data/org.libvirt.Connect.xml | 34 +++++ data/org.libvirt.NodeDevice.xml | 45 +++++++ src/Makefile.am | 1 + src/connect.c | 148 +++++++++++++++++++++ src/connect.h | 2 + src/events.c | 42 ++++++ src/nodedev.c | 283 ++++++++++++++++++++++++++++++++++++++++ src/nodedev.h | 9 ++ src/util.c | 35 +++++ src/util.h | 15 +++ tests/Makefile.am | 1 + tests/libvirttest.py | 13 ++ tests/test_connect.py | 27 ++++ tests/test_nodedev.py | 52 ++++++++ tests/xmldata.py | 16 +++ 16 files changed, 724 insertions(+) create mode 100644 data/org.libvirt.NodeDevice.xml create mode 100644 src/nodedev.c create mode 100644 src/nodedev.h create mode 100755 tests/test_nodedev.py -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- 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

On Fri, Jun 15, 2018 at 07:03:37PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- 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);
I would prefer nodeDevPath. Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 37daed0..137e67b 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -160,6 +160,12 @@ <arg name="flags" type="u" direction="in"/> <arg name="networks" type="ao" direction="out"/> </method> + <method name="ListNodeDevices"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virConnectListAllNodeDevices"/> + <arg name="flags" type="u" direction="in"/> + <arg name="devs" type="ao" direction="out"/> + </method> <method name="ListNWFilters"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virConnectListAllNWFilters"/> diff --git a/src/connect.c b/src/connect.c index 08898c8..919172a 100644 --- a/src/connect.c +++ b/src/connect.c @@ -798,6 +798,43 @@ virtDBusConnectListNetworks(GVariant *inArgs, *outArgs = g_variant_new_tuple(&gnetworks, 1); } +static void +virtDBusConnectListNodeDevices(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNodeDevicePtr) devs = NULL; + guint flags; + GVariantBuilder builder; + GVariant *gdevs; + + g_variant_get(inArgs, "(u)", &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + if (virConnectListAllNodeDevices(connect->connection, &devs, flags) < 0) + return virtDBusUtilSetLastVirtError(error); + + g_variant_builder_init(&builder, G_VARIANT_TYPE("ao")); + + for (gint i = 0; devs[i]; i++) { + g_autofree gchar *path = NULL; + path = virtDBusUtilBusPathForVirNodeDevice(devs[i], + connect->devPath); + + g_variant_builder_add(&builder, "o", path); + } + + gdevs = g_variant_builder_end(&builder); + *outArgs = g_variant_new_tuple(&gdevs, 1); +} + static void virtDBusConnectListNWFilters(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -1632,6 +1669,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "GetSysinfo", virtDBusConnectGetSysinfo }, { "ListDomains", virtDBusConnectListDomains }, { "ListNetworks", virtDBusConnectListNetworks }, + { "ListNodeDevices", virtDBusConnectListNodeDevices }, { "ListNWFilters", virtDBusConnectListNWFilters }, { "ListSecrets", virtDBusConnectListSecrets }, { "ListStoragePools", virtDBusConnectListStoragePools }, -- 2.15.0

On Fri, Jun 15, 2018 at 07:03:38PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 7 +++++++ src/connect.c | 13 +++++++++++++ src/connect.h | 1 + src/events.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 137e67b..3828832 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -339,6 +339,13 @@ <arg name="network" type="o"/> <arg name="event" type="i"/> </signal> + <signal name="NodeDeviceEvent"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virConnectNodeDeviceEventLifecycleCallback"/> + <arg name="dev" type="o"/> + <arg name="event" type="i"/> + <arg name="detail" type="i"/> + </signal> <signal name="SecretEvent"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virConnectSecretEventLifecycleCallback"/> diff --git a/src/connect.c b/src/connect.c index 919172a..1c27768 100644 --- a/src/connect.c +++ b/src/connect.c @@ -65,6 +65,16 @@ virtDBusConnectClose(virtDBusConnect *connect, } } + for (gint i = 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) { + if (connect->devCallbackIds[i] >= 0) { + if (deregisterEvents) { + virConnectNetworkEventDeregisterAny(connect->connection, + connect->devCallbackIds[i]); + } + connect->devCallbackIds[i] = -1; + } + } + for (gint i = 0; i < VIR_SECRET_EVENT_ID_LAST; i++) { if (connect->secretCallbackIds[i] >= 0) { if (deregisterEvents) { @@ -1744,6 +1754,9 @@ virtDBusConnectNew(virtDBusConnect **connectp, for (gint i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++) connect->networkCallbackIds[i] = -1; + for (gint i = 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) + connect->devCallbackIds[i] = -1; + for (gint i = 0; i < VIR_SECRET_EVENT_ID_LAST; i++) connect->secretCallbackIds[i] = -1; diff --git a/src/connect.h b/src/connect.h index 3b62edd..a864041 100644 --- a/src/connect.h +++ b/src/connect.h @@ -24,6 +24,7 @@ struct virtDBusConnect { gint domainCallbackIds[VIR_DOMAIN_EVENT_ID_LAST]; gint networkCallbackIds[VIR_NETWORK_EVENT_ID_LAST]; + gint devCallbackIds[VIR_NODE_DEVICE_EVENT_ID_LAST]; gint secretCallbackIds[VIR_SECRET_EVENT_ID_LAST]; gint storagePoolCallbackIds[VIR_STORAGE_POOL_EVENT_ID_LAST]; }; diff --git a/src/events.c b/src/events.c index b51664f..60cbecd 100644 --- a/src/events.c +++ b/src/events.c @@ -567,6 +567,29 @@ virtDBusEventsNetworkEvent(virConnectPtr connection G_GNUC_UNUSED, return 0; } +static gint +virtDBusEventsNodeDeviceEvent(virConnectPtr connection G_GNUC_UNUSED, + virNodeDevicePtr dev, + gint event, + gint detail, + gpointer opaque) +{ + virtDBusConnect *connect = opaque; + g_autofree gchar *path = NULL; + + path = virtDBusUtilBusPathForVirNodeDevice(dev, connect->devPath); + + g_dbus_connection_emit_signal(connect->bus, + NULL, + connect->connectPath, + VIRT_DBUS_CONNECT_INTERFACE, + "NodeDeviceEvent", + g_variant_new("(oii)", path, event, detail), + NULL); + + return 0; +} + static gint virtDBusEventsSecretEvent(virConnectPtr connection G_GNUC_UNUSED, virSecretPtr secret, @@ -666,6 +689,21 @@ virtDBusEventsRegisterNetworkEvent(virtDBusConnect *connect, NULL); } +static void +virtDBusEventsRegisterNodeDeviceEvent(virtDBusConnect *connect, + gint id, + virConnectNodeDeviceEventGenericCallback callback) +{ + g_assert(connect->devCallbackIds[id] == -1); + + connect->devCallbackIds[id] = virConnectNodeDeviceEventRegisterAny(connect->connection, + NULL, + id, + VIR_NODE_DEVICE_EVENT_CALLBACK(callback), + connect, + NULL); +} + static void virtDBusEventsRegisterSecretEvent(virtDBusConnect *connect, gint id, @@ -791,6 +829,10 @@ virtDBusEventsRegister(virtDBusConnect *connect) VIR_NETWORK_EVENT_ID_LIFECYCLE, VIR_NETWORK_EVENT_CALLBACK(virtDBusEventsNetworkEvent)); + virtDBusEventsRegisterNodeDeviceEvent(connect, + VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE, + VIR_NODE_DEVICE_EVENT_CALLBACK(virtDBusEventsNodeDeviceEvent)); + virtDBusEventsRegisterSecretEvent(connect, VIR_SECRET_EVENT_ID_LIFECYCLE, VIR_SECRET_EVENT_CALLBACK(virtDBusEventsSecretEvent)); -- 2.15.0

On Fri, Jun 15, 2018 at 07:03:39PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 7 +++++++ src/connect.c | 13 +++++++++++++ src/connect.h | 1 + src/events.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+)
[...]
diff --git a/src/connect.h b/src/connect.h index 3b62edd..a864041 100644 --- a/src/connect.h +++ b/src/connect.h @@ -24,6 +24,7 @@ struct virtDBusConnect {
gint domainCallbackIds[VIR_DOMAIN_EVENT_ID_LAST]; gint networkCallbackIds[VIR_NETWORK_EVENT_ID_LAST]; + gint devCallbackIds[VIR_NODE_DEVICE_EVENT_ID_LAST];
I would prefer nodeDevCallbackIds.
gint secretCallbackIds[VIR_SECRET_EVENT_ID_LAST]; gint storagePoolCallbackIds[VIR_STORAGE_POOL_EVENT_ID_LAST]; };
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 7 +++++++ src/connect.c | 30 ++++++++++++++++++++++++++++++ tests/libvirttest.py | 3 +++ tests/test_connect.py | 14 ++++++++++++++ tests/xmldata.py | 16 ++++++++++++++++ 5 files changed, 70 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 3828832..d8b0d9e 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -208,6 +208,13 @@ <arg name="uuid" type="s" direction="in"/> <arg name="network" type="o" direction="out"/> </method> + <method name="NodeDeviceCreateXML"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceCreateXML"/> + <arg name="xml" type="s" direction="in"/> + <arg name="flags" type="u" direction="in"/> + <arg name="dev" type="o" direction="out"/> + </method> <method name="NWFilterDefineXML"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterDefineXML"/> diff --git a/src/connect.c b/src/connect.c index 1c27768..5e146a6 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1069,6 +1069,35 @@ virtDBusConnectNetworkLookupByUUID(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); } +static void +virtDBusConnectNodeDeviceCreateXML(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNodeDevice) dev = NULL; + g_autofree gchar *path = NULL; + gchar *xml; + guint flags; + + g_variant_get(inArgs, "(&su)", &xml, &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + dev = virNodeDeviceCreateXML(connect->connection, xml, flags); + if (!dev) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirNodeDevice(dev, connect->devPath); + + *outArgs = g_variant_new("(o)", path); +} + static void virtDBusConnectNWFilterDefineXML(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -1687,6 +1716,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NetworkDefineXML", virtDBusConnectNetworkDefineXML }, { "NetworkLookupByName", virtDBusConnectNetworkLookupByName }, { "NetworkLookupByUUID", virtDBusConnectNetworkLookupByUUID }, + { "NodeDeviceCreateXML", virtDBusConnectNodeDeviceCreateXML }, { "NWFilterDefineXML", virtDBusConnectNWFilterDefineXML }, { "NWFilterLookupByName", virtDBusConnectNWFilterLookupByName }, { "NWFilterLookupByUUID", virtDBusConnectNWFilterLookupByUUID }, diff --git a/tests/libvirttest.py b/tests/libvirttest.py index 6d1a9d0..6b6cb4c 100644 --- a/tests/libvirttest.py +++ b/tests/libvirttest.py @@ -217,6 +217,9 @@ class NetworkEvent(IntEnum): STARTED = 2 STOPPED = 3 +class NodeDeviceEvent(IntEnum): + CREATED = 0 + DELETED = 1 class StoragePoolBuildFlags(IntEnum): NEW = 0 diff --git a/tests/test_connect.py b/tests/test_connect.py index 57b385e..e532016 100755 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -155,6 +155,20 @@ class TestConnect(libvirttest.BaseTestClass): path = getattr(self.connect, lookup_method_name)(prop) assert original_path == path + def test_connect_node_device_create_xml(self): + def node_device_created(path, event, _detail): + if event != libvirttest.NodeDeviceEvent.CREATED: + return + assert isinstance(path, dbus.ObjectPath) + self.loop.quit() + + self.connect.connect_to_signal('NodeDeviceEvent', node_device_created) + + path = self.connect.NodeDeviceCreateXML(xmldata.minimal_node_device_xml, 0) + assert isinstance(path, dbus.ObjectPath) + + self.main_loop() + def test_connect_node_get_cpu_stats(self): stats = self.connect.NodeGetCPUStats(0, 0) assert isinstance(stats, dbus.Dictionary) diff --git a/tests/xmldata.py b/tests/xmldata.py index 926bd2c..25bb089 100644 --- a/tests/xmldata.py +++ b/tests/xmldata.py @@ -26,6 +26,22 @@ minimal_network_xml = ''' </network> ''' +minimal_node_device_xml = ''' +<device> + <name>scsi_host22</name> + <parent>scsi_host2</parent> + <capability type='scsi_host'> + <host>22</host> + <unique_id>22</unique_id> + <capability type='fc_host'> + <wwnn>2000000098765432</wwnn> + <wwpn>1000000098765432</wwpn> + <fabric_wwn>2000000098769876</fabric_wwn> + </capability> + </capability> +</device> +''' + minimal_storage_pool_xml = ''' <pool type='dir'> <name>foo</name> -- 2.15.0

On Fri, Jun 15, 2018 at 07:03:40PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 7 +++++++ src/connect.c | 30 ++++++++++++++++++++++++++++++ tests/libvirttest.py | 3 +++ tests/test_connect.py | 14 ++++++++++++++ tests/xmldata.py | 16 ++++++++++++++++ 5 files changed, 70 insertions(+)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- Some note about the test: 1: The previous test should not use the node_device_create fixture introduced here for the following reason: The fixture is creating the device in the setup of the test since the device creation is not supposed to be tested in other tests apart from the CreateXML test. Only that test should not have the creation in the setup, but in the actual test `call` part. 2: I didn't create the get_test_node_device function as other entities have because ListNodeDevices method is not supported by the test driver data/org.libvirt.NodeDevice.xml | 4 ++++ src/nodedev.c | 42 +++++++++++++++++++++++++++++++++++++++++ tests/Makefile.am | 1 + tests/libvirttest.py | 10 ++++++++++ tests/test_nodedev.py | 31 ++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100755 tests/test_nodedev.py diff --git a/data/org.libvirt.NodeDevice.xml b/data/org.libvirt.NodeDevice.xml index 7ca26d0..4ca2e11 100644 --- a/data/org.libvirt.NodeDevice.xml +++ b/data/org.libvirt.NodeDevice.xml @@ -3,5 +3,9 @@ <node name="/org/libvirt/nodedev"> <interface name="org.libvirt.NodeDevice"> + <method name="Destroy"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDestroy"/> + </method> </interface> </node> diff --git a/src/nodedev.c b/src/nodedev.c index 188df74..ec87bd8 100644 --- a/src/nodedev.c +++ b/src/nodedev.c @@ -3,11 +3,53 @@ #include <libvirt/libvirt.h> +static virNodeDevicePtr +virtDBusNodeDeviceGetVirNodeDevice(virtDBusConnect *connect, + const gchar *objectPath, + GError **error) +{ + virNodeDevicePtr dev; + + if (virtDBusConnectOpen(connect, error) < 0) + return NULL; + + dev = virtDBusUtilVirNodeDeviceFromBusPath(connect->connection, + objectPath, + connect->devPath); + if (!dev) { + virtDBusUtilSetLastVirtError(error); + return NULL; + } + + return dev; +} + +static void +virtDBusNodeDeviceDestroy(GVariant *inArgs G_GNUC_UNUSED, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNodeDevice) dev = NULL; + + dev = virtDBusNodeDeviceGetVirNodeDevice(connect, objectPath, error); + if (!dev) + return; + + if (virNodeDeviceDestroy(dev) < 0) + virtDBusUtilSetLastVirtError(error); +} + static virtDBusGDBusPropertyTable virtDBusNodeDevicePropertyTable[] = { { 0 } }; static virtDBusGDBusMethodTable virtDBusNodeDeviceMethodTable[] = { + { "Destroy", virtDBusNodeDeviceDestroy }, { 0 } }; diff --git a/tests/Makefile.am b/tests/Makefile.am index 4cae303..e841627 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -7,6 +7,7 @@ test_programs = \ test_connect.py \ test_domain.py \ test_network.py \ + test_nodedev.py \ test_storage.py check_PROGRAMS = \ diff --git a/tests/libvirttest.py b/tests/libvirttest.py index 6b6cb4c..06e52c0 100644 --- a/tests/libvirttest.py +++ b/tests/libvirttest.py @@ -71,6 +71,16 @@ class BaseTestClass(): if self.timeout: raise TimeoutError() + @pytest.fixture + def node_device_create(self): + """ Fixture to create dummy node device on the test driver + + This fixture should be used in the setup of every test manipulating + with node devices. + """ + path = self.connect.NodeDeviceCreateXML(xmldata.minimal_node_device_xml, 0) + return path + @pytest.fixture def storage_volume_create(self): """ Fixture to create dummy storage volume on the test driver diff --git a/tests/test_nodedev.py b/tests/test_nodedev.py new file mode 100755 index 0000000..8ef8e32 --- /dev/null +++ b/tests/test_nodedev.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +import dbus +import libvirttest +import pytest + + +@pytest.mark.usefixtures("node_device_create") +class TestNodeDevice(libvirttest.BaseTestClass): + """ Tests for methods and properties of the NodeDevice interface + """ + + def test_node_device_destroy(self): + def node_device_deleted(path, event, _detail): + if event != libvirttest.NodeDeviceEvent.DELETED: + return + assert isinstance(path, dbus.ObjectPath) + self.loop.quit() + + self.connect.connect_to_signal('NodeDeviceEvent', node_device_deleted) + + test_node_device_path = self.node_device_create() + obj = self.bus.get_object('org.libvirt', test_node_device_path) + interface_obj = dbus.Interface(obj, 'org.libvirt.NodeDevice') + interface_obj.Destroy() + + self.main_loop() + + +if __name__ == '__main__': + libvirttest.run() -- 2.15.0

On Fri, Jun 15, 2018 at 07:03:41PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> ---
Some note about the test:
1: The previous test should not use the node_device_create fixture introduced here for the following reason: The fixture is creating the device in the setup of the test since the device creation is not supposed to be tested in other tests apart from the CreateXML test. Only that test should not have the creation in the setup, but in the actual test `call` part.
2: I didn't create the get_test_node_device function as other entities have because ListNodeDevices method is not supported by the test driver
data/org.libvirt.NodeDevice.xml | 4 ++++ src/nodedev.c | 42 +++++++++++++++++++++++++++++++++++++++++ tests/Makefile.am | 1 + tests/libvirttest.py | 10 ++++++++++ tests/test_nodedev.py | 31 ++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100755 tests/test_nodedev.py
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.NodeDevice.xml | 5 +++++ src/nodedev.c | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/data/org.libvirt.NodeDevice.xml b/data/org.libvirt.NodeDevice.xml index 4ca2e11..ea9bd7c 100644 --- a/data/org.libvirt.NodeDevice.xml +++ b/data/org.libvirt.NodeDevice.xml @@ -7,5 +7,10 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDestroy"/> </method> + <method name="Detach"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDetachFlags"/> + <arg name="flags" type="u" direction="in"/> + </method> </interface> </node> diff --git a/src/nodedev.c b/src/nodedev.c index ec87bd8..e8551b8 100644 --- a/src/nodedev.c +++ b/src/nodedev.c @@ -44,12 +44,37 @@ virtDBusNodeDeviceDestroy(GVariant *inArgs G_GNUC_UNUSED, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusNodeDeviceDetach(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNodeDevice) dev = NULL; + const gchar *driverName; + guint flags; + + g_variant_get(inArgs, "(&su)", &driverName, &flags); + + dev = virtDBusNodeDeviceGetVirNodeDevice(connect, objectPath, error); + if (!dev) + return; + + if (virNodeDeviceDetachFlags(dev, driverName, flags) < 0) + virtDBusUtilSetLastVirtError(error); +} + static virtDBusGDBusPropertyTable virtDBusNodeDevicePropertyTable[] = { { 0 } }; static virtDBusGDBusMethodTable virtDBusNodeDeviceMethodTable[] = { { "Destroy", virtDBusNodeDeviceDestroy }, + { "Detach", virtDBusNodeDeviceDetach }, { 0 } }; -- 2.15.0

On Fri, Jun 15, 2018 at 07:03:42PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.NodeDevice.xml | 5 +++++ src/nodedev.c | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
diff --git a/data/org.libvirt.NodeDevice.xml b/data/org.libvirt.NodeDevice.xml index 4ca2e11..ea9bd7c 100644 --- a/data/org.libvirt.NodeDevice.xml +++ b/data/org.libvirt.NodeDevice.xml @@ -7,5 +7,10 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDestroy"/> </method> + <method name="Detach"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDetachFlags"/> + <arg name="flags" type="u" direction="in"/>
Missing driverName argument.
+ </method> </interface> </node>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.NodeDevice.xml | 5 +++++ src/nodedev.c | 22 ++++++++++++++++++++++ tests/test_nodedev.py | 8 ++++++++ 3 files changed, 35 insertions(+) diff --git a/data/org.libvirt.NodeDevice.xml b/data/org.libvirt.NodeDevice.xml index ea9bd7c..b4caac3 100644 --- a/data/org.libvirt.NodeDevice.xml +++ b/data/org.libvirt.NodeDevice.xml @@ -3,6 +3,11 @@ <node name="/org/libvirt/nodedev"> <interface name="org.libvirt.NodeDevice"> + <property name="Name" type="s" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceGetName"/> + <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> + </property> <method name="Destroy"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDestroy"/> diff --git a/src/nodedev.c b/src/nodedev.c index e8551b8..9647fb6 100644 --- a/src/nodedev.c +++ b/src/nodedev.c @@ -24,6 +24,27 @@ virtDBusNodeDeviceGetVirNodeDevice(virtDBusConnect *connect, return dev; } +static void +virtDBusNodeDeviceGetName(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNodeDevice) dev = NULL; + const gchar *name; + + dev = virtDBusNodeDeviceGetVirNodeDevice(connect, objectPath, error); + if (!dev) + return; + + name = virNodeDeviceGetName(dev); + if (!name) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("s", name); +} + static void virtDBusNodeDeviceDestroy(GVariant *inArgs G_GNUC_UNUSED, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -69,6 +90,7 @@ virtDBusNodeDeviceDetach(GVariant *inArgs, } static virtDBusGDBusPropertyTable virtDBusNodeDevicePropertyTable[] = { + { "Name", virtDBusNodeDeviceGetName, NULL }, { 0 } }; diff --git a/tests/test_nodedev.py b/tests/test_nodedev.py index 8ef8e32..cc7199a 100755 --- a/tests/test_nodedev.py +++ b/tests/test_nodedev.py @@ -26,6 +26,14 @@ class TestNodeDevice(libvirttest.BaseTestClass): self.main_loop() + def test_node_device_properties_type(self): + """ Ensure correct return type for NodeDevice properties + """ + test_node_device_path = self.node_device_create() + obj = self.bus.get_object('org.libvirt', test_node_device_path) + props = obj.GetAll('org.libvirt.NodeDevice', dbus_interface=dbus.PROPERTIES_IFACE) + assert isinstance(props['Name'], dbus.String) + if __name__ == '__main__': libvirttest.run() -- 2.15.0

On Fri, Jun 15, 2018 at 07:03:43PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.NodeDevice.xml | 5 +++++ src/nodedev.c | 22 ++++++++++++++++++++++ tests/test_nodedev.py | 8 ++++++++ 3 files changed, 35 insertions(+)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.NodeDevice.xml | 5 +++++ src/nodedev.c | 22 ++++++++++++++++++++++ tests/test_nodedev.py | 1 + 3 files changed, 28 insertions(+) diff --git a/data/org.libvirt.NodeDevice.xml b/data/org.libvirt.NodeDevice.xml index b4caac3..c4b4075 100644 --- a/data/org.libvirt.NodeDevice.xml +++ b/data/org.libvirt.NodeDevice.xml @@ -8,6 +8,11 @@ value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceGetName"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> + <property name="Parent" type="s" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceGetParent"/> + <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> + </property> <method name="Destroy"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDestroy"/> diff --git a/src/nodedev.c b/src/nodedev.c index 9647fb6..c597411 100644 --- a/src/nodedev.c +++ b/src/nodedev.c @@ -45,6 +45,27 @@ virtDBusNodeDeviceGetName(const gchar *objectPath, *value = g_variant_new("s", name); } +static void +virtDBusNodeDeviceGetParent(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNodeDevice) dev = NULL; + const gchar *parent; + + dev = virtDBusNodeDeviceGetVirNodeDevice(connect, objectPath, error); + if (!dev) + return; + + parent = virNodeDeviceGetParent(dev); + if (!parent) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("s", parent); +} + static void virtDBusNodeDeviceDestroy(GVariant *inArgs G_GNUC_UNUSED, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -91,6 +112,7 @@ virtDBusNodeDeviceDetach(GVariant *inArgs, static virtDBusGDBusPropertyTable virtDBusNodeDevicePropertyTable[] = { { "Name", virtDBusNodeDeviceGetName, NULL }, + { "Parent", virtDBusNodeDeviceGetParent, NULL }, { 0 } }; diff --git a/tests/test_nodedev.py b/tests/test_nodedev.py index cc7199a..39343ae 100755 --- a/tests/test_nodedev.py +++ b/tests/test_nodedev.py @@ -33,6 +33,7 @@ class TestNodeDevice(libvirttest.BaseTestClass): obj = self.bus.get_object('org.libvirt', test_node_device_path) props = obj.GetAll('org.libvirt.NodeDevice', dbus_interface=dbus.PROPERTIES_IFACE) assert isinstance(props['Name'], dbus.String) + assert isinstance(props['Parent'], dbus.String) if __name__ == '__main__': -- 2.15.0

On Fri, Jun 15, 2018 at 07:03:44PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.NodeDevice.xml | 5 +++++ src/nodedev.c | 22 ++++++++++++++++++++++ tests/test_nodedev.py | 1 + 3 files changed, 28 insertions(+)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.NodeDevice.xml | 6 ++++++ src/nodedev.c | 28 ++++++++++++++++++++++++++++ tests/test_nodedev.py | 6 ++++++ 3 files changed, 40 insertions(+) diff --git a/data/org.libvirt.NodeDevice.xml b/data/org.libvirt.NodeDevice.xml index c4b4075..1185bca 100644 --- a/data/org.libvirt.NodeDevice.xml +++ b/data/org.libvirt.NodeDevice.xml @@ -22,5 +22,11 @@ value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDetachFlags"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="GetXMLDesc"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceGetXMLDesc"/> + <arg name="flags" type="u" direction="in"/> + <arg name="xml" type="s" direction="out"/> + </method> </interface> </node> diff --git a/src/nodedev.c b/src/nodedev.c index c597411..e61242d 100644 --- a/src/nodedev.c +++ b/src/nodedev.c @@ -110,6 +110,33 @@ virtDBusNodeDeviceDetach(GVariant *inArgs, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusNodeDeviceGetXMLDesc(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNodeDevice) dev = NULL; + g_autofree gchar *xml = NULL; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + dev = virtDBusNodeDeviceGetVirNodeDevice(connect, objectPath, error); + if (!dev) + return; + + xml = virNodeDeviceGetXMLDesc(dev, flags); + if (!xml) + return virtDBusUtilSetLastVirtError(error); + + *outArgs = g_variant_new("(s)", xml); +} + static virtDBusGDBusPropertyTable virtDBusNodeDevicePropertyTable[] = { { "Name", virtDBusNodeDeviceGetName, NULL }, { "Parent", virtDBusNodeDeviceGetParent, NULL }, @@ -119,6 +146,7 @@ static virtDBusGDBusPropertyTable virtDBusNodeDevicePropertyTable[] = { static virtDBusGDBusMethodTable virtDBusNodeDeviceMethodTable[] = { { "Destroy", virtDBusNodeDeviceDestroy }, { "Detach", virtDBusNodeDeviceDetach }, + { "GetXMLDesc", virtDBusNodeDeviceGetXMLDesc }, { 0 } }; diff --git a/tests/test_nodedev.py b/tests/test_nodedev.py index 39343ae..64c97b2 100755 --- a/tests/test_nodedev.py +++ b/tests/test_nodedev.py @@ -26,6 +26,12 @@ class TestNodeDevice(libvirttest.BaseTestClass): self.main_loop() + def test_node_device_get_xml_description(self): + test_node_device_path = self.node_device_create() + obj = self.bus.get_object('org.libvirt', test_node_device_path) + interface_obj = dbus.Interface(obj, 'org.libvirt.NodeDevice') + assert isinstance(interface_obj.GetXMLDesc(0), dbus.String) + def test_node_device_properties_type(self): """ Ensure correct return type for NodeDevice properties """ -- 2.15.0

On Fri, Jun 15, 2018 at 07:03:45PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.NodeDevice.xml | 6 ++++++ src/nodedev.c | 28 ++++++++++++++++++++++++++++ tests/test_nodedev.py | 6 ++++++ 3 files changed, 40 insertions(+)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.NodeDevice.xml | 5 +++++ src/nodedev.c | 37 +++++++++++++++++++++++++++++++++++++ tests/test_nodedev.py | 6 ++++++ 3 files changed, 48 insertions(+) diff --git a/data/org.libvirt.NodeDevice.xml b/data/org.libvirt.NodeDevice.xml index 1185bca..bf85958 100644 --- a/data/org.libvirt.NodeDevice.xml +++ b/data/org.libvirt.NodeDevice.xml @@ -28,5 +28,10 @@ <arg name="flags" type="u" direction="in"/> <arg name="xml" type="s" direction="out"/> </method> + <method name="ListCaps"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceListCaps"/> + <arg name="names" type="as" direction="out"/> + </method> </interface> </node> diff --git a/src/nodedev.c b/src/nodedev.c index e61242d..01fcd35 100644 --- a/src/nodedev.c +++ b/src/nodedev.c @@ -137,6 +137,42 @@ virtDBusNodeDeviceGetXMLDesc(GVariant *inArgs, *outArgs = g_variant_new("(s)", xml); } +static void +virtDBusNodeDeviceListCaps(GVariant *inArgs G_GNUC_UNUSED, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNodeDevice) dev = NULL; + g_autoptr(virtDBusCharArray) caps = NULL; + gint ncaps; + GVariant *gret; + GVariantBuilder builder; + + dev = virtDBusNodeDeviceGetVirNodeDevice(connect, objectPath, error); + if (!dev) + return; + + if ((ncaps = virNodeDeviceNumOfCaps(dev)) < 0) + return virtDBusUtilSetLastVirtError(error); + + caps = g_new0(char *, ncaps + 1); + + if ((ncaps = virNodeDeviceListCaps(dev, caps, ncaps)) < 0) + return virtDBusUtilSetLastVirtError(error); + + g_variant_builder_init(&builder, G_VARIANT_TYPE("as")); + for (gint i = 0; i < ncaps; i++) + g_variant_builder_add(&builder, "s", caps[i]); + gret = g_variant_builder_end(&builder); + + *outArgs = g_variant_new_tuple(&gret, 1); +} + static virtDBusGDBusPropertyTable virtDBusNodeDevicePropertyTable[] = { { "Name", virtDBusNodeDeviceGetName, NULL }, { "Parent", virtDBusNodeDeviceGetParent, NULL }, @@ -147,6 +183,7 @@ static virtDBusGDBusMethodTable virtDBusNodeDeviceMethodTable[] = { { "Destroy", virtDBusNodeDeviceDestroy }, { "Detach", virtDBusNodeDeviceDetach }, { "GetXMLDesc", virtDBusNodeDeviceGetXMLDesc }, + { "ListCaps", virtDBusNodeDeviceListCaps }, { 0 } }; diff --git a/tests/test_nodedev.py b/tests/test_nodedev.py index 64c97b2..6aa6211 100755 --- a/tests/test_nodedev.py +++ b/tests/test_nodedev.py @@ -32,6 +32,12 @@ class TestNodeDevice(libvirttest.BaseTestClass): interface_obj = dbus.Interface(obj, 'org.libvirt.NodeDevice') assert isinstance(interface_obj.GetXMLDesc(0), dbus.String) + def test_node_device_list_caps(self): + test_node_device_path = self.node_device_create() + obj = self.bus.get_object('org.libvirt', test_node_device_path) + interface_obj = dbus.Interface(obj, 'org.libvirt.NodeDevice') + assert isinstance(interface_obj.ListCaps(), dbus.Array) + def test_node_device_properties_type(self): """ Ensure correct return type for NodeDevice properties """ -- 2.15.0

On Fri, Jun 15, 2018 at 07:03:46PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.NodeDevice.xml | 5 +++++ src/nodedev.c | 37 +++++++++++++++++++++++++++++++++++++ tests/test_nodedev.py | 6 ++++++ 3 files changed, 48 insertions(+)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 29 +++++++++++++++++++++++++++++ tests/test_connect.py | 13 +++++++++++++ 3 files changed, 48 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index d8b0d9e..a030d57 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -215,6 +215,12 @@ <arg name="flags" type="u" direction="in"/> <arg name="dev" type="o" direction="out"/> </method> + <method name="NodeDeviceLookupByName"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceLookupByName"/> + <arg name="name" type="s" direction="in"/> + <arg name="dev" type="o" direction="out"/> + </method> <method name="NWFilterDefineXML"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterDefineXML"/> diff --git a/src/connect.c b/src/connect.c index 5e146a6..6192f47 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1098,6 +1098,34 @@ virtDBusConnectNodeDeviceCreateXML(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); } +static void +virtDBusConnectNodeDeviceLookupByName(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNodeDevice) dev = NULL; + g_autofree gchar *path = NULL; + const gchar *name; + + g_variant_get(inArgs, "(s)", &name); + + if (!virtDBusConnectOpen(connect, error)) + return; + + dev = virNodeDeviceLookupByName(connect->connection, name); + if (!dev) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirNodeDevice(dev, connect->devPath); + + *outArgs = g_variant_new("(o)", path); +} + static void virtDBusConnectNWFilterDefineXML(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -1717,6 +1745,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NetworkLookupByName", virtDBusConnectNetworkLookupByName }, { "NetworkLookupByUUID", virtDBusConnectNetworkLookupByUUID }, { "NodeDeviceCreateXML", virtDBusConnectNodeDeviceCreateXML }, + { "NodeDeviceLookupByName", virtDBusConnectNodeDeviceLookupByName }, { "NWFilterDefineXML", virtDBusConnectNWFilterDefineXML }, { "NWFilterLookupByName", virtDBusConnectNWFilterLookupByName }, { "NWFilterLookupByUUID", virtDBusConnectNWFilterLookupByUUID }, diff --git a/tests/test_connect.py b/tests/test_connect.py index e532016..7084397 100755 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -143,6 +143,19 @@ class TestConnect(libvirttest.BaseTestClass): self.main_loop() + @pytest.mark.usefixtures("node_device_create") + @pytest.mark.parametrize("lookup_method_name,lookup_item", [ + ("NodeDeviceLookupByName", 'Name'), + ]) + def test_connect_node_device_lookup_by_property(self, lookup_method_name, lookup_item): + """Parameterized test for all NodeDeviceLookupBy* API calls of Connect interface + """ + original_path = self.node_device_create() + obj = self.bus.get_object('org.libvirt', original_path) + prop = obj.Get('org.libvirt.NodeDevice', lookup_item, dbus_interface=dbus.PROPERTIES_IFACE) + path = getattr(self.connect, lookup_method_name)(prop) + assert original_path == path + @pytest.mark.parametrize("lookup_method_name,lookup_item", [ ("NetworkLookupByName", 'Name'), ("NetworkLookupByUUID", 'UUID'), -- 2.15.0

On Fri, Jun 15, 2018 at 07:03:47PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 29 +++++++++++++++++++++++++++++ tests/test_connect.py | 13 +++++++++++++ 3 files changed, 48 insertions(+)
[...]
diff --git a/src/connect.c b/src/connect.c index 5e146a6..6192f47 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1098,6 +1098,34 @@ virtDBusConnectNodeDeviceCreateXML(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); }
+static void +virtDBusConnectNodeDeviceLookupByName(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNodeDevice) dev = NULL; + g_autofree gchar *path = NULL; + const gchar *name; + + g_variant_get(inArgs, "(s)", &name);
s/(s)/(&s)/ Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 8 ++++++++ src/connect.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index a030d57..7014a09 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -221,6 +221,14 @@ <arg name="name" type="s" direction="in"/> <arg name="dev" type="o" direction="out"/> </method> + <method name="NodeDeviceLookupSCSIHostByWWN"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceLookupSCSIHostByWWN"/> + <arg name="wwnn" type="s" direction="in"/> + <arg name="wwpn" type="s" direction="in"/> + <arg name="flags" type="u" direction="in"/> + <arg name="dev" type="o" direction="out"/> + </method> <method name="NWFilterDefineXML"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterDefineXML"/> diff --git a/src/connect.c b/src/connect.c index 6192f47..e1406dd 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1126,6 +1126,37 @@ virtDBusConnectNodeDeviceLookupByName(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); } +static void +virtDBusConnectNodeDeviceLookupSCSIHostByWWN(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNodeDevice) dev = NULL; + g_autofree gchar *path = NULL; + const gchar *wwnn; + const gchar *wwpn; + guint flags; + + g_variant_get(inArgs, "(&s&su)", &wwnn, &wwpn, &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + dev = virNodeDeviceLookupSCSIHostByWWN(connect->connection, wwnn, wwpn, + flags); + if (!dev) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirNodeDevice(dev, connect->devPath); + + *outArgs = g_variant_new("(o)", path); +} + static void virtDBusConnectNWFilterDefineXML(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -1746,6 +1777,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NetworkLookupByUUID", virtDBusConnectNetworkLookupByUUID }, { "NodeDeviceCreateXML", virtDBusConnectNodeDeviceCreateXML }, { "NodeDeviceLookupByName", virtDBusConnectNodeDeviceLookupByName }, + { "NodeDeviceLookupSCSIHostByWWN", virtDBusConnectNodeDeviceLookupSCSIHostByWWN }, { "NWFilterDefineXML", virtDBusConnectNWFilterDefineXML }, { "NWFilterLookupByName", virtDBusConnectNWFilterLookupByName }, { "NWFilterLookupByUUID", virtDBusConnectNWFilterLookupByUUID }, -- 2.15.0

On Fri, Jun 15, 2018 at 07:03:48PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 8 ++++++++ src/connect.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.NodeDevice.xml | 4 ++++ src/nodedev.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/data/org.libvirt.NodeDevice.xml b/data/org.libvirt.NodeDevice.xml index bf85958..56deee3 100644 --- a/data/org.libvirt.NodeDevice.xml +++ b/data/org.libvirt.NodeDevice.xml @@ -33,5 +33,9 @@ value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceListCaps"/> <arg name="names" type="as" direction="out"/> </method> + <method name="ReAttach"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceReAttach"/> + </method> </interface> </node> diff --git a/src/nodedev.c b/src/nodedev.c index 01fcd35..1d15d79 100644 --- a/src/nodedev.c +++ b/src/nodedev.c @@ -173,6 +173,26 @@ virtDBusNodeDeviceListCaps(GVariant *inArgs G_GNUC_UNUSED, *outArgs = g_variant_new_tuple(&gret, 1); } +static void +virtDBusNodeDeviceReAttach(GVariant *inArgs G_GNUC_UNUSED, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNodeDevice) dev = NULL; + + dev = virtDBusNodeDeviceGetVirNodeDevice(connect, objectPath, error); + if (!dev) + return; + + if (virNodeDeviceReAttach(dev) < 0) + virtDBusUtilSetLastVirtError(error); +} + static virtDBusGDBusPropertyTable virtDBusNodeDevicePropertyTable[] = { { "Name", virtDBusNodeDeviceGetName, NULL }, { "Parent", virtDBusNodeDeviceGetParent, NULL }, @@ -184,6 +204,7 @@ static virtDBusGDBusMethodTable virtDBusNodeDeviceMethodTable[] = { { "Detach", virtDBusNodeDeviceDetach }, { "GetXMLDesc", virtDBusNodeDeviceGetXMLDesc }, { "ListCaps", virtDBusNodeDeviceListCaps }, + { "ReAttach", virtDBusNodeDeviceReAttach }, { 0 } }; -- 2.15.0

On Fri, Jun 15, 2018 at 07:03:49PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.NodeDevice.xml | 4 ++++ src/nodedev.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.NodeDevice.xml | 4 ++++ src/nodedev.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/data/org.libvirt.NodeDevice.xml b/data/org.libvirt.NodeDevice.xml index 56deee3..5464c9a 100644 --- a/data/org.libvirt.NodeDevice.xml +++ b/data/org.libvirt.NodeDevice.xml @@ -37,5 +37,9 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceReAttach"/> </method> + <method name="Reset"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceReset"/> + </method> </interface> </node> diff --git a/src/nodedev.c b/src/nodedev.c index 1d15d79..7982fd1 100644 --- a/src/nodedev.c +++ b/src/nodedev.c @@ -193,6 +193,26 @@ virtDBusNodeDeviceReAttach(GVariant *inArgs G_GNUC_UNUSED, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusNodeDeviceReset(GVariant *inArgs G_GNUC_UNUSED, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNodeDevice) dev = NULL; + + dev = virtDBusNodeDeviceGetVirNodeDevice(connect, objectPath, error); + if (!dev) + return; + + if (virNodeDeviceReset(dev) < 0) + virtDBusUtilSetLastVirtError(error); +} + static virtDBusGDBusPropertyTable virtDBusNodeDevicePropertyTable[] = { { "Name", virtDBusNodeDeviceGetName, NULL }, { "Parent", virtDBusNodeDeviceGetParent, NULL }, @@ -205,6 +225,7 @@ static virtDBusGDBusMethodTable virtDBusNodeDeviceMethodTable[] = { { "GetXMLDesc", virtDBusNodeDeviceGetXMLDesc }, { "ListCaps", virtDBusNodeDeviceListCaps }, { "ReAttach", virtDBusNodeDeviceReAttach }, + { "Reset", virtDBusNodeDeviceReset }, { 0 } }; -- 2.15.0

On Fri, Jun 15, 2018 at 07:03:50PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.NodeDevice.xml | 4 ++++ src/nodedev.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
participants (2)
-
Katerina Koukiou
-
Pavel Hrdina