[libvirt PATCH 07/25] vircgroup: remove useless cgroup->path variable

Pavel Hrdina phrdina at redhat.com
Tue Nov 3 12:41:19 UTC 2020


It is only used for debug and error purposes which can be easily
replaced by @placement.

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 src/util/vircgroup.c     | 20 ++++++--------------
 src/util/vircgrouppriv.h |  2 --
 src/util/vircgroupv1.c   |  8 +++-----
 src/util/vircgroupv2.c   |  4 +---
 tests/vircgrouptest.c    | 29 ++++++++++-------------------
 5 files changed, 20 insertions(+), 43 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index e3c45e93cb..7ff23e1218 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -669,13 +669,6 @@ virCgroupNew(pid_t pid,
     *group = NULL;
     newGroup = g_new0(virCgroup, 1);
 
-    if (path[0] == '/' || !parent) {
-        newGroup->path = g_strdup(path);
-    } else {
-        newGroup->path = g_strdup_printf("%s%s%s", parent->path,
-                                         STREQ(parent->path, "") ? "" : "/", path);
-    }
-
     if (virCgroupDetect(newGroup, pid, controllers, path, parent) < 0)
         return -1;
 
@@ -2388,8 +2381,8 @@ virCgroupKillInternal(virCgroupPtr group,
     g_autofree char *keypath = NULL;
     bool done = false;
     FILE *fp = NULL;
-    VIR_DEBUG("group=%p path=%s signum=%d pids=%p",
-              group, group->path, signum, pids);
+    VIR_DEBUG("group=%p signum=%d pids=%p",
+              group, signum, pids);
 
     if (virCgroupPathOfController(group, controller, taskFile, &keypath) < 0)
         return -1;
@@ -2471,8 +2464,8 @@ virCgroupKillRecursiveInternal(virCgroupPtr group,
     g_autoptr(DIR) dp = NULL;
     struct dirent *ent;
     int direrr;
-    VIR_DEBUG("group=%p path=%s signum=%d pids=%p",
-              group, group->path, signum, pids);
+    VIR_DEBUG("group=%p signum=%d pids=%p",
+              group, signum, pids);
 
     if (virCgroupPathOfController(group, controller, "", &keypath) < 0)
         return -1;
@@ -2532,7 +2525,7 @@ virCgroupKillRecursive(virCgroupPtr group, int signum)
     virCgroupBackendPtr *backends = virCgroupBackendGetAll();
     g_autoptr(GHashTable) pids = g_hash_table_new_full(g_int64_hash, g_int64_equal, g_free, NULL);
 
-    VIR_DEBUG("group=%p path=%s signum=%d", group, group->path, signum);
+    VIR_DEBUG("group=%p signum=%d", group, signum);
 
     for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
         if (backends && backends[i] && backends[i]->available()) {
@@ -2563,7 +2556,7 @@ virCgroupKillPainfully(virCgroupPtr group)
 {
     size_t i;
     int ret;
-    VIR_DEBUG("cgroup=%p path=%s", group, group->path);
+    VIR_DEBUG("cgroup=%p", group);
     for (i = 0; i < 15; i++) {
         int signum;
         if (i == 0)
@@ -3491,7 +3484,6 @@ virCgroupFree(virCgroupPtr group)
     VIR_FREE(group->unified.mountPoint);
     VIR_FREE(group->unified.placement);
 
-    VIR_FREE(group->path);
     VIR_FREE(group);
 }
 
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
index f85a36efdb..af8bf99888 100644
--- a/src/util/vircgrouppriv.h
+++ b/src/util/vircgrouppriv.h
@@ -60,8 +60,6 @@ typedef struct _virCgroupV2Controller virCgroupV2Controller;
 typedef virCgroupV2Controller *virCgroupV2ControllerPtr;
 
 struct _virCgroup {
-    char *path;
-
     virCgroupBackendPtr backends[VIR_CGROUP_BACKEND_TYPE_LAST];
 
     virCgroupV1Controller legacy[VIR_CGROUP_CONTROLLER_LAST];
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 61fb359f8d..6bb819410b 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -545,7 +545,9 @@ virCgroupV1CpuSetInherit(virCgroupPtr parent,
         "cpuset.memory_migrate",
     };
 
-    VIR_DEBUG("Setting up inheritance %s -> %s", parent->path, group->path);
+    VIR_DEBUG("Setting up inheritance %s -> %s",
+              parent->legacy[VIR_CGROUP_CONTROLLER_CPUSET].placement,
+              group->legacy[VIR_CGROUP_CONTROLLER_CPUSET].placement);
     for (i = 0; i < G_N_ELEMENTS(inherit_values); i++) {
         g_autofree char *value = NULL;
 
@@ -583,7 +585,6 @@ virCgroupV1SetMemoryUseHierarchy(virCgroupPtr group)
     if (value == 1)
         return 0;
 
-    VIR_DEBUG("Setting up %s/%s", group->path, filename);
     if (virCgroupSetValueU64(group,
                              VIR_CGROUP_CONTROLLER_MEMORY,
                              filename, 1) < 0)
@@ -601,7 +602,6 @@ virCgroupV1MakeGroup(virCgroupPtr parent,
 {
     size_t i;
 
-    VIR_DEBUG("Make group %s", group->path);
     for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
         g_autofree char *path = NULL;
 
@@ -671,7 +671,6 @@ virCgroupV1Remove(virCgroupPtr group)
     int rc = 0;
     size_t i;
 
-    VIR_DEBUG("Removing cgroup %s", group->path);
     for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
         g_autofree char *grppath = NULL;
 
@@ -697,7 +696,6 @@ virCgroupV1Remove(virCgroupPtr group)
         VIR_DEBUG("Removing cgroup %s and all child cgroups", grppath);
         rc = virCgroupRemoveRecursively(grppath);
     }
-    VIR_DEBUG("Done removing cgroup %s", group->path);
 
     return rc;
 }
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index 530e5d2ce9..0467a72566 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -413,8 +413,6 @@ virCgroupV2MakeGroup(virCgroupPtr parent,
         return 0;
     }
 
-    VIR_DEBUG("Make group %s", group->path);
-
     controller = virCgroupV2GetAnyController(group);
     if (virCgroupV2PathOfController(group, controller, "", &path) < 0)
         return -1;
@@ -424,7 +422,7 @@ virCgroupV2MakeGroup(virCgroupPtr parent,
     if (!virFileExists(path) &&
         (!create || (mkdir(path, 0755) < 0 && errno != EEXIST))) {
         virReportSystemError(errno, _("Failed to create v2 cgroup '%s'"),
-                             group->path);
+                             path);
         return -1;
     }
 
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
index 6c1a766fa2..0dd5e3f0b4 100644
--- a/tests/vircgrouptest.c
+++ b/tests/vircgrouptest.c
@@ -38,7 +38,6 @@
 VIR_LOG_INIT("tests.cgrouptest");
 
 static int validateCgroup(virCgroupPtr cgroup,
-                          const char *expectPath,
                           const char **expectMountPoint,
                           const char **expectLinkPoint,
                           const char **expectPlacement,
@@ -48,12 +47,6 @@ static int validateCgroup(virCgroupPtr cgroup,
 {
     size_t i;
 
-    if (STRNEQ(cgroup->path, expectPath)) {
-        fprintf(stderr, "Wrong path '%s', expected '%s'\n",
-                cgroup->path, expectPath);
-        return -1;
-    }
-
     for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
         if (STRNEQ_NULLABLE(expectMountPoint[i],
                             cgroup->legacy[i].mountPoint)) {
@@ -240,7 +233,7 @@ static int testCgroupNewForSelf(const void *args G_GNUC_UNUSED)
         return -1;
     }
 
-    return validateCgroup(cgroup, "", mountsFull, links, placement, NULL, NULL, 0);
+    return validateCgroup(cgroup, mountsFull, links, placement, NULL, NULL, 0);
 }
 
 
@@ -314,14 +307,14 @@ static int testCgroupNewForPartition(const void *args G_GNUC_UNUSED)
         fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv);
         return -1;
     }
-    rv = validateCgroup(cgroup, "/virtualmachines.partition", mountsSmall, links, placementSmall, NULL, NULL, 0);
+    rv = validateCgroup(cgroup, mountsSmall, links, placementSmall, NULL, NULL, 0);
     virCgroupFree(cgroup);
 
     if ((rv = virCgroupNewPartition("/virtualmachines", true, -1, &cgroup)) != 0) {
         fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv);
         return -1;
     }
-    return validateCgroup(cgroup, "/virtualmachines.partition", mountsFull, links, placementFull, NULL, NULL, 0);
+    return validateCgroup(cgroup, mountsFull, links, placementFull, NULL, NULL, 0);
 }
 
 
@@ -365,8 +358,7 @@ static int testCgroupNewForPartitionNested(const void *args G_GNUC_UNUSED)
         return -1;
     }
 
-    return validateCgroup(cgroup, "/deployment.partition/production.partition",
-                          mountsFull, links, placementFull, NULL, NULL, 0);
+    return validateCgroup(cgroup, mountsFull, links, placementFull, NULL, NULL, 0);
 }
 
 
@@ -416,8 +408,7 @@ static int testCgroupNewForPartitionNestedDeep(const void *args G_GNUC_UNUSED)
         return -1;
     }
 
-    return validateCgroup(cgroup, "/user/berrange.user/production.partition",
-                          mountsFull, links, placementFull, NULL, NULL, 0);
+    return validateCgroup(cgroup, mountsFull, links, placementFull, NULL, NULL, 0);
 }
 
 
@@ -448,7 +439,7 @@ static int testCgroupNewForPartitionDomain(const void *args G_GNUC_UNUSED)
         return -1;
     }
 
