All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] Add UBIFS support to xfstests
@ 2017-05-31  8:54 David Oberhollenzer
  2017-05-31  8:54 ` [PATCH v2 1/4] Add tests for character devices David Oberhollenzer
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: David Oberhollenzer @ 2017-05-31  8:54 UTC (permalink / raw)
  To: fstests; +Cc: linux-mtd, richard

Hello,


this patch series attempts to add support for UBIFS to xfstests,
loosely based on the previous patches for xfstests-dev.

UBIFS is a filesystem for unmanaged flash memory devices. It works on
top of UBI (Unsorted Block Images) which is a wear leveling and volume
management layer on top of MTD (memory technology device) which
abstracts flash memory devices.

Since the semantics of MTD and UBI devices are drastically different
from normal block devices, they are exposed to user space as character
devices with ioctls for special operations.

The first patch adds helpers for dealing with character devices, the
second one actually adds the UBIFS support and goes into a little more
detail in its commit message on the quirks of UBIFS in contrast to
other file systems.

One notable quirk is the lack of needing an mkfs.ubifs tool. The kernel
component automatically formats empty UBI devices when mounting them
with '-t ubifs'.

There actually is an mkfs.ubifs, but it is mainly used for creating
images. Also, at the time of writing, it does not yet support the
recently added UBIFS extensions for file level encryption.

Instead of using the mkfs.ubifs tool, the _scratch_mkfs function is
patched to truncate the UBI volume instead, which also required some
changes to a few tests.

The last two patches modify existing tests to work with UBIFS, i.e. in
case of generic/398 to be more tolerant of returned error numbers and
in the last patch to also accept a local character device and properly
specify the filesystem type when remounting.


The patch series has been tested inside a Debian Jessie VM, using the 
UBIFS
kernel tree from git://git.infradead.org/linux-ubifs.git and nandsim 
emulating a nand flash device.


Changes from the last version:
 - Minor refactoring and verbose commentary added as requested
 - Added check for required utilities
 - Addition of a _require_local_device helper for some tests
   instead of completely removing the local device check
 - Broken up into more fine grained patch set and split away
   xfstests-bld patches which are currently still in progress


The necessity of an additional -ubifs switch was discussed but
auto detection of UBIFS formated UBI devices could not be reproduced
on my end and is unlikely to work with empty UBI volumes anyway.


David

[1] http://www.linux-mtd.infradead.org/nand-data/nanddata.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/4] Add tests for character devices
  2017-05-31  8:54 [PATCH v2] Add UBIFS support to xfstests David Oberhollenzer
@ 2017-05-31  8:54 ` David Oberhollenzer
  2017-05-31 11:07   ` Eryu Guan
  2017-05-31  8:54 ` [PATCH v2 2/4] Add support for UBIFS David Oberhollenzer
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: David Oberhollenzer @ 2017-05-31  8:54 UTC (permalink / raw)
  To: fstests; +Cc: linux-mtd, richard, David Oberhollenzer

Implement _is_char_dev similar to _is_block_dev to test for
character devices.

Add a _require_local_device test. This test is similar to
_require_block_device but checks if the path refers to a
block or a character device.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
---
 common/rc | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/common/rc b/common/rc
index ba215961..ae8ea550 100644
--- a/common/rc
+++ b/common/rc
@@ -1363,6 +1363,26 @@ _is_block_dev()
     fi
 }
 
+# returns device number if a file is a character device
+#
+_is_char_dev()
+{
+    if [ $# -ne 1 ]
+    then
+	echo "Usage: _is_char_dev dev" 1>&2
+	exit 1
+    fi
+
+    _dev=$1
+    if [ -L "${_dev}" ]; then
+        _dev=`readlink -f "${_dev}"`
+    fi
+
+    if [ -c "${_dev}" ]; then
+        src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
+    fi
+}
+
 # Do a command, log it to $seqres.full, optionally test return status
 # and die if command fails. If called with one argument _do executes the
 # command, logs it, and returns its exit status. With two arguments _do
@@ -1791,6 +1811,23 @@ _require_block_device()
 	fi
 }
 
