xfs
[Top] [All Lists]

xfstests: standard way of handling loop devices

To: xfs@xxxxxxxxxxx
Subject: xfstests: standard way of handling loop devices
From: Tomas Racek <tracek@xxxxxxxxxx>
Date: Thu, 9 Aug 2012 04:30:21 -0400 (EDT)
In-reply-to: <1664629800.716769.1344498186489.JavaMail.root@xxxxxxxxxx>
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

<Prev in Thread] Current Thread [Next in Thread>