]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
dm-error: add functions to create dm-error device
authorAnand Jain <Anand.Jain@oracle.com>
Mon, 21 Sep 2015 03:06:18 +0000 (13:06 +1000)
committerDave Chinner <david@fromorbit.com>
Mon, 21 Sep 2015 03:06:18 +0000 (13:06 +1000)
Controlled EIO from the device is achieved using the dm device.
Helper functions are at common/dmerror.

Broadly steps will include calling _dmerror_init().
_dmerror_init() will use SCRATCH_DEV to create dm linear device and assign
DMERROR_DEV to /dev/mapper/error-test.

When test script is ready to get EIO, the test cases can call
_dmerror_load_table() which then it will load the dm error.
so that reading DMERROR_DEV will cause EIO. After the test case is
complete, cleanup must be done by calling _dmerror_cleanup().

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
common/dmerror [new file with mode: 0644]
common/rc

diff --git a/common/dmerror b/common/dmerror
new file mode 100644 (file)
index 0000000..a81856d
--- /dev/null
@@ -0,0 +1,79 @@
+##/bin/bash
+#
+# Copyright (c) 2015 Oracle.  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
+#
+#
+# common functions for setting up and tearing down a dmerror device
+
+# this test requires the device mapper error target
+#
+_dmerror_required()
+{
+       _require_command "$DMSETUP_PROG" dmsetup
+
+       _require_block_device $SCRATCH_DEV
+       _require_sane_bdev_flush $SCRATCH_DEV
+
+       modprobe dm-mod >/dev/null 2>&1
+       $DMSETUP_PROG targets | grep error >/dev/null 2>&1
+       [ $? -ne 0 ] && _notrun "This test requires dm error support"
+}
+
+_dmerror_init()
+{
+       local dm_backing_dev=$SCRATCH_DEV
+
+       $DMSETUP_PROG remove error-test > /dev/null 2>&1
+
+       local blk_dev_size=`blockdev --getsz $dm_backing_dev`
+
+       DMERROR_DEV='/dev/mapper/error-test'
+
+       DMLINEAR_TABLE="0 $blk_dev_size linear $dm_backing_dev 0"
+
+       $DMSETUP_PROG create error-test --table "$DMLINEAR_TABLE" || \
+               _fatal "failed to create dm linear device"
+
+       DMERROR_TABLE="0 $blk_dev_size error $dm_backing_dev 0"
+}
+
+_dmerror_mount_options()
+{
+       echo `_common_dev_mount_options $*` $DMERROR_DEV $SCRATCH_MNT
+}
+
+_dmerror_mount()
+{
+       _mount -t $FSTYP `_dmerror_mount_options $*`
+}
+
+_dmerror_cleanup()
+{
+       $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
+       $DMSETUP_PROG remove error-test > /dev/null 2>&1
+}
+
+_dmerror_load_table()
+{
+       $DMSETUP_PROG suspend error-test
+       [ $? -ne 0 ] && _fail  "dmsetup suspend failed"
+
+       $DMSETUP_PROG load error-test --table "$DMERROR_TABLE"
+       [ $? -ne 0 ] && _fail "dmsetup failed to load error table"
+
+       $DMSETUP_PROG resume error-test
+       [ $? -ne 0 ] && _fail  "dmsetup resume failed"
+}
index 0049f6ecf5174690798c130941640f1258e87960..1094de4b22eab7be1636f95321bd358d0ca96147 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -211,11 +211,20 @@ _mount_ops_filter()
 
 }
 
+# Used for mounting non-scratch devices (e.g. loop, dm constructs)
+# with the safe set of scratch mount options (e.g. loop image may be
+# hosted on $SCRATCH_DEV, so can't use external scratch devices).
+_common_dev_mount_options()
+{
+       echo $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $*
+}
+
 _scratch_mount_options()
 {
-    _scratch_options mount
+       _scratch_options mount
 
-    echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
+       echo `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
+                                       $SCRATCH_DEV $SCRATCH_MNT
 }
 
 _scratch_mount()