render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
404507
From 6532e10f6ddec18ab70f58dc660062d369b82304 Mon Sep 17 00:00:00 2001
404507
Message-Id: <6532e10f6ddec18ab70f58dc660062d369b82304@dist-git>
404507
From: Martin Kletzander <mkletzan@redhat.com>
404507
Date: Wed, 31 Jan 2018 16:32:17 +0100
404507
Subject: [PATCH] conf: Sort cache banks in capabilities XML
404507
404507
https://bugzilla.redhat.com/show_bug.cgi?id=1289368
404507
404507
Because the cache banks are initialized based on the order in which their
404507
respective directories exist on the filesystem, they can appear in different
404507
order.  This is here mainly for tests because the cache directory might have
404507
different order of children nodes and tests would fail otherwise.  It should not
404507
be the case with sysfs, but one can never be sure.  And this does not take
404507
almost any extra time, mainly because it gets initialized once per driver.
404507
404507
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
404507
Reviewed-by: John Ferlan <jferlan@redhat.com>
404507
(cherry picked from commit b4698edcb0a459332b24410f59698005af37eecb)
404507
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
404507
---
404507
 src/conf/capabilities.c | 23 +++++++++++++++++++++++
404507
 1 file changed, 23 insertions(+)
404507
404507
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
404507
index 9920a675ac..1f7d8cdb31 100644
404507
--- a/src/conf/capabilities.c
404507
+++ b/src/conf/capabilities.c
404507
@@ -1561,6 +1561,23 @@ virCapsHostCacheBankFree(virCapsHostCacheBankPtr ptr)
404507
     VIR_FREE(ptr);
404507
 }
404507
 
404507
+
404507
+static int
404507
+virCapsHostCacheBankSorter(const void *a,
404507
+                           const void *b)
404507
+{
404507
+    virCapsHostCacheBankPtr ca = *(virCapsHostCacheBankPtr *)a;
404507
+    virCapsHostCacheBankPtr cb = *(virCapsHostCacheBankPtr *)b;
404507
+
404507
+    if (ca->level < cb->level)
404507
+        return -1;
404507
+    if (ca->level > cb->level)
404507
+        return 1;
404507
+
404507
+    return ca->id - cb->id;
404507
+}
404507
+
404507
+
404507
 int
404507
 virCapabilitiesInitCaches(virCapsPtr caps)
404507
 {
404507
@@ -1700,6 +1717,12 @@ virCapabilitiesInitCaches(virCapsPtr caps)
404507
             goto cleanup;
404507
     }
404507
 
404507
+    /* Sort the array in order for the tests to be predictable.  This way we can
404507
+     * still traverse the directory instead of guessing names (in case there is
404507
+     * 'index1' and 'index3' but no 'index2'). */
404507
+    qsort(caps->host.caches, caps->host.ncaches,
404507
+          sizeof(*caps->host.caches), virCapsHostCacheBankSorter);
404507
+
404507
     ret = 0;
404507
  cleanup:
404507
     VIR_FREE(type);
404507
-- 
404507
2.16.1
404507