common/fuzzy: if the fuzz verb is random, keep fuzzing until we get a new value
[xfstests-dev.git] / common / dmlogwrites
1 ##/bin/bash
2 #
3 # Copyright (c) 2015 Facebook, Inc.  All Rights Reserved.
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it would be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write the Free Software Foundation,
16 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17 #
18 #
19 # common functions for setting up and tearing down a dm log-writes device
20
21 _require_log_writes()
22 {
23         [ -z "$LOGWRITES_DEV" -o ! -b "$LOGWRITES_DEV" ] && \
24                 _notrun "This test requires a valid \$LOGWRITES_DEV"
25
26         _exclude_scratch_mount_option dax
27         _require_dm_target log-writes
28         _require_test_program "log-writes/replay-log"
29 }
30
31 _log_writes_init()
32 {
33         local BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
34         LOGWRITES_NAME=logwrites-test
35         LOGWRITES_DMDEV=/dev/mapper/$LOGWRITES_NAME
36         LOGWRITES_TABLE="0 $BLK_DEV_SIZE log-writes $SCRATCH_DEV $LOGWRITES_DEV"
37         $DMSETUP_PROG create $LOGWRITES_NAME --table "$LOGWRITES_TABLE" || \
38                 _fail "failed to create log-writes device"
39         $DMSETUP_PROG mknodes > /dev/null 2>&1
40 }
41
42 _log_writes_mark()
43 {
44         [ $# -ne 1 ] && _fail "_log_writes_mark takes one argument"
45         $DMSETUP_PROG message $LOGWRITES_NAME 0 mark $1
46 }
47
48 _log_writes_mkfs()
49 {
50         _scratch_options mkfs
51         _mkfs_dev $SCRATCH_OPTIONS $LOGWRITES_DMDEV
52         _log_writes_mark mkfs
53 }
54
55 _log_writes_mount()
56 {
57         _scratch_options mount
58         $MOUNT_PROG -t $FSTYP `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
59                 $LOGWRITES_DMDEV $SCRATCH_MNT
60 }
61
62 _log_writes_unmount()
63 {
64         $UMOUNT_PROG $SCRATCH_MNT
65 }
66
67 # _log_writes_replay_log <mark>
68 #
69 # This replays the log contained on $LOGWRITES_DEV onto $SCRATCH_DEV upto the
70 # mark passed in.
71 _log_writes_replay_log()
72 {
73         _mark=$1
74
75         $here/src/log-writes/replay-log --log $LOGWRITES_DEV --replay $SCRATCH_DEV \
76                 --end-mark $_mark >> $seqres.full 2>&1
77         [ $? -ne 0 ] && _fail "replay failed"
78 }
79
80 _log_writes_remove()
81 {
82         $DMSETUP_PROG remove $LOGWRITES_NAME > /dev/null 2>&1
83         $DMSETUP_PROG mknodes > /dev/null 2>&1
84 }
85
86 _log_writes_cleanup()
87 {
88         $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
89         _log_writes_remove
90 }