From nobody Wed Jul 16 13:32:13 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 1532111714721311.1151141903862; Fri, 20 Jul 2018 11:35:14 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9563EC04AC47; Fri, 20 Jul 2018 18:35:12 +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 4C977CAE87; Fri, 20 Jul 2018 18:35:12 +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 B1CE53F7D2; Fri, 20 Jul 2018 18:35:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6KIZ6g5023524 for ; Fri, 20 Jul 2018 14:35:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id A5B8A111E41E; Fri, 20 Jul 2018 18:35:06 +0000 (UTC) Received: from unused.bos.redhat.com (unknown [10.16.197.171]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85410111E405; Fri, 20 Jul 2018 18:35:06 +0000 (UTC) From: Anya Harter To: libvir-list@redhat.com Date: Fri, 20 Jul 2018 14:34:45 -0400 Message-Id: <9b475ed7847d20d433ef63bd74660bebad234b63.1531836010.git.aharter@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: phrdina@redhat.com, Anya Harter Subject: [libvirt] [dbus PATCH v2 01/17] Introduce Interface 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 20 Jul 2018 18:35:13 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Anya Harter Reviewed-by: J=EF=BF=BDn Tomko --- data/Makefile.am | 1 + data/org.libvirt.Interface.xml | 7 ++++ src/Makefile.am | 2 ++ src/connect.c | 6 ++++ src/connect.h | 1 + src/interface.c | 65 ++++++++++++++++++++++++++++++++++ src/interface.h | 9 +++++ src/util.c | 35 ++++++++++++++++++ src/util.h | 15 ++++++++ 9 files changed, 141 insertions(+) create mode 100644 data/org.libvirt.Interface.xml create mode 100644 src/interface.c create mode 100644 src/interface.h diff --git a/data/Makefile.am b/data/Makefile.am index 7b523da..35a0bbd 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -33,6 +33,7 @@ polkit_DATA =3D \ interfaces_files =3D \ org.libvirt.Connect.xml \ org.libvirt.Domain.xml \ + org.libvirt.Interface.xml \ org.libvirt.Network.xml \ org.libvirt.NodeDevice.xml \ org.libvirt.NWFilter.xml \ diff --git a/data/org.libvirt.Interface.xml b/data/org.libvirt.Interface.xml new file mode 100644 index 0000000..93fa32f --- /dev/null +++ b/data/org.libvirt.Interface.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/src/Makefile.am b/src/Makefile.am index b5bf129..d0e8f0d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -41,6 +41,8 @@ libvirt_dbus_SOURCES =3D \ events.h \ gdbus.c \ gdbus.h \ + interface.c \ + interface.h \ main.c \ network.c \ network.h \ diff --git a/src/connect.c b/src/connect.c index 9275121..3dc434d 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1,6 +1,7 @@ #include "connect.h" #include "domain.h" #include "events.h" +#include "interface.h" #include "network.h" #include "nodedev.h" #include "nwfilter.h" @@ -1809,6 +1810,7 @@ virtDBusConnectFree(virtDBusConnect *connect) virtDBusConnectClose(connect, TRUE); =20 g_free(connect->domainPath); + g_free(connect->interfacePath); g_free(connect->networkPath); g_free(connect->nodeDevPath); g_free(connect->nwfilterPath); @@ -1869,6 +1871,10 @@ virtDBusConnectNew(virtDBusConnect **connectp, if (error && *error) return; =20 + virtDBusInterfaceRegister(connect, error); + if (error && *error) + return; + virtDBusNetworkRegister(connect, error); if (error && *error) return; diff --git a/src/connect.h b/src/connect.h index 0b9ae10..961b115 100644 --- a/src/connect.h +++ b/src/connect.h @@ -13,6 +13,7 @@ struct virtDBusConnect { const gchar *uri; const gchar *connectPath; gchar *domainPath; + gchar *interfacePath; gchar *networkPath; gchar *nodeDevPath; gchar *nwfilterPath; diff --git a/src/interface.c b/src/interface.c new file mode 100644 index 0000000..3c32f0f --- /dev/null +++ b/src/interface.c @@ -0,0 +1,65 @@ +#include "interface.h" +#include "util.h" + +#include + +static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] =3D { + { 0 } +}; + +static virtDBusGDBusMethodTable virtDBusInterfaceMethodTable[] =3D { + { 0 } +}; + +static gchar ** +virtDBusInterfaceEnumerate(gpointer userData) +{ + virtDBusConnect *connect =3D userData; + g_autoptr(virInterfacePtr) interfaces =3D NULL; + gint num =3D 0; + gchar **ret =3D NULL; + + if (!virtDBusConnectOpen(connect, NULL)) + return NULL; + + num =3D virConnectListAllInterfaces(connect->connection, &interfaces, = 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 virtDBusUtilBusPathForVirInterface(interfaces[i], + connect->interfacePath= ); + } + + return ret; +} + +static GDBusInterfaceInfo *interfaceInfo; + +void +virtDBusInterfaceRegister(virtDBusConnect *connect, + GError **error) +{ + connect->interfacePath =3D g_strdup_printf("%s/interface", + connect->connectPath); + + if (!interfaceInfo) { + interfaceInfo =3D virtDBusGDBusLoadIntrospectData(VIRT_DBUS_INTERF= ACE_INTERFACE, + error); + if (!interfaceInfo) + return; + } + + virtDBusGDBusRegisterSubtree(connect->bus, + connect->interfacePath, + interfaceInfo, + virtDBusInterfaceEnumerate, + virtDBusInterfaceMethodTable, + virtDBusInterfacePropertyTable, + connect); +} diff --git a/src/interface.h b/src/interface.h new file mode 100644 index 0000000..8e5ee0a --- /dev/null +++ b/src/interface.h @@ -0,0 +1,9 @@ +#pragma once + +#include "connect.h" + +#define VIRT_DBUS_INTERFACE_INTERFACE "org.libvirt.Interface" + +void +virtDBusInterfaceRegister(virtDBusConnect *connect, + GError **error); diff --git a/src/util.c b/src/util.c index 8c822f2..9e11285 100644 --- a/src/util.c +++ b/src/util.c @@ -278,6 +278,41 @@ virtDBusUtilVirDomainListFree(virDomainPtr *domains) g_free(domains); } =20 +virInterfacePtr +virtDBusUtilVirInterfaceFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *interfacePath) +{ + g_autofree gchar *macstr =3D NULL; + gsize prefixLen =3D strlen(interfacePath) + 1; + + macstr =3D virtDBusUtilDecodeStr(path + prefixLen); + + return virInterfaceLookupByMACString(connection, macstr); +} + +gchar * +virtDBusUtilBusPathForVirInterface(virInterfacePtr interface, + const gchar *interfacePath) +{ + const gchar *macstr =3D NULL; + g_autofree const gchar *encodedMACStr =3D NULL; + + macstr =3D virInterfaceGetMACString(interface); + encodedMACStr =3D virtDBusUtilEncodeStr(macstr); + + return g_strdup_printf("%s/%s", interfacePath, encodedMACStr); +} + +void +virtDBusUtilVirInterfaceListFree(virInterfacePtr *interfaces) +{ + for (gint i =3D 0; interfaces[i] !=3D NULL; i++) + virInterfaceFree(interfaces[i]); + + g_free(interfaces); +} + virNetworkPtr virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection, const gchar *path, diff --git a/src/util.h b/src/util.h index a688a3d..b05c2fc 100644 --- a/src/util.h +++ b/src/util.h @@ -65,6 +65,21 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainPtr, virtDBusUtil= VirDomainListFree); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainStatsRecordPtr, virDomainStatsRecor= dListFree); =20 +virInterfacePtr +virtDBusUtilVirInterfaceFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *interfacePath); + +gchar * +virtDBusUtilBusPathForVirInterface(virInterfacePtr interface, + const gchar *interfacePath); + +void +virtDBusUtilVirInterfaceListFree(virInterfacePtr *interfaces); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virInterface, virInterfaceFree); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virInterfacePtr, virtDBusUtilVirInterfaceLis= tFree); + virNetworkPtr virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection, const gchar *path, --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list