+# this test requires a path to refere to a local block or character device
+# $1 - device
+_require_local_device()
+{
+	if [ -z "$1" ]; then
+		echo "Usage: _require_local_device <dev>" 1>&2
+		exit 1
+	fi
+	if [ "`_is_block_dev "$1"`" != "" ]; then
+		return 0
+	fi
+	if [ "`_is_char_dev "$1"`" != "" ]; then
+		return 0
+	fi
+	_notrun "require $1 to be local device"
+}
+
 # brd based ram disks erase the device when they receive a flush command when no
 # active references are present. This causes problems for DM devices sitting on
 # top of brd devices as DM doesn't hold active references to the brd device.
-- 
2.12.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/4] Add support for UBIFS
  2017-05-31  8:54 [PATCH v2] Add UBIFS support to xfstests David Oberhollenzer
  2017-05-31  8:54 ` [PATCH v2 1/4] Add tests for character devices David Oberhollenzer
@ 2017-05-31  8:54 ` David Oberhollenzer
  2017-05-31 11:12   ` Eryu Guan
  2017-05-31  8:54 ` [PATCH v2 3/4] Accept failing with EPERM in addition to ENOKEY for rename without key David Oberhollenzer
  2017-05-31  8:54 ` [PATCH v2 4/4] Fix block device requirements and manual scratch mounts David Oberhollenzer
  3 siblings, 1 reply; 7+ messages in thread
From: David Oberhollenzer @ 2017-05-31  8:54 UTC (permalink / raw)
  To: fstests; +Cc: linux-mtd, richard, David Oberhollenzer

UBIFS is a filesystem for unmanaged flash memory devices. It works on top of
UBI (Unsorted Block Images) which is a wear leveling and volume management
layer on top of flash memory devices, which are handled by the MTD subsystem
(memory technology device).

Since the semantics of flash devices are drastically different from regular
block devices (blocks or "pages" must be erased before writing, only larger
groups of pages or "erase blocks" can be erased at once, page write must be
in order within an erase block, etc...) it was decided to expose MTD devices
as character devices with ioctls for operations like erase.

Since erasing a flash erase block causes physical wear on the device,
eventually causing the erase blocks to go bad, the UBI layer provides mainly
transparent wear leveling on top of MTD devices. UBI does not attempt to
emulate a regular block device, but rather something like a flash memory with
idealized characteristics that can be partitioned into multiple UBI volumes
in a fashion somewhat similar to LVM. UBI volumes are also exposed to user
space as character devices.

This patch mainly deals with some quirks of UBIFS like working on top of
character devices instead of block devices. Also UBIFS automatically formats
UBI devices when trying to mount an empty device. The mkfs.ubifs program is
mainly used for creating images. This patch changes _scratch_mkfs and
_scratch_mkfs_encrypted to truncate the UBI volume instead, relying on the
kernel to reformat it on the next mount.

For _scratch_mkfs_encrypted this is actually required to get the encryption
tests to run, because mkfs.ubifs, at the time of writing this, the kernel
support for UBIFS encryption is fairly recent and mkfs.ubifs does not have
proper support yet.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
---
 check          |  2 ++
 common/config  | 16 +++++++++++++---
 common/encrypt |  4 ++++
 common/rc      | 34 ++++++++++++++++++++++++++++++++++
 4 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/check b/check
index 9cef58b4..f8db3cd6 100755
--- a/check
+++ b/check
@@ -70,6 +70,7 @@ check options
     -overlay		test overlay
     -pvfs2          test PVFS2
     -tmpfs              test TMPFS
+    -ubifs              test ubifs
     -l			line mode diff
     -udiff		show unified diff (default)
     -n			show me, do not run tests
@@ -267,6 +268,7 @@ while [ $# -gt 0 ]; do
 	-overlay)	FSTYP=overlay; export OVERLAY=true ;;
 	-pvfs2)		FSTYP=pvfs2 ;;
 	-tmpfs)		FSTYP=tmpfs ;;
+	-ubifs)		FSTYP=ubifs ;;
 
 	-g)	group=$2 ; shift ;
 		GROUP_LIST="$GROUP_LIST ${group//,/ }"
diff --git a/common/config b/common/config
index 8211356c..5bf3f65f 100644
--- a/common/config
+++ b/common/config
@@ -320,6 +320,9 @@ _mount_opts()
 		# We need to specify the size at mount, use 1G by default
 		export MOUNT_OPTIONS="-o size=1G $TMPFS_MOUNT_OPTIONS"
 		;;
+	ubifs)
+		export MOUNT_OPTIONS=$UBIFS_MOUNT_OPTIONS
+		;;
 	*)
 		;;
 	esac
@@ -455,13 +458,20 @@ _check_device()
 		return 0
 	fi
 
-	if [ "$FSTYP" == "overlay" ]; then
+	case "$FSTYP" in
+	overlay)
 		if [ ! -d "$dev" ]; then
 			_fatal "common/config: $name ($dev) is not a directory for overlay"
 		fi
-	else
+		;;
+	ubifs)
+		if [ ! -c "$dev" ]; then
+			_fatal "common/config: $name ($dev) is not a character device"
+		fi
+		;;
+	*)
 		_fatal "common/config: $name ($dev) is not a block device or a network filesystem"
-	fi
+	esac
 }
 
 # check and return a canonical mount point path
diff --git a/common/encrypt b/common/encrypt
index 723f1b11..83ef918a 100644
--- a/common/encrypt
+++ b/common/encrypt
@@ -71,6 +71,10 @@ _scratch_mkfs_encrypted()
 	ext4|f2fs)
 		_scratch_mkfs -O encrypt
 		;;
+	ubifs)
+		# erase the UBI volume; reformated automatically on next mount
+		ubiupdatevol ${SCRATCH_DEV} -t
+		;;
 	*)
 		_notrun "No encryption support for $FSTYP"
 		;;
diff --git a/common/rc b/common/rc
index ae8ea550..7a97e5d6 100644
--- a/common/rc
+++ b/common/rc
@@ -176,6 +176,11 @@ case "$FSTYP" in
 	 ;;
     pvfs2)
 	;;
+    ubifs)
+	if ! type "ubiupdatevol" > /dev/null; then
+		_fatal "mtd-utils ubiupdatevol not found"
+	fi
+	;;
 esac
 
 if [ ! -z "$REPORT_LIST" ]; then
@@ -812,6 +817,11 @@ _scratch_mkfs()
 		# do nothing for tmpfs
 		return 0
 		;;
+	ubifs)
+		# erase the UBI volume; reformated automatically on next mount
+		ubiupdatevol ${SCRATCH_DEV} -t
+		return 0
+		;;
 	ext4)
 		_scratch_mkfs_ext4 $*
 		return $?
@@ -1576,6 +1586,15 @@ _require_scratch_nocheck()
 		    _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
 		fi
 		;;
+	ubifs)
+		# ubifs needs an UBI volume. This will be a char device, not a block device.
+		if [ ! -c "$SCRATCH_DEV" ]; then
+			_notrun "this test requires a valid UBI volume for \$SCRATCH_DEV"
+		fi
+		if [ ! -d "$SCRATCH_MNT" ]; then
+			_notrun "this test requires a valid \$SCRATCH_MNT"
+		fi
+		;;
 	*)
 		 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
 		 then
@@ -1670,6 +1689,15 @@ _require_test()
 		    _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
 		fi
 		;;
+	ubifs)
+		# ubifs needs an UBI volume. This will be a char device, not a block device.
+		if [ ! -c "$TEST_DEV" ]; then
+			_notrun "this test requires a valid UBI volume for \$TEST_DEV"
+		fi
+		if [ ! -d "$TEST_DIR" ]; then
+			_notrun "this test requires a valid \$TEST_DIR"
+		fi
+		;;
 	*)
 		 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
 		 then
@@ -2555,6 +2583,9 @@ _check_test_fs()
     tmpfs)
 	# no way to check consistency for tmpfs
 	;;
+    ubifs)
+	# there is no fsck program for ubifs yet
+	;;
     *)
 	_check_generic_filesystem $TEST_DEV
 	;;
@@ -2604,6 +2635,9 @@ _check_scratch_fs()
     tmpfs)
 	# no way to check consistency for tmpfs
 	;;
+    ubifs)
+	# there is no fsck program for ubifs yet
+	;;
     *)
 	_check_generic_filesystem $device
 	;;
-- 
2.12.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/4] Accept failing with EPERM in addition to ENOKEY for rename without key
  2017-05-31  8:54 [PATCH v2] Add UBIFS support to xfstests David Oberhollenzer
  2017-05-31  8:54 ` [PATCH v2 1/4] Add tests for character devices David Oberhollenzer
  2017-05-31  8:54 ` [PATCH v2 2/4] Add support for UBIFS David Oberhollenzer
@ 2017-05-31  8:54 ` David Oberhollenzer
  2017-05-31  8:54 ` [PATCH v2 4/4] Fix block device requirements and manual scratch mounts David Oberhollenzer
  3 siblings, 0 replies; 7+ messages in thread
From: David Oberhollenzer @ 2017-05-31  8:54 UTC (permalink / raw)
  To: fstests; +Cc: linux-mtd, richard, David Oberhollenzer

Some filesystems (e.g. UBIFS) fail with EPERM when trying to move a
file into an encrypted directory via cross rename, without having
access to the encryption key.

Since rename is perfectly allowed to return EPERM, which is also tested
for, and no precise specification seems to exist that clarifies when to
expect EPERM and when ENOKEY, this patch modifies the generic/398 test
to accept both, for the test case where the key is not available.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
---
 tests/generic/398     | 10 ++++++++--
 tests/generic/398.out |  4 ++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/tests/generic/398 b/tests/generic/398
index b486b9c5..53b092d8 100755
--- a/tests/generic/398
+++ b/tests/generic/398
@@ -43,6 +43,12 @@ _cleanup()
 	rm -f $tmp.*
 }
 
+_filter_enokey()
+{
+	# rename without key can also fail with EPERM instead of ENOKEY
+	sed -e "s/Required key not available/Operation not permitted/g"
+}
+
 # get standard environment, filters and checks
 . ./common/rc
 . ./common/filter
@@ -149,9 +155,9 @@ efile1=$(find $edir1 -type f)
 efile2=$(find $edir2 -type f)
 
 echo -e "\n\n*** Exchange encrypted <=> encrypted without key ***"
-src/renameat2 -x $efile1 $efile2
+src/renameat2 -x $efile1 $efile2 |& _filter_enokey
 echo -e "\n*** Exchange encrypted <=> unencrypted without key ***"
-src/renameat2 -x $efile1 $udir/ufile
+src/renameat2 -x $efile1 $udir/ufile |& _filter_enokey
 
 # success, all done
 status=0
diff --git a/tests/generic/398.out b/tests/generic/398.out
index 8e08270d..f9274878 100644
--- a/tests/generic/398.out
+++ b/tests/generic/398.out
@@ -39,7 +39,7 @@ Operation not permitted
 
 
 *** Exchange encrypted <=> encrypted without key ***
-Required key not available
+Operation not permitted
 
 *** Exchange encrypted <=> unencrypted without key ***
-Required key not available
+Operation not permitted
-- 
2.12.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 4/4] Fix block device requirements and manual scratch mounts
  2017-05-31  8:54 [PATCH v2] Add UBIFS support to xfstests David Oberhollenzer
                   ` (2 preceding siblings ...)
  2017-05-31  8:54 ` [PATCH v2 3/4] Accept failing with EPERM in addition to ENOKEY for rename without key David Oberhollenzer
@ 2017-05-31  8:54 ` David Oberhollenzer
  3 siblings, 0 replies; 7+ messages in thread
