From 489202ad9fe2dd9e417335c7274ba522adfc490b Mon Sep 17 00:00:00 2001
Message-Id: <489202ad9fe2dd9e417335c7274ba522adfc490b@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:06 +0200
Subject: [PATCH] vircgroup: Extract placement validation into function
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 3ae7b99094dc72616f902289afc407df738c9ce9)
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <5728512c8e969952c0502fb4119f2930ae4bc49c.1561993099.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/util/vircgroup.c | 52 +++++++++++++++++++++++++++-----------------
1 file changed, 32 insertions(+), 20 deletions(-)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 6f27c50cbd..2bc4febf23 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -630,6 +630,36 @@ virCgroupDetectPlacement(virCgroupPtr group,
}
+static int
+virCgroupValidatePlacement(virCgroupPtr group,
+ pid_t pid)
+{
+ size_t i;
+
+ for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
+ if (!group->controllers[i].mountPoint)
+ continue;
+
+ if (!group->controllers[i].placement) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Could not find placement for controller %s at %s"),
+ virCgroupControllerTypeToString(i),
+ group->controllers[i].placement);
+ return -1;
+ }
+
+ VIR_DEBUG("Detected mount/mapping %zu:%s at %s in %s for pid %lld",
+ i,
+ virCgroupControllerTypeToString(i),
+ group->controllers[i].mountPoint,
+ group->controllers[i].placement,
+ (long long) pid);
+ }
+
+ return 0;
+}
+
+
static int
virCgroupDetectControllers(virCgroupPtr group,
int controllers)
@@ -701,7 +731,6 @@ virCgroupDetect(virCgroupPtr group,
const char *path,
virCgroupPtr parent)
{
- size_t i;
int rc;
VIR_DEBUG("group=%p controllers=%d path=%s parent=%p",
@@ -738,25 +767,8 @@ virCgroupDetect(virCgroupPtr group,
return -1;
/* Check that for every mounted controller, we found our placement */
- for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
- if (!group->controllers[i].mountPoint)
- continue;
-
- if (!group->controllers[i].placement) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Could not find placement for controller %s at %s"),
- virCgroupControllerTypeToString(i),
- group->controllers[i].placement);
- return -1;
- }
-
- VIR_DEBUG("Detected mount/mapping %zu:%s at %s in %s for pid %lld",
- i,
- virCgroupControllerTypeToString(i),
- group->controllers[i].mountPoint,
- group->controllers[i].placement,
- (long long) pid);
- }
+ if (virCgroupValidatePlacement(group, pid) < 0)
+ return -1;
return 0;
}
--
2.22.0