fstests: Replace all __[u]intNN_t types with standard [u]intNN_t
[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 # Starting from v4.15-rc1, DAX support was added to dm-log-writes, but note
32 # that it doesn't track the data that we write via the mmap(), so we can't do
33 # any data integrity checking. We can only verify that the metadata writes for
34 # the page faults happened, e.g. when mmap(2) with MAP_SYNC flag.
35 #
36 # Introduce a new helper to check if dm-log-writes target supports DAX
37 # explicitly. But this is considered as a temporary workaround, we want to move
38 # all the DAX check back to _require_log_writes when dm-log-writes gains full
39 # DAX support and remove this helper.
40 _require_log_writes_dax()
41 {
42         [ -z "$LOGWRITES_DEV" -o ! -b "$LOGWRITES_DEV" ] && \
43                 _notrun "This test requires a valid \$LOGWRITES_DEV"
44
45         _require_dm_target log-writes
46         _require_test_program "log-writes/replay-log"
47
48         local ret=0
49         _log_writes_init
50         _log_writes_mkfs > /dev/null 2>&1
51         _log_writes_mount -o dax > /dev/null 2>&1
52         # Check options to be sure. XFS ignores dax option
53         # and goes on if dev underneath does not support dax.
54         _fs_options $LOGWRITES_DMDEV | grep -qw "dax"
55         ret=$?
56         _log_writes_cleanup
57         if [ $ret -ne 0 ]; then
58                 _notrun "$LOGWRITES_DMDEV $FSTYP does not support -o dax"
59         fi
60 }
61
62 _log_writes_init()
63 {
64         local BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
65         LOGWRITES_NAME=logwrites-test
66         LOGWRITES_DMDEV=/dev/mapper/$LOGWRITES_NAME
67         LOGWRITES_TABLE="0 $BLK_DEV_SIZE log-writes $SCRATCH_DEV $LOGWRITES_DEV"
68         $DMSETUP_PROG create $LOGWRITES_NAME --table "$LOGWRITES_TABLE" || \
69                 _fail "failed to create log-writes device"
70         $DMSETUP_PROG mknodes > /dev/null 2>&1
71 }
72
73 _log_writes_mark()
74 {
75         [ $# -ne 1 ] && _fail "_log_writes_mark takes one argument"
76         $DMSETUP_PROG message $LOGWRITES_NAME 0 mark $1
77 }
78
79 _log_writes_mkfs()
80 {
81         _scratch_options mkfs
82         _mkfs_dev $SCRATCH_OPTIONS $LOGWRITES_DMDEV
83         _log_writes_mark mkfs
84 }
85
86 _log_writes_mount()
87 {
88         _scratch_options mount
89         $MOUNT_PROG -t $FSTYP `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
90                 $LOGWRITES_DMDEV $SCRATCH_MNT
91 }
92
93 _log_writes_unmount()
94 {
95         $UMOUNT_PROG $SCRATCH_MNT
96 }
97
98 # _log_writes_replay_log <mark>
99 #
100 # This replays the log contained on $LOGWRITES_DEV onto $SCRATCH_DEV upto the
101 # mark passed in.
102 _log_writes_replay_log()
103 {
104         _mark=$1
105
106         $here/src/log-writes/replay-log --log $LOGWRITES_DEV --find \
107                 --end-mark $_mark >> $seqres.full 2>&1
108         [ $? -ne 0 ] && _fail "mark '$_mark' does not exist"
109
110         $here/src/log-writes/replay-log --log $LOGWRITES_DEV --replay $SCRATCH_DEV \
111                 --end-mark $_mark >> $seqres.full 2>&1
112         [ $? -ne 0 ] && _fail "replay failed"
113 }
114
115 _log_writes_remove()
116 {
117         $DMSETUP_PROG remove $LOGWRITES_NAME > /dev/null 2>&1
118         $DMSETUP_PROG mknodes > /dev/null 2>&1
119 }
120
121 _log_writes_cleanup()
122 {
123         $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
124         # wait for device to be fully settled so that 'dmsetup remove' doesn't
125         # fail due to EBUSY
126         $UDEV_SETTLE_PROG >/dev/null 2>&1
127         _log_writes_remove
128 }