From 914e7896e22b86b3faf9e1beb13b67f2548f7b04 Mon Sep 17 00:00:00 2001 From: Andrew Burford Date: Sat, 14 May 2022 11:30:08 -0400 Subject: [PATCH] update idmap-tests and create self-stack test --- idmap-tests/Makefile | 4 ++++ idmap-tests/test.sh | 29 +++++++++++++++++------------ tests/self-stack.sh | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 idmap-tests/Makefile create mode 100755 tests/self-stack.sh diff --git a/idmap-tests/Makefile b/idmap-tests/Makefile new file mode 100644 index 0000000..8227b2a --- /dev/null +++ b/idmap-tests/Makefile @@ -0,0 +1,4 @@ +mount-idmapped: + gcc mount-idmapped.c -o mount-idmapped +test: mount-idmapped + sh test.sh diff --git a/idmap-tests/test.sh b/idmap-tests/test.sh index 0cd9aae..3d8eb01 100755 --- a/idmap-tests/test.sh +++ b/idmap-tests/test.sh @@ -11,22 +11,22 @@ function runcmd sleep 0.25 $@ ret=$? - if test $ret -ne 0 && test "$1" != 'lsof'; then + if test $ret -ne 0 && test "$1 $2 $3" != 'mount -t wrapfs'; then echo "$0: exit code $ret" exit $ret fi } -if cat /proc/mounts | grep $SCRATCH_DIR; then - runcmd umount $SCRATCH_DIR -fi - -if ! id luser &>/dev/null; then - runcmd adduser --shell /bin/sh luser -fi +dirs="$TMP_DIR $LOWER_DIR $SCRATCH_DIR" +for d in $dirs; do + echo checking dir $d + if cat /proc/mounts | grep $d; then + runcmd umount $d + fi +done runcmd mkfs -t $FS_TYPE $SCRATCH_DEV <<< y -runcmd mount /dev/sdb $SCRATCH_DIR +runcmd mount $SCRATCH_DEV $SCRATCH_DIR runcmd rm -rf $SCRATCH_DIR/* runcmd touch $SCRATCH_DIR/root runcmd touch $SCRATCH_DIR/ubuntu @@ -37,7 +37,12 @@ ls1=$(ls -l $SCRATCH_DIR) runcmd ./mount-idmapped --map-mount b:0:1000:1 --map-mount b:1000:1001:1 --map-mount b:1001:0:1 $SCRATCH_DIR $LOWER_DIR runcmd mount -t wrapfs $LOWER_DIR $TMP_DIR -ls2=$(ls -l $TMP_DIR) +if test $ret != 32; then + echo wrapfs returned unexpected error: $ret +else + echo wrapfs returned correct error attempting to mount on idmapped mount +fi -echo $ls1 -echo $ls2 +#ls2=$(ls -l $TMP_DIR) +#echo $ls1 +#echo $ls2 diff --git a/tests/self-stack.sh b/tests/self-stack.sh new file mode 100755 index 0000000..37f741a --- /dev/null +++ b/tests/self-stack.sh @@ -0,0 +1,36 @@ +#!/bin/sh +SCRATCH_DEV=/dev/sdb +SCRATCH_DIR=/n/scratch +LOWER_DIR=/n/lower +TMP_DIR=/n/tmp +FS_TYPE=ext4 + +function runcmd +{ + echo "CMD: $@" + sleep 0.25 + $@ + ret=$? + if test $ret -ne 0 && test "$1 $2 $3" != 'mount -t wrapfs'; then + echo "$0: exit code $ret" + exit $ret + fi +} + +dirs="$TMP_DIR $LOWER_DIR $SCRATCH_DIR" +for d in $dirs; do + echo checking dir $d + if cat /proc/mounts | grep $d; then + runcmd umount $d + fi +done + +runcmd mkfs -t $FS_TYPE $SCRATCH_DEV <<< y +runcmd mount $SCRATCH_DEV $SCRATCH_DIR +runcmd mount -t wrapfs $SCRATCH_DIR $LOWER_DIR +runcmd mount -t wrapfs $LOWER_DIR $TMP_DIR +if test $ret != 32; then + echo wrapfs returned unexpected error code attempting to mount on top of itself: $ret +else + echo wrapfs returned expected error code +fi -- 2.43.0