Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add locks before mount and unmount functions #103

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions flexvolume/blobfuse/deployment/blobfuse-flexvol-installer/blobfuse
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ JQ="/usr/bin/jq"
BLOBFUSE="blobfuse"
LOG="/var/log/blobfuse-driver.log"
VER="1.0.17"
MOUNTLOCKFILE=/tmp/mount-lock.txt
UNMOUNTLOCKFILE=/tmp/unmount-lock.txt

usage() {
err "Invalid usage. Usage: "
Expand All @@ -31,6 +33,20 @@ ismounted() {
fi
return 1
}
addLock() {
lockfile=$1
if [ -e ${lockfile} ] && kill -0 `cat ${lockfile}`; then
echo "already running"
exit
fi
echo $$ > ${lockfile}

}

removeLock() {
lockfile=$1
rm -f ${LOCKFILE}
}

mount() {
MNTPATH="$1"
Expand All @@ -53,7 +69,7 @@ mount() {
err "{\"status\": \"Failure\", \"message\": \"validation failed, error log:container is empty\"}"
exit 1
fi

if [ -z "${TMP_PATH}" ]; then
TMP_PATH="/mnt/blobfuse$RANDOM/"
echo `date` "INFO: tmp-path not specified, use default path: ${TMP_PATH}" >> $LOG
Expand All @@ -65,16 +81,19 @@ mount() {
exit 0
fi

if [ ! -z "${DRIVERPATH}" ]; then
BLOBFUSE=$DRIVERPATH
echo "`date` INF: set driver path as $BLOBFUSE " >> $LOG
fi
if [ ! -z "${DRIVERPATH}" ]; then
BLOBFUSE=$DRIVERPATH
echo "`date` INF: set driver path as $BLOBFUSE " >> $LOG
fi

read_only_param=""
if [ $READ_WRITE = "ro" ]; then
read_only_param="-o ro"
fi

addLock $MOUNTLOCKFILE
trap "rm -f ${MOUNTLOCKFILE}; exit" INT TERM EXIT

echo "`date` EXEC: mkdir -p ${MNTPATH}" >> $LOG
mkdir -p ${MNTPATH} >>$LOG 2>&1

Expand All @@ -84,12 +103,12 @@ mount() {
export AZURE_STORAGE_ACCESS_KEY=${ACCOUNTKEY}
echo "`date` INF: AZURE_STORAGE_ACCESS_KEY is set " >> $LOG
fi

if [ ! -z "${BLOBENDPOINT}" ]; then
export AZURE_STORAGE_BLOB_ENDPOINT=${BLOBENDPOINT}
echo "`date` INF: BLOBENDPOINT is set " >> $LOG
fi

if [ ! -z "${ACCOUNTSASTOKEN}" ]; then
export AZURE_STORAGE_SAS_TOKEN=${ACCOUNTSASTOKEN}
echo "`date` INF: AZURE_STORAGE_SAS_TOKEN is set " >> $LOG
Expand All @@ -101,7 +120,7 @@ mount() {

# mkdir to fix issue: https://github.com/Azure/kubernetes-volume-drivers/issues/58 on blobfuse 1.2.3
mkdir -p ${TMP_PATH}

#mounting
echo "`date` EXEC: ${BLOBFUSE} ${MNTPATH} --container-name=${CONTAINER} --tmp-path=${TMP_PATH} -o allow_other ${read_only_param} ${MOUNT_OPTIONS}" >>$LOG
${BLOBFUSE} ${MNTPATH} --container-name=${CONTAINER} --tmp-path=${TMP_PATH} -o allow_other ${read_only_param} ${MOUNT_OPTIONS}
Expand All @@ -112,11 +131,14 @@ mount() {
fi

log '{"status": "Success"}'
removeLock $MOUNTLOCKFILE
exit 0
}

unmount() {
MNTPATH="$1"
addLock $MOUNTLOCKFILE
trap "rm -f ${MOUNTLOCKFILE}; exit" INT TERM EXIT

if ! ismounted ; then
log '{"status": "Success"}'
Expand Down Expand Up @@ -147,6 +169,7 @@ unmount() {
fi

log '{"status": "Success"}'
removeLock $MOUNTLOCKFILE
exit 0
}

Expand Down