3 # Copyright (c) 2015 Facebook, Inc. All Rights Reserved.
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.
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.
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
19 # common functions for setting up and tearing down a dm log-writes device
23 [ -z "$LOGWRITES_DEV" -o ! -b "$LOGWRITES_DEV" ] && \
24 _notrun "This test requires a valid \$LOGWRITES_DEV"
26 _exclude_scratch_mount_option dax
27 _require_dm_target log-writes
28 _require_test_program "log-writes/replay-log"
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.
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()
42 [ -z "$LOGWRITES_DEV" -o ! -b "$LOGWRITES_DEV" ] && \
43 _notrun "This test requires a valid \$LOGWRITES_DEV"
45 _require_dm_target log-writes
46 _require_test_program "log-writes/replay-log"
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"
57 if [ $ret -ne 0 ]; then
58 _notrun "$LOGWRITES_DMDEV $FSTYP does not support -o dax"
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
75 [ $# -ne 1 ] && _fail "_log_writes_mark takes one argument"
76 $DMSETUP_PROG message $LOGWRITES_NAME 0 mark $1
82 _mkfs_dev $SCRATCH_OPTIONS $LOGWRITES_DMDEV
88 _scratch_options mount
89 $MOUNT_PROG -t $FSTYP `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
90 $LOGWRITES_DMDEV $SCRATCH_MNT
95 $UMOUNT_PROG $SCRATCH_MNT
98 # _log_writes_replay_log <mark>
100 # This replays the log contained on $LOGWRITES_DEV onto $SCRATCH_DEV upto the
102 _log_writes_replay_log()
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"
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"
117 $DMSETUP_PROG remove $LOGWRITES_NAME > /dev/null 2>&1
118 $DMSETUP_PROG mknodes > /dev/null 2>&1
121 _log_writes_cleanup()
123 $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
124 # wait for device to be fully settled so that 'dmsetup remove' doesn't
126 $UDEV_SETTLE_PROG >/dev/null 2>&1
130 # Convert log writes mark to entry number
131 # Result entry number is output to stdout, could be empty if not found
132 _log_writes_mark_to_entry_number()
137 [ -z "$mark" ] && _fatal \
138 "mark must be given for _log_writes_mark_to_entry_number"
140 ret=$($here/src/log-writes/replay-log --find --log $LOGWRITES_DEV \
141 --end-mark $mark 2> /dev/null)
142 [ -z "$ret" ] && return
143 ret=$(echo "$ret" | cut -f1 -d\@)
144 echo "mark $mark has entry number $ret" >> $seqres.full
148 # Find next fua write entry number
149 # Result entry number is output to stdout, could be empty if not found
150 _log_writes_find_next_fua()
155 [ -z "$start_entry" ] && start_entry=0
156 ret=$($here/src/log-writes/replay-log --find --log $LOGWRITES_DEV \
157 --next-fua --start-entry $start_entry 2> /dev/null)
158 [ -z "$ret" ] && return
160 # Result should be something like "1024@offset" where 1024 is the
161 # entry number we need
162 ret=$(echo "$ret" | cut -f1 -d\@)
163 echo "next fua is entry number $ret" >> $seqres.full
167 # Replay log range to specified entry
168 # $1: End entry. The entry with this number *WILL* be replayed
169 _log_writes_replay_log_range()
173 [ -z "$end" ] && _fail \
174 "end entry must be specified for _log_writes_replay_log_range"
176 # To ensure we replay the last entry,
177 # we need to manually increase the end entry number to ensure
179 echo "=== replay to $end ===" >> $seqres.full
180 $here/src/log-writes/replay-log --log $LOGWRITES_DEV \
181 --replay $SCRATCH_DEV --limit $(($end + 1)) \
183 [ $? -ne 0 ] && _fail "replay failed"