Skip to contentSkip to conversation

xfstests: test ext4 statfs

PATCH In review Eric Sandeen 2 participants 5 messages Oct 25, 2012 – Oct 29, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfstests: test ext4 statfs

Calculating free blocks in ext[234] is surprisingly hard, since by default we report "bsd" style df which doesn't count filesystem "overhead" blocks as used.

With a lot of code dedicated to sorting out what to report as free, things tend to go wrong surprisingly often.

Here's a test to actually try to stop the next regression. ;)

NB: For bsddf, the kernel currently does not count journal blocks as overhead; it probably should. But the test below looks to have the result within 1% of perfection, so it still passes even if the kernel doesn't count the journal against free blocks.

---

289 new file +103 -0
new file mode 100755
index 0000000..bf0e897
@@ -0,0 +1,103 @@
+#! /bin/bash
+# FS QA Test No. 286
+#
+# Test overhead & df output for extN filesystems
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2012 Red Hat, Inc.  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#-----------------------------------------------------------------------
+#
+# creator
[email protected]
+
+seq=`basename $0`
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+    cd /
+    rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs ext2 ext3 ext4
+_supported_os Linux
+_require_scratch
+
+rm -f $seq.full
+
+_scratch_mkfs >> $seq.full 2>&1
+
+# Get the honest truth about block counts straight from metadata on disk
+TOTAL_BLOCKS=`dumpe2fs -h $SCRATCH_DEV 2>/dev/null \
+		| awk '/Block count:/{print $3}'`
+
+FREE_BLOCKS=`dumpe2fs -h $SCRATCH_DEV 2>/dev/null \
+		| awk '/Free blocks:/{print $3}'`
+
+# nb: kernels today don't count journal blocks  as overhead, but should.
+# For most filesystems this will still be within tolerance.
+# Overhead is all the blocks (already) used by the fs itself:
+OVERHEAD=$(($TOTAL_BLOCKS-$FREE_BLOCKS))
+
+#  bsddf|minixdf
+#         Set the behaviour  for  the  statfs  system  call.  The  minixdf
+#         behaviour is to return in the f_blocks field the total number of
+#         blocks of the filesystem, while the bsddf  behaviour  (which  is
+#         the default) is to subtract the overhead blocks used by the ext2
+#         filesystem and not available for file storage.
+
+# stat -f output looks like this; we get f_blocks from that, which
+# varies depending on the df mount options used below:
+
+#   File: "/mnt/test"
+#    ID: affc5f2b2f57652 Namelen: 255     Type: ext2/ext3
+# Block size: 4096       Fundamental block size: 4096
+# Blocks: Total: 5162741    Free: 5118725    Available: 4856465
+# Inodes: Total: 1313760    Free: 1313749
+
+_scratch_mount "-o minixdf"
+MINIX_F_BLOCKS=`stat -f $SCRATCH_MNT | awk '/^Blocks/{print $3}'`
+umount $SCRATCH_MNT
+
+_scratch_mount "-o bsddf"
+BSD_F_BLOCKS=`stat -f $SCRATCH_MNT | awk '/^Blocks/{print $3}'`
+umount $SCRATCH_MNT
+
+# Echo data to $seq.full for analysis
+echo "Overhead is $OVERHEAD blocks out of $TOTAL_BLOCKS ($FREE_BLOCKS free)" >> $seq.full
+echo "MINIX free blocks $MINIX_F_BLOCKS" >> $seq.full
+echo "BSD free blocks $BSD_F_BLOCKS" >> $seq.full
+
+# minix should be exactly equal (hence tolerance of 0)
+_within_tolerance "minix f_blocks" $MINIX_F_BLOCKS $TOTAL_BLOCKS 0 -v
+# bsd should be within ... we'll say 1% for some slop
+_within_tolerance "bsd f_blocks" $BSD_F_BLOCKS $(($TOTAL_BLOCKS-$OVERHEAD)) 1% -v
+
+# success, all done
+status=0
+exit
289.out new file +3 -0
new file mode 100644
index 0000000..a4de760
@@ -0,0 +1,3 @@
+QA output created by 289
+minix f_blocks is in range
+bsd f_blocks is in range
group +1 -0
index fb0f8eb..a846b60 100644
@@ -407,3 +407,4 @@ deprecated
 286 other
 287 auto dump quota quick
 288 auto quick ioctl trim
