[PATCH 3/5] Rename virCgroupMounted to virCgroupHasController & make it more robust

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

The virCgroupMounted method is badly named, since a controller can be
mounted, but disabled in the current object. Rename the method to be
virCgroupHasController. Also make it tolerant to a  NULL virCgroupPtr
and out-of-range controller index, to avoid duplication of these
checks in all callers

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 src/libvirt_private.syms |  2 +-
 src/lxc/lxc_driver.c     | 12 +-----------
 src/lxc/lxc_process.c    | 10 +++++-----
 src/qemu/qemu_cgroup.c   | 14 +-------------
 src/util/vircgroup.c     | 13 +++++++++----
 src/util/vircgroup.h     |  2 +-
 6 files changed, 18 insertions(+), 35 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index f75d681..f23f80d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1111,7 +1111,7 @@ virCgroupGetMemSwapUsage;
 virCgroupKill;
 virCgroupKillPainfully;
 virCgroupKillRecursive;
-virCgroupMounted;
+virCgroupHasController;
 virCgroupMoveTask;
 virCgroupPathOfController;
 virCgroupRemove;
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 989c2f3..6737f13 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1641,17 +1641,7 @@ cleanup:
 static bool lxcCgroupControllerActive(virLXCDriverPtr driver,
                                       int controller)
 {
-    if (driver->cgroup == NULL)
-        return false;
-    if (controller < 0 || controller >= VIR_CGROUP_CONTROLLER_LAST)
-        return false;
-    if (!virCgroupMounted(driver->cgroup, controller))
-        return false;
-#if 0
-    if (driver->cgroupControllers & (1 << controller))
-        return true;
-#endif
-    return true;
+    return virCgroupHasController(driver->cgroup, controller);
 }
 
 
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 670a032..8c8778a 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -1006,20 +1006,20 @@ int virLXCProcessStart(virConnectPtr conn,
         return -1;
     }
 
-    if (!virCgroupMounted(lxc_driver->cgroup,
+    if (!virCgroupHasController(lxc_driver->cgroup,
                           VIR_CGROUP_CONTROLLER_CPUACCT)) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Unable to find 'cpuacct' cgroups controller mount"));
         return -1;
     }
-    if (!virCgroupMounted(lxc_driver->cgroup,
-                          VIR_CGROUP_CONTROLLER_DEVICES)) {
+    if (!virCgroupHasController(lxc_driver->cgroup,
+                                VIR_CGROUP_CONTROLLER_DEVICES)) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Unable to find 'devices' cgroups controller mount"));
         return -1;
     }
-    if (!virCgroupMounted(lxc_driver->cgroup,
-                          VIR_CGROUP_CONTROLLER_MEMORY)) {
+    if (!virCgroupHasController(lxc_driver->cgroup,
+                                VIR_CGROUP_CONTROLLER_MEMORY)) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Unable to find 'memory' cgroups controller mount"));
         return -1;
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 2cdc2b7..5aa9416 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -48,19 +48,7 @@ static const char *const defaultDeviceACL[] = {
 bool qemuCgroupControllerActive(virQEMUDriverPtr driver,
                                 int controller)
 {
-    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
-    bool ret = false;
-
-    if (driver->cgroup == NULL)
-        goto cleanup;
-    if (controller < 0 || controller >= VIR_CGROUP_CONTROLLER_LAST)
-        goto cleanup;
-    if (!virCgroupMounted(driver->cgroup, controller))
-        goto cleanup;
-
-cleanup:
-    virObjectUnref(cfg);
-    return ret;
+    return virCgroupHasController(driver->cgroup, controller);
 }
 
 static int
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 0d6db58..ccdb1dd 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -94,15 +94,20 @@ void virCgroupFree(virCgroupPtr *group)
 }
 
 /**
- * virCgroupMounted: query whether a cgroup subsystem is mounted or not
+ * virCgroupHasController: query whether a cgroup controller is present
  *
- * @cgroup: The group structure to be queried
+ * @cgroup: The group structure to be queried, or NULL
  * @controller: cgroup subsystem id
  *
- * Returns true if a cgroup is subsystem is mounted.
+ * Returns true if a cgroup controller is mounted and is associated
+ * with this cgroup object.
  */
-bool virCgroupMounted(virCgroupPtr cgroup, int controller)
+bool virCgroupHasController(virCgroupPtr cgroup, int controller)
 {
+    if (!cgroup)
+        return false;
+    if (controller < 0 || controller >= VIR_CGROUP_CONTROLLER_LAST)
+        return false;
     return cgroup->controllers[controller].mountPoint != NULL;
 }
 
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
index 725d2d0..4c1134d 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -161,7 +161,7 @@ int virCgroupRemoveRecursively(char *grppath);
 int virCgroupRemove(virCgroupPtr group);
 
 void virCgroupFree(virCgroupPtr *group);
-bool virCgroupMounted(virCgroupPtr cgroup, int controller);
+bool virCgroupHasController(virCgroupPtr cgroup, int controller);
 
 int virCgroupKill(virCgroupPtr group, int signum);
 int virCgroupKillRecursive(virCgroupPtr group, int signum);
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]