Re: [PATCH v3 1/2] common: new helper to alloacate fixed size files

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



On Tue, Sep 20, 2022 at 09:35:13AM +0200, Pavel Reichl wrote:
> Helper that creates files of specified size using falloc if supported,
> otherwise pwrite is used.
> 
> Signed-off-by: Pavel Reichl <preichl@xxxxxxxxxx>
> ---
>  common/rc         | 13 +++++++++++++
>  tests/generic/694 |  2 +-
>  2 files changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/common/rc b/common/rc
> index a25cbcd0..77866582 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -4925,6 +4925,19 @@ hexdump()
>  	_fail "Use _hexdump(), please!"
>  }
>  
> +# Helper to write a file containing specified number of bytes using
> +# falloc if supported, otherwise use pwrite
> +_create_sizedfile()
> +{
> +	length=$1
> +	file=$2
> +
> +	$XFS_IO_PROG -F -fc "falloc 0 $length" $file 2>&1 | grep -q "Operation not supported"

Do we need to make sure if the $file really get $length space, due to if might
fail but not due to "Operation not supported", e.g. ENOSPC or others.

> +	if [ $? -eq 0 ]; then
> +		$XFS_IO_PROG -F -fc "pwrite -W 0 $length" $file >/dev/null
> +	fi

Another question I'm thinking is do we need "-t" to make sure the $file isn't
bigger than what we want. And do we need to truncate the file to $length, to
make sure fs doesn't allocate more space?

Thanks,
Zorro

> +}
> +
>  init_rc
>  
>  ################################################################################
> diff --git a/tests/generic/694 b/tests/generic/694
> index dfd988df..64c3dd9a 100755
> --- a/tests/generic/694
> +++ b/tests/generic/694
> @@ -30,7 +30,7 @@ junk_dir=$TEST_DIR/$seq
>  junk_file=$junk_dir/junk
>  mkdir -p $junk_dir
>  
> -$XFS_IO_PROG -f -c "pwrite -W 0 4G" $junk_file > /dev/null
> +_create_sizedfile 4G $junk_file
>  
>  iblocks=`stat -c '%b' $junk_file`
>  
> -- 
> 2.37.3
> 




[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux