fstests: Add support for UBIFS
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Wed, 7 Jun 2017 08:20:45 +0000 (10:20 +0200)
committerEryu Guan <eguan@redhat.com>
Thu, 8 Jun 2017 02:53:27 +0000 (10:53 +0800)
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.

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.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
check
common/config
common/encrypt
common/rc

diff --git a/check b/check
index 9cef58b40bb3adec82518c514ecafa9527d61236..f8db3cd6dfabce81fcbb55e06b9f886a526bc091 100755 (executable)
--- 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//,/ }"
index 090e91175baa866ef1dc6440a7c65b7105d7bb3d..5091db9d50998063f00cbb3d05513722116ea06a 100644 (file)
@@ -199,6 +199,7 @@ export TIMEOUT_PROG="`set_prog_path timeout`"
 export MAN_PROG="`set_prog_path man`"
 export NFS4_SETFACL_PROG="`set_prog_path nfs4_setfacl`"
 export NFS4_GETFACL_PROG="`set_prog_path nfs4_getfacl`"
+export UBIUPDATEVOL_PROG="`set_prog_path ubiupdatevol`"
 
 # use 'udevadm settle' or 'udevsettle' to wait for lv to be settled.
 # newer systems have udevadm command but older systems like RHEL5 don't.
@@ -323,6 +324,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
@@ -458,13 +462,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
index 723f1b111c20eb6a9716f351f78d9053acd8dade..a6fd89d991224136704d105d144d5b43fb4cc4a4 100644 (file)
@@ -71,6 +71,10 @@ _scratch_mkfs_encrypted()
        ext4|f2fs)
                _scratch_mkfs -O encrypt
                ;;
+       ubifs)
+               # erase the UBI volume; reformated automatically on next mount
+               $UBIUPDATEVOL_PROG ${SCRATCH_DEV} -t
+               ;;
        *)
                _notrun "No encryption support for $FSTYP"
                ;;
index d4d2633ec00728670df06f5b8289bd931961c364..ff1b75c9cd253846234b3eebd6c065b6bdba1641 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -177,6 +177,9 @@ case "$FSTYP" in
         ;;
     pvfs2)
        ;;
+    ubifs)
+       [ "$UBIUPDATEVOL_PROG" = "" ] && _fatal "ubiupdatevol not found"
+       ;;
 esac
 
 if [ ! -z "$REPORT_LIST" ]; then
@@ -813,6 +816,11 @@ _scratch_mkfs()
                # do nothing for tmpfs
                return 0
                ;;
+       ubifs)
+               # erase the UBI volume; reformated automatically on next mount
+               $UBIUPDATEVOL_PROG ${SCRATCH_DEV} -t
+               return 0
+               ;;
        ext4)
                _scratch_mkfs_ext4 $*
                return $?
@@ -1576,6 +1584,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 +1687,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 +2581,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 +2633,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
        ;;