]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cgroup: Drop resource partition from virSystemdMakeScopeName
authorPeter Krempa <pkrempa@redhat.com>
Thu, 16 Jul 2015 13:35:05 +0000 (15:35 +0200)
committerCole Robinson <crobinso@redhat.com>
Wed, 23 Dec 2015 22:58:44 +0000 (17:58 -0500)
The scope name, even according to our docs is
"machine-$DRIVER\x2d$VMNAME.scope" virSystemdMakeScopeName would use the
resource partition name instead of "machine-" if it was specified thus
creating invalid scope paths.

This makes libvirt drop cgroups for a VM that uses custom resource
partition upon reconnecting since the detected scope name would not
match the expected name generated by virSystemdMakeScopeName.

The error is exposed by the following log entry:

debug : virCgroupValidateMachineGroup:302 : Name 'machine-qemu\x2dtestvm.scope' for controller 'cpu' does not match 'testvm', 'testvm.libvirt-qemu' or 'machine-test-qemu\x2dtestvm.scope'

for a "/machine/test" resource and "testvm" vm.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1238570
(cherry picked from commit 88f6c007c3fb4324396ec397de57c8a80ba7b31d)

src/lxc/lxc_process.c
src/qemu/qemu_cgroup.c
src/util/vircgroup.c
src/util/vircgroup.h
src/util/virsystemd.c
src/util/virsystemd.h
tests/virsystemdtest.c

