render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Pablo Greco 40546a
From 3928ca076fac13572f14c20f38bcf5fb205d7670 Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <3928ca076fac13572f14c20f38bcf5fb205d7670@dist-git>
Pablo Greco 40546a
From: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Date: Mon, 1 Jul 2019 17:07:14 +0200
Pablo Greco 40546a
Subject: [PATCH] vircgroup: introduce virCgroupV2ValidateMachineGroup
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
When reconnecting to a domain we are validating the cgroup name.
Pablo Greco 40546a
In case of cgroup v2 we need to validate only the new format for host
Pablo Greco 40546a
without systemd '{machinename}.libvirt-{drivername}' or scope name
Pablo Greco 40546a
generated by systemd.
Pablo Greco 40546a
Pablo Greco 40546a
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
(cherry picked from commit 3a365ef697b8fedb929725c46753481a63ae3de7)
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: <97d6369bcfc2943c708fd9bfc94f71ab10e00535.1561993100.git.phrdina@redhat.com>
Pablo Greco 40546a
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Pablo Greco 40546a
---
Pablo Greco 40546a
 src/util/vircgroupv2.c | 43 ++++++++++++++++++++++++++++++++++++++++++
Pablo Greco 40546a
 1 file changed, 43 insertions(+)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
Pablo Greco 40546a
index 4ab9f2b792..02dc4e4686 100644
Pablo Greco 40546a
--- a/src/util/vircgroupv2.c
Pablo Greco 40546a
+++ b/src/util/vircgroupv2.c
Pablo Greco 40546a
@@ -36,6 +36,7 @@
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
@@ -90,10 +91,52 @@ virCgroupV2Available(void)
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+static bool
Pablo Greco 40546a
+virCgroupV2ValidateMachineGroup(virCgroupPtr group,
Pablo Greco 40546a
+                                const char *name ATTRIBUTE_UNUSED,
Pablo Greco 40546a
+                                const char *drivername,
Pablo Greco 40546a
+                                const char *machinename)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    VIR_AUTOFREE(char *) partmachinename = NULL;
Pablo Greco 40546a
+    VIR_AUTOFREE(char *) scopename = NULL;
Pablo Greco 40546a
+    char *tmp;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (virAsprintf(&partmachinename, "%s.libvirt-%s", machinename,
Pablo Greco 40546a
+                    drivername) < 0) {
Pablo Greco 40546a
+        return false;
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (virCgroupPartitionEscape(&partmachinename) < 0)
Pablo Greco 40546a
+        return false;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (!(scopename = virSystemdMakeScopeName(machinename, drivername,
Pablo Greco 40546a
+                                              false))) {
Pablo Greco 40546a
+        return false;
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (virCgroupPartitionEscape(&scopename) < 0)
Pablo Greco 40546a
+        return false;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (!(tmp = strrchr(group->unified.placement, '/')))
Pablo Greco 40546a
+        return false;
Pablo Greco 40546a
+    tmp++;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (STRNEQ(tmp, partmachinename) &&
Pablo Greco 40546a
+        STRNEQ(tmp, scopename)) {
Pablo Greco 40546a
+        VIR_DEBUG("Name '%s' for unified does not match '%s' or '%s'",
Pablo Greco 40546a
+                  tmp, partmachinename, scopename);
Pablo Greco 40546a
+        return false;
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    return true;
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
 virCgroupBackend virCgroupV2Backend = {
Pablo Greco 40546a
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
Pablo Greco 40546a
 
Pablo Greco 40546a
     .available = virCgroupV2Available,
Pablo Greco 40546a
+    .validateMachineGroup = virCgroupV2ValidateMachineGroup,
Pablo Greco 40546a
 };
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a