summaryrefslogtreecommitdiff
path: root/nova/virt
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2023-05-04 10:27:32 +0000
committerGerrit Code Review <review@openstack.org>2023-05-04 10:27:32 +0000
commitcb2cdee4c9c8ca91089aae6254a3e9e39ab639ea (patch)
tree438ec9bc7c875d30e5e3b3fd05bfdce869285381 /nova/virt
parentdeac3a2f8a3d7937177a5237e40f081d2e5b4c9a (diff)
parent973ff4fc1a0586937d13f2b39e517422713b1003 (diff)
downloadnova-cb2cdee4c9c8ca91089aae6254a3e9e39ab639ea.tar.gz
Merge "Have host look for CPU controller of cgroupsv2 location."
Diffstat (limited to 'nova/virt')
-rw-r--r--nova/virt/libvirt/host.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/nova/virt/libvirt/host.py b/nova/virt/libvirt/host.py
index 9658a5791d..1ae86d9f47 100644
--- a/nova/virt/libvirt/host.py
+++ b/nova/virt/libvirt/host.py
@@ -1643,15 +1643,44 @@ class Host(object):
CONFIG_CGROUP_SCHED may be disabled in some kernel configs to
improve scheduler latency.
"""
+ return self._has_cgroupsv1_cpu_controller() or \
+ self._has_cgroupsv2_cpu_controller()
+
+ def _has_cgroupsv1_cpu_controller(self):
+ LOG.debug(f"Searching host: '{self.get_hostname()}' "
+ "for CPU controller through CGroups V1...")
try:
with open("/proc/self/mounts", "r") as fd:
for line in fd.readlines():
# mount options and split options
bits = line.split()[3].split(",")
if "cpu" in bits:
+ LOG.debug("CPU controller found on host.")
+ return True
+ LOG.debug("CPU controller missing on host.")
+ return False
+ except IOError as ex:
+ LOG.debug(f"Search failed due to: '{ex}'. "
+ "Maybe the host is not running under CGroups V1. "
+ "Deemed host to be missing controller by this approach.")
+ return False
+
+ def _has_cgroupsv2_cpu_controller(self):
+ LOG.debug(f"Searching host: '{self.get_hostname()}' "
+ "for CPU controller through CGroups V2...")
+ try:
+ with open("/sys/fs/cgroup/cgroup.controllers", "r") as fd:
+ for line in fd.readlines():
+ bits = line.split()
+ if "cpu" in bits:
+ LOG.debug("CPU controller found on host.")
return True
+ LOG.debug("CPU controller missing on host.")
return False
- except IOError:
+ except IOError as ex:
+ LOG.debug(f"Search failed due to: '{ex}'. "
+ "Maybe the host is not running under CGroups V2. "
+ "Deemed host to be missing controller by this approach.")
return False
def get_canonical_machine_type(self, arch, machine) -> str: