5050
5151typeset datafile1=" $( mktemp -t zvol_misc_fua1.XXXXXX) "
5252typeset datafile2=" $( mktemp -t zvol_misc_fua2.XXXXXX) "
53+ typeset datafile3=" $( mktemp -t zvol_misc_fua3_log.XXXXXX) "
5354typeset zvolpath=${ZVOL_DEVDIR} /$TESTPOOL /$TESTVOL
5455
56+ typeset DISK1=${DISKS%% * }
5557function cleanup
5658{
57- rm " $datafile1 " " $datafile2 "
59+ log_must zpool remove $TESTPOOL $datafile3
60+ rm " $datafile1 " " $datafile2 " " $datafile2 "
61+ }
62+
63+ # Prints the total number of sync writes for a vdev
64+ # $1: vdev
65+ function get_sync
66+ {
67+ zpool iostat -p -H -v -r $TESTPOOL $1 | \
68+ awk ' /[0-9]+$/{s+=$4+$5} END{print s}'
5869}
5970
6071function do_test {
6172 # Wait for udev to create symlinks to our zvol
6273 block_device_wait $zvolpath
6374
75+ # Write using sync (creates FLUSH calls after writes, but not FUA)
76+ old_vdev_writes=$( get_sync $DISK1 )
77+ old_log_writes=$( get_sync $datafile3 )
78+
79+ log_must fio --name=write_iops --size=5M \
80+ --ioengine=libaio --verify=0 --bs=4K \
81+ --iodepth=1 --rw=randwrite --group_reporting=1 \
82+ --filename=$zvolpath --sync=1
83+
84+ vdev_writes=$(( $(get_sync $DISK1 ) - $old_vdev_writes ))
85+ log_writes=$(( $(get_sync $datafile3 ) - $old_log_writes ))
86+
87+ # When we're doing sync writes, we should see many more writes go to
88+ # the log vs the first vdev. Experiments show anywhere from a 160-320x
89+ # ratio of writes to the log vs the first vdev (due to some straggler
90+ # writes to the first vdev).
91+ #
92+ # Check that we have a large ratio (100x) of sync writes going to the
93+ # log device
94+ ratio=$(( $log_writes / $vdev_writes ))
95+ log_note " Got $log_writes log writes, $vdev_writes vdev writes."
96+ if [ $ratio -lt 100 ] ; then
97+ log_fail " Expected > 100x more log writes than vdev writes. "
98+ fi
99+
64100 # Create a data file
65101 log_must dd if=/dev/urandom of=" $datafile1 " bs=1M count=5
66102
@@ -81,6 +117,8 @@ log_assert "Verify that a ZFS volume can do Force Unit Access (FUA)"
81117log_onexit cleanup
82118
83119log_must zfs set compression=off $TESTPOOL /$TESTVOL
120+ log_must truncate -s 100M $datafile3
121+ log_must zpool add $TESTPOOL log $datafile3
84122
85123log_note " Testing without blk-mq"
86124
0 commit comments