c1c534
From af86f99a7745f9d54c3f4e42f58130478e6aa9f5 Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <af86f99a7745f9d54c3f4e42f58130478e6aa9f5@dist-git>
c1c534
From: Martin Kletzander <mkletzan@redhat.com>
c1c534
Date: Wed, 31 Jan 2018 16:32:26 +0100
c1c534
Subject: [PATCH] conf: Use virResctrlInfo in capabilities
c1c534
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1289368
c1c534
c1c534
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
c1c534
(cherry picked from commit 3bbae43d8cc79ef1cd0b9a4ea2440203a0edc959)
c1c534
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
c1c534
---
c1c534
 src/conf/capabilities.c | 53 ++++++++++++++++++++++++-------------------------
c1c534
 src/conf/capabilities.h |  2 ++
c1c534
 2 files changed, 28 insertions(+), 27 deletions(-)
c1c534
c1c534
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
c1c534
index e93eaed2f0..edf9f54f77 100644
c1c534
--- a/src/conf/capabilities.c
c1c534
+++ b/src/conf/capabilities.c
c1c534
@@ -245,6 +245,7 @@ virCapabilitiesDispose(void *object)
c1c534
     VIR_FREE(caps->host.netprefix);
c1c534
     VIR_FREE(caps->host.pagesSize);
c1c534
     virCPUDefFree(caps->host.cpu);
c1c534
+    virObjectUnref(caps->host.resctrl);
c1c534
 }
c1c534
 
c1c534
 /**
c1c534
@@ -1592,6 +1593,20 @@ virCapsHostCacheBankSorter(const void *a,
c1c534
 }
c1c534
 
c1c534
 
c1c534
+static int
c1c534
+virCapabilitiesInitResctrl(virCapsPtr caps)
c1c534
+{
c1c534
+    if (caps->host.resctrl)
c1c534
+        return 0;
c1c534
+
c1c534
+    caps->host.resctrl = virResctrlInfoNew();
c1c534
+    if (!caps->host.resctrl)
c1c534
+        return -1;
c1c534
+
c1c534
+    return virResctrlGetInfo(caps->host.resctrl);
c1c534
+}
c1c534
+
c1c534
+
c1c534
 int
c1c534
 virCapabilitiesInitCaches(virCapsPtr caps)
c1c534
 {
c1c534
@@ -1600,7 +1615,6 @@ virCapabilitiesInitCaches(virCapsPtr caps)
c1c534
     ssize_t pos = -1;
c1c534
     DIR *dirp = NULL;
c1c534
     int ret = -1;
c1c534
-    int typeret;
c1c534
     char *path = NULL;
c1c534
     char *type = NULL;
c1c534
     struct dirent *ent = NULL;
c1c534
@@ -1611,6 +1625,9 @@ virCapabilitiesInitCaches(virCapsPtr caps)
c1c534
      * lose information. */
c1c534
     const int cache_min_level = 3;
c1c534
 
c1c534
+    if (virCapabilitiesInitResctrl(caps) < 0)
c1c534
+        return -1;
c1c534
+
c1c534
     /* offline CPUs don't provide cache info */
c1c534
     if (virFileReadValueBitmap(&cpus, "%s/cpu/online", SYSFS_SYSTEM_PATH) < 0)
c1c534
         return -1;
c1c534
@@ -1676,32 +1693,6 @@ virCapabilitiesInitCaches(virCapsPtr caps)
c1c534
                                        SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0)
c1c534
                 goto cleanup;
c1c534
 
c1c534
-            typeret = virResctrlGetCacheControlType(bank->level);
c1c534
-            if (typeret < 0)
c1c534
-                goto cleanup;
c1c534
-
c1c534
-            if (typeret == 1) {
c1c534
-                if (virResctrlGetCacheInfo(bank->level,
c1c534
-                                           bank->size,
c1c534
-                                           VIR_CACHE_TYPE_BOTH,
c1c534
-                                           &bank->controls,
c1c534
-                                           &bank->ncontrols) < 0)
c1c534
-                    goto cleanup;
c1c534
-            } else if (typeret == 2) {
c1c534
-                if (virResctrlGetCacheInfo(bank->level,
c1c534
-                                           bank->size,
c1c534
-                                           VIR_CACHE_TYPE_CODE,
c1c534
-                                           &bank->controls,
c1c534
-                                           &bank->ncontrols) < 0)
c1c534
-                    goto cleanup;
c1c534
-                if (virResctrlGetCacheInfo(bank->level,
c1c534
-                                           bank->size,
c1c534
-                                           VIR_CACHE_TYPE_DATA,
c1c534
-                                           &bank->controls,
c1c534
-                                           &bank->ncontrols) < 0)
c1c534
-                    goto cleanup;
c1c534
-            }
c1c534
-
c1c534
             kernel_type = virCacheKernelTypeFromString(type);
c1c534
             if (kernel_type < 0) {
c1c534
                 virReportError(VIR_ERR_INTERNAL_ERROR,
c1c534
@@ -1717,6 +1708,14 @@ virCapabilitiesInitCaches(virCapsPtr caps)
c1c534
                     break;
c1c534
             }
c1c534
             if (i == caps->host.ncaches) {
c1c534
+                /* If it is a new cache, then update its resctrl information. */
c1c534
+                if (virResctrlInfoGetCache(caps->host.resctrl,
c1c534
+                                           bank->level,
c1c534
+                                           bank->size,
c1c534
+                                           &bank->ncontrols,
c1c534
+                                           &bank->controls) < 0)
c1c534
+                    goto cleanup;
c1c534
+
c1c534
                 if (VIR_APPEND_ELEMENT(caps->host.caches,
c1c534
                                        caps->host.ncaches,
c1c534
                                        bank) < 0) {
c1c534
diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
c1c534
index 27b88cb5ed..694a3590bf 100644
c1c534
--- a/src/conf/capabilities.h
c1c534
+++ b/src/conf/capabilities.h
c1c534
@@ -170,6 +170,8 @@ struct _virCapsHost {
c1c534
     size_t nnumaCell_max;
c1c534
     virCapsHostNUMACellPtr *numaCell;
c1c534
 
c1c534
+    virResctrlInfoPtr resctrl;
c1c534
+
c1c534
     size_t ncaches;
c1c534
     virCapsHostCacheBankPtr *caches;
c1c534
 
c1c534
-- 
c1c534
2.16.1
c1c534