Skip to contentSkip to conversation

fstests: dirent file type tests

PATCH New Amir Goldstein 2 participants 6 messages Dec 20, 2016 – Dec 24, 2016

lore
Share & tools
lore
#0 lore raw

v2 cover fstests: dirent file type tests

generic/396 runs some tests on directory file types.

_supports_filetype() helper is used by this test and by overlayfs to check for file type support of upper dir fs.

Tested with tmpfs, ext2, ext4, xfs for d_type supported fs and with xfs -m crc=0 -n ftype=0 for d_type unsupported fs

Tested that overlay tests run over tmpfs (generic ftype check) Tested that overlay tests run over xfs (ftype=1) Tested that overlay tests do not run over xfs (ftype=0)

v2:
- use helper to test for file type support
- allow DT_UNKNOWN type, but only for all files
- verify . and .. have DT_DIR type

v1:
- verify that d_type matches actual file type

Amir Goldstein (3):
common/rc: factor out _supports_filetype() helper common/rc: add generic file type support check generic/396: test correct d_type values

 .gitignore            |   1 +
 common/rc             |  42 +++++++++++++-------
 src/Makefile          |   2 +-
 src/t_dir_type.c      | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/396     |  87 ++++++++++++++++++++++++++++++++++++++++
 tests/generic/396.out |   9 +++++
 tests/generic/group   |   1 +
 7 files changed, 235 insertions(+), 15 deletions(-)
 create mode 100644 src/t_dir_type.c
 create mode 100755 tests/generic/396
 create mode 100644 tests/generic/396.out
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/3 common/rc: factor out _supports_filetype() helper

_overlay_mount_dirs() checks for the filetype feature on upper dir fs.

factor out that feature test to a helper.

---
 common/rc | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)
common/rc +19 -14
index 2639fbd..288517f 100644
@@ -264,6 +264,23 @@ _scratch_mount_options()
 					$SCRATCH_DEV $SCRATCH_MNT
 }
 
+_supports_filetype()
+{
+	local dir=$1
+	shift 1
+
+	local upper_fst=$(df --output=fstype $dir | tail -1)
+	case "$upper_fst" in
+	xfs)
+		xfs_info $dir | grep -q "ftype=1"
+		;;
+	ext2|ext3|ext4)
+		tune2fs -l $(df --output=source $dir | tail -1) | \
+		   grep -q filetype
+		;;
+	esac
+}
+
 # helper function to do the actual overlayfs mount operation
 _overlay_mount_dirs()
 {
@@ -284,20 +301,8 @@ _overlay_mount()
 	local mnt=$2
 	shift 2
 
-	local upper_fst=$(df --output=fstype $dir | tail -1)
-	case "$upper_fst" in
-	xfs)
-		if ! xfs_info $dir | grep -q "ftype=1" ; then
-			_notrun "upper fs needs to support d_type"
-		fi
-		;;
-	ext2|ext3|ext4)
-		if ! tune2fs -l $(df --output=source $dir | tail -1) | \
-		   grep -q filetype ; then
-			_notrun "upper fs needs to support d_type"
-		fi
-		;;
-	esac
+	_supports_filetype $dir || \
+		_notrun "upper fs needs to support d_type"
 
 	mkdir -p $dir/$OVERLAY_UPPER_DIR
 	mkdir -p $dir/$OVERLAY_LOWER_DIR
Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 2/3 common/rc: add generic file type support check

In reply to Amir Goldstein

_supports_filetype() helper checks if the filetype feature is enabled for xfs and ext* file sytems.

Add a check for the generic case where we don't know how to test file system filetype feature.

Introduce a helper utility t_dir_type that lists directory entries filtered by file type.

Check for filetype feature by expecting to find no directory entries listed as DT_UNKNOWN inside a test directory.

---
 .gitignore       |   1 +
 common/rc        |   9 +++++
 src/Makefile     |   2 +-
 src/t_dir_type.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 119 insertions(+), 1 deletion(-)
 create mode 100644 src/t_dir_type.c
.gitignore +1 -0
index b8d13a0..7dcea14 100644
@@ -94,6 +94,7 @@
 /src/t_access_root
 /src/t_dir_offset
 /src/t_dir_offset2
+/src/t_dir_type
 /src/t_futimens
 /src/t_getcwd
 /src/t_holes
common/rc +9 -0
index 288517f..a779c50 100644
@@ -278,6 +278,15 @@ _supports_filetype()
 		tune2fs -l $(df --output=source $dir | tail -1) | \
 		   grep -q filetype
 		;;
+	*)
+		testfile=$dir/$$.ftype
+		touch $testfile
+		# look for DT_UNKNOWN files
+		unknowns=$(src/t_dir_type $dir u | wc -l)
+		rm $testfile
+		# 0 unknowns is success
+		return $unknowns
+		;;
 	esac
 }
 
src/Makefile +1 -1
index 4056496..94d74aa 100644
@@ -21,7 +21,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
 	stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \
 	seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \
 	renameat2 t_getcwd e4compact test-nextquota punch-alternating \
