Skip to contentSkip to conversation

define common get_max_file_size function

PATCH In review Yufen Yu 3 participants 6 messages Feb 26, 2019 – Mar 4, 2019

lore
Share & tools
lore

Yufen Yu

author
#0 lore raw

v2 cover define common get_max_file_size function

We move get_max_file_size from generic/485 to common rc, and add max filesize limit to generic/299.

In addition, we pick up the common function get_max_lfs_filesize() from generic/349, 350, 351 to make code more concise.

Yufen Yu (2):
commom/rc: use the common function get_max_file_size common/rc: add get_max_lfs_filesize to return MAX_LFS_FILESIZE

 common/rc         | 39 +++++++++++++++++++++++++++++++++++++++
 tests/generic/299 |  5 +++++
 tests/generic/349 | 12 +-----------
 tests/generic/350 | 12 +-----------
 tests/generic/351 | 12 +-----------
 tests/generic/485 | 23 -----------------------
 6 files changed, 47 insertions(+), 56 deletions(-)
Signature · 1 line
2.16.2.dirty
author
#1 lore raw

PATCH v2 1/2 commom/rc: use the common function get_max_file_size

Move the function get_max_file_size() of generci/485 to common/rc, and add the max filesize limit to generic/299.

---
 common/rc         | 23 +++++++++++++++++++++++
 tests/generic/299 |  5 +++++
 tests/generic/485 | 23 -----------------------
 3 files changed, 28 insertions(+), 23 deletions(-)
common/rc +23 -0
index e5da6484..987f3e23 100644
@@ -3785,6 +3785,29 @@ _require_scratch_feature()
 	esac
 }
 
+# Get the maximum size of a file in $TEST_DIR (s_maxbytes).  On ext4 this will
+# be UINT32_MAX * block_size, but other filesystems may allow up to LLONG_MAX.
+get_max_file_size()
+{
+	local testfile=$TEST_DIR/maxfilesize.$seq
+	local l=0
+	local r=9223372036854775807 # LLONG_MAX
+
+	rm -f $testfile
+	while (( l < r )); do
+		# Use _math() to avoid signed integer overflow.
+		local m=$(_math "($l + $r + 1) / 2")
+		if $XFS_IO_PROG -f -c "truncate $m" $testfile \
+			|& grep -q 'File too large'
+		then
+			r=$(( m - 1 ))
+		else
+			l=$m
+		fi
+	done
+	echo $l
+}
+
 # The maximum filesystem label length, /not/ including terminating NULL
 _label_get_max()
 {
tests/generic/299 +5 -0
index c4d74fc8..494bf61c 100755
@@ -33,6 +33,11 @@ NUM_JOBS=$((4*LOAD_FACTOR))
 BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
 FILE_SIZE=$((BLK_DEV_SIZE * 512))
 
+max_file_size=$(get_max_file_size)
+if [ $max_file_size -lt $FILE_SIZE ]; then
+	FILE_SIZE=$max_file_size
+fi
+
 cat >$fio_config <<EOF
 ###########
 # $seq test fio activity
tests/generic/485 +0 -23
index e88ac2e4..d55535c2 100755
@@ -37,29 +37,6 @@ _require_xfs_io_command "falloc" "-k"
 _require_xfs_io_command "finsert"
 _require_xfs_io_command "truncate"
 
-# Get the maximum size of a file in $TEST_DIR (s_maxbytes).  On ext4 this will
-# be UINT32_MAX * block_size, but other filesystems may allow up to LLONG_MAX.
-get_max_file_size()
-{
-	local testfile=$TEST_DIR/maxfilesize.$seq
-	local l=0
-	local r=9223372036854775807 # LLONG_MAX
-
-	rm -f $testfile
-	while (( l < r )); do
-		# Use _math() to avoid signed integer overflow.
-		local m=$(_math "($l + $r + 1) / 2")
-		if $XFS_IO_PROG -f -c "truncate $m" $testfile \
-			|& grep -q 'File too large'
-		then
-			r=$(( m - 1 ))
-		else
-			l=$m
-		fi
-	done
-	echo $l
-}
-
 block_size=$(_get_file_block_size $TEST_DIR)
 max_file_size=$(get_max_file_size)
 max_blocks=$((max_file_size / block_size))
Signature · 1 line
2.16.2.dirty
#2 lore raw

Re: [PATCH v2 1/2] commom/rc: use the common function get_max_file_size

Quoted 2 lines · Yufen Yu

Move the function get_max_file_size() of generci/485 to common/rc, and add the max filesize limit to generic/299.

There should be explainations in commit log on why the max filesize should be limited in generic/299, like your v1 patch did. I'll add them back on commit.

Quoted 13 lines
---
 common/rc         | 23 +++++++++++++++++++++++
 tests/generic/299 |  5 +++++
 tests/generic/485 | 23 -----------------------
 3 files changed, 28 insertions(+), 23 deletions(-)
common/rc +0 -0
index e5da6484..987f3e23 100644

common/rc _require_scratch_feature() · line 3790

Quoted 6 lines
common/rc +3 -0
@@ -3785,6 +3785,29 @@ _require_scratch_feature()
 	esac
 }
 
