|
Pablo Greco |
40546a |
From e950a43b63a79cf68e835d800688d759ba408178 Mon Sep 17 00:00:00 2001
|
|
Pablo Greco |
40546a |
Message-Id: <e950a43b63a79cf68e835d800688d759ba408178@dist-git>
|
|
Pablo Greco |
40546a |
From: Pavel Hrdina <phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
Date: Mon, 1 Jul 2019 17:06:25 +0200
|
|
Pablo Greco |
40546a |
Subject: [PATCH] vircgroup: extract virCgroupV1ValidateMachineGroup
|
|
Pablo Greco |
40546a |
MIME-Version: 1.0
|
|
Pablo Greco |
40546a |
Content-Type: text/plain; charset=UTF-8
|
|
Pablo Greco |
40546a |
Content-Transfer-Encoding: 8bit
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
|
|
Pablo Greco |
40546a |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
Pablo Greco |
40546a |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
(cherry picked from commit 61629d5be3a4809fe05feb15adbc8f2c27916702)
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Conflicts:
|
|
Pablo Greco |
40546a |
src/util/vircgroupv1.c: missing commit c0abcca417
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
Message-Id: <a34a0141721e9e27c0b3337108c13d36caa6bb79.1561993100.git.phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
Pablo Greco |
40546a |
---
|
|
Pablo Greco |
40546a |
src/util/vircgroup.c | 85 +------------------------------------
|
|
Pablo Greco |
40546a |
src/util/vircgroupbackend.h | 7 +++
|
|
Pablo Greco |
40546a |
src/util/vircgrouppriv.h | 2 +
|
|
Pablo Greco |
40546a |
src/util/vircgroupv1.c | 85 +++++++++++++++++++++++++++++++++++++
|
|
Pablo Greco |
40546a |
4 files changed, 96 insertions(+), 83 deletions(-)
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
|
|
Pablo Greco |
40546a |
index 15d0cb65ac..6825623478 100644
|
|
Pablo Greco |
40546a |
--- a/src/util/vircgroup.c
|
|
Pablo Greco |
40546a |
+++ b/src/util/vircgroup.c
|
|
Pablo Greco |
40546a |
@@ -216,7 +216,7 @@ virCgroupPartitionNeedsEscaping(const char *path)
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
-static int
|
|
Pablo Greco |
40546a |
+int
|
|
Pablo Greco |
40546a |
virCgroupPartitionEscape(char **path)
|
|
Pablo Greco |
40546a |
{
|
|
Pablo Greco |
40546a |
int rc;
|
|
Pablo Greco |
40546a |
@@ -235,87 +235,6 @@ virCgroupPartitionEscape(char **path)
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
-static bool
|
|
Pablo Greco |
40546a |
-virCgroupValidateMachineGroup(virCgroupPtr group,
|
|
Pablo Greco |
40546a |
- const char *name,
|
|
Pablo Greco |
40546a |
- const char *drivername,
|
|
Pablo Greco |
40546a |
- const char *machinename)
|
|
Pablo Greco |
40546a |
-{
|
|
Pablo Greco |
40546a |
- size_t i;
|
|
Pablo Greco |
40546a |
- VIR_AUTOFREE(char *) partname = NULL;
|
|
Pablo Greco |
40546a |
- VIR_AUTOFREE(char *) scopename_old = NULL;
|
|
Pablo Greco |
40546a |
- VIR_AUTOFREE(char *) scopename_new = NULL;
|
|
Pablo Greco |
40546a |
- VIR_AUTOFREE(char *) partmachinename = NULL;
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
- if (virAsprintf(&partname, "%s.libvirt-%s",
|
|
Pablo Greco |
40546a |
- name, drivername) < 0)
|
|
Pablo Greco |
40546a |
- return false;
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
- if (virCgroupPartitionEscape(&partname) < 0)
|
|
Pablo Greco |
40546a |
- return false;
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
- if (virAsprintf(&partmachinename, "%s.libvirt-%s",
|
|
Pablo Greco |
40546a |
- machinename, drivername) < 0 ||
|
|
Pablo Greco |
40546a |
- virCgroupPartitionEscape(&partmachinename) < 0)
|
|
Pablo Greco |
40546a |
- return false;
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
- if (!(scopename_old = virSystemdMakeScopeName(name, drivername, true)))
|
|
Pablo Greco |
40546a |
- return false;
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
- if (!(scopename_new = virSystemdMakeScopeName(machinename,
|
|
Pablo Greco |
40546a |
- drivername, false)))
|
|
Pablo Greco |
40546a |
- return false;
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
- if (virCgroupPartitionEscape(&scopename_old) < 0)
|
|
Pablo Greco |
40546a |
- return false;
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
- if (virCgroupPartitionEscape(&scopename_new) < 0)
|
|
Pablo Greco |
40546a |
- return false;
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
- for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
|
|
Pablo Greco |
40546a |
- char *tmp;
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
- if (i == VIR_CGROUP_CONTROLLER_SYSTEMD)
|
|
Pablo Greco |
40546a |
- continue;
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
- if (!group->controllers[i].placement)
|
|
Pablo Greco |
40546a |
- continue;
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
- tmp = strrchr(group->controllers[i].placement, '/');
|
|
Pablo Greco |
40546a |
- if (!tmp)
|
|
Pablo Greco |
40546a |
- return false;
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
- if (i == VIR_CGROUP_CONTROLLER_CPU ||
|
|
Pablo Greco |
40546a |
- i == VIR_CGROUP_CONTROLLER_CPUACCT ||
|
|
Pablo Greco |
40546a |
- i == VIR_CGROUP_CONTROLLER_CPUSET) {
|
|
Pablo Greco |
40546a |
- if (STREQ(tmp, "/emulator"))
|
|
Pablo Greco |
40546a |
- *tmp = '\0';
|
|
Pablo Greco |
40546a |
- tmp = strrchr(group->controllers[i].placement, '/');
|
|
Pablo Greco |
40546a |
- if (!tmp)
|
|
Pablo Greco |
40546a |
- return false;
|
|
Pablo Greco |
40546a |
- }
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
- tmp++;
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
- if (STRNEQ(tmp, name) &&
|
|
Pablo Greco |
40546a |
- STRNEQ(tmp, machinename) &&
|
|
Pablo Greco |
40546a |
- STRNEQ(tmp, partname) &&
|
|
Pablo Greco |
40546a |
- STRNEQ(tmp, partmachinename) &&
|
|
Pablo Greco |
40546a |
- STRNEQ(tmp, scopename_old) &&
|
|
Pablo Greco |
40546a |
- STRNEQ(tmp, scopename_new)) {
|
|
Pablo Greco |
40546a |
- VIR_DEBUG("Name '%s' for controller '%s' does not match "
|
|
Pablo Greco |
40546a |
- "'%s', '%s', '%s', '%s' or '%s'",
|
|
Pablo Greco |
40546a |
- tmp, virCgroupControllerTypeToString(i),
|
|
Pablo Greco |
40546a |
- name, machinename, partname,
|
|
Pablo Greco |
40546a |
- scopename_old, scopename_new);
|
|
Pablo Greco |
40546a |
- return false;
|
|
Pablo Greco |
40546a |
- }
|
|
Pablo Greco |
40546a |
- }
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
- return true;
|
|
Pablo Greco |
40546a |
-}
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
static int
|
|
Pablo Greco |
40546a |
virCgroupCopyMounts(virCgroupPtr group,
|
|
Pablo Greco |
40546a |
virCgroupPtr parent)
|
|
Pablo Greco |
40546a |
@@ -1508,7 +1427,7 @@ virCgroupNewDetectMachine(const char *name,
|
|
Pablo Greco |
40546a |
return -1;
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
- if (!virCgroupValidateMachineGroup(*group, name, drivername, machinename)) {
|
|
Pablo Greco |
40546a |
+ if (!(*group)->backend->validateMachineGroup(*group, name, drivername, machinename)) {
|
|
Pablo Greco |
40546a |
VIR_DEBUG("Failed to validate machine name for '%s' driver '%s'",
|
|
Pablo Greco |
40546a |
name, drivername);
|
|
Pablo Greco |
40546a |
virCgroupFree(group);
|
|
Pablo Greco |
40546a |
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
|
|
Pablo Greco |
40546a |
index 88f51416b0..daf47bac09 100644
|
|
Pablo Greco |
40546a |
--- a/src/util/vircgroupbackend.h
|
|
Pablo Greco |
40546a |
+++ b/src/util/vircgroupbackend.h
|
|
Pablo Greco |
40546a |
@@ -35,11 +35,18 @@ typedef enum {
|
|
Pablo Greco |
40546a |
typedef bool
|
|
Pablo Greco |
40546a |
(*virCgroupAvailableCB)(void);
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
+typedef bool
|
|
Pablo Greco |
40546a |
+(*virCgroupValidateMachineGroupCB)(virCgroupPtr group,
|
|
Pablo Greco |
40546a |
+ const char *name,
|
|
Pablo Greco |
40546a |
+ const char *drivername,
|
|
Pablo Greco |
40546a |
+ const char *machinename);
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
struct _virCgroupBackend {
|
|
Pablo Greco |
40546a |
virCgroupBackendType type;
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
/* Mandatory callbacks that need to be implemented for every backend. */
|
|
Pablo Greco |
40546a |
virCgroupAvailableCB available;
|
|
Pablo Greco |
40546a |
+ virCgroupValidateMachineGroupCB validateMachineGroup;
|
|
Pablo Greco |
40546a |
};
|
|
Pablo Greco |
40546a |
typedef struct _virCgroupBackend virCgroupBackend;
|
|
Pablo Greco |
40546a |
typedef virCgroupBackend *virCgroupBackendPtr;
|
|
Pablo Greco |
40546a |
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
|
|
Pablo Greco |
40546a |
index 2caa966fee..e7f4a1f0fc 100644
|
|
Pablo Greco |
40546a |
--- a/src/util/vircgrouppriv.h
|
|
Pablo Greco |
40546a |
+++ b/src/util/vircgrouppriv.h
|
|
Pablo Greco |
40546a |
@@ -53,6 +53,8 @@ struct _virCgroup {
|
|
Pablo Greco |
40546a |
virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST];
|
|
Pablo Greco |
40546a |
};
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
+int virCgroupPartitionEscape(char **path);
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
int virCgroupNewPartition(const char *path,
|
|
Pablo Greco |
40546a |
bool create,
|
|
Pablo Greco |
40546a |
int controllers,
|
|
Pablo Greco |
40546a |
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
|
|
Pablo Greco |
40546a |
index 73045b1109..b78cdcab53 100644
|
|
Pablo Greco |
40546a |
--- a/src/util/vircgroupv1.c
|
|
Pablo Greco |
40546a |
+++ b/src/util/vircgroupv1.c
|
|
Pablo Greco |
40546a |
@@ -30,11 +30,14 @@
|
|
Pablo Greco |
40546a |
#include "vircgrouppriv.h"
|
|
Pablo Greco |
40546a |
#undef __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
+#include "viralloc.h"
|
|
Pablo Greco |
40546a |
#include "vircgroup.h"
|
|
Pablo Greco |
40546a |
#include "vircgroupbackend.h"
|
|
Pablo Greco |
40546a |
#include "vircgroupv1.h"
|
|
Pablo Greco |
40546a |
#include "virfile.h"
|
|
Pablo Greco |
40546a |
#include "virlog.h"
|
|
Pablo Greco |
40546a |
+#include "virstring.h"
|
|
Pablo Greco |
40546a |
+#include "virsystemd.h"
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
VIR_LOG_INIT("util.cgroup");
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
@@ -76,10 +79,92 @@ virCgroupV1Available(void)
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
+static bool
|
|
Pablo Greco |
40546a |
+virCgroupV1ValidateMachineGroup(virCgroupPtr group,
|
|
Pablo Greco |
40546a |
+ const char *name,
|
|
Pablo Greco |
40546a |
+ const char *drivername,
|
|
Pablo Greco |
40546a |
+ const char *machinename)
|
|
Pablo Greco |
40546a |
+{
|
|
Pablo Greco |
40546a |
+ size_t i;
|
|
Pablo Greco |
40546a |
+ VIR_AUTOFREE(char *) partname = NULL;
|
|
Pablo Greco |
40546a |
+ VIR_AUTOFREE(char *) scopename_old = NULL;
|
|
Pablo Greco |
40546a |
+ VIR_AUTOFREE(char *) scopename_new = NULL;
|
|
Pablo Greco |
40546a |
+ VIR_AUTOFREE(char *) partmachinename = NULL;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virAsprintf(&partname, "%s.libvirt-%s",
|
|
Pablo Greco |
40546a |
+ name, drivername) < 0)
|
|
Pablo Greco |
40546a |
+ return false;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virCgroupPartitionEscape(&partname) < 0)
|
|
Pablo Greco |
40546a |
+ return false;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virAsprintf(&partmachinename, "%s.libvirt-%s",
|
|
Pablo Greco |
40546a |
+ machinename, drivername) < 0 ||
|
|
Pablo Greco |
40546a |
+ virCgroupPartitionEscape(&partmachinename) < 0)
|
|
Pablo Greco |
40546a |
+ return false;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (!(scopename_old = virSystemdMakeScopeName(name, drivername, true)))
|
|
Pablo Greco |
40546a |
+ return false;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (!(scopename_new = virSystemdMakeScopeName(machinename,
|
|
Pablo Greco |
40546a |
+ drivername, false)))
|
|
Pablo Greco |
40546a |
+ return false;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virCgroupPartitionEscape(&scopename_old) < 0)
|
|
Pablo Greco |
40546a |
+ return false;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virCgroupPartitionEscape(&scopename_new) < 0)
|
|
Pablo Greco |
40546a |
+ return false;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
|
|
Pablo Greco |
40546a |
+ char *tmp;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (i == VIR_CGROUP_CONTROLLER_SYSTEMD)
|
|
Pablo Greco |
40546a |
+ continue;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (!group->controllers[i].placement)
|
|
Pablo Greco |
40546a |
+ continue;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ tmp = strrchr(group->controllers[i].placement, '/');
|
|
Pablo Greco |
40546a |
+ if (!tmp)
|
|
Pablo Greco |
40546a |
+ return false;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (i == VIR_CGROUP_CONTROLLER_CPU ||
|
|
Pablo Greco |
40546a |
+ i == VIR_CGROUP_CONTROLLER_CPUACCT ||
|
|
Pablo Greco |
40546a |
+ i == VIR_CGROUP_CONTROLLER_CPUSET) {
|
|
Pablo Greco |
40546a |
+ if (STREQ(tmp, "/emulator"))
|
|
Pablo Greco |
40546a |
+ *tmp = '\0';
|
|
Pablo Greco |
40546a |
+ tmp = strrchr(group->controllers[i].placement, '/');
|
|
Pablo Greco |
40546a |
+ if (!tmp)
|
|
Pablo Greco |
40546a |
+ return false;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ tmp++;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (STRNEQ(tmp, name) &&
|
|
Pablo Greco |
40546a |
+ STRNEQ(tmp, machinename) &&
|
|
Pablo Greco |
40546a |
+ STRNEQ(tmp, partname) &&
|
|
Pablo Greco |
40546a |
+ STRNEQ(tmp, partmachinename) &&
|
|
Pablo Greco |
40546a |
+ STRNEQ(tmp, scopename_old) &&
|
|
Pablo Greco |
40546a |
+ STRNEQ(tmp, scopename_new)) {
|
|
Pablo Greco |
40546a |
+ VIR_DEBUG("Name '%s' for controller '%s' does not match "
|
|
Pablo Greco |
40546a |
+ "'%s', '%s', '%s', '%s' or '%s'",
|
|
Pablo Greco |
40546a |
+ tmp, virCgroupV1ControllerTypeToString(i),
|
|
Pablo Greco |
40546a |
+ name, machinename, partname,
|
|
Pablo Greco |
40546a |
+ scopename_old, scopename_new);
|
|
Pablo Greco |
40546a |
+ return false;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ return true;
|
|
Pablo Greco |
40546a |
+}
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
virCgroupBackend virCgroupV1Backend = {
|
|
Pablo Greco |
40546a |
.type = VIR_CGROUP_BACKEND_TYPE_V1,
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
.available = virCgroupV1Available,
|
|
Pablo Greco |
40546a |
+ .validateMachineGroup = virCgroupV1ValidateMachineGroup,
|
|
Pablo Greco |
40546a |
};
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
--
|
|
Pablo Greco |
40546a |
2.22.0
|
|
Pablo Greco |
40546a |
|