From nobody Wed May 14 08:53:31 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 1525704377542903.7845891802943; Mon, 7 May 2018 07:46:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 18F52C0C274A; Mon, 7 May 2018 14:46:16 +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 CF87B60BE0; Mon, 7 May 2018 14:46:15 +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 4DC685BBE4; Mon, 7 May 2018 14:46:15 +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 w47Ef3ne032352 for ; Mon, 7 May 2018 10:41:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5CE702024CA2; Mon, 7 May 2018 14:41:03 +0000 (UTC) Received: from katerina.brq.redhat.com (unknown [10.43.2.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id D8E572024CA1 for ; Mon, 7 May 2018 14:41:02 +0000 (UTC) From: Katerina Koukiou To: libvir-list@redhat.com Date: Mon, 7 May 2018 16:40:42 +0200 Message-Id: <20180507144100.25045-2-kkoukiou@redhat.com> In-Reply-To: <20180507144100.25045-1-kkoukiou@redhat.com> References: <20180507144100.25045-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/19] Introduce StoragePool 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 07 May 2018 14:46:16 +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.StoragePool.xml | 7 +++++ src/Makefile.am | 3 +- src/connect.c | 6 ++++ src/connect.h | 1 + src/storagepool.c | 65 ++++++++++++++++++++++++++++++++++++= ++++ src/storagepool.h | 9 ++++++ src/util.c | 33 ++++++++++++++++++++ src/util.h | 16 ++++++++++ 9 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 data/org.libvirt.StoragePool.xml create mode 100644 src/storagepool.c create mode 100644 src/storagepool.h diff --git a/data/Makefile.am b/data/Makefile.am index 61702df..4d2af45 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -21,7 +21,8 @@ polkit_DATA =3D $(polkit_files:.rules.in=3D.rules) interfaces_files =3D \ org.libvirt.Connect.xml \ org.libvirt.Domain.xml \ - org.libvirt.Network.xml + org.libvirt.Network.xml \ + org.libvirt.StoragePool.xml interfacesdir =3D $(DBUS_INTERFACES_DIR) interfaces_DATA =3D $(interfaces_files) =20 diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePoo= l.xml new file mode 100644 index 0000000..504a166 --- /dev/null +++ b/data/org.libvirt.StoragePool.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/src/Makefile.am b/src/Makefile.am index 158398a..5e082da 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,7 +9,8 @@ DAEMON_SOURCES =3D \ domain.c domain.h \ events.c events.h \ gdbus.c gdbus.h \ - network.c network.h + network.c network.h \ + storagepool.c storagepool.h =20 EXTRA_DIST =3D \ $(DAEMON_SOURCES) diff --git a/src/connect.c b/src/connect.c index fd335e3..e838e98 100644 --- a/src/connect.c +++ b/src/connect.c @@ -2,6 +2,7 @@ #include "domain.h" #include "events.h" #include "network.h" +#include "storagepool.h" #include "util.h" =20 #include @@ -1105,6 +1106,7 @@ virtDBusConnectFree(virtDBusConnect *connect) =20 g_free(connect->domainPath); g_free(connect->networkPath); + g_free(connect->storagePoolPath); g_free(connect); } G_DEFINE_AUTOPTR_CLEANUP_FUNC(virtDBusConnect, virtDBusConnectFree); @@ -1154,6 +1156,10 @@ virtDBusConnectNew(virtDBusConnect **connectp, if (error && *error) return; =20 + virtDBusStoragePoolRegister(connect, error); + if (error && *error) + return; + *connectp =3D connect; connect =3D NULL; } diff --git a/src/connect.h b/src/connect.h index f89bc9d..d6c3830 100644 --- a/src/connect.h +++ b/src/connect.h @@ -14,6 +14,7 @@ struct virtDBusConnect { const gchar *connectPath; gchar *domainPath; gchar *networkPath; + gchar *storagePoolPath; virConnectPtr connection; GMutex lock; =20 diff --git a/src/storagepool.c b/src/storagepool.c new file mode 100644 index 0000000..f1421ef --- /dev/null +++ b/src/storagepool.c @@ -0,0 +1,65 @@ +#include "storagepool.h" +#include "util.h" + +#include + +static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] =3D { + { 0 } +}; + +static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] =3D { + { 0 } +}; + +static gchar ** +virtDBusStoragePoolEnumerate(gpointer userData) +{ + virtDBusConnect *connect =3D userData; + g_autoptr(virStoragePoolPtr) storagePools =3D NULL; + gint num =3D 0; + gchar **ret =3D NULL; + + if (!virtDBusConnectOpen(connect, NULL)) + return NULL; + + num =3D virConnectListAllStoragePools(connect->connection, &storagePoo= ls, 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 virtDBusUtilBusPathForVirStoragePool(storagePools[i], + connect->storagePool= Path); + } + + return ret; +} + +static GDBusInterfaceInfo *interfaceInfo; + +void +virtDBusStoragePoolRegister(virtDBusConnect *connect, + GError **error) +{ + connect->storagePoolPath =3D g_strdup_printf("%s/storagepool", + connect->connectPath); + + if (!interfaceInfo) { + interfaceInfo =3D virtDBusGDBusLoadIntrospectData(VIRT_DBUS_STORAG= EPOOL_INTERFACE, + error); + if (!interfaceInfo) + return; + } + + virtDBusGDBusRegisterSubtree(connect->bus, + connect->storagePoolPath, + interfaceInfo, + virtDBusStoragePoolEnumerate, + virtDBusStoragePoolMethodTable, + virtDBusStoragePoolPropertyTable, + connect); +} diff --git a/src/storagepool.h b/src/storagepool.h new file mode 100644 index 0000000..fb2bffb --- /dev/null +++ b/src/storagepool.h @@ -0,0 +1,9 @@ +#pragma once + +#include "connect.h" + +#define VIRT_DBUS_STORAGEPOOL_INTERFACE "org.libvirt.StoragePool" + +void +virtDBusStoragePoolRegister(virtDBusConnect *connect, + GError **error); diff --git a/src/util.c b/src/util.c index 548fac8..e90be3b 100644 --- a/src/util.c +++ b/src/util.c @@ -255,3 +255,36 @@ virtDBusUtilStringListFree(virtDBusCharArray *item) =20 g_free(item); } + +virStoragePoolPtr +virtDBusUtilVirStoragePoolFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *storagePoolPath) +{ + g_autofree gchar *name =3D NULL; + gsize prefixLen =3D strlen(storagePoolPath) + 1; + + name =3D virtDBusUtilDecodeUUID(path + prefixLen); + + return virStoragePoolLookupByUUIDString(connection, name); +} + +gchar * +virtDBusUtilBusPathForVirStoragePool(virStoragePoolPtr storagePool, + const gchar *storagePoolPath) +{ + gchar uuid[VIR_UUID_STRING_BUFLEN] =3D ""; + g_autofree gchar *newUuid =3D NULL; + virStoragePoolGetUUIDString(storagePool, uuid); + newUuid =3D virtDBusUtilEncodeUUID(uuid); + return g_strdup_printf("%s/%s", storagePoolPath, newUuid); +} + +void +virtDBusUtilVirStoragePoolListFree(virStoragePoolPtr *storagePools) +{ + for (gint i =3D 0; storagePools[i] !=3D NULL; i++) + virStoragePoolFree(storagePools[i]); + + g_free(storagePools); +} diff --git a/src/util.h b/src/util.h index 3309803..d932b66 100644 --- a/src/util.h +++ b/src/util.h @@ -78,3 +78,19 @@ void virtDBusUtilStringListFree(virtDBusCharArray *item); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virtDBusCharArray, virtDBusUtilStringListFre= e); + +virStoragePoolPtr +virtDBusUtilVirStoragePoolFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *storagePoolPath); + +gchar * +virtDBusUtilBusPathForVirStoragePool(virStoragePoolPtr storagePool, + const gchar *storagePoolPath); + +void +virtDBusUtilVirStoragePoolListFree(virStoragePoolPtr *storagePools); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePool, virStoragePoolFree); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePoolPtr, + virtDBusUtilVirStoragePoolListFree); --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list