+289 auto quick

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#1 lore raw
Quoted 25 lines · Eric Sandeen

Calculating free blocks in ext[234] is surprisingly hard, since by default we report "bsd" style df which doesn't count filesystem "overhead" blocks as used.

With a lot of code dedicated to sorting out what to report as free, things tend to go wrong surprisingly often.

Here's a test to actually try to stop the next regression. ;)

NB: For bsddf, the kernel currently does not count journal blocks as overhead; it probably should. But the test below looks to have the result within 1% of perfection, so it still passes even if the kernel doesn't count the journal against free blocks.

---

289 new file +0 -0
new file mode 100755
index 0000000..bf0e897

289 line 2

Quoted 2 lines
289 new file +2 -0
@@ -0,0 +1,103 @@
+#! /bin/bash
+# FS QA Test No. 286
                      ^
                    289

I know this may change at commit time. ;)

Quoted 30 lines
289 new file +30 -0
+#
+# Test overhead & df output for extN filesystems
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2012 Red Hat, Inc.  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#-----------------------------------------------------------------------
+#
+# creator
[email protected]
+
+seq=`basename $0`
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15

289 line 42

Quoted 10 lines
289 new file +10 -0
+
+_cleanup()
+{
+    cd /
+    rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter# ./check 289
FSTYP         -- ext4
PLATFORM      -- Linux/x86_64 cxfsxe4 3.7.0-rc2+
MKFS_OPTIONS  -- /dev/sdc2

MOUNT_OPTIONS -- -o acl,user_xattr /dev/sdc2 /xfs_scratch

289 - output mismatch (see 289.out.bad)

289.out.bad renamed from 289.out +2 -1
@@ -1,3 +1,4 @@
 QA output created by 289
-minix f_blocks is in range
+minix f_blocks has value of 7208959
+minix f_blocks is NOT in range 7323904 .. 7323904
 bsd f_blocks is in range

Ran: 289
Failures: 289
Failed 1 of 1 tests

Quoted 43 lines
289 new file +43 -0
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs ext2 ext3 ext4
+_supported_os Linux
+_require_scratch
+
+rm -f $seq.full
+
+_scratch_mkfs >> $seq.full 2>&1
+
+# Get the honest truth about block counts straight from metadata on disk
+TOTAL_BLOCKS=`dumpe2fs -h $SCRATCH_DEV 2>/dev/null \
+		| awk '/Block count:/{print $3}'`
+
+FREE_BLOCKS=`dumpe2fs -h $SCRATCH_DEV 2>/dev/null \
+		| awk '/Free blocks:/{print $3}'`
+
+# nb: kernels today don't count journal blocks  as overhead, but should.
+# For most filesystems this will still be within tolerance.
+# Overhead is all the blocks (already) used by the fs itself:
+OVERHEAD=$(($TOTAL_BLOCKS-$FREE_BLOCKS))
+
+#  bsddf|minixdf
+#         Set the behaviour  for  the  statfs  system  call.  The  minixdf
+#         behaviour is to return in the f_blocks field the total number of
+#         blocks of the filesystem, while the bsddf  behaviour  (which  is
+#         the default) is to subtract the overhead blocks used by the ext2
+#         filesystem and not available for file storage.
+
+# stat -f output looks like this; we get f_blocks from that, which
+# varies depending on the df mount options used below:
+
+#   File: "/mnt/test"
+#    ID: affc5f2b2f57652 Namelen: 255     Type: ext2/ext3
+# Block size: 4096       Fundamental block size: 4096
+# Blocks: Total: 5162741    Free: 5118725    Available: 4856465
+# Inodes: Total: 1313760    Free: 1313749
+
+_scratch_mount "-o minixdf"
+MINIX_F_BLOCKS=`stat -f $SCRATCH_MNT | awk '/^Blocks/{print $3}'`
+umount $SCRATCH_MNT

289 line 95

Quoted 10 lines
289 new file +10 -0
+
+_scratch_mount "-o bsddf"
+BSD_F_BLOCKS=`stat -f $SCRATCH_MNT | awk '/^Blocks/{print $3}'`
+umount $SCRATCH_MNT
+
+# Echo data to $seq.full for analysis
+echo "Overhead is $OVERHEAD blocks out of $TOTAL_BLOCKS ($FREE_BLOCKS free)" >> $seq.full
+echo "MINIX free blocks $MINIX_F_BLOCKS" >> $seq.full
+echo "BSD free blocks $BSD_F_BLOCKS" >> $seq.full
+

This passes for ext[23] but not ext4.

289 line 97

Quoted 2 lines
289 new file +2 -0
+# minix should be exactly equal (hence tolerance of 0)
+_within_tolerance "minix f_blocks" $MINIX_F_BLOCKS $TOTAL_BLOCKS 0 -v

This is what I got when I ran it on an 80G SSD.

Model: ATA INTEL SSDSA2M080 (scsi)
Disk /dev/sdc: 80.0GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt_sync_mbr

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  30.0GB  30.0GB  ext4         primary
 2      30.0GB  60.0GB  30.0GB  ext4         primary
# ./check 289
FSTYP         -- ext4
PLATFORM      -- Linux/x86_64 cxfsxe4 3.7.0-rc2+
MKFS_OPTIONS  -- /dev/sdc2
MOUNT_OPTIONS -- -o acl,user_xattr /dev/sdc2 /xfs_scratch

289 - output mismatch (see 289.out.bad)

289.out.bad renamed from 289.out +2 -1
@@ -1,3 +1,4 @@
 QA output created by 289
-minix f_blocks is in range
+minix f_blocks has value of 7208959
+minix f_blocks is NOT in range 7323904 .. 7323904
 bsd f_blocks is in range

Ran: 289
Failures: 289
Failed 1 of 1 tests

Quoted 21 lines
289 new file +6 -0
+# bsd should be within ... we'll say 1% for some slop
+_within_tolerance "bsd f_blocks" $BSD_F_BLOCKS $(($TOTAL_BLOCKS-$OVERHEAD)) 1% -v
+
+# success, all done
+status=0
+exit
289.out new file +3 -0
new file mode 100644
index 0000000..a4de760
@@ -0,0 +1,3 @@
+QA output created by 289
+minix f_blocks is in range
+bsd f_blocks is in range
group +0 -0
index fb0f8eb..a846b60 100644

group deprecated · line 410

Quoted 4 lines
group +1 -0
@@ -407,3 +407,4 @@ deprecated
  286 other
  287 auto dump quota quick
  288 auto quick ioctl trim
+289 auto quick

Regards
--Rich

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#2 lore raw
Quoted 30 lines · Rich Johnston
Quoted 25 lines · Eric Sandeen

Calculating free blocks in ext[234] is surprisingly hard, since by default we report "bsd" style df which doesn't count filesystem "overhead" blocks as used.

With a lot of code dedicated to sorting out what to report as free, things tend to go wrong surprisingly often.

Here's a test to actually try to stop the next regression. ;)

NB: For bsddf, the kernel currently does not count journal blocks as overhead; it probably should. But the test below looks to have the result within 1% of perfection, so it still passes even if the kernel doesn't count the journal against free blocks.

---

289 new file +0 -0
new file mode 100755
index 0000000..bf0e897

289 line 2

Quoted 2 lines
289 new file +2 -0
@@ -0,0 +1,103 @@
+#! /bin/bash
+# FS QA Test No. 286
                      ^
                    289
Quoted 1 line

I know this may change at commit time. ;)

