summaryrefslogtreecommitdiffstats
path: root/remote/modules/run-virt/data/opt/openslx/scripts
diff options
context:
space:
mode:
authorSimon Rettberg2015-12-04 18:41:06 +0100
committerSimon Rettberg2015-12-04 18:41:06 +0100
commit2189358ee76b57102ad323b5b993e8b8b30254a6 (patch)
tree3ca709da17d314cf9e304058f898e880fc3fffb9 /remote/modules/run-virt/data/opt/openslx/scripts
parent[run-virt] adapted dnbd3-mount code for VMs to use dnbd3-fuse (diff)
downloadtm-scripts-2189358ee76b57102ad323b5b993e8b8b30254a6.tar.gz
tm-scripts-2189358ee76b57102ad323b5b993e8b8b30254a6.tar.xz
tm-scripts-2189358ee76b57102ad323b5b993e8b8b30254a6.zip
[run-virt] Minor cleanups in setup and error handling
Diffstat (limited to 'remote/modules/run-virt/data/opt/openslx/scripts')
-rw-r--r--remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_image_access.inc80
1 files changed, 39 insertions, 41 deletions
diff --git a/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_image_access.inc b/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_image_access.inc
index ebe802e4..c669a210 100644
--- a/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_image_access.inc
+++ b/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_image_access.inc
@@ -10,53 +10,50 @@ dnbd3_fuse_mount_point="/tmp/virt/${USER}.fuse"
# Try to use dnbd3 to access the image
unset vm_diskfile
unset vm_revision
-unset dnbd3
-unset dnbd3error
-if [ -n "$SLX_DNBD3_SERVERS" -o -n "$SLX_DNBD3_PRIO_SERVERS" ] && [ "x$SLX_VM_DNBD3" = "xyes" ]; then
- if [ -e "/dev/dnbd0" -a -e "/var/run/dnbd3.socket" ]; then
- mkdir -p "${dnbd3_fuse_mount_point}"
- # try to unmount first
- fusermount -u "${dnbd3_fuse_mount_point}"
- # start dnbd3-fuse in subshell
- (
- fuselog="$(dnbd3-fuse -f -o allow_other -h "$SLX_DNBD3_SERVERS" -i "${imgrelpath}" "${dnbd3_fuse_mount_point}" 2>&1)"
- RET=$?
- if [ "$RET" != "0" ]; then
- writelog "dnbd3-fuse stopped working. Log: \n${fuselog}\n"
- # hack to get the stderr logs pushed to sat
- tmplog="$(mktemp)"
- echo "$fuselog" > "${tmplog}"
- slxlog "virt-dnbd3-fuse" "dnbd3-fuse stopped serving '${imgrelpath}' from '${SLX_DNBD3_SERVERS}' with error code: $RET" "${tmplog}"
- fi
- ) &
- # give it a bit of time
- usleep 200000
- # check if we have the image
- for TIMEOUT in 1 1; do
- if [ -r "${dnbd3_fuse_mount_point}/img" ]; then
- vm_revision="$(grep "Revision:" "${dnbd3_fuse_mount_point}/status" | cut -d" " -f2)"
- vm_diskfile="${dnbd3_fuse_mount_point}/img"
- writelog "DNBD3: $vm_diskfile on $dnbd3 with rid $vm_revision"
- vmpath="$vm_diskfile"
- break
- fi
- sleep $TIMEOUT
- done
-
- if [ -z "$vm_diskfile" ]; then
- slxlog "virt-dnbd3" "No dnbd3 server for ${imgrelpath} found ($SLX_DNBD3_PRIO_SERVERS $TMP_SERVERS $dnbd3error), trying NFS/CIFS..."
- writelog "No working dnbd3 server found :-("
+if ! which dnbd3-fuse; then
+ writelog "Can't use dnbd3 as dnbd3-fuse binary is not in PATH"
+elif [ -z "$SLX_DNBD3_SERVERS" ] || [ "x$SLX_VM_DNBD3" != "xyes" ]; then
+ writelog "Can't use dnbd3 as no servers are given in config, or SLX_VM_DNBD3 is not set to yes"
+else
+ mkdir -p "${dnbd3_fuse_mount_point}"
+ # try to unmount first
+ fusermount -u "${dnbd3_fuse_mount_point}"
+ # start dnbd3-fuse in subshell
+ (
+ tmplog="$(mktemp)"
+ [ -z "$tmplog" ] && tmplog="/tmp/dnbd3-fuse.$$.$RANDOM.$USER"
+ dnbd3-fuse -f -o allow_other,max_readahead=262144 -h "$SLX_DNBD3_SERVERS" -i "${imgrelpath}" "${dnbd3_fuse_mount_point}" > "$tmplog" 2>&1
+ RET=$?
+ if [ "$RET" != "0" ]; then
+ writelog "dnbd3-fuse stopped working (Exit code $RET)"
+ slxlog "virt-dnbd3-fuse" "dnbd3-fuse stopped/refused serving '${imgrelpath}' from '${SLX_DNBD3_SERVERS}' with error code: $RET" "${tmplog}"
+ fi
+ sleep 1
+ rm -f -- "$tmplog"
+ ) &
+ # give it a bit of time
+ usleep 200000
+ # check if we have the image
+ for TIMEOUT in 1 1; do
+ if [ -r "${dnbd3_fuse_mount_point}/img" ]; then
+ vm_revision="$(grep "^Revision:" "${dnbd3_fuse_mount_point}/status" | cut -d" " -f2)"
+ vm_diskfile="${dnbd3_fuse_mount_point}/img"
+ writelog "DNBD3: $imgrelpath on $vm_diskfile with rid $vm_revision"
+ vmpath="$vm_diskfile"
+ break
fi
- else
- writelog "Can't use dnbd3 as it's not loaded, or the daemon is not running..."
+ sleep $TIMEOUT
+ done
+
+ if [ -z "$vm_diskfile" ]; then
+ slxlog "virt-dnbd3" "No dnbd3 server for ${imgrelpath} found, trying NFS/CIFS..."
+ writelog "No working dnbd3 server found :-("
fi
-else
- writelog "Can't use dnbd3 as no servers are given in config"
fi
# $vm_diskfile will be empty if dnbd3 is not used or failed. Let's try to fall back to NFS/CIFS via file system
if [ -z "$vm_diskfile" ]; then
- new_vmpath=$(ls "${vmpath}.r"* | grep -E -o '\.r[0-9]+$' | grep -o -E '[0-9]+' | sort -n | tail -1)
+ new_vmpath=$(ls "${vmpath}.r"* | grep -E -o '\.r[0-9]+$' | grep -o -E '[0-9]+' | sort -n | tail -n 1)
[ -n "$new_vmpath" ] && vmpath="${vmpath}.r${new_vmpath}"
vm_diskfile="$vmpath"
fi
@@ -69,3 +66,4 @@ if ! [ -e "${vmpath}" ]; then
fi
writelog "Virtual machine disk file: $vm_diskfile"
+