-	attr-list-by-handle-cursor-test listxattr dio-interleaved
+	attr-list-by-handle-cursor-test listxattr dio-interleaved t_dir_type
 
 SUBDIRS =
 
src/t_dir_type.c new file +108 -0

108 lines not on this page · raw message

Signature · 1 line
2.7.4
#3 lore raw

PATCH v2 3/3 generic/396: test correct d_type values

In reply to Amir Goldstein

Verify correct d_type values of dir entries.

This test does NOT require that file system support the filetype feature. It verifies that either all file types are reported as DT_UNKNOWN or that all file types are reported correctly.

For fs for which we know how to test the filetype feature (xfs|ext*) verify getting DT_UNKNOWN IFF feature is disabled.

Verify special dir entries . and .. are always reported as DT_DIR.

---
 tests/generic/396     | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/396.out |  9 ++++++
 tests/generic/group   |  1 +
 3 files changed, 97 insertions(+)
 create mode 100755 tests/generic/396
 create mode 100644 tests/generic/396.out
tests/generic/396 new file +87 -0
new file mode 100755
index 0000000..fbd2e79
@@ -0,0 +1,87 @@
+#! /bin/bash
+# FSQA Test No. 396
+#
+# Test filetype feature
+#
+# This test does NOT require that file system support the d_type feature.
+# It verifies that either all file types are reported as DT_UNKNOWN
+# or all file types are reported correctly.
+#
+# For fs for which we know how to test the filetype feature (xfs|ext*)
+# verify getting DT_UNKNOWN IFF feature is disabled.
+#
+# Verify special dir entries . and .. are always reported as DT_DIR.
+#
+#-----------------------------------------------------------------------
+#
+# Copyright (C) 2016 CTERA Networks. All Rights Reserved.
+# Author: Amir Goldstein <[email protected]>
+#
+# 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
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_scratch
+
+rm -f $seqres.full
+
+_scratch_mkfs >>$seqres.full 2>&1
+
+_scratch_mount
+
+# Create our test files.
+testdir=$SCRATCH_MNT/find-by-type
+mkdir -p $testdir
+mkdir $testdir/d
+touch $testdir/f
+ln -s $testdir/f $testdir/l
+mknod $testdir/c c 1 1
+mknod $testdir/b b 1 1
+mknod $testdir/p p
+
+# Test d_type DT_DIR for . and ..
+# this should be correct on all fs regardless of filetype feature
+src/t_dir_type $testdir d | grep -F '.' | sort
+
+# Test that either all file type are unknown or all are valid
+if _supports_filetype $testdir; then
+	# print real file types
+	src/t_dir_type $testdir | grep -vF '.' | sort
+else
+	# list unknown files and print filename as fake file type
+	src/t_dir_type $testdir u | awk '{ print $1, $1 }' | sort
+fi
+
+status=0
+exit
tests/generic/396.out new file +9 -0
new file mode 100644
index 0000000..de11c24
@@ -0,0 +1,9 @@
+QA output created by 396
+. d
+.. d
+b b
+c c
+d d
+f f
+l l
+p p
tests/generic/group +1 -0
index 20b31ef..24c242f 100644
@@ -397,3 +397,4 @@
 392 auto quick metadata
 393 auto quick rw
 394 auto quick
+396 auto quick
Signature · 1 line
2.7.4
#4 lore raw

PATCH v3 3/3 generic/396: test correct d_type values

Verify correct d_type values of dir entries.

This test does NOT require that file system support the filetype feature. It verifies that either all file types are reported as DT_UNKNOWN or that all file types are reported correctly.

For fs for which we know how to test the filetype feature (xfs|ext*) verify getting DT_UNKNOWN IFF filetype feature is disabled.

Special dir entries . and .. MAY be reported as DT_UNKNOWN IF filetype feature is disabled (ext4), but MAY also be reported as DT_DIR in this case (xfs).

---
 tests/generic/396     | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/396.out |  9 +++++
 tests/generic/group   |  1 +
 3 files changed, 103 insertions(+)
 create mode 100755 tests/generic/396
 create mode 100644 tests/generic/396.out

Added another test to the matrix, found another special case to handle:
ext4 vs. xfs returns DT_UNKNOWN for . and .. on ! _supports_filetype.

Fixes the test to correctly handle both cases.

Tested with tmpfs, ext2, ext4, xfs for d_type supported fs Tested with xfs -m crc=0 -n ftype=0 for d_type unsupported fs Tested with ext2/ext4 -O ^filetype for d_type unsupported fs

v3:
- allow DT_UNKNOWN type for . and .. when filetype feature is disabled (ext4)

v2:
- use helper to test for file type support
- allow DT_UNKNOWN type, but only for all files
- verify . and .. have DT_DIR type

v1:
- verify that d_type matches actual file type

