xfstests: standard way of handling loop devices

Tomas Racek tracek at redhat.com
Thu Aug 9 03:30:21 CDT 2012


Hi,

I am currently working on tests that check FITRIM implementation (251, 260 and one new I'm writing now) and I want to use loopback device as fallback if $SCRATCH_DEV doesn't support discard. Has anybody been working on some xfstests' standard way of creating/destroying loop devices?

I could do with something as simple as this (in common.rc):

_create_loop_device()
{
        size=${1}
        dev=`losetup -f`
        file="$TEST_DIR/$(basename $dev).fs"
        truncate -s $size $file || _fail "Cannot create image file $file"
        losetup $dev $file || _fail "Cannot associate $file with $dev"
        echo $dev
}

_destroy_loop_device()
{
        dev=${1}
        umount $dev 2>&1
        file=`losetup -a | grep $dev | sed -n "s/.*(\(.*\))$/\1/p"`
        losetup -d $dev && rm -f $file || _fail "Cannot destroy loop device"
}

Do you think it's sufficient or do you have different opinion on handling this?

Thanks for comments!

Tomas



More information about the xfs mailing list