+# Get the maximum size of a file in $TEST_DIR (s_maxbytes).  On ext4 this will
+# be UINT32_MAX * block_size, but other filesystems may allow up to LLONG_MAX.
+get_max_file_size()

We usually name common helper functions with the leading underscore, e.g. _get_max_file_size, I'll fix the naming and all the calls in tests on commit.

Thanks,
Eryu

Quoted 76 lines
common/rc +20 -0
+{
+	local testfile=$TEST_DIR/maxfilesize.$seq
+	local l=0
+	local r=9223372036854775807 # LLONG_MAX
+
+	rm -f $testfile
+	while (( l < r )); do
+		# Use _math() to avoid signed integer overflow.
+		local m=$(_math "($l + $r + 1) / 2")
+		if $XFS_IO_PROG -f -c "truncate $m" $testfile \
+			|& grep -q 'File too large'
+		then
+			r=$(( m - 1 ))
+		else
+			l=$m
+		fi
+	done
+	echo $l
+}
+
 # The maximum filesystem label length, /not/ including terminating NULL
 _label_get_max()
 {
tests/generic/299 +5 -0
index c4d74fc8..494bf61c 100755
@@ -33,6 +33,11 @@ NUM_JOBS=$((4*LOAD_FACTOR))
 BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
 FILE_SIZE=$((BLK_DEV_SIZE * 512))
 
+max_file_size=$(get_max_file_size)
+if [ $max_file_size -lt $FILE_SIZE ]; then
+	FILE_SIZE=$max_file_size
+fi
+
 cat >$fio_config <<EOF
 ###########
 # $seq test fio activity
tests/generic/485 +0 -23
index e88ac2e4..d55535c2 100755
@@ -37,29 +37,6 @@ _require_xfs_io_command "falloc" "-k"
 _require_xfs_io_command "finsert"
 _require_xfs_io_command "truncate"
 
-# Get the maximum size of a file in $TEST_DIR (s_maxbytes).  On ext4 this will
-# be UINT32_MAX * block_size, but other filesystems may allow up to LLONG_MAX.
-get_max_file_size()
-{
-	local testfile=$TEST_DIR/maxfilesize.$seq
-	local l=0
-	local r=9223372036854775807 # LLONG_MAX
-
-	rm -f $testfile
-	while (( l < r )); do
-		# Use _math() to avoid signed integer overflow.
-		local m=$(_math "($l + $r + 1) / 2")
-		if $XFS_IO_PROG -f -c "truncate $m" $testfile \
-			|& grep -q 'File too large'
-		then
-			r=$(( m - 1 ))
-		else
-			l=$m
-		fi
-	done
-	echo $l
-}
-
 block_size=$(_get_file_block_size $TEST_DIR)
 max_file_size=$(get_max_file_size)
 max_blocks=$((max_file_size / block_size))
Signature · 1 line
2.16.2.dirty
author
#3 lore raw

PATCH v2 2/2 common/rc: add get_max_lfs_filesize to return MAX_LFS_FILESIZE

In reply to Yufen Yu

Pick up the common function get_max_lfs_filesize() to return MAX_LFS_FILESIZE.

---
 common/rc         | 16 ++++++++++++++++
 tests/generic/349 | 12 +-----------
 tests/generic/350 | 12 +-----------
 tests/generic/351 | 12 +-----------
 4 files changed, 19 insertions(+), 33 deletions(-)
common/rc +16 -0
index 987f3e23..07883540 100644
@@ -3808,6 +3808,22 @@ get_max_file_size()
 	echo $l
 }
 