From: David Oberhollenzer @ 2017-05-31  8:54 UTC (permalink / raw)
  To: fstests; +Cc: linux-mtd, richard, David Oberhollenzer

Some tests require the scratch volume to be a block device,
although they don't do anything block device specific like
the device mapper tests. They actually only require a local
device and fail with network or overlay pseudo mount devices.

The same tests also try to mount the scratch device manually
after running _scratch_mkfs. For UBIFS, _scratch_mkfs simply
truncates the UBI volume and relies on the kernel to re-format
the volume on the next mount. This fails if the fs type is not
specified explicitly when mounting.

This patch replaces the block device requirement with a
generic check for a local device and adds a filesystem
specification to all manual mounts of the scratch device
to a mount point.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
---
 tests/generic/076 |  2 +-
 tests/generic/409 |  8 ++++----
 tests/generic/410 |  8 ++++----
 tests/generic/411 | 10 +++++-----
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/tests/generic/076 b/tests/generic/076
index 64e69583..a29f160a 100755
--- a/tests/generic/076
+++ b/tests/generic/076
@@ -56,7 +56,7 @@ _supported_fs generic
 _supported_os IRIX Linux
 
 _require_scratch
-_require_block_device $SCRATCH_DEV
+_require_local_device $SCRATCH_DEV
 
 echo "*** init fs"
 
diff --git a/tests/generic/409 b/tests/generic/409
index 4bfedf73..22af44c8 100755
--- a/tests/generic/409
+++ b/tests/generic/409
@@ -64,7 +64,7 @@ _supported_fs generic
 _supported_os Linux
 _require_test
 _require_scratch
-_require_block_device $SCRATCH_DEV
+_require_local_device $SCRATCH_DEV
 
 fs_stress()
 {
@@ -114,7 +114,7 @@ start_test()
 	local type=$1
 
 	_scratch_mkfs >$seqres.full 2>&1
-	_get_mount $SCRATCH_DEV $MNTHEAD
+	_get_mount -t $FSTYP $SCRATCH_DEV $MNTHEAD
 	$MOUNT_PROG --make-"${type}" $MNTHEAD
 	mkdir $mpA $mpB $mpC $mpD
 }
@@ -133,7 +133,7 @@ bind_run()
 	start_test $dest
 
 	echo "bind $source on $dest"
-	_get_mount $SCRATCH_DEV $mpA
+	_get_mount -t $FSTYP $SCRATCH_DEV $mpA
 	mkdir -p $mpA/dir 2>/dev/null
 	$MOUNT_PROG --make-shared $mpA
 	_get_mount --bind $mpA $mpB
@@ -147,7 +147,7 @@ bind_run()
 	fi
 	_get_mount --bind $mpC $mpD
 	for m in $mpA $mpB $mpC $mpD; do
