|
|
404507 |
From 12745d1c8180273ad1028da0da7440cb959819eb Mon Sep 17 00:00:00 2001
|
|
|
404507 |
Message-Id: <12745d1c8180273ad1028da0da7440cb959819eb@dist-git>
|
|
|
404507 |
From: Martin Kletzander <mkletzan@redhat.com>
|
|
|
404507 |
Date: Wed, 31 Jan 2018 16:32:40 +0100
|
|
|
404507 |
Subject: [PATCH] util: Add helpers for getting resctrl group allocs
|
|
|
404507 |
|
|
|
404507 |
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
|
|
|
404507 |
(cherry picked from commit f6199295a9656a79e29cab9ed5694f040c266998)
|
|
|
404507 |
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
|
|
|
404507 |
|
|
|
404507 |
https://bugzilla.redhat.com/show_bug.cgi?id=1289368
|
|
|
404507 |
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
|
|
|
404507 |
---
|
|
|
404507 |
src/util/virresctrl.c | 81 ++++++++++++++++++++++++++++++++++-----------------
|
|
|
404507 |
1 file changed, 54 insertions(+), 27 deletions(-)
|
|
|
404507 |
|
|
|
404507 |
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
|
|
|
404507 |
index 42876c6e2b..df6461a046 100644
|
|
|
404507 |
--- a/src/util/virresctrl.c
|
|
|
404507 |
+++ b/src/util/virresctrl.c
|
|
|
404507 |
@@ -1041,6 +1041,55 @@ virResctrlAllocParse(virResctrlInfoPtr resctrl,
|
|
|
404507 |
}
|
|
|
404507 |
|
|
|
404507 |
|
|
|
404507 |
+static int
|
|
|
404507 |
+virResctrlAllocGetGroup(virResctrlInfoPtr resctrl,
|
|
|
404507 |
+ const char *groupname,
|
|
|
404507 |
+ virResctrlAllocPtr *alloc)
|
|
|
404507 |
+{
|
|
|
404507 |
+ char *schemata = NULL;
|
|
|
404507 |
+ int rv = virFileReadValueString(&schemata,
|
|
|
404507 |
+ SYSFS_RESCTRL_PATH
|
|
|
404507 |
+ "/%s/schemata",
|
|
|
404507 |
+ groupname);
|
|
|
404507 |
+
|
|
|
404507 |
+ *alloc = NULL;
|
|
|
404507 |
+
|
|
|
404507 |
+ if (rv < 0)
|
|
|
404507 |
+ return rv;
|
|
|
404507 |
+
|
|
|
404507 |
+ *alloc = virResctrlAllocNew();
|
|
|
404507 |
+ if (!*alloc)
|
|
|
404507 |
+ goto error;
|
|
|
404507 |
+
|
|
|
404507 |
+ if (virResctrlAllocParse(resctrl, *alloc, schemata) < 0)
|
|
|
404507 |
+ goto error;
|
|
|
404507 |
+
|
|
|
404507 |
+ VIR_FREE(schemata);
|
|
|
404507 |
+ return 0;
|
|
|
404507 |
+
|
|
|
404507 |
+ error:
|
|
|
404507 |
+ VIR_FREE(schemata);
|
|
|
404507 |
+ virObjectUnref(*alloc);
|
|
|
404507 |
+ *alloc = NULL;
|
|
|
404507 |
+ return -1;
|
|
|
404507 |
+}
|
|
|
404507 |
+
|
|
|
404507 |
+
|
|
|
404507 |
+static virResctrlAllocPtr
|
|
|
404507 |
+virResctrlAllocGetDefault(virResctrlInfoPtr resctrl)
|
|
|
404507 |
+{
|
|
|
404507 |
+ virResctrlAllocPtr ret = NULL;
|
|
|
404507 |
+ int rv = virResctrlAllocGetGroup(resctrl, ".", &ret;;
|
|
|
404507 |
+
|
|
|
404507 |
+ if (rv == -2) {
|
|
|
404507 |
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
404507 |
+ _("Could not read schemata file for the default group"));
|
|
|
404507 |
+ }
|
|
|
404507 |
+
|
|
|
404507 |
+ return ret;
|
|
|
404507 |
+}
|
|
|
404507 |
+
|
|
|
404507 |
+
|
|
|
404507 |
static void
|
|
|
404507 |
virResctrlAllocSubtractPerType(virResctrlAllocPerTypePtr dst,
|
|
|
404507 |
virResctrlAllocPerTypePtr src)
|
|
|
404507 |
@@ -1141,7 +1190,6 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl)
|
|
|
404507 |
virResctrlAllocPtr alloc = NULL;
|
|
|
404507 |
struct dirent *ent = NULL;
|
|
|
404507 |
DIR *dirp = NULL;
|
|
|
404507 |
- char *schemata = NULL;
|
|
|
404507 |
int rv = -1;
|
|
|
404507 |
|
|
|
404507 |
if (virResctrlInfoIsEmpty(resctrl)) {
|
|
|
404507 |
@@ -1154,22 +1202,12 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl)
|
|
|
404507 |
if (!ret)
|
|
|
404507 |
return NULL;
|
|
|
404507 |
|
|
|
404507 |
- if (virFileReadValueString(&schemata,
|
|
|
404507 |
- SYSFS_RESCTRL_PATH
|
|
|
404507 |
- "/schemata") < 0) {
|
|
|
404507 |
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
404507 |
- _("Could not read schemata file for the default group"));
|
|
|
404507 |
- goto error;
|
|
|
404507 |
- }
|
|
|
404507 |
-
|
|
|
404507 |
- alloc = virResctrlAllocNew();
|
|
|
404507 |
+ alloc = virResctrlAllocGetDefault(resctrl);
|
|
|
404507 |
if (!alloc)
|
|
|
404507 |
goto error;
|
|
|
404507 |
|
|
|
404507 |
- if (virResctrlAllocParse(resctrl, alloc, schemata) < 0)
|
|
|
404507 |
- goto error;
|
|
|
404507 |
-
|
|
|
404507 |
virResctrlAllocSubtract(ret, alloc);
|
|
|
404507 |
+ virObjectUnref(alloc);
|
|
|
404507 |
|
|
|
404507 |
if (virDirOpen(&dirp, SYSFS_RESCTRL_PATH) < 0)
|
|
|
404507 |
goto error;
|
|
|
404507 |
@@ -1178,11 +1216,7 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl)
|
|
|
404507 |
if (STREQ(ent->d_name, "info"))
|
|
|
404507 |
continue;
|
|
|
404507 |
|
|
|
404507 |
- VIR_FREE(schemata);
|
|
|
404507 |
- rv = virFileReadValueString(&schemata,
|
|
|
404507 |
- SYSFS_RESCTRL_PATH
|
|
|
404507 |
- "/%s/schemata",
|
|
|
404507 |
- ent->d_name);
|
|
|
404507 |
+ rv = virResctrlAllocGetGroup(resctrl, ent->d_name, &alloc);
|
|
|
404507 |
if (rv == -2)
|
|
|
404507 |
continue;
|
|
|
404507 |
|
|
|
404507 |
@@ -1193,15 +1227,9 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl)
|
|
|
404507 |
goto error;
|
|
|
404507 |
}
|
|
|
404507 |
|
|
|
404507 |
- virObjectUnref(alloc);
|
|
|
404507 |
- alloc = virResctrlAllocNew();
|
|
|
404507 |
- if (!alloc)
|
|
|
404507 |
- goto error;
|
|
|
404507 |
-
|
|
|
404507 |
- if (virResctrlAllocParse(resctrl, alloc, schemata) < 0)
|
|
|
404507 |
- goto error;
|
|
|
404507 |
-
|
|
|
404507 |
virResctrlAllocSubtract(ret, alloc);
|
|
|
404507 |
+ virObjectUnref(alloc);
|
|
|
404507 |
+ alloc = NULL;
|
|
|
404507 |
}
|
|
|
404507 |
if (rv < 0)
|
|
|
404507 |
goto error;
|
|
|
404507 |
@@ -1209,7 +1237,6 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl)
|
|
|
404507 |
cleanup:
|
|
|
404507 |
virObjectUnref(alloc);
|
|
|
404507 |
VIR_DIR_CLOSE(dirp);
|
|
|
404507 |
- VIR_FREE(schemata);
|
|
|
404507 |
return ret;
|
|
|
404507 |
|
|
|
404507 |
error:
|
|
|
404507 |
--
|
|
|
404507 |
2.16.1
|
|
|
404507 |
|