xfs
[Top] [All Lists]

Re: [PATCH 2/3] xfstests: Add new standard loop handling functions

To: Tomas Racek <tracek@xxxxxxxxxx>
Subject: Re: [PATCH 2/3] xfstests: Add new standard loop handling functions
From: Eric Sandeen <sandeen@xxxxxxxxxxx>
Date: Sun, 03 Feb 2013 10:08:06 -0600
Cc: xfs@xxxxxxxxxxx, lczerner@xxxxxxxxxx
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1359886798-8818-2-git-send-email-tracek@xxxxxxxxxx>
References: <1359886798-8818-1-git-send-email-tracek@xxxxxxxxxx> <1359886798-8818-2-git-send-email-tracek@xxxxxxxxxx>
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130107 Thunderbird/17.0.2
On 2/3/13 4:19 AM, Tomas Racek wrote:
> Add _create_loop_device and _destroy_loop_device to uniformly handle
> loopback devices.

Good idea, small comment below

> Signed-off-by: Tomas Racek <tracek@xxxxxxxxxx>
> ---
>  common.rc | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/common.rc b/common.rc
> index 0cccb94..67a5e3a 100644
> --- a/common.rc
> +++ b/common.rc
> @@ -1833,6 +1833,20 @@ _require_dumpe2fs()
>       fi
>  }
>  
> +_create_loop_device()
> +{
> +     file=$1
> +     dev=`losetup -f`
> +     losetup $dev $file || _fail "Cannot associate $file with $dev"
> +     echo $dev

In theory this is a little racy, right?  the loop device could become
used in between.

I wonder if something like:

_create_loop_device()
{
        dev=`losetup -f --show $file` || _fail "Cannot associate $file with 
$dev"
        echo $dev
}

would work better?  From the manpage:

       -f, --find
              find the first unused loop device. If a file argument is present,
               use this device. Otherwise, print its name

       --show print device name if the -f option and a file argument are 
present.

So this will set up the first available loop device and print its name.

Thanks,
-Eric   

> +}
> +
> +_destroy_loop_device()
> +{
> +     dev=$1
> +     losetup -d $dev || _fail "Cannot destroy loop device $dev"
> +}
> +
>  
> ################################################################################
>  
>  if [ "$iam" != new -a "$iam" != bench ]
> 

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