From nobody Wed May 14 02:51:34 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 15289920068893.7143233198214602; Thu, 14 Jun 2018 09:00:06 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF17330832F3; Thu, 14 Jun 2018 16:00:04 +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 5653D90800; Thu, 14 Jun 2018 16:00:04 +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 94CB14CA83; Thu, 14 Jun 2018 16:00:03 +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 w5EFxx0Y003724 for ; Thu, 14 Jun 2018 11:59:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id E6FE210FFE52; Thu, 14 Jun 2018 15:59:58 +0000 (UTC) Received: from katerina.brq.redhat.com (unknown [10.43.2.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8914910FFE4D for ; Thu, 14 Jun 2018 15:59:58 +0000 (UTC) From: Katerina Koukiou To: libvir-list@redhat.com Date: Thu, 14 Jun 2018 17:59:37 +0200 Message-Id: <20180614155953.30292-2-kkoukiou@redhat.com> In-Reply-To: <20180614155953.30292-1-kkoukiou@redhat.com> References: <20180614155953.30292-1-kkoukiou@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [dbus PATCH v2 01/17] Introduce StorageVol 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.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 14 Jun 2018 16:00:05 +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 | 4 ++- data/org.libvirt.StorageVol.xml | 7 ++++ src/Makefile.am | 4 ++- src/connect.c | 6 ++++ src/connect.h | 1 + src/storagevol.c | 77 +++++++++++++++++++++++++++++++++++++= ++++ src/storagevol.h | 9 +++++ src/util.c | 35 +++++++++++++++++++ src/util.h | 16 +++++++++ 9 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 data/org.libvirt.StorageVol.xml create mode 100644 src/storagevol.c create mode 100644 src/storagevol.h diff --git a/data/Makefile.am b/data/Makefile.am index fdec857..721b874 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -24,7 +24,9 @@ interfaces_files =3D \ org.libvirt.Network.xml \ org.libvirt.NWFilter.xml \ org.libvirt.Secret.xml \ - org.libvirt.StoragePool.xml + org.libvirt.StoragePool.xml \ + org.libvirt.StorageVol.xml \ + $(NULL) interfacesdir =3D $(DBUS_INTERFACES_DIR) interfaces_DATA =3D $(interfaces_files) =20 diff --git a/data/org.libvirt.StorageVol.xml b/data/org.libvirt.StorageVol.= xml new file mode 100644 index 0000000..c72c847 --- /dev/null +++ b/data/org.libvirt.StorageVol.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/src/Makefile.am b/src/Makefile.am index 22128c2..53d1a23 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,7 +12,9 @@ DAEMON_SOURCES =3D \ network.c network.h \ nwfilter.c nwfilter.h \ secret.c secret.h \ - storagepool.c storagepool.h + storagepool.c storagepool.h \ + storagevol.c storagevol.h \ + $(NULL) =20 EXTRA_DIST =3D \ $(DAEMON_SOURCES) diff --git a/src/connect.c b/src/connect.c index 75ae1cd..1090e3e 100644 --- a/src/connect.c +++ b/src/connect.c @@ -5,6 +5,7 @@ #include "nwfilter.h" #include "secret.h" #include "storagepool.h" +#include "storagevol.h" #include "util.h" =20 #include @@ -1612,6 +1613,7 @@ virtDBusConnectFree(virtDBusConnect *connect) g_free(connect->nwfilterPath); g_free(connect->secretPath); g_free(connect->storagePoolPath); + g_free(connect->storageVolPath); g_free(connect); } G_DEFINE_AUTOPTR_CLEANUP_FUNC(virtDBusConnect, virtDBusConnectFree); @@ -1679,6 +1681,10 @@ virtDBusConnectNew(virtDBusConnect **connectp, if (error && *error) return; =20 + virtDBusStorageVolRegister(connect, error); + if (error && *error) + return; + *connectp =3D connect; connect =3D NULL; } diff --git a/src/connect.h b/src/connect.h index fe672ed..341dfc4 100644 --- a/src/connect.h +++ b/src/connect.h @@ -17,6 +17,7 @@ struct virtDBusConnect { gchar *nwfilterPath; gchar *secretPath; gchar *storagePoolPath; + gchar *storageVolPath; virConnectPtr connection; GMutex lock; =20 diff --git a/src/storagevol.c b/src/storagevol.c new file mode 100644 index 0000000..0097a7f --- /dev/null +++ b/src/storagevol.c @@ -0,0 +1,77 @@ +#include "storagevol.h" +#include "util.h" + +#include + +static virtDBusGDBusPropertyTable virtDBusStorageVolPropertyTable[] =3D { + { 0 } +}; + +static virtDBusGDBusMethodTable virtDBusStorageVolMethodTable[] =3D { + { 0 } +}; + +static gchar ** +virtDBusStorageVolEnumerate(gpointer userData) +{ + virtDBusConnect *connect =3D userData; + g_autoptr(virStoragePoolPtr) storagePools =3D NULL; + gint numPools =3D 0; + GPtrArray *list =3D NULL; + + if (!virtDBusConnectOpen(connect, NULL)) + return NULL; + + numPools =3D virConnectListAllStoragePools(connect->connection, + &storagePools, 0); + if (numPools <=3D 0) + return NULL; + + list =3D g_ptr_array_new(); + + for (gint i =3D 0; i < numPools; i++) { + g_autoptr(virStorageVolPtr) storageVols =3D NULL; + gint numVols; + + numVols =3D virStoragePoolListAllVolumes(storagePools[i], + &storageVols, 0); + if (numVols <=3D 0) + continue; + + for (gint j =3D 0; j < numVols; j++) { + gchar *volPath =3D virtDBusUtilBusPathForVirStorageVol(storag= eVols[j], + connect-= >storageVolPath); + g_ptr_array_add(list, volPath); + } + } + + if (list->len > 0) + g_ptr_array_add(list, NULL); + + return (gchar **)g_ptr_array_free(list, FALSE); +} + +static GDBusInterfaceInfo *interfaceInfo; + +void +virtDBusStorageVolRegister(virtDBusConnect *connect, + GError **error) +{ + connect->storageVolPath =3D g_strdup_printf("%s/storagevol", + connect->connectPath); + + if (!interfaceInfo) { + interfaceInfo =3D virtDBusGDBusLoadIntrospectData(VIRT_DBUS_STORAG= EVOL_INTERFACE, + error); + if (!interfaceInfo) + return; + } + + virtDBusGDBusRegisterSubtree(connect->bus, + connect->storageVolPath, + interfaceInfo, + virtDBusStorageVolEnumerate, + virtDBusStorageVolMethodTable, + virtDBusStorageVolPropertyTable, + connect); +} diff --git a/src/storagevol.h b/src/storagevol.h new file mode 100644 index 0000000..e2a893b --- /dev/null +++ b/src/storagevol.h @@ -0,0 +1,9 @@ +#pragma once + +#include "connect.h" + +#define VIRT_DBUS_STORAGEVOL_INTERFACE "org.libvirt.StorageVol" + +void +virtDBusStorageVolRegister(virtDBusConnect *connect, + GError **error); diff --git a/src/util.c b/src/util.c index 1268736..ac6d11b 100644 --- a/src/util.c +++ b/src/util.c @@ -417,3 +417,38 @@ virtDBusUtilVirStoragePoolListFree(virStoragePoolPtr *= storagePools) =20 g_free(storagePools); } + +virStorageVolPtr +virtDBusUtilVirStorageVolFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *storageVolPath) +{ + g_autofree gchar *key =3D NULL; + gsize prefixLen =3D strlen(storageVolPath) + 1; + + key =3D virtDBusUtilDecodeStr(path + prefixLen); + + return virStorageVolLookupByKey(connection, key); +} + +gchar * +virtDBusUtilBusPathForVirStorageVol(virStorageVolPtr storageVol, + const gchar *storageVolPath) +{ + const gchar *key =3D NULL; + g_autofree const gchar *encodedKey =3D NULL; + + key =3D virStorageVolGetKey(storageVol); + encodedKey =3D virtDBusUtilEncodeStr(key); + + return g_strdup_printf("%s/%s", storageVolPath, encodedKey); +} + +void +virtDBusUtilVirStorageVolListFree(virStorageVolPtr *storageVols) +{ + for (gint i =3D 0; storageVols[i] !=3D NULL; i++) + virStorageVolFree(storageVols[i]); + + g_free(storageVols); +} diff --git a/src/util.h b/src/util.h index 56e0409..bf08d5d 100644 --- a/src/util.h +++ b/src/util.h @@ -133,3 +133,19 @@ virtDBusUtilVirStoragePoolListFree(virStoragePoolPtr *= storagePools); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePool, virStoragePoolFree); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePoolPtr, virtDBusUtilVirStoragePoolListFree); + +virStorageVolPtr +virtDBusUtilVirStorageVolFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *storageVolPath); + +gchar * +virtDBusUtilBusPathForVirStorageVol(virStorageVolPtr storageVol, + const gchar *storageVolPath); + +void +virtDBusUtilVirStorageVolListFree(virStorageVolPtr *storageVols); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageVol, virStorageVolFree); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageVolPtr, + virtDBusUtilVirStorageVolListFree); --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list