From d2da726fe76e61f4c499421d8d2bd588ca41b770 Mon Sep 17 00:00:00 2001 From: Emmanuel Dreyfus Date: Thu, 9 Oct 2014 09:08:57 +0200 Subject: Regression test portability: loopback devices Introduce functions to deal with loopback devices setup, mount and umount. Remove test for xfsprogs for non Linux systems, as loopback devices can be populated with other filesystems (e.g.: FFS for NetBSD) While there, remove mount.nfs test for non Linux systems. At least NetBSD has it in base system as mount_nfs. BUG: 1129939 Change-Id: I816b36e1d3e6933f92acf19d9be8eeaaa333356e Signed-off-by: Emmanuel Dreyfus Reviewed-on: http://review.gluster.org/8914 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- tests/include.rc | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) (limited to 'tests/include.rc') diff --git a/tests/include.rc b/tests/include.rc index 3af4764b1e4..1a0fb06002f 100644 --- a/tests/include.rc +++ b/tests/include.rc @@ -652,3 +652,153 @@ fi # probably the safest option there and on anything we don't recognize, but # if you want to reduce the noise level and know the correct option for # your favorite platform please feel free to add it here. + +function SETUP_LOOP () +{ + if [ $# != 1 ] ; then + echo "SETUP_LOOP usage" >&2 + exit 1; + fi + + backend=$1 + + case ${OSTYPE} in + Linux) + losetup --find --show ${backend} + ;; + NetBSD) + vnd=`vnconfig -l|awk -F: '/not in use/{print $1; exit}'` + if [ "x${vnd}" = "x" ] ; then + echo "no more vnd" >&2 + exit 1; + fi + vnconfig ${vnd} ${backend} + echo ${vnd} + ;; + *) + echo "Please define SETUP_LOOP for ${OSTYPE} in include.rc" >&2 + exit 1; + ;; + esac +} + +function MKFS_LOOP () +{ + args=`getopt i: $*` + if [ $? -ne 0 ] ; then + echo "MKFS_LOOP usage" >&2 + exit 1; + fi + set -- ${args} + + isize="" + while test $# -gt 0; do + case "$1" in + -i) isize=$2; shift ;; + --) shift; break ;; + esac + shift + done + + dev=$1 + + case ${OSTYPE} in + Linux) + test "x${isize}" != "x" && isize="-i size=${isize}" + mkfs.xfs -f ${isize} ${dev} + ;; + NetBSD) + test "x${isize}" != "x" && isize="-i ${isize}" + + echo ${dev} | grep -q '^vnd' + if [ $? -ne 0 ] ; then + vnd=`vnconfig -l|awk -F: '/not in use/{print $1; exit}'` + if [ "x${vnd}" = "x" ] ; then + echo "no more vnd" >&2 + exit 1; + fi + vnconfig ${vnd} ${dev} + else + vnd=${dev} + fi + newfs ${isize} /dev/r${vnd}a + ;; + *) + echo "Please define MKFS_LOOP for ${OSTYPE} in include.rc" >&2 + exit 1; + ;; + esac +} + +function MOUNT_LOOP () +{ + if [ $# != 2 ] ; then + echo "MOUNT_LOOP usage" >&2 + exit 1; + fi + + dev=$1 + target=$2 + + case ${OSTYPE} in + Linux) + echo ${dev} | grep -q '^/dev/loop' + if [ $? -eq 0 ] ; then + mount -t xfs ${dev} ${target} + else + mount -o loop ${dev} ${target} + fi + ;; + NetBSD) + echo ${dev} | grep -q '^vnd' + if [ $? -ne 0 ] ; then + ino=`/usr/bin/stat -f %i ${dev}` + dev=`vnconfig -l | awk -v ino=${ino} -F'[: ]*' '($5 == ino) {print $1}'` + fi + + mount /dev/${dev}a ${target} >&2 + if [ $? -ne 0 ] ; then + echo "failed to mount /dev/${dev}a on ${target}" >&2 + exit 1 + fi + + mkdir -p ${target}/.attribute/system ${target}/.attribute/user + mount -u -o extattr ${target} >&2 + + ;; + *) + echo "Please define MOUNT_LOOP for ${OSTYPE} in include.rc" >&2 + exit 1; + ;; + esac +} + +function UMOUNT_LOOP () +{ + case ${OSTYPE} in + Linux) + force_umount $* + ;; + NetBSD) + for target in $* ; do + dev=`mount | awk -v target=${target} '($3 == target) {print $1}'` + force_umount ${target} + echo ${dev} | grep -q '^/dev/vnd' + if [ $? -eq 0 ] ; then + dev=`echo ${dev} | sed 's|^/dev/||; s|a$||'` + vnconfig -u ${dev} + else + ino=`/usr/bin/stat -f %i ${dev}` + dev=`vnconfig -l | awk -v ino=${ino} -F'[: ]*' '($5 == ino) {print $1}'` + if [ "x${dev}" != "x" ] ; then + vnconfig -u ${dev} + fi + fi + done + ;; + *) + echo "Please define UMOUNT_LOOP for ${OSTYPE} in include.rc" >&2 + exit 1; + ;; + esac +} -- cgit