-		_get_mount $SCRATCH_DEV $m/dir
+		_get_mount -t $FSTYP $SCRATCH_DEV $m/dir
 		fs_stress $m/dir
 		find_mnt
 		_put_mount
diff --git a/tests/generic/410 b/tests/generic/410
index f2e0d1bb..18cb0c1c 100755
--- a/tests/generic/410
+++ b/tests/generic/410
@@ -72,7 +72,7 @@ _supported_fs generic
 _supported_os Linux
 _require_test
 _require_scratch
-_require_block_device $SCRATCH_DEV
+_require_local_device $SCRATCH_DEV
 
 fs_stress()
 {
@@ -120,7 +120,7 @@ start_test()
 	local type=$1
 
 	_scratch_mkfs >$seqres.full 2>&1
-	_get_mount $SCRATCH_DEV $MNTHEAD
+	_get_mount -t $FSTYP $SCRATCH_DEV $MNTHEAD
 	$MOUNT_PROG --make-"${type}" $MNTHEAD
 	mkdir $mpA $mpB $mpC
 }
@@ -143,7 +143,7 @@ run()
 	start_test private
 
 	echo "make-$cmd a $orgs mount"
-	_get_mount $SCRATCH_DEV $mpA
+	_get_mount -t $FSTYP $SCRATCH_DEV $mpA
 	mkdir -p $mpA/dir 2>/dev/null
 	$MOUNT_PROG --make-shared $mpA
 
@@ -165,7 +165,7 @@ run()
 			find_mnt
 		else
 			for m in $mpA $mpB $mpC; do
-				_get_mount $SCRATCH_DEV $m/dir
+				_get_mount -t $FSTYP $SCRATCH_DEV $m/dir
 				fs_stress $m/dir
 				find_mnt
 				_put_mount
diff --git a/tests/generic/411 b/tests/generic/411
index 7b2dd33b..5db49a44 100755
--- a/tests/generic/411
+++ b/tests/generic/411
@@ -53,7 +53,7 @@ _supported_fs generic
 _supported_os Linux
 _require_test
 _require_scratch
-_require_block_device $SCRATCH_DEV
+_require_local_device $SCRATCH_DEV
 
 fs_stress()
 {
@@ -103,7 +103,7 @@ start_test()
 	local type=$1
 
 	_scratch_mkfs >$seqres.full 2>&1
-	_get_mount $SCRATCH_DEV $MNTHEAD
+	_get_mount -t $FSTYP $SCRATCH_DEV $MNTHEAD
 	$MOUNT_PROG --make-"${type}" $MNTHEAD
 	mkdir $mpA $mpB $mpC
 }