+# get MAX_LFS_FILESIZE
+get_max_lfs_filesize()
+{
+	case "$(getconf LONG_BIT)" in
+	"32")
+       echo $(( ($(getconf PAGE_SIZE) << ($(getconf LONG_BIT) - 1) ) - 1))
+	       ;;
+	"64")
+	       echo 9223372036854775807
+	       ;;
+	*)
+	       _fail "sizeof(long) == $(getconf LONG_BIT)?"
+	       ;;
+	esac
+}
+
 # The maximum filesystem label length, /not/ including terminating NULL
 _label_get_max()
 {
tests/generic/349 +1 -11
index f01f817d..45d0619b 100755
@@ -50,17 +50,7 @@ md5sum $dev | sed -e "s|$dev|SCSI_DEBUG_DEV|g"
 
 echo "Zero range to MAX_LFS_FILESIZE"
 # zod = MAX_LFS_FILESIZE
-case "$(getconf LONG_BIT)" in
-"32")
-	zod=$(( ($(getconf PAGE_SIZE) << ($(getconf LONG_BIT) - 1) ) - 1))
-	;;
-"64")
-	zod=9223372036854775807
-	;;
-*)
-	_fail "sizeof(long) == $(getconf LONG_BIT)?"
-	;;
-esac
+zod=$(get_max_lfs_filesize)
 $XFS_IO_PROG -c "fzero -k 0 $zod" $dev
 
 echo "Check contents"
tests/generic/350 +1 -11
index 0aea4c09..a8f2939b 100755
@@ -47,17 +47,7 @@ md5sum $dev | sed -e "s|$dev|SCSI_DEBUG_DEV|g"
 
 echo "Punch to MAX_LFS_FILESIZE"
 # zod = MAX_LFS_FILESIZE
-case "$(getconf LONG_BIT)" in
-"32")
-	zod=$(( ($(getconf PAGE_SIZE) << ($(getconf LONG_BIT) - 1) ) - 1))
-	;;
-"64")
-	zod=9223372036854775807
-	;;
-*)
-	_fail "sizeof(long) == $(getconf LONG_BIT)?"
-	;;
-esac
+zod=$(get_max_lfs_filesize)
 $XFS_IO_PROG -c "fpunch 0 $zod" $dev
 
 echo "Check contents"
tests/generic/351 +1 -11
index e326dca1..c250bac4 100755
@@ -62,17 +62,7 @@ $XFS_IO_PROG -c "fpunch 512 512" $dev
 
 echo "Zero range past MAX_LFS_FILESIZE keep size"
 # zod = MAX_LFS_FILESIZE
-case "$(getconf LONG_BIT)" in
-"32")
-	zod=$(( ($(getconf PAGE_SIZE) << ($(getconf LONG_BIT) - 1) ) - 1))
-	;;
-"64")
-	zod=9223372036854775807
-	;;
-*)
-	_fail "sizeof(long) == $(getconf LONG_BIT)?"
-	;;
-esac
+zod=$(get_max_lfs_filesize)
 $XFS_IO_PROG -c "fzero -k 512k $zod" $dev
 
 echo "Zero range past MAX_LFS_FILESIZE"
Signature · 1 line
2.16.2.dirty
#4 lore raw

Re: [PATCH v2 2/2] common/rc: add get_max_lfs_filesize to return MAX_LFS_FILESIZE

Quoted 16 lines · Yufen Yu

Pick up the common function get_max_lfs_filesize() to return MAX_LFS_FILESIZE.

---
 common/rc         | 16 ++++++++++++++++
 tests/generic/349 | 12 +-----------
 tests/generic/350 | 12 +-----------
 tests/generic/351 | 12 +-----------
 4 files changed, 19 insertions(+), 33 deletions(-)
