7a3408
From 1934effeed51b631703bc7880c46a75afa065058 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <1934effeed51b631703bc7880c46a75afa065058@dist-git>
7a3408
From: Peter Krempa <pkrempa@redhat.com>
7a3408
Date: Wed, 22 Jul 2015 07:24:17 +0200
7a3408
Subject: [PATCH] cgroup: Drop resource partition from virSystemdMakeScopeName
7a3408
7a3408
The scope name, even according to our docs is
7a3408
"machine-$DRIVER\x2d$VMNAME.scope" virSystemdMakeScopeName would use the
7a3408
resource partition name instead of "machine-" if it was specified thus
7a3408
creating invalid scope paths.
7a3408
7a3408
This makes libvirt drop cgroups for a VM that uses custom resource
7a3408
partition upon reconnecting since the detected scope name would not
7a3408
match the expected name generated by virSystemdMakeScopeName.
7a3408
7a3408
The error is exposed by the following log entry:
7a3408
7a3408
debug : virCgroupValidateMachineGroup:302 : Name 'machine-qemu\x2dtestvm.scope' for controller 'cpu' does not match 'testvm', 'testvm.libvirt-qemu' or 'machine-test-qemu\x2dtestvm.scope'
7a3408
7a3408
for a "/machine/test" resource and "testvm" vm.
7a3408
7a3408
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1238570
7a3408
(cherry picked from commit 88f6c007c3fb4324396ec397de57c8a80ba7b31d)
7a3408
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/lxc/lxc_process.c  |  6 ------
7a3408
 src/qemu/qemu_cgroup.c |  3 ---
7a3408
 src/util/vircgroup.c   | 11 ++---------
7a3408
 src/util/vircgroup.h   |  1 -
7a3408
 src/util/virsystemd.c  |  9 ++-------
7a3408
 src/util/virsystemd.h  |  3 +--
7a3408
 tests/virsystemdtest.c | 20 +++++++-------------
7a3408
 7 files changed, 12 insertions(+), 41 deletions(-)
7a3408
7a3408
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
7a3408
index 2bdce3b..87ee484 100644
7a3408
--- a/src/lxc/lxc_process.c
7a3408
+++ b/src/lxc/lxc_process.c
7a3408
@@ -1319,9 +1319,6 @@ int virLXCProcessStart(virConnectPtr conn,
7a3408
      * more reliable way to kill everything off if something
7a3408
      * goes wrong from here onwards ... */
7a3408
     if (virCgroupNewDetectMachine(vm->def->name, "lxc", vm->pid,
7a3408
-                                  vm->def->resource ?
7a3408
-                                  vm->def->resource->partition :
7a3408
-                                  NULL,
7a3408
                                   -1, &priv->cgroup) < 0)
7a3408
         goto cleanup;
7a3408
 
7a3408
@@ -1505,9 +1502,6 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm,
7a3408
             goto error;
7a3408
 
7a3408
         if (virCgroupNewDetectMachine(vm->def->name, "lxc", vm->pid,
7a3408
-                                      vm->def->resource ?
7a3408
-                                      vm->def->resource->partition :
7a3408
-                                      NULL,
7a3408
                                       -1, &priv->cgroup) < 0)
7a3408
             goto error;
7a3408
 
7a3408
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
7a3408
index 8ed74ee..ab21e12 100644
7a3408
--- a/src/qemu/qemu_cgroup.c
7a3408
+++ b/src/qemu/qemu_cgroup.c
7a3408
@@ -855,9 +855,6 @@ qemuConnectCgroup(virQEMUDriverPtr driver,
7a3408
     if (virCgroupNewDetectMachine(vm->def->name,
7a3408
                                   "qemu",
7a3408
                                   vm->pid,
7a3408
-                                  vm->def->resource ?
7a3408
-                                  vm->def->resource->partition :
7a3408
-                                  NULL,
7a3408
                                   cfg->cgroupControllers,
7a3408
                                   &priv->cgroup) < 0)
7a3408
         goto cleanup;
7a3408
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
7a3408
index cbe0234..29b2ab9 100644
7a3408
--- a/src/util/vircgroup.c
7a3408
+++ b/src/util/vircgroup.c
7a3408
@@ -243,7 +243,6 @@ static bool
7a3408
 virCgroupValidateMachineGroup(virCgroupPtr group,
7a3408
                               const char *name,
7a3408
                               const char *drivername,
7a3408
-                              const char *partition,
7a3408
                               bool stripEmulatorSuffix)
7a3408
 {
7a3408
     size_t i;
7a3408
@@ -258,10 +257,7 @@ virCgroupValidateMachineGroup(virCgroupPtr group,
7a3408
     if (virCgroupPartitionEscape(&partname) < 0)
7a3408
         goto cleanup;
7a3408
 
7a3408
-    if (!partition)
7a3408
-        partition = "/machine";
7a3408
-
7a3408
-    if (!(scopename = virSystemdMakeScopeName(name, drivername, partition)))
7a3408
+    if (!(scopename = virSystemdMakeScopeName(name, drivername)))
7a3408
         goto cleanup;
7a3408
 
7a3408
     if (virCgroupPartitionEscape(&scopename) < 0)
7a3408
@@ -1498,7 +1494,6 @@ int
7a3408
 virCgroupNewDetectMachine(const char *name,
7a3408
                           const char *drivername,
7a3408
                           pid_t pid,
7a3408
-                          const char *partition,
7a3408
                           int controllers,
7a3408
                           virCgroupPtr *group)
7a3408
 {
7a3408
@@ -1508,8 +1503,7 @@ virCgroupNewDetectMachine(const char *name,
7a3408
         return -1;
7a3408
     }
7a3408
 
7a3408
-    if (!virCgroupValidateMachineGroup(*group, name, drivername, partition,
7a3408
-                                       true)) {
7a3408
+    if (!virCgroupValidateMachineGroup(*group, name, drivername, true)) {
7a3408
         VIR_DEBUG("Failed to validate machine name for '%s' driver '%s'",
7a3408
                   name, drivername);
7a3408
         virCgroupFree(group);
7a3408
@@ -4047,7 +4041,6 @@ int
7a3408
 virCgroupNewDetectMachine(const char *name ATTRIBUTE_UNUSED,
7a3408
                           const char *drivername ATTRIBUTE_UNUSED,
7a3408
                           pid_t pid ATTRIBUTE_UNUSED,
7a3408
-                          const char *partition ATTRIBUTE_UNUSED,
7a3408
                           int controllers ATTRIBUTE_UNUSED,
7a3408
                           virCgroupPtr *group ATTRIBUTE_UNUSED)
7a3408
 {
7a3408
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
7a3408
index e75c522..675a185 100644
7a3408
--- a/src/util/vircgroup.h
7a3408
+++ b/src/util/vircgroup.h
7a3408
@@ -92,7 +92,6 @@ int virCgroupNewDetect(pid_t pid,
7a3408
 int virCgroupNewDetectMachine(const char *name,
7a3408
                               const char *drivername,
7a3408
                               pid_t pid,
7a3408
-                              const char *partition,
7a3408
                               int controllers,
7a3408
                               virCgroupPtr *group);
7a3408
 
7a3408
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
7a3408
index 8cedf8d..54c409d 100644
7a3408
--- a/src/util/virsystemd.c
7a3408
+++ b/src/util/virsystemd.c
7a3408
@@ -80,16 +80,11 @@ static void virSystemdEscapeName(virBufferPtr buf,
7a3408
 
7a3408
 
7a3408
 char *virSystemdMakeScopeName(const char *name,
7a3408
-                              const char *drivername,
7a3408
-                              const char *partition)
7a3408
+                              const char *drivername)
7a3408
 {
7a3408
     virBuffer buf = VIR_BUFFER_INITIALIZER;
7a3408
 
7a3408
-    if (*partition == '/')
7a3408
-        partition++;
7a3408
-
7a3408
-    virSystemdEscapeName(&buf, partition);
7a3408
-    virBufferAddChar(&buf, '-');
7a3408
+    virBufferAddLit(&buf, "machine-");
7a3408
     virSystemdEscapeName(&buf, drivername);
7a3408
     virBufferAddLit(&buf, "\\x2d");
7a3408
     virSystemdEscapeName(&buf, name);
7a3408
diff --git a/src/util/virsystemd.h b/src/util/virsystemd.h
7a3408
index 7a29dba..8af2169 100644
7a3408
--- a/src/util/virsystemd.h
7a3408
+++ b/src/util/virsystemd.h
7a3408
@@ -25,8 +25,7 @@
7a3408
 # include "internal.h"
7a3408
 
7a3408
 char *virSystemdMakeScopeName(const char *name,
7a3408
-                              const char *drivername,
7a3408
-                              const char *slicename);
7a3408
+                              const char *drivername);
7a3408
 char *virSystemdMakeSliceName(const char *partition);
7a3408
 
7a3408
 char *virSystemdMakeMachineName(const char *name,
7a3408
diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c
7a3408
index 261c4cc..d0b9335 100644
7a3408
--- a/tests/virsystemdtest.c
7a3408
+++ b/tests/virsystemdtest.c
7a3408
@@ -340,7 +340,6 @@ static int testCreateNetwork(const void *opaque ATTRIBUTE_UNUSED)
7a3408
 
7a3408
 struct testScopeData {
7a3408
     const char *name;
7a3408
-    const char *partition;
7a3408
     const char *expected;
7a3408
 };
7a3408
 
7a3408
@@ -351,9 +350,7 @@ testScopeName(const void *opaque)
7a3408
     int ret = -1;
7a3408
     char *actual = NULL;
7a3408
 
7a3408
-    if (!(actual = virSystemdMakeScopeName(data->name,
7a3408
-                                           "lxc",
7a3408
-                                           data->partition)))
7a3408
+    if (!(actual = virSystemdMakeScopeName(data->name, "lxc")))
7a3408
         goto cleanup;
7a3408
 
7a3408
     if (STRNEQ(actual, data->expected)) {
7a3408
@@ -472,22 +469,19 @@ mymain(void)
7a3408
     if (virtTestRun("Test create with network ", testCreateNetwork, NULL) < 0)
7a3408
         ret = -1;
7a3408
 
7a3408
-# define TEST_SCOPE(name, partition, unitname)                          \
7a3408
+# define TEST_SCOPE(name, unitname)                                     \
7a3408
     do {                                                                \
7a3408
         struct testScopeData data = {                                   \
7a3408
-            name, partition, unitname                                   \
7a3408
+            name, unitname                                              \
7a3408
         };                                                              \
7a3408
         if (virtTestRun("Test scopename", testScopeName, &data) < 0)    \
7a3408
             ret = -1;                                                   \
7a3408
     } while (0)
7a3408
 
7a3408
-    TEST_SCOPE("demo", "/machine", "machine-lxc\\x2ddemo.scope");
7a3408
-    TEST_SCOPE("demo-name", "/machine", "machine-lxc\\x2ddemo\\x2dname.scope");
7a3408
-    TEST_SCOPE("demo!name", "/machine", "machine-lxc\\x2ddemo\\x21name.scope");
7a3408
-    TEST_SCOPE(".demo", "/machine", "machine-lxc\\x2d\\x2edemo.scope");
7a3408
-    TEST_SCOPE("demo", "/machine/eng-dept", "machine-eng\\x2ddept-lxc\\x2ddemo.scope");
7a3408
-    TEST_SCOPE("demo", "/machine/eng-dept/testing!stuff",
7a3408
-               "machine-eng\\x2ddept-testing\\x21stuff-lxc\\x2ddemo.scope");
7a3408
+    TEST_SCOPE("demo", "machine-lxc\\x2ddemo.scope");
7a3408
+    TEST_SCOPE("demo-name", "machine-lxc\\x2ddemo\\x2dname.scope");
7a3408
+    TEST_SCOPE("demo!name", "machine-lxc\\x2ddemo\\x21name.scope");
7a3408
+    TEST_SCOPE(".demo", "machine-lxc\\x2d\\x2edemo.scope");
7a3408
 
7a3408
 # define TESTS_PM_SUPPORT_HELPER(name, function)                        \
7a3408
     do {                                                                \
7a3408
-- 
7a3408
2.5.0
7a3408