tests/generic/396 new file +93 -0
new file mode 100755
index 0000000..0d4a17d
@@ -0,0 +1,93 @@
+#! /bin/bash
+# FSQA Test No. 396
+#
+# Test filetype feature
+#
+# This test does NOT require that file system support the d_type feature.
+# It verifies that either all file types are reported as DT_UNKNOWN
+# or all file types are reported correctly.
+#
+# For fs for which we know how to test the filetype feature (xfs|ext*)
+# verify getting DT_UNKNOWN IFF feature is disabled.
+# Special dir entries . and .. MAY be reported as DT_UNKNOWN IF filetype
+# feature is disabled (ext4), but MAY also be reported as DT_DIR in this
+# case (xfs).
+#
+#-----------------------------------------------------------------------
+#
+# Copyright (C) 2016 CTERA Networks. All Rights Reserved.
+# Author: Amir Goldstein <[email protected]>
+#
+# 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
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_scratch
+
+rm -f $seqres.full
+
+_scratch_mkfs >>$seqres.full 2>&1
+
+_scratch_mount
+
+# Create our test files.
+testdir=$SCRATCH_MNT/find-by-type
+mkdir -p $testdir
+mkdir $testdir/d
+touch $testdir/f
+ln -s $testdir/f $testdir/l
+mknod $testdir/c c 1 1
+mknod $testdir/b b 1 1
+mknod $testdir/p p
+
+# Test d_type of . and ..
+# it must be DT_DIR on fs with filetype support and it could be
+# either DR_DIR or DT_UNKNOWN on fs without filetype support
+src/t_dir_type $testdir d | grep -F '.' | sort
+
+# Test that either all file types are unknown or all are correct
+if _supports_filetype $testdir; then
+	# print real file types
+	src/t_dir_type $testdir | grep -vF '.' | sort
+else
+	# print fake dir file type for . and .. if they are DT_UNKNOWN
+	src/t_dir_type $testdir u | grep -F '.' | \
+		awk '{ print $1, "d" }' | sort
+	# list unknown files and print filename as fake file type
+	src/t_dir_type $testdir u | grep -vF '.' | \
+		awk '{ print $1, $1 }' | sort
+fi
+
+status=0
+exit
tests/generic/396.out new file +9 -0
new file mode 100644
index 0000000..de11c24
@@ -0,0 +1,9 @@
+QA output created by 396
+. d
+.. d
+b b
+c c
+d d
+f f
+l l
+p p
tests/generic/group +1 -0
index 20b31ef..24c242f 100644
@@ -397,3 +397,4 @@
 392 auto quick metadata
 393 auto quick rw
 394 auto quick
+396 auto quick
Signature · 1 line
2.7.4
#5 lore raw

Re: [PATCH v3 3/3] generic/396: test correct d_type values

Quoted 94 lines · Amir Goldstein

Verify correct d_type values of dir entries.

This test does NOT require that file system support the filetype feature. It verifies that either all file types are reported as DT_UNKNOWN or that all file types are reported correctly.

For fs for which we know how to test the filetype feature (xfs|ext*) verify getting DT_UNKNOWN IFF filetype feature is disabled.

Special dir entries . and .. MAY be reported as DT_UNKNOWN IF filetype feature is disabled (ext4), but MAY also be reported as DT_DIR in this case (xfs).

---
 tests/generic/396     | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/396.out |  9 +++++
 tests/generic/group   |  1 +
 3 files changed, 103 insertions(+)
 create mode 100755 tests/generic/396
 create mode 100644 tests/generic/396.out

Added another test to the matrix, found another special case to handle:
ext4 vs. xfs returns DT_UNKNOWN for . and .. on ! _supports_filetype.

Fixes the test to correctly handle both cases.

Tested with tmpfs, ext2, ext4, xfs for d_type supported fs Tested with xfs -m crc=0 -n ftype=0 for d_type unsupported fs Tested with ext2/ext4 -O ^filetype for d_type unsupported fs

v3:
- allow DT_UNKNOWN type for . and .. when filetype feature is disabled (ext4)

v2:
- use helper to test for file type support
- allow DT_UNKNOWN type, but only for all files
- verify . and .. have DT_DIR type

v1:
- verify that d_type matches actual file type

tests/generic/396 new file +46 -0
new file mode 100755
index 0000000..0d4a17d
@@ -0,0 +1,93 @@
+#! /bin/bash
+# FSQA Test No. 396
+#
+# Test filetype feature
+#
+# This test does NOT require that file system support the d_type feature.
+# It verifies that either all file types are reported as DT_UNKNOWN
+# or all file types are reported correctly.
+#
+# For fs for which we know how to test the filetype feature (xfs|ext*)
+# verify getting DT_UNKNOWN IFF feature is disabled.
+# Special dir entries . and .. MAY be reported as DT_UNKNOWN IF filetype
+# feature is disabled (ext4), but MAY also be reported as DT_DIR in this
+# case (xfs).
+#
+#-----------------------------------------------------------------------
+#
+# Copyright (C) 2016 CTERA Networks. All Rights Reserved.
+# Author: Amir Goldstein <[email protected]>
+#
+# 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
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	rm -f $tmp.*

tests/generic/396 line 56

Quoted 10 lines
tests/generic/396 new file +10 -0
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_scratch

I added a "_require_test_program t_dir_type" here and merged.

Thanks,
Eryu