Skip to content

Commit 4f3de02

Browse files
committed
Add script to ensure cgroups are not co-mounted in rhel7/lxc. If required, script will unmount co-mounted cgroups and remount them seperately
1 parent f3b5a6e commit 4f3de02

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
309309
private String _ovsPvlanVmPath;
310310
private String _routerProxyPath;
311311
private String _ovsTunnelPath;
312+
private String _setupCgroupPath;
312313
private String _host;
313314
private String _dcId;
314315
private String _pod;
@@ -706,6 +707,17 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
706707
_hypervisorType = HypervisorType.KVM;
707708
}
708709

710+
//Verify that cpu,cpuacct cgroups are not co-mounted
711+
if(HypervisorType.LXC.equals(getHypervisorType())){
712+
_setupCgroupPath = Script.findScript(kvmScriptsDir, "setup-cgroups.sh");
713+
if (_setupCgroupPath == null) {
714+
throw new ConfigurationException("Unable to find the setup-cgroups.sh");
715+
}
716+
if(!checkCgroups()){
717+
throw new ConfigurationException("cpu,cpuacct cgroups are co-mounted");
718+
}
719+
}
720+
709721
_hypervisorURI = (String)params.get("hypervisor.uri");
710722
if (_hypervisorURI == null) {
711723
_hypervisorURI = LibvirtConnection.getHypervisorURI(_hypervisorType.toString());
@@ -5218,4 +5230,15 @@ public HypervisorType getHypervisorType(){
52185230
return _hypervisorType;
52195231
}
52205232

5233+
private boolean checkCgroups(){
5234+
final Script command = new Script(_setupCgroupPath, 5 * 1000, s_logger);
5235+
String result;
5236+
result = command.execute();
5237+
if (result != null) {
5238+
s_logger.debug("cgroup check failed:" + result);
5239+
return false;
5240+
}
5241+
return true;
5242+
}
5243+
52215244
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
20+
21+
# Script to fix cgroups co-mounted issue
22+
# Applies to RHEL7 versions only
23+
# Detect if cpu,cpuacct cgroups are co-mounted
24+
# If co-mounted, unmount and mount them seperately
25+
26+
#set -x
27+
28+
#Check distribution version for RHEL
29+
if [ -f '/etc/redhat-release' ];
30+
then
31+
#Check RHEL version for 7
32+
if grep 'Red Hat Enterprise Linux Server release 7' /etc/redhat-release > /dev/null
33+
then
34+
# Check if cgroups if co-mounted
35+
if [ -d '/sys/fs/cgroup/cpu,cpuacct' ];
36+
then
37+
# cgroups co-mounted. Requires remount
38+
umount /sys/fs/cgroup/cpu,cpuacct
39+
rm /sys/fs/cgroup/cpu
40+
rm /sys/fs/cgroup/cpuacct
41+
rm -rf /sys/fs/cgroup/cpu,cpuacct
42+
mkdir -p /sys/fs/cgroup/cpu
43+
mkdir -p /sys/fs/cgroup/cpuacct
44+
mount -t cgroup -o cpu cpu "/sys/fs/cgroup/cpu"
45+
mount -t cgroup -o cpuacct cpuacct "/sys/fs/cgroup/cpuacct"
46+
# Verify that cgroups are not co-mounted
47+
if [ -d '/sys/fs/cgroup/cpu,cpuacct' ];
48+
then
49+
echo "cgroups still co-mounted"
50+
exit 1;
51+
fi
52+
fi
53+
fi
54+
fi
55+
56+
exit 0

0 commit comments

Comments
 (0)