index bed407a5642ec43e950d5b2b630efcb406513ef6..9a8aaa974cdcfb33d5ab0077617258471f2fe2bd 100644 (file)
@@ -1318,9 +1318,6 @@ int virLXCProcessStart(virConnectPtr conn,
      * more reliable way to kill everything off if something
      * goes wrong from here onwards ... */
     if (virCgroupNewDetectMachine(vm->def->name, "lxc", vm->pid,
-                                  vm->def->resource ?
-                                  vm->def->resource->partition :
-                                  NULL,
                                   -1, &priv->cgroup) < 0)
         goto cleanup;
 
@@ -1504,9 +1501,6 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm,
             goto error;
 
         if (virCgroupNewDetectMachine(vm->def->name, "lxc", vm->pid,
-                                      vm->def->resource ?
-                                      vm->def->resource->partition :
-                                      NULL,
                                       -1, &priv->cgroup) < 0)
             goto error;
 
index 3f3457a7a148f40a5a1456e577dda6f02c57a378..f9141ef8c573725dcf5a76e8f3702b9e55567dab 100644 (file)
@@ -839,9 +839,6 @@ qemuConnectCgroup(virQEMUDriverPtr driver,
     if (virCgroupNewDetectMachine(vm->def->name,
                                   "qemu",
                                   vm->pid,
-                                  vm->def->resource ?
-                                  vm->def->resource->partition :
-                                  NULL,
                                   cfg->cgroupControllers,
                                   &priv->cgroup) < 0)
         goto cleanup;
index 6957e81d547227a05e35efd6c96b0d6c138ed199..212810596f7b0b8643a7f43093514a50bb305d51 100644 (file)
@@ -243,7 +243,6 @@ static bool
 virCgroupValidateMachineGroup(virCgroupPtr group,
                               const char *name,
                               const char *drivername,
-                              const char *partition,
                               bool stripEmulatorSuffix)
 {
     size_t i;
@@ -258,10 +257,7 @@ virCgroupValidateMachineGroup(virCgroupPtr group,
     if (virCgroupPartitionEscape(&partname) < 0)
         goto cleanup;
 
-    if (!partition)
-        partition = "/machine";
-
-    if (!(scopename = virSystemdMakeScopeName(name, drivername, partition)))
+    if (!(scopename = virSystemdMakeScopeName(name, drivername)))
         goto cleanup;
 
     if (virCgroupPartitionEscape(&scopename) < 0)
@@ -1551,7 +1547,6 @@ int
 virCgroupNewDetectMachine(const char *name,
                           const char *drivername,
                           pid_t pid,
-                          const char *partition,
                           int controllers,
                           virCgroupPtr *group)
 {
@@ -1561,8 +1556,7 @@ virCgroupNewDetectMachine(const char *name,
         return -1;
     }
 
-    if (!virCgroupValidateMachineGroup(*group, name, drivername, partition,
-                                       true)) {
+    if (!virCgroupValidateMachineGroup(*group, name, drivername, true)) {
         VIR_DEBUG("Failed to validate machine name for '%s' driver '%s'",
                   name, drivername);
         virCgroupFree(group);
@@ -4059,7 +4053,6 @@ int
 virCgroupNewDetectMachine(const char *name ATTRIBUTE_UNUSED,
                           const char *drivername ATTRIBUTE_UNUSED,
                           pid_t pid ATTRIBUTE_UNUSED,
-                          const char *partition ATTRIBUTE_UNUSED,
                           int controllers ATTRIBUTE_UNUSED,
                           virCgroupPtr *group ATTRIBUTE_UNUSED)
 {
index 9f984e787d1f6273074ecfa8be86e6f314214abe..20e034ca27bc4b8159d668c9638ad58407d8f18c 100644 (file)
@@ -89,7 +89,6 @@ int virCgroupNewDetect(pid_t pid,
 int virCgroupNewDetectMachine(const char *name,
                               const char *drivername,
                               pid_t pid,
-                              const char *partition,
                               int controllers,
                               virCgroupPtr *group);
 
index 8cedf8db75816a7234e7400fc918e99aacf62cb4..54c409d7f6de921a1465d00ce5f549131815fe16 100644 (file)
@@ -80,16 +80,11 @@ static void virSystemdEscapeName(virBufferPtr buf,
 
 
 char *virSystemdMakeScopeName(const char *name,
-                              const char *drivername,
-                              const char *partition)
+                              const char *drivername)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
 
-    if (*partition == '/')
-        partition++;
-
-    virSystemdEscapeName(&buf, partition);
-    virBufferAddChar(&buf, '-');
+    virBufferAddLit(&buf, "machine-");
     virSystemdEscapeName(&buf, drivername);
     virBufferAddLit(&buf, "\\x2d");
     virSystemdEscapeName(&buf, name);
index 7a29dbafffe5d890b1984fcac881ba8d99609cc3..8af2169101888a53aaba31dec9b7a3d3e8aff81b 100644 (file)
@@ -25,8 +25,7 @@
 # include "internal.h"
 
 char *virSystemdMakeScopeName(const char *name,
-                              const char *drivername,
-                              const char *slicename);
+                              const char *drivername);
 char *virSystemdMakeSliceName(const char *partition);
 
 char *virSystemdMakeMachineName(const char *name,
index 261c4cc345f4121c87350675e09fd9cfca5f6910..d0b9335b24ae28c6f26876478e878c3a827d121b 100644 (file)
@@ -340,7 +340,6 @@ static int testCreateNetwork(const void *opaque ATTRIBUTE_UNUSED)
 
 struct testScopeData {
     const char *name;
-    const char *partition;
     const char *expected;
 };
 
@@ -351,9 +350,7 @@ testScopeName(const void *opaque)
     int ret = -1;
     char *actual = NULL;
 
-    if (!(actual = virSystemdMakeScopeName(data->name,
-                                           "lxc",
-                                           data->partition)))
+    if (!(actual = virSystemdMakeScopeName(data->name, "lxc")))
         goto cleanup;
 
     if (STRNEQ(actual, data->expected)) {
@@ -472,22 +469,19 @@ mymain(void)
     if (virtTestRun("Test create with network ", testCreateNetwork, NULL) < 0)
         ret = -1;
 
-# define TEST_SCOPE(name, partition, unitname)                          \
+# define TEST_SCOPE(name, unitname)                                     \
     do {                                                                \
         struct testScopeData data = {                                   \
-            name, partition, unitname                                   \
+            name, unitname                                              \
         };                                                              \
         if (virtTestRun("Test scopename", testScopeName, &data) < 0)    \
             ret = -1;                                                   \
     } while (0)
 
-    TEST_SCOPE("demo", "/machine", "machine-lxc\\x2ddemo.scope");
-    TEST_SCOPE("demo-name", "/machine", "machine-lxc\\x2ddemo\\x2dname.scope");
-    TEST_SCOPE("demo!name", "/machine", "machine-lxc\\x2ddemo\\x21name.scope");
-    TEST_SCOPE(".demo", "/machine", "machine-lxc\\x2d\\x2edemo.scope");
-    TEST_SCOPE("demo", "/machine/eng-dept", "machine-eng\\x2ddept-lxc\\x2ddemo.scope");
-    TEST_SCOPE("demo", "/machine/eng-dept/testing!stuff",
-               "machine-eng\\x2ddept-testing\\x21stuff-lxc\\x2ddemo.scope");
+    TEST_SCOPE("demo", "machine-lxc\\x2ddemo.scope");
+    TEST_SCOPE("demo-name", "machine-lxc\\x2ddemo\\x2dname.scope");
+    TEST_SCOPE("demo!name", "machine-lxc\\x2ddemo\\x21name.scope");
+    TEST_SCOPE(".demo", "machine-lxc\\x2d\\x2edemo.scope");
 
 # define TESTS_PM_SUPPORT_HELPER(name, function)                        \
     do {                                                                \