@@ -125,17 +125,17 @@ crash_test()
 {
 	start_test shared
 
-	_get_mount $SCRATCH_DEV $mpA
+	_get_mount -t $FSTYP $SCRATCH_DEV $mpA
 	mkdir $mpA/mnt1
 	$MOUNT_PROG --make-shared $mpA
 	_get_mount --bind $mpA $mpB
 	_get_mount --bind $mpA $mpC
 	$MOUNT_PROG --make-slave $mpB
 	$MOUNT_PROG --make-slave $mpC
-	_get_mount $SCRATCH_DEV $mpA/mnt1
+	_get_mount -t $FSTYP $SCRATCH_DEV $mpA/mnt1
 	mkdir $mpA/mnt1/mnt2
 
-	_get_mount $SCRATCH_DEV $mpB/mnt1/mnt2
+	_get_mount -t $FSTYP $SCRATCH_DEV $mpB/mnt1/mnt2
 	find_mnt
 	fs_stress $mpB/mnt1/mnt2
 
-- 
2.12.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/4] Add tests for character devices
  2017-05-31  8:54 ` [PATCH v2 1/4] Add tests for character devices David Oberhollenzer
@ 2017-05-31 11:07   ` Eryu Guan
  0 siblings, 0 replies; 7+ messages in thread
From: Eryu Guan @ 2017-05-31 11:07 UTC (permalink / raw)
  To: David Oberhollenzer; +Cc: fstests, linux-mtd, richard

On Wed, May 31, 2017 at 10:54:30AM +0200, David Oberhollenzer wrote:
> Implement _is_char_dev similar to _is_block_dev to test for
> character devices.
> 
> Add a _require_local_device test. This test is similar to
> _require_block_device but checks if the path refers to a
> block or a character device.
> 
> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>

v2 looks fine to me overall, though I don't have the environment to test
ubifs support.

I have some nits below and to other patches :)

> ---
>  common/rc | 37 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 37 insertions(+)
> 
> diff --git a/common/rc b/common/rc
> index ba215961..ae8ea550 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -1363,6 +1363,26 @@ _is_block_dev()
>      fi
>  }
>  
> +# returns device number if a file is a character device
> +#
> +_is_char_dev()
> +{
> +    if [ $# -ne 1 ]
> +    then
> +	echo "Usage: _is_char_dev dev" 1>&2
> +	exit 1
> +    fi
> +
> +    _dev=$1
> +    if [ -L "${_dev}" ]; then
> +        _dev=`readlink -f "${_dev}"`
> +    fi
> +
> +    if [ -c "${_dev}" ]; then
> +        src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
> +    fi
> +}
> +

Please use one tab for indention for new code, and place 'then' on the
same line as 'if'. (I know this is copied from the old _is_block_dev(),
and the new code style is not documented anywhere yet.. sorry about
that).

Thanks,
Eryu

>  # Do a command, log it to $seqres.full, optionally test return status
>  # and die if command fails. If called with one argument _do executes the
>  # command, logs it, and returns its exit status. With two arguments _do
> @@ -1791,6 +1811,23 @@ _require_block_device()
>  	fi
>  }
>  
> +# this test requires a path to refere to a local block or character device
> +# $1 - device
> +_require_local_device()
> +{
> +	if [ -z "$1" ]; then
> +		echo "Usage: _require_local_device <dev>" 1>&2
> +		exit 1
> +	fi
> +	if [ "`_is_block_dev "$1"`" != "" ]; then
> +		return 0
> +	fi
> +	if [ "`_is_char_dev "$1"`" != "" ]; then
> +		return 0
> +	fi
> +	_notrun "require $1 to be local device"
> +}
> +
>  # brd based ram disks erase the device when they receive a flush command when no
>  # active references are present. This causes problems for DM devices sitting on
>  # top of brd devices as DM doesn't hold active references to the brd device.
> -- 
> 2.12.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/4] Add support for UBIFS
  2017-05-31  8:54 ` [PATCH v2 2/4] Add support for UBIFS David Oberhollenzer
@ 2017-05-31 11:12   ` Eryu Guan
  0 siblings, 0 replies; 7+ messages in thread
From: Eryu Guan @ 2017-05-31 11:12 UTC (permalink / raw)
  To: David Oberhollenzer; +Cc: fstests, linux-mtd, richard

