Skip to content

Instantly share code, notes, and snippets.

@mbentley
Created March 10, 2017 21:22
Show Gist options
  • Save mbentley/4dbdd400cf6d152c5d0741f2f6a0341e to your computer and use it in GitHub Desktop.
Save mbentley/4dbdd400cf6d152c5d0741f2f6a0341e to your computer and use it in GitHub Desktop.
Check to see if deferred deletion is supported
#!/bin/bash
PIPE1=/run/dss-$$-fifo1
PIPE2=/run/dss-$$-fifo2
TEMPDIR=$(mktemp --tmpdir -d)
platform_supports_deferred_deletion() {
local deferred_deletion_supported=1
trap cleanup_pipes EXIT
if [ ! -x "./dss-child-read-write.sh" ];then
return 1
fi
mkfifo $PIPE1
mkfifo $PIPE2
unshare -m ./dss-child-read-write.sh $PIPE1 $PIPE2 "$TEMPDIR" &
read -t 10 n <>$PIPE1
if [ "$n" != "start" ];then
return 1
fi
rmdir $TEMPDIR > /dev/null 2>&1
deferred_deletion_supported=$?
echo "finish" > $PIPE2
return $deferred_deletion_supported
}
cleanup_pipes(){
rm -f $PIPE1
rm -f $PIPE2
rmdir $TEMPDIR 2>/dev/null
}
platform_supports_deferred_deletion
if [ "$?" -eq 1 ]
then
echo "Deferred deletion is not supported"
else
echo "Deferred deletion is supported"
fi
#!/bin/bash
# This is a helper script which is called by container-storage-setup.sh (d-s-s).
# This script helps in providing synchronization primitives to d-s-s so that
# d-s-s can determine whether deferred deletion is supported by the underlying
# kernel or not.
# $1 is named FIFO pipe.
# This helper script will write to $1 to signal d-s-s that unshare has been completed successfully.
# $2 is another named FIFO pipe.
# This helper script will read from $2. The write for this pipe would come from d-s-s to indicate
# that helper script can terminate now.
# $3 is absolute path to a temp dir which child will bind mount. Parent will
# later try to remove this dir.
if ! mount -o bind $3 $3; then
echo "stop" > $1
exit 1
fi
echo "start" > $1
read -t 10 n <>$2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment