From nobody Wed May 14 02:38:50 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 1528794045232529.0229839393478; Tue, 12 Jun 2018 02:00:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 85D813086258; Tue, 12 Jun 2018 09:00:41 +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 411FB308332B; Tue, 12 Jun 2018 09:00:41 +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 BC5924CA80; Tue, 12 Jun 2018 09:00:40 +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 w5C90VM2006293 for ; Tue, 12 Jun 2018 05:00:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id B36532022DF7; Tue, 12 Jun 2018 09:00:31 +0000 (UTC) Received: from katerina.brq.redhat.com (unknown [10.43.2.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A5912022DF5 for ; Tue, 12 Jun 2018 09:00:31 +0000 (UTC) From: Katerina Koukiou To: libvir-list@redhat.com Date: Tue, 12 Jun 2018 11:00:14 +0200 Message-Id: <20180612090028.2800-2-kkoukiou@redhat.com> In-Reply-To: <20180612090028.2800-1-kkoukiou@redhat.com> References: <20180612090028.2800-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/15] 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 12 Jun 2018 09:00:44 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Katerina Koukiou --- data/Makefile.am | 3 +- data/org.libvirt.StorageVol.xml | 7 +++ src/Makefile.am | 3 +- src/connect.c | 6 +++ src/connect.h | 1 + src/storagevol.c | 96 +++++++++++++++++++++++++++++++++++++= ++++ src/storagevol.h | 9 ++++ src/util.c | 35 +++++++++++++++ src/util.h | 16 +++++++ 9 files changed, 174 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..5688cab 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -24,7 +24,8 @@ 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 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..539e722 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,7 +12,8 @@ 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 =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..dad7d11 --- /dev/null +++ b/src/storagevol.c @@ -0,0 +1,96 @@ +#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; + gint numVols =3D 0; + gint numVolsTotal =3D 0; + gint offset =3D 0; + gchar **ret =3D NULL; + + if (!virtDBusConnectOpen(connect, NULL)) + return NULL; + + numPools =3D virConnectListAllStoragePools(connect->connection, + &storagePools, 0); + if (numPools < 0) + return NULL; + + if (numPools =3D=3D 0) + return NULL; + + for (gint i =3D 0; i < numPools; i++) { + g_autoptr(virStorageVolPtr) storageVols =3D NULL; + + numVols =3D virStoragePoolListAllVolumes(storagePools[i], + &storageVols, 0); + if (numVols < 0) + return NULL; + + if (numVols =3D=3D 0) + return NULL; + + numVolsTotal +=3D numVols; + } + + ret =3D g_new0(gchar *, numVolsTotal + 1); + + for (gint i =3D 0; i < numPools; i++) { + g_autoptr(virStorageVolPtr) storageVols =3D NULL; + + numVols =3D virStoragePoolListAllVolumes(storagePools[i], + &storageVols, 0); + if (numVols < 0) + return NULL; + + if (numVols =3D=3D 0) + return NULL; + + for (gint j =3D 0; j < numVols; j++) { + ret[offset] =3D virtDBusUtilBusPathForVirStorageVol(storageVol= s[j], + connect->sto= rageVolPath); + offset++; + } + } + + return ret; +} + +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..1d11ce6 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); + + key =3D virtDBusUtilDecodeStr(path + prefixLen + 1); + + 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