common/rc +0 -0
index 987f3e23..07883540 100644

common/rc get_max_file_size() · line 3816

Quoted 9 lines
common/rc +6 -0
@@ -3808,6 +3808,22 @@ get_max_file_size()
 	echo $l
 }
 
+# get MAX_LFS_FILESIZE
+get_max_lfs_filesize()
+{
+	case "$(getconf LONG_BIT)" in
+	"32")
+       echo $(( ($(getconf PAGE_SIZE) << ($(getconf LONG_BIT) - 1) ) - 1))

Indenion problem here.

common/rc get_max_file_size() · line 3819

Quoted 3 lines
common/rc +3 -0
+	       ;;
+	"64")
+	       echo 9223372036854775807

Mixing space and tab as indentions.

I'll fix them on commit.

Thanks,
Eryu

Quoted 82 lines
common/rc +7 -0
+	       ;;
+	*)
+	       _fail "sizeof(long) == $(getconf LONG_BIT)?"
+	       ;;
+	esac
+}
+
 # The maximum filesystem label length, /not/ including terminating NULL
 _label_get_max()
 {
tests/generic/349 +1 -11
index f01f817d..45d0619b 100755
@@ -50,17 +50,7 @@ md5sum $dev | sed -e "s|$dev|SCSI_DEBUG_DEV|g"
 
 echo "Zero range to MAX_LFS_FILESIZE"
 # zod = MAX_LFS_FILESIZE
-case "$(getconf LONG_BIT)" in
-"32")
-	zod=$(( ($(getconf PAGE_SIZE) << ($(getconf LONG_BIT) - 1) ) - 1))
-	;;
-"64")
-	zod=9223372036854775807
-	;;
-*)
-	_fail "sizeof(long) == $(getconf LONG_BIT)?"
-	;;
-esac
+zod=$(get_max_lfs_filesize)
 $XFS_IO_PROG -c "fzero -k 0 $zod" $dev
 
 echo "Check contents"
tests/generic/350 +1 -11
index 0aea4c09..a8f2939b 100755
@@ -47,17 +47,7 @@ md5sum $dev | sed -e "s|$dev|SCSI_DEBUG_DEV|g"
 
 echo "Punch to MAX_LFS_FILESIZE"
 # zod = MAX_LFS_FILESIZE
-case "$(getconf LONG_BIT)" in
-"32")
-	zod=$(( ($(getconf PAGE_SIZE) << ($(getconf LONG_BIT) - 1) ) - 1))
-	;;
-"64")
-	zod=9223372036854775807
-	;;
-*)
-	_fail "sizeof(long) == $(getconf LONG_BIT)?"
-	;;
-esac
+zod=$(get_max_lfs_filesize)
 $XFS_IO_PROG -c "fpunch 0 $zod" $dev
 
 echo "Check contents"
tests/generic/351 +1 -11
index e326dca1..c250bac4 100755
@@ -62,17 +62,7 @@ $XFS_IO_PROG -c "fpunch 512 512" $dev
 
 echo "Zero range past MAX_LFS_FILESIZE keep size"
 # zod = MAX_LFS_FILESIZE
-case "$(getconf LONG_BIT)" in
-"32")
-	zod=$(( ($(getconf PAGE_SIZE) << ($(getconf LONG_BIT) - 1) ) - 1))
-	;;
-"64")
-	zod=9223372036854775807
-	;;
-*)
-	_fail "sizeof(long) == $(getconf LONG_BIT)?"
-	;;
-esac
+zod=$(get_max_lfs_filesize)
 $XFS_IO_PROG -c "fzero -k 512k $zod" $dev
 
 echo "Zero range past MAX_LFS_FILESIZE"
Signature · 1 line
2.16.2.dirty
#5 lore raw

Re: [PATCH v2 2/2] common/rc: add get_max_lfs_filesize to return MAX_LFS_FILESIZE

Quoted 20 lines · Eryu Guan
Quoted 19 lines · Yufen Yu

Pick up the common function get_max_lfs_filesize() to return MAX_LFS_FILESIZE.

---
 common/rc         | 16 ++++++++++++++++
 tests/generic/349 | 12 +-----------
 tests/generic/350 | 12 +-----------
 tests/generic/351 | 12 +-----------
 4 files changed, 19 insertions(+), 33 deletions(-)