meh, right. Dumb to have it in the file, maybe.

Quoted 54 lines
Quoted 30 lines
289 new file +30 -0
+#
+# Test overhead & df output for extN filesystems
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2012 Red Hat, Inc.  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#-----------------------------------------------------------------------
+#
+# creator
[email protected]
+
+seq=`basename $0`
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1    # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15

289 line 42

Quoted 10 lines
289 new file +10 -0
+
+_cleanup()
+{
+    cd /
+    rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter# ./check 289
FSTYP         -- ext4
PLATFORM      -- Linux/x86_64 cxfsxe4 3.7.0-rc2+
MKFS_OPTIONS  -- /dev/sdc2

MOUNT_OPTIONS -- -o acl,user_xattr /dev/sdc2 /xfs_scratch

289 - output mismatch (see 289.out.bad)

289.out.bad 2012-10-26 12:35:03.000000000 -0500 renamed from 289.out 2012-10-26 12:33:27.000000000 -0500 +2 -1
@@ -1,3 +1,4 @@
 QA output created by 289
-minix f_blocks is in range
+minix f_blocks has value of 7208959
+minix f_blocks is NOT in range 7323904 .. 7323904
 bsd f_blocks is in range
Quoted 3 lines

Ran: 289
Failures: 289
Failed 1 of 1 tests

Yep - it's an ext4 bug. I sent a patch to fix it.

[PATCH] ext4: fix overhead calculations in ext4_stats, again

You might want to retest w/ that.

-Eric

Quoted 47 lines
Quoted 47 lines
289 new file +47 -0
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs ext2 ext3 ext4
+_supported_os Linux
+_require_scratch
+
+rm -f $seq.full
+
+_scratch_mkfs >> $seq.full 2>&1
+
+# Get the honest truth about block counts straight from metadata on disk
+TOTAL_BLOCKS=`dumpe2fs -h $SCRATCH_DEV 2>/dev/null \
+        | awk '/Block count:/{print $3}'`
+
+FREE_BLOCKS=`dumpe2fs -h $SCRATCH_DEV 2>/dev/null \
+        | awk '/Free blocks:/{print $3}'`
+
+# nb: kernels today don't count journal blocks  as overhead, but should.
+# For most filesystems this will still be within tolerance.
+# Overhead is all the blocks (already) used by the fs itself:
+OVERHEAD=$(($TOTAL_BLOCKS-$FREE_BLOCKS))
+
+#  bsddf|minixdf
+#         Set the behaviour  for  the  statfs  system  call.  The  minixdf
+#         behaviour is to return in the f_blocks field the total number of
+#         blocks of the filesystem, while the bsddf  behaviour  (which  is
+#         the default) is to subtract the overhead blocks used by the ext2
+#         filesystem and not available for file storage.
+
+# stat -f output looks like this; we get f_blocks from that, which
+# varies depending on the df mount options used below:
+
+#   File: "/mnt/test"
+#    ID: affc5f2b2f57652 Namelen: 255     Type: ext2/ext3
+# Block size: 4096       Fundamental block size: 4096
+# Blocks: Total: 5162741    Free: 5118725    Available: 4856465
+# Inodes: Total: 1313760    Free: 1313749
+
+_scratch_mount "-o minixdf"
+MINIX_F_BLOCKS=`stat -f $SCRATCH_MNT | awk '/^Blocks/{print $3}'`
+umount $SCRATCH_MNT
+
+_scratch_mount "-o bsddf"
+BSD_F_BLOCKS=`stat -f $SCRATCH_MNT | awk '/^Blocks/{print $3}'`
+umount $SCRATCH_MNT
Quoted 8 lines

289 line 95

Quoted 6 lines
289 new file +6 -0
+
+# Echo data to $seq.full for analysis
+echo "Overhead is $OVERHEAD blocks out of $TOTAL_BLOCKS ($FREE_BLOCKS free)" >> $seq.full
+echo "MINIX free blocks $MINIX_F_BLOCKS" >> $seq.full
+echo "BSD free blocks $BSD_F_BLOCKS" >> $seq.full
+

This passes for ext[23] but not ext4.

*nod*

Quoted 54 lines

289 line 97

Quoted 2 lines
289 new file +2 -0
+# minix should be exactly equal (hence tolerance of 0)
+_within_tolerance "minix f_blocks" $MINIX_F_BLOCKS $TOTAL_BLOCKS 0 -v

This is what I got when I ran it on an 80G SSD.

Model: ATA INTEL SSDSA2M080 (scsi)
Disk /dev/sdc: 80.0GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt_sync_mbr

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  30.0GB  30.0GB  ext4         primary
 2      30.0GB  60.0GB  30.0GB  ext4         primary
# ./check 289
FSTYP         -- ext4
PLATFORM      -- Linux/x86_64 cxfsxe4 3.7.0-rc2+
MKFS_OPTIONS  -- /dev/sdc2
MOUNT_OPTIONS -- -o acl,user_xattr /dev/sdc2 /xfs_scratch

289 - output mismatch (see 289.out.bad)

289.out.bad 2012-10-26 12:35:03.000000000 -0500 renamed from 289.out 2012-10-26 12:33:27.000000000 -0500 +2 -1
@@ -1,3 +1,4 @@
 QA output created by 289
-minix f_blocks is in range
+minix f_blocks has value of 7208959
+minix f_blocks is NOT in range 7323904 .. 7323904
 bsd f_blocks is in range

Ran: 289
Failures: 289
Failed 1 of 1 tests

Quoted 20 lines
289 new file +6 -0
+# bsd should be within ... we'll say 1% for some slop
+_within_tolerance "bsd f_blocks" $BSD_F_BLOCKS $(($TOTAL_BLOCKS-$OVERHEAD)) 1% -v
+
+# success, all done
+status=0
+exit
289.out new file +3 -0
new file mode 100644
index 0000000..a4de760
@@ -0,0 +1,3 @@
+QA output created by 289
+minix f_blocks is in range
+bsd f_blocks is in range
group +0 -0
index fb0f8eb..a846b60 100644
@@ -407,3 +407,4 @@ deprecated
Quoted 9 lines

group deprecated · line 410

Quoted 5 lines
group +1 -0
  286 other
  287 auto dump quota quick
  288 auto quick ioctl trim
+289 auto quick

Regards
--Rich

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by
#3 lore raw
Quoted 23 lines · Eric Sandeen
Quoted 15 lines · Rich Johnston
Quoted 14 lines · Eric Sandeen

Calculating free blocks in ext[234] is surprisingly hard, since by default we report "bsd" style df which doesn't count filesystem "overhead" blocks as used.

With a lot of code dedicated to sorting out what to report as free, things tend to go wrong surprisingly often.

Here's a test to actually try to stop the next regression. ;)

NB: For bsddf, the kernel currently does not count journal blocks as overhead; it probably should. But the test below looks to have the result within 1% of perfection, so it still passes even if the kernel doesn't count the journal against free blocks.

Quoted 4 lines
Quoted 4 lines

---

Quoted 9 lines

Yep - it's an ext4 bug. I sent a patch to fix it.

[PATCH] ext4: fix overhead calculations in ext4_stats, again

You might want to retest w/ that.

-Eric

Quoted 1 line
Quoted 1 line

+

Thanks Eric,

Everything passes now.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#4 lore raw

xfstests: test ext4 statfs

Calculating free blocks in ext[234] is surprisingly hard, since by default we report "bsd" style df which doesn't count filesystem "overhead" blocks as used.

With a lot of code dedicated to sorting out what to report as free, things tend to go wrong surprisingly often.

Here's a test to actually try to stop the next regression. ;)

NB: For bsddf, the kernel currently does not count journal blocks as overhead; it probably should. But the test below looks to have the result within 1% of perfection, so it still passes even if the kernel doesn't count the journal against free blocks.

Eric,

This patch has been committed to git://oss.sgi.com/xfs/cmds/xfstests, master branch, commit 0b2ab695.

Thanks
--Rich

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs