render / rpms / libvirt

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