]> xenbits.xensource.com Git - libvirt.git/commitdiff
vircgroup: introduce virCgroupV2ValidateMachineGroup
authorPavel Hrdina <phrdina@redhat.com>
Fri, 14 Sep 2018 16:19:53 +0000 (18:19 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Fri, 5 Oct 2018 13:53:29 +0000 (15:53 +0200)
When reconnecting to a domain we are validating the cgroup name.
In case of cgroup v2 we need to validate only the new format for host
without systemd '{machinename}.libvirt-{drivername}' or scope name
generated by systemd.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/util/vircgroupv2.c

index cc599a408e2a1cf87a57f0d70b09c040dc4d16e9..8e010a403bd8f3d748666f9114d33bfd14f2e586 100644 (file)
@@ -35,6 +35,7 @@
 #include "virfile.h"
 #include "virlog.h"
 #include "virstring.h"
+#include "virsystemd.h"
 
 VIR_LOG_INIT("util.cgroup");
 
@@ -89,10 +90,52 @@ virCgroupV2Available(void)
 }
 
 
+static bool
+virCgroupV2ValidateMachineGroup(virCgroupPtr group,
+                                const char *name ATTRIBUTE_UNUSED,
+                                const char *drivername,
+                                const char *machinename)
+{
+    VIR_AUTOFREE(char *) partmachinename = NULL;
+    VIR_AUTOFREE(char *) scopename = NULL;
+    char *tmp;
+
+    if (virAsprintf(&partmachinename, "%s.libvirt-%s", machinename,
+                    drivername) < 0) {
+        return false;
+    }
+
+    if (virCgroupPartitionEscape(&partmachinename) < 0)
+        return false;
+
+    if (!(scopename = virSystemdMakeScopeName(machinename, drivername,
+                                              false))) {
+        return false;
+    }
+
+    if (virCgroupPartitionEscape(&scopename) < 0)
+        return false;
+
+    if (!(tmp = strrchr(group->unified.placement, '/')))
+        return false;
+    tmp++;
+
+    if (STRNEQ(tmp, partmachinename) &&
+        STRNEQ(tmp, scopename)) {
+        VIR_DEBUG("Name '%s' for unified does not match '%s' or '%s'",
+                  tmp, partmachinename, scopename);
+        return false;
+    }
+
+    return true;
+}
+
+
 virCgroupBackend virCgroupV2Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
 
     .available = virCgroupV2Available,
+    .validateMachineGroup = virCgroupV2ValidateMachineGroup,
 };