From nobody Thu Jul 3 21:33:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1529082264039168.8406167869673; Fri, 15 Jun 2018 10:04:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 88B743002739; Fri, 15 Jun 2018 17:04:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 54EC510A33DE; Fri, 15 Jun 2018 17:04:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E04B34CA87; Fri, 15 Jun 2018 17:04:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w5FH3rW4029778 for ; Fri, 15 Jun 2018 13:03:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2F1902026609; Fri, 15 Jun 2018 17:03:53 +0000 (UTC) Received: from katerina.brq.redhat.com (unknown [10.43.2.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7055202660C for ; Fri, 15 Jun 2018 17:03:52 +0000 (UTC) From: Katerina Koukiou To: libvirt-list@redhat.com Date: Fri, 15 Jun 2018 19:03:37 +0200 Message-Id: <20180615170350.20851-2-kkoukiou@redhat.com> In-Reply-To: <20180615170350.20851-1-kkoukiou@redhat.com> References: <20180615170350.20851-1-kkoukiou@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [dbus PATCH 01/14] Introduce NodeDevice Interface X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 15 Jun 2018 17:04:23 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Katerina Koukiou Reviewed-by: Pavel Hrdina --- 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 =3D \ 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 @@ + + + + + + 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 =3D \ 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); =20 + 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; =20 + 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 + +static virtDBusGDBusPropertyTable virtDBusNodeDevicePropertyTable[] =3D { + { 0 } +}; + +static virtDBusGDBusMethodTable virtDBusNodeDeviceMethodTable[] =3D { + { 0 } +}; + +static gchar ** +virtDBusNodeDeviceEnumerate(gpointer userData) +{ + virtDBusConnect *connect =3D userData; + g_autoptr(virNodeDevicePtr) devs =3D NULL; + gint num =3D 0; + gchar **ret =3D NULL; + + if (!virtDBusConnectOpen(connect, NULL)) + return NULL; + + num =3D virConnectListAllNodeDevices(connect->connection, &devs, 0); + if (num < 0) + return NULL; + + if (num =3D=3D 0) + return NULL; + + ret =3D g_new0(gchar *, num + 1); + + for (gint i =3D 0; i < num; i++) { + ret[i] =3D virtDBusUtilBusPathForVirNodeDevice(devs[i], + connect->devPath); + } + + return ret; +} + +static GDBusInterfaceInfo *interfaceInfo; + +void +virtDBusNodeDeviceRegister(virtDBusConnect *connect, + GError **error) +{ + connect->devPath =3D g_strdup_printf("%s/nodedev", + connect->connectPath); + + if (!interfaceInfo) { + interfaceInfo =3D virtDBusGDBusLoadIntrospectData(VIRT_DBUS_NODEDE= V_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); } =20 +virNodeDevicePtr +virtDBusUtilVirNodeDeviceFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *devPath) +{ + g_autofree gchar *name =3D NULL; + gsize prefixLen =3D strlen(devPath) + 1; + + name =3D virtDBusUtilDecodeStr(path + prefixLen); + + return virNodeDeviceLookupByName(connection, name); +} + +gchar * +virtDBusUtilBusPathForVirNodeDevice(virNodeDevicePtr dev, + const gchar *devPath) +{ + const gchar *name =3D NULL; + g_autofree const gchar *encodedName =3D NULL; + + name =3D virNodeDeviceGetName(dev); + encodedName =3D virtDBusUtilEncodeStr(name); + + return g_strdup_printf("%s/%s", devPath, encodedName); +} + +void +virtDBusUtilVirNodeDeviceListFree(virNodeDevicePtr *devs) +{ + for (gint i =3D 0; devs[i] !=3D 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, virtDBusUtilVirNetworkListFre= e); =20 +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, virtDBusUtilVirNodeDeviceL= istFree); + virNWFilterPtr virtDBusUtilVirNWFilterFromBusPath(virConnectPtr connection, const gchar *path, --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list