summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2018-04-10 15:10:37 +0200
committerJonathan Bauer2018-04-10 15:10:37 +0200
commit7209b23fb01fd35f6aab2f9e1323efa37eddb823 (patch)
tree78c47e55dc549ac11c22b6962813e327dc29ad0b
parent[slx-issue] support for SLX_PXE_NETIF (diff)
downloadmltk-7209b23fb01fd35f6aab2f9e1323efa37eddb823.tar.gz
mltk-7209b23fb01fd35f6aab2f9e1323efa37eddb823.tar.xz
mltk-7209b23fb01fd35f6aab2f9e1323efa37eddb823.zip
[run-virt] check for /tmp/virt not in RAM
to cater for usecases where /tmp is in RAM but /tmp/virt is backed by, e.g., an NFS (Ramboz)
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc15
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc2
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc18
3 files changed, 27 insertions, 8 deletions
diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc
index b3bc1cdf..00211c94 100644
--- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc
+++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc
@@ -31,14 +31,15 @@ if check_dep mkdir && ! mkdir -p "$TMPDIR"; then
EXIT_TYPE="internal" EXIT_REASON="Konnte kein Arbeitsverzeichnis für die VM-Sitzung anlegen." cleanexit 1
fi
-# Determine if /tmp resides on the hdd
-# This variable is empty (but set!) if no hard drive was mounted on /tmp
+# Check that /tmp/virt is not in RAM.
+# Either mounted directly (e.g. NFS) or backed by hdd mounted /tmp.
+# This variable is empty (but set!) if /tmp/virt isn't backed at all
# else it will be non-empty (check with helper function 'notempty').
-declare -g TMP_ON_HDD=
-if ! grep -q -E '\s+/tmp\s+tmpfs\s+' '/proc/mounts'; then
- writelog "Hard drive partition mounted on /tmp"
- TMP_ON_HDD=1
- readonly TMP_ON_HDD
+declare -g TMPDIR_NOT_RAM=
+if ! dir_on_tmpfs /tmp/virt ; then
+ writelog "/tmp/virt is not in RAM, will allocate more RAM to VMs."
+ TMPDIR_NOT_RAM=1
+ readonly TMPDIR_NOT_RAM
fi
# Get a unique VM_ID for the current invocation
diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc
index 04f3b22e..c59a82b0 100644
--- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc
+++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc
@@ -34,7 +34,7 @@ set_virt_memory() {
# Amount of memory for the VM. Be generous if diff is written to HDD
local min=768
local reserve max
- if notempty TMP_ON_HDD; then
+ if notempty TMPDIR_NOT_RAM; then
if lsmod | grep -q '^nvidia'; then
max=2800
reserve=28
diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc
index 30676152..2336718a 100644
--- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc
+++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc
@@ -468,3 +468,21 @@ clean_string() {
tr '[A-Z]' '[a-z]' | tr -d -c '[a-z0-9\-]'
fi
}
+
+# Helper to check whether given directory resides in RAM, either
+# by being mounted as tmpfs or not mounted at all in which case
+# we assume the same. Returns 0 if so, 1 otherwise.
+dir_on_tmpfs() {
+ local current_dir="$1"
+ while [ -n "$current_dir" ]; do
+ local mount_line="$(awk -v dir="$current_dir" '$2 == dir' /proc/mounts)"
+ if [ -z "$mount_line" ]; then
+ # check its parent directory
+ current_dir="${current_dir%/*}"
+ continue
+ fi
+ [ "x$(cut -d' ' -f3 <<< ${mount_line})" == "xtmpfs" ]
+ return $?
+ done
+ return 0
+}