]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
common/rc: Add tests for character devices
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Wed, 7 Jun 2017 08:20:44 +0000 (10:20 +0200)
committerEryu Guan <eguan@redhat.com>
Thu, 8 Jun 2017 02:53:27 +0000 (10:53 +0800)
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>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
common/rc

index 87e6ff08b18d4f231534dc34efc20825d18a9cf1..d4d2633ec00728670df06f5b8289bd931961c364 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -1364,6 +1364,25 @@ _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
@@ -1792,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.