summaryrefslogtreecommitdiffstats
path: root/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes
diff options
context:
space:
mode:
authorSimon Rettberg2019-07-10 17:16:54 +0200
committerSimon Rettberg2019-07-10 17:16:54 +0200
commit2794fd635816b03d19f19ea620629a2e9f4b38a1 (patch)
tree58b81141ba20db4a5c07822e6d04e4d087d8af66 /core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes
parent[run-virt/*] Make VIRTCMDOPTS an array for space safeness (diff)
downloadmltk-2794fd635816b03d19f19ea620629a2e9f4b38a1.tar.gz
mltk-2794fd635816b03d19f19ea620629a2e9f4b38a1.tar.xz
mltk-2794fd635816b03d19f19ea620629a2e9f4b38a1.zip
[run-virt] Use slx-tools to determine if /tmp/virt is in RAM
Also avoid triple-negation for the according variable...
Diffstat (limited to 'core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes')
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc13
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc16
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc27
3 files changed, 17 insertions, 39 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 79b2ddd1..97d08440 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
@@ -11,14 +11,15 @@ fi
# 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 TMPDIR_NOT_RAM=
-if ! dir_on_tmpfs /tmp/virt ; then
+# This variable will be true or false
+declare -g TMPDIR_IN_RAM=false
+if fs_path_isvolatile /tmp/virt ; then
+ TMPDIR_IN_RAM=true
+ writelog "/tmp/virt is in RAM, will allocate little RAM to VMs."
+else
writelog "/tmp/virt is not in RAM, will allocate more RAM to VMs."
- TMPDIR_NOT_RAM=1
- readonly TMPDIR_NOT_RAM
fi
+readonly TMPDIR_IN_RAM
# Get a unique VM_ID for the current invocation
get_vm_id
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 c3a5009f..414c654a 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
@@ -31,24 +31,28 @@ set_virt_memory() {
EXIT_TYPE="internal" EXIT_REASON="Konnte die Größe des Arbeitsspeichers nicht ermitteln!" cleanexit 1
fi
- # Amount of memory for the VM. Be generous if diff is written to HDD
+ # Calculare amount of memory for the VM. Be generous if diff is written to HDD.
+ # First, determine how much should be left to the host system. Minimum is 1GB.
local min=1024
local reserve max
- if notempty TMPDIR_NOT_RAM; then
+ if $TMPDIR_IN_RAM; then
+ # tmp in RAM, so reserve a lot for the system since that is where the HDD diff goes.
+ reserve=65
+ max=8192 # But max. 8GB
+ else
+ # We have a backing store for the HDD diff, be generous
if lsmod | grep -q '^nvidia'; then
+ # With nvidia cards, the host needs a bit more RAM.
max=2800
reserve=28
else
max=1800
reserve=21
fi
- else
- reserve=65
- max=8192
fi
# Calculate absulute amount of RAM that should stay available to the host
- local reserve="$(( ( HOST_MEM_TOTAL * reserve ) / 100 ))"
+ reserve="$(( ( HOST_MEM_TOTAL * reserve ) / 100 ))"
# Respect some upper and lower bounds for the host amount
[ "$reserve" -lt "$min" ] && reserve="$min"
[ "$reserve" -gt "$max" ] && reserve="$max"
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 abf66842..08ab4f72 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
@@ -499,33 +499,6 @@ clean_string() {
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
- # NG: check if / is fully backed by hard drive
- local dmsetup_state="/run/openslx/dmsetup.state"
- if [ -s "$dmsetup_state" ]; then
- local dnbd3_cow_dev="$SLX_DNBD3_DEVICE_COW"
- [ -z "$dnbd3_cow_dev" ] && dnbd3_cow_dev="/dev/mapper/root"
- grep -qE "^${dnbd3_cow_dev}\s+/\s+type=0" "$dmsetup_state"
- return $?
- fi
- # else assume old-gen were / was in RAM
- return 0
-}
-
# Helper to detect given cpu flags.
# If more than one flag is given, assume that matching
# any of them is sufficient.