replay-log: add support for replaying ops in target device sector range
[xfstests-dev.git] / common / dmhugedisk
1 ##/bin/bash
2 # Routines for creating huge (fake) disks
3 #-----------------------------------------------------------------------
4 #  Copyright (c) 2016 Oracle.  All Rights Reserved.
5 #  This program is free software; you can redistribute it and/or modify
6 #  it under the terms of the GNU General Public License as published by
7 #  the Free Software Foundation; either version 2 of the License, or
8 #  (at your option) any later version.
9 #
10 #  This program is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #  GNU General Public License for more details.
14 #
15 #  You should have received a copy of the GNU General Public License
16 #  along with this program; if not, write to the Free Software
17 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 #  USA
19 #
20 #  Contact information: Oracle Corporation, 500 Oracle Parkway,
21 #  Redwood Shores, CA 94065, USA, or: http://www.oracle.com/
22 #-----------------------------------------------------------------------
23
24 _require_dmhugedisk()
25 {
26         _require_dm_target zero
27         _require_dm_target snapshot
28 }
29
30 _dmhugedisk_init()
31 {
32         test -z "$1" && _fatal "must specify sector count to _dmhugedisk_init"
33         local dm_backing_dev=$SCRATCH_DEV
34
35         $DMSETUP_PROG remove huge-test > /dev/null 2>&1
36         $DMSETUP_PROG remove huge-test-zero > /dev/null 2>&1
37
38         local blk_dev_size=$1
39
40         DMHUGEDISK_ZERO='/dev/mapper/huge-test-zero'
41         DMHUGEDISK_DEV='/dev/mapper/huge-test'
42
43         DMHUGEDISK_ZERO_TABLE="0 $blk_dev_size zero"
44         DMHUGEDISK_DEV_TABLE="0 $blk_dev_size snapshot $DMHUGEDISK_ZERO $SCRATCH_DEV N 512"
45
46         $DMSETUP_PROG create huge-test-zero --table "$DMHUGEDISK_ZERO_TABLE" || \
47                 _fatal "failed to create dm huge zero device"
48         $DMSETUP_PROG create huge-test --table "$DMHUGEDISK_DEV_TABLE" || \
49                 _fatal "failed to create dm huge device"
50 }
51
52 _dmhugedisk_cleanup()
53 {
54         $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
55         # wait for device to be fully settled so that 'dmsetup remove' doesn't
56         # fail due to EBUSY
57         $UDEV_SETTLE_PROG >/dev/null 2>&1
58         $DMSETUP_PROG remove huge-test > /dev/null 2>&1
59         $DMSETUP_PROG remove huge-test-zero > /dev/null 2>&1
60 }