common/rc +0 -0
index 987f3e23..07883540 100644
@@ -3808,6 +3808,22 @@ get_max_file_size()
 	echo $l
 }
 
Quoted 2 lines

common/rc get_max_file_size() · line 3812

Quoted 2 lines
common/rc +2 -0
+# get MAX_LFS_FILESIZE
+get_max_lfs_filesize()

Somehow, this got committed upstream without the leading "_" in common/rc, but generic/{349-351} do have it, which causes those tests to regress.

I will send a patch with my weekly fixes rollup later this afternoon.

--D

Quoted 100 lines

common/rc get_max_file_size() · line 3816

Quoted 4 lines
common/rc +4 -0
+{
+	case "$(getconf LONG_BIT)" in
+	"32")
+       echo $(( ($(getconf PAGE_SIZE) << ($(getconf LONG_BIT) - 1) ) - 1))

Indenion problem here.

common/rc get_max_file_size() · line 3819

Quoted 3 lines
common/rc +3 -0
+	       ;;
+	"64")
+	       echo 9223372036854775807

Mixing space and tab as indentions.

I'll fix them on commit.

Thanks,
Eryu

Quoted 82 lines
common/rc +7 -0
+	       ;;
+	*)
+	       _fail "sizeof(long) == $(getconf LONG_BIT)?"
+	       ;;
+	esac
+}
+
 # The maximum filesystem label length, /not/ including terminating NULL
 _label_get_max()
 {
tests/generic/349 +1 -11
index f01f817d..45d0619b 100755
@@ -50,17 +50,7 @@ md5sum $dev | sed -e "s|$dev|SCSI_DEBUG_DEV|g"
 
 echo "Zero range to MAX_LFS_FILESIZE"
 # zod = MAX_LFS_FILESIZE
-case "$(getconf LONG_BIT)" in
-"32")
-	zod=$(( ($(getconf PAGE_SIZE) << ($(getconf LONG_BIT) - 1) ) - 1))
-	;;
-"64")
-	zod=9223372036854775807
-	;;
-*)
-	_fail "sizeof(long) == $(getconf LONG_BIT)?"
-	;;
-esac
+zod=$(get_max_lfs_filesize)
 $XFS_IO_PROG -c "fzero -k 0 $zod" $dev
 
 echo "Check contents"
tests/generic/350 +1 -11
index 0aea4c09..a8f2939b 100755
@@ -47,17 +47,7 @@ md5sum $dev | sed -e "s|$dev|SCSI_DEBUG_DEV|g"
 
 echo "Punch to MAX_LFS_FILESIZE"
 # zod = MAX_LFS_FILESIZE
-case "$(getconf LONG_BIT)" in
-"32")
-	zod=$(( ($(getconf PAGE_SIZE) << ($(getconf LONG_BIT) - 1) ) - 1))
-	;;
-"64")
-	zod=9223372036854775807
-	;;
-*)
-	_fail "sizeof(long) == $(getconf LONG_BIT)?"
-	;;
-esac
+zod=$(get_max_lfs_filesize)
 $XFS_IO_PROG -c "fpunch 0 $zod" $dev
 
 echo "Check contents"
tests/generic/351 +1 -11
index e326dca1..c250bac4 100755
@@ -62,17 +62,7 @@ $XFS_IO_PROG -c "fpunch 512 512" $dev
 
 echo "Zero range past MAX_LFS_FILESIZE keep size"
 # zod = MAX_LFS_FILESIZE
-case "$(getconf LONG_BIT)" in
-"32")
-	zod=$(( ($(getconf PAGE_SIZE) << ($(getconf LONG_BIT) - 1) ) - 1))
-	;;
-"64")
-	zod=9223372036854775807
-	;;
-*)
-	_fail "sizeof(long) == $(getconf LONG_BIT)?"
-	;;
-esac
+zod=$(get_max_lfs_filesize)
 $XFS_IO_PROG -c "fzero -k 512k $zod" $dev
 
 echo "Zero range past MAX_LFS_FILESIZE"
Signature · 1 line
2.16.2.dirty