From 1d7f30a13e156ee1a359f6f59a4ff994eac1ca90 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 12 Nov 2021 15:55:54 +0100 Subject: [mount-store] Take greater care where the .notmounted flag is written While the task manager should make sure only one invocation if mount-store is running, add a few extra checks whether a mount-point is pulled under our feet, or mounted when we don't expect it. This includes making sure dmsd is not accessing the share while we're trying to manipulate it. --- scripts/mount-store | 19 ++++++++++++++++++- .../org/openslx/taskmanager/tasks/MountVmStore.java | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/scripts/mount-store b/scripts/mount-store index 3cff451..6a21bf6 100755 --- a/scripts/mount-store +++ b/scripts/mount-store @@ -125,6 +125,12 @@ disable_nfs_export () { fi } +start_dmsd () { + if "$DMSD_WAS_RUNNING"; then + systemctl --no-block start dmsd.service + fi +} + # Quick safty measure -- if any local FS is mounted, do nothing and print warning if different type is requested CURRENT_TYPE="$( awk -v DEST="$DEST" '$2 == DEST {print $3}' /proc/mounts )" if [ -n "$CURRENT_TYPE" ] && ! [[ "$CURRENT_TYPE" == nfs* || "$CURRENT_TYPE" == cifs* ]]; then @@ -148,8 +154,10 @@ systemctl stop dnbd3-server.service # Already mounted? TRIES=0 NFS_WAS_RUNNING=false +DMSD_WAS_RUNNING=false systemctl is-active -q nfs-kernel-server.service && NFS_WAS_RUNNING=true -while awk '{print $2}' "/proc/mounts" | grep -Fxq "${DEST}"; do +systemctl is-active -q dmsd.service && DMSD_WAS_RUNNING=true +while mountpoint "${DEST}"; do echo "Trying to unmount '$DEST'..." systemctl stop nfs-kernel-server.service if [ "$TRIES" -gt 5 ]; then @@ -172,6 +180,7 @@ while awk '{print $2}' "/proc/mounts" | grep -Fxq "${DEST}"; do RET=$? fi [ "$RET" = 0 ] && break + systemctl stop dmsd.service sleep 1 TRIES=$(( TRIES + 1 )) done @@ -194,6 +203,7 @@ fi if [[ "${SOURCE}" == "null" ]]; then prepare_storage "local" systemctl --no-block start dnbd3-server.service + start_dmsd enable_nfs_export echo "Success. Now using internal storage." exit 0 @@ -203,6 +213,11 @@ fi disable_nfs_export +if mountpoint "${DEST}"; then + echo "**** Something was mounted to $DEST in the meantime. Aborting ****" + # Use the "nothing changed" exit code, as another concurrent invocation has changed stuff, apparently + exit 99 +fi touch "${FLAG}" if [[ "${SOURCE}" == "unknown" ]]; then @@ -225,6 +240,7 @@ exec_mount () { echo "Mount succeeded, checking write permissions...." prepare_storage "$fstype" RET=$? + mountpoint "$DEST" && rm -f -- "$FLAG" [ "$RET" -eq "0" ] && return 0 umount -v "$DEST" || umount -v -f -l "$DEST" return "$RET" @@ -323,6 +339,7 @@ if [ "$RET" = "0" ]; then echo "-- Share mounted successfully! --" echo "----------------------------------" systemctl --no-block start dnbd3-server.service + start_dmsd fi exit "$RET" diff --git a/src/main/java/org/openslx/taskmanager/tasks/MountVmStore.java b/src/main/java/org/openslx/taskmanager/tasks/MountVmStore.java index d0530cc..791fcad 100644 --- a/src/main/java/org/openslx/taskmanager/tasks/MountVmStore.java +++ b/src/main/java/org/openslx/taskmanager/tasks/MountVmStore.java @@ -47,7 +47,7 @@ public class MountVmStore extends SystemCommandTask @Override protected String[] initCommandLine() { - if ( !isRunning.compareAndSet( null, this ) ) { + while ( !isRunning.compareAndSet( null, this ) ) { MountVmStore current = isRunning.get(); if ( current != null ) { if ( current.equals( this ) ) { -- cgit v1.2.3-55-g7522