[libvirt PATCH 2/2] conf: use a hash table for storing nwfilter object list

Ján Tomko jtomko at redhat.com
Thu Mar 10 10:27:25 UTC 2022


On a Thursday in 2022, Daniel P. Berrangé wrote:
>The current use of an array for nwfilter objects requires
>the caller to iterate over all elements to find a filter,
>and also requires locking each filter.
>
>Switching to a pair of hash tables enables O(1) lookups
>both by name and uuid, with no locking required.
>
>Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
>---
> src/conf/virnwfilterobj.c              | 264 +++++++++++++++++--------
> src/nwfilter/nwfilter_gentech_driver.c |   8 +-
> 2 files changed, 179 insertions(+), 93 deletions(-)
>
>diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c
>index 6bbdf6e6fa..808283e4ed 100644
>--- a/src/conf/virnwfilterobj.c
>+++ b/src/conf/virnwfilterobj.c
>+static void
>+virNWFilterObjListCount(void *payload,
>+                        void *key G_GNUC_UNUSED,
>+                        void *opaque)
>+{
>+    virNWFilterObj *obj = payload;
>+    struct virNWFilterObjListData *data = opaque;
>+    g_auto(virLockGuard) lock = virObjectLockGuard(obj);

VIR_LOCK_GUARD lock =

Otherwise clang complains about an unused variable.

>+
>+    if (data->filter(data->conn, obj->def))
>+        data->count++;
>+}
>+
>+

[...]

>+static void
>+virNWFilterObjListCopyNames(void *payload,
>+                            void *key G_GNUC_UNUSED,
>+                            void *opaque)
>+{
>+    virNWFilterObj *obj = payload;
>+    struct virNWFilterNameData *data = opaque;
>+    g_auto(virLockGuard) lock = virObjectLockGuard(obj);
>+

Same here.

>+    if (data->filter &&
>+        !data->filter(data->conn, obj->def))
>+        return;
>+
>+    if (data->numnames < data->maxnames) {
>+        data->names[data->numnames] = g_strdup(obj->def->name);
>+        data->numnames++;
>+    }
>+}
>+

Reviewed-by: Ján Tomko <jtomko at redhat.com>

Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20220310/c37c0295/attachment.sig>


More information about the libvir-list mailing list