xfs
[Top] [All Lists]

Re: [PATCH] common: new function to get real device path name and basena

To: Eryu Guan <eguan@xxxxxxxxxx>
Subject: Re: [PATCH] common: new function to get real device path name and basename
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Tue, 22 Apr 2014 15:10:51 +1000
Cc: xfs@xxxxxxxxxxx
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1398137247-4883-1-git-send-email-eguan@xxxxxxxxxx>
References: <1398137247-4883-1-git-send-email-eguan@xxxxxxxxxx>
User-agent: Mutt/1.5.21 (2010-09-15)
On Tue, Apr 22, 2014 at 11:27:27AM +0800, Eryu Guan wrote:
> If TEST_DEV or SCRATCH_DEV is symlink(mostly a lvm lv), a simple
> basename is not enough, symlink should be followed.
> 
> This task is common enough, so introduce new helper functions and
> replace all readlink calls in
> 
> ext4/305
> generic/009
> generic/019
> generic/285
> generic/312
> 
> Signed-off-by: Eryu Guan <eguan@xxxxxxxxxx>
> ---
>  common/rc         | 16 ++++++++++++++++
>  tests/ext4/305    |  2 +-
>  tests/generic/009 |  2 +-
>  tests/generic/019 |  4 +---
>  tests/generic/285 |  2 +-
>  tests/generic/312 |  2 +-
>  6 files changed, 21 insertions(+), 7 deletions(-)
> 
> diff --git a/common/rc b/common/rc
> index acf419b..68b040d 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -2302,6 +2302,22 @@ init_rc()
>       export XFS_IO_PROG="$XFS_IO_PROG -F"
>  }
>  
> +# get real device path name by following link
> +_real_dev()
> +{
> +     local _dev=$1
> +     if [ -b "$_dev" ] && [ -L "$_dev" ]; then
> +             _dev=`readlink -f "$_dev"`
> +     fi
> +     echo $_dev
> +}
> +
> +# basename of a device
> +_basename_dev()
> +{
> +     echo `basename $(_real_dev $1)`
> +}

I don't really like that function name.  It describes the
implementation, not what the function actually returns. i.e. we're
getting the -short- device names here, basename is the implemenation
used to turn a full device name to a short device name...

Cheers,

Dave
-- 
Dave Chinner
david@xxxxxxxxxxxxx

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