-    return validateCgroup(domaincgroup, "/production.partition/foo.libvirt-lxc", mountsFull, links, placement, NULL, NULL, 0);
+    return validateCgroup(domaincgroup, mountsFull, links, placement, NULL, NULL, 0);
 }
 
 static int testCgroupNewForPartitionDomainEscaped(const void *args G_GNUC_UNUSED)
@@ -493,7 +484,7 @@ static int testCgroupNewForPartitionDomainEscaped(const void *args G_GNUC_UNUSED
      * since our fake /proc/cgroups pretends this controller
      * isn't compiled into the kernel
      */
-    return validateCgroup(domaincgroup, "/_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc", mountsFull, links, placement, NULL, NULL, 0);
+    return validateCgroup(domaincgroup, mountsFull, links, placement, NULL, NULL, 0);
 }
 
 static int testCgroupNewForSelfAllInOne(const void *args G_GNUC_UNUSED)
@@ -514,7 +505,7 @@ static int testCgroupNewForSelfAllInOne(const void *args G_GNUC_UNUSED)
         return -1;
     }
 
-    return validateCgroup(cgroup, "", mountsAllInOne, linksAllInOne, placement, NULL, NULL, 0);
+    return validateCgroup(cgroup, mountsAllInOne, linksAllInOne, placement, NULL, NULL, 0);
 }
 
 
@@ -547,7 +538,7 @@ static int testCgroupNewForSelfUnified(const void *args G_GNUC_UNUSED)
         return -1;
     }
 
-    return validateCgroup(cgroup, "", empty, empty, empty,
+    return validateCgroup(cgroup, empty, empty, empty,
                           "/not/really/sys/fs/cgroup", "/", controllers);
 }
 
@@ -580,7 +571,7 @@ static int testCgroupNewForSelfHybrid(const void *args G_GNUC_UNUSED)
         return -1;
     }
 
-    return validateCgroup(cgroup, "", mounts, empty, placement,
+    return validateCgroup(cgroup, mounts, empty, placement,
                           "/not/really/sys/fs/cgroup/unified", "/", controllers);
 }
 
-- 
2.26.2




More information about the libvir-list mailing list