On Wed, May 31, 2017 at 10:54:31AM +0200, David Oberhollenzer wrote:
> UBIFS is a filesystem for unmanaged flash memory devices. It works on top of
> UBI (Unsorted Block Images) which is a wear leveling and volume management
> layer on top of flash memory devices, which are handled by the MTD subsystem
> (memory technology device).
> 
> Since the semantics of flash devices are drastically different from regular
> block devices (blocks or "pages" must be erased before writing, only larger
> groups of pages or "erase blocks" can be erased at once, page write must be
> in order within an erase block, etc...) it was decided to expose MTD devices
> as character devices with ioctls for operations like erase.
> 
> Since erasing a flash erase block causes physical wear on the device,
> eventually causing the erase blocks to go bad, the UBI layer provides mainly
> transparent wear leveling on top of MTD devices. UBI does not attempt to
> emulate a regular block device, but rather something like a flash memory with
> idealized characteristics that can be partitioned into multiple UBI volumes
> in a fashion somewhat similar to LVM. UBI volumes are also exposed to user
> space as character devices.
> 
> This patch mainly deals with some quirks of UBIFS like working on top of
> character devices instead of block devices. Also UBIFS automatically formats
> UBI devices when trying to mount an empty device. The mkfs.ubifs program is
> mainly used for creating images. This patch changes _scratch_mkfs and
> _scratch_mkfs_encrypted to truncate the UBI volume instead, relying on the
> kernel to reformat it on the next mount.
> 
> For _scratch_mkfs_encrypted this is actually required to get the encryption
> tests to run, because mkfs.ubifs, at the time of writing this, the kernel
> support for UBIFS encryption is fairly recent and mkfs.ubifs does not have
> proper support yet.
> 
> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
> ---
>  check          |  2 ++
>  common/config  | 16 +++++++++++++---
>  common/encrypt |  4 ++++
>  common/rc      | 34 ++++++++++++++++++++++++++++++++++
>  4 files changed, 53 insertions(+), 3 deletions(-)
> 
> diff --git a/check b/check
> index 9cef58b4..f8db3cd6 100755
> --- a/check
> +++ b/check
> @@ -70,6 +70,7 @@ check options
>      -overlay		test overlay
>      -pvfs2          test PVFS2
>      -tmpfs              test TMPFS
> +    -ubifs              test ubifs
>      -l			line mode diff
>      -udiff		show unified diff (default)
>      -n			show me, do not run tests
> @@ -267,6 +268,7 @@ while [ $# -gt 0 ]; do
>  	-overlay)	FSTYP=overlay; export OVERLAY=true ;;
>  	-pvfs2)		FSTYP=pvfs2 ;;
>  	-tmpfs)		FSTYP=tmpfs ;;
> +	-ubifs)		FSTYP=ubifs ;;
>  
>  	-g)	group=$2 ; shift ;
>  		GROUP_LIST="$GROUP_LIST ${group//,/ }"
> diff --git a/common/config b/common/config
> index 8211356c..5bf3f65f 100644
> --- a/common/config
> +++ b/common/config
> @@ -320,6 +320,9 @@ _mount_opts()
>  		# We need to specify the size at mount, use 1G by default
>  		export MOUNT_OPTIONS="-o size=1G $TMPFS_MOUNT_OPTIONS"
>  		;;
> +	ubifs)
> +		export MOUNT_OPTIONS=$UBIFS_MOUNT_OPTIONS
> +		;;
>  	*)
>  		;;
>  	esac
> @@ -455,13 +458,20 @@ _check_device()
>  		return 0
>  	fi
>  
> -	if [ "$FSTYP" == "overlay" ]; then
> +	case "$FSTYP" in
> +	overlay)
>  		if [ ! -d "$dev" ]; then
>  			_fatal "common/config: $name ($dev) is not a directory for overlay"
>  		fi
> -	else
> +		;;
> +	ubifs)
> +		if [ ! -c "$dev" ]; then
> +			_fatal "common/config: $name ($dev) is not a character device"
> +		fi
> +		;;
> +	*)
>  		_fatal "common/config: $name ($dev) is not a block device or a network filesystem"
> -	fi
> +	esac
>  }
>  
>  # check and return a canonical mount point path
> diff --git a/common/encrypt b/common/encrypt
> index 723f1b11..83ef918a 100644
> --- a/common/encrypt
> +++ b/common/encrypt
> @@ -71,6 +71,10 @@ _scratch_mkfs_encrypted()
>  	ext4|f2fs)
>  		_scratch_mkfs -O encrypt
>  		;;
> +	ubifs)
> +		# erase the UBI volume; reformated automatically on next mount
> +		ubiupdatevol ${SCRATCH_DEV} -t

$UBIUPDATEVOL_PROG ${SCRATCH_DEV} -t, see below.

> +		;;
>  	*)
>  		_notrun "No encryption support for $FSTYP"
>  		;;
> diff --git a/common/rc b/common/rc
> index ae8ea550..7a97e5d6 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -176,6 +176,11 @@ case "$FSTYP" in
>  	 ;;
>      pvfs2)
>  	;;
> +    ubifs)
> +	if ! type "ubiupdatevol" > /dev/null; then
> +		_fatal "mtd-utils ubiupdatevol not found"
> +	fi
> +	;;

Please define a UBIUPDATEVOL_PROG in common/rc and check for
$UBIUPDATEVOL_PROG here, like other fs types do. Once it's validated, we
can use $UBIUPDATEVOL_PROG elsewhere in fstests.

Thanks,
Eryu

>  esac
>  
>  if [ ! -z "$REPORT_LIST" ]; then
> @@ -812,6 +817,11 @@ _scratch_mkfs()
>  		# do nothing for tmpfs
>  		return 0
>  		;;
> +	ubifs)
> +		# erase the UBI volume; reformated automatically on next mount
> +		ubiupdatevol ${SCRATCH_DEV} -t
> +		return 0
> +		;;
>  	ext4)
>  		_scratch_mkfs_ext4 $*
>  		return $?
> @@ -1576,6 +1586,15 @@ _require_scratch_nocheck()
>  		    _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
>  		fi
>  		;;
> +	ubifs)
> +		# ubifs needs an UBI volume. This will be a char device, not a block device.
> +		if [ ! -c "$SCRATCH_DEV" ]; then
> +			_notrun "this test requires a valid UBI volume for \$SCRATCH_DEV"
> +		fi
> +		if [ ! -d "$SCRATCH_MNT" ]; then
> +			_notrun "this test requires a valid \$SCRATCH_MNT"
> +		fi
> +		;;
>  	*)
>  		 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
>  		 then
> @@ -1670,6 +1689,15 @@ _require_test()
>  		    _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
>  		fi
>  		;;
> +	ubifs)
> +		# ubifs needs an UBI volume. This will be a char device, not a block device.
> +		if [ ! -c "$TEST_DEV" ]; then
> +			_notrun "this test requires a valid UBI volume for \$TEST_DEV"
> +		fi
> +		if [ ! -d "$TEST_DIR" ]; then
> +			_notrun "this test requires a valid \$TEST_DIR"
> +		fi
> +		;;
>  	*)
>  		 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
>  		 then
> @@ -2555,6 +2583,9 @@ _check_test_fs()
>      tmpfs)
>  	# no way to check consistency for tmpfs
>  	;;
> +    ubifs)
> +	# there is no fsck program for ubifs yet
> +	;;
>      *)
>  	_check_generic_filesystem $TEST_DEV
>  	;;
> @@ -2604,6 +2635,9 @@ _check_scratch_fs()
>      tmpfs)
>  	# no way to check consistency for tmpfs
>  	;;
> +    ubifs)
> +	# there is no fsck program for ubifs yet
> +	;;
>      *)
>  	_check_generic_filesystem $device
>  	;;
> -- 
> 2.12.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-05-31 11:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-31  8:54 [PATCH v2] Add UBIFS support to xfstests David Oberhollenzer
2017-05-31  8:54 ` [PATCH v2 1/4] Add tests for character devices David Oberhollenzer
2017-05-31 11:07   ` Eryu Guan
2017-05-31  8:54 ` [PATCH v2 2/4] Add support for UBIFS David Oberhollenzer
2017-05-31 11:12   ` Eryu Guan
2017-05-31  8:54 ` [PATCH v2 3/4] Accept failing with EPERM in addition to ENOKEY for rename without key David Oberhollenzer
2017-05-31  8:54 ` [PATCH v2 4/4] Fix block device requirements and manual scratch mounts David Oberhollenzer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.