summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2015-12-04 15:15:36 +0100
committerJonathan Bauer2015-12-04 15:15:36 +0100
commitf7c26d9353e0fc6a07c1508ea79602d7399af497 (patch)
tree05549e13dbc0c74f8fe93dc094dd92aaa1ae6c00
parent[dnbd3] added fuse.conf as static file & pam_script hook to add PAM_USER to t... (diff)
downloadtm-scripts-f7c26d9353e0fc6a07c1508ea79602d7399af497.tar.gz
tm-scripts-f7c26d9353e0fc6a07c1508ea79602d7399af497.tar.xz
tm-scripts-f7c26d9353e0fc6a07c1508ea79602d7399af497.zip
[run-virt] adapted dnbd3-mount code for VMs to use dnbd3-fuse
-rw-r--r--remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_image_access.inc47
1 files changed, 32 insertions, 15 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 99fa0238..ebe802e4 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
@@ -2,7 +2,10 @@
# Include: Setup dnbd for image access, nfs/cifs fallback #
###########################################################
-writelog "Now in setup_image_access.inc ..."
+writelog "Now in setup_image_access.inc ..."
+
+# Mount path for images mounted with dnbd3-fuse
+dnbd3_fuse_mount_point="/tmp/virt/${USER}.fuse"
# Try to use dnbd3 to access the image
unset vm_diskfile
@@ -11,21 +14,35 @@ 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
- # Shuffle server list
- [ -n "$SLX_DNBD3_SERVERS" ] && TMP_SERVERS=$(for SRV in $SLX_DNBD3_SERVERS; do echo "$RANDOM $SRV"; done | sort -u | sed -r 's/^[0-9]+ //')
- for SRV in $SLX_DNBD3_PRIO_SERVERS $TMP_SERVERS; do
- dnbd3=$(dnbd3-client -h "$SRV" -i "${imgrelpath}" -r 0)
- RET=$?
- if [ "$RET" = "0" ]; then
- vm_revision=$(cat "/sys/block/${dnbd3#/dev/}/net/rid")
- writelog "DNBD3: $vm_diskfile on $dnbd3 with rid $vm_revision"
- vm_diskfile="$dnbd3"
- vmpath="$vm_diskfile"
- break
- fi
- dnbd3error="$dnbd3error ($RET/$dnbd3)"
- usleep 200000
+ 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 :-("