1#!/bin/ksh -p 2# SPDX-License-Identifier: CDDL-1.0 3# 4# CDDL HEADER START 5# 6# The contents of this file are subject to the terms of the 7# Common Development and Distribution License (the "License"). 8# You may not use this file except in compliance with the License. 9# 10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11# or https://opensource.org/licenses/CDDL-1.0. 12# See the License for the specific language governing permissions 13# and limitations under the License. 14# 15# When distributing Covered Code, include this CDDL HEADER in each 16# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17# If applicable, add the following below this CDDL HEADER, with the 18# fields enclosed by brackets "[]" replaced with your own identifying 19# information: Portions Copyright [yyyy] [name of copyright owner] 20# 21# CDDL HEADER END 22# 23 24# 25# Copyright (c) 2022 by Lawrence Livermore National Security, LLC. 26# 27 28. $STF_SUITE/include/libtest.shlib 29. $STF_SUITE/tests/functional/zvol/zvol_common.shlib 30 31# 32# DESCRIPTION: 33# Verify that a zvol Force Unit Access (FUA) write works. 34# 35# STRATEGY: 36# 1. dd write 5MB of data with "oflag=dsync,direct" to a zvol. Those flags 37# together do a FUA write. 38# 3. Verify the data is correct. 39# 3. Repeat 1-2 for both the blk-mq and non-blk-mq cases. 40 41verify_runnable "global" 42 43if ! is_physical_device $DISKS; then 44 log_unsupported "This directory cannot be run on raw files." 45fi 46 47if ! is_linux ; then 48 log_unsupported "Only linux supports dd with oflag=dsync for FUA writes" 49fi 50 51typeset datafile1="$(mktemp -t zvol_misc_fua1.XXXXXX)" 52typeset datafile2="$(mktemp -t zvol_misc_fua2.XXXXXX)" 53typeset datafile3="$(mktemp -t zvol_misc_fua3_log.XXXXXX)" 54typeset zvolpath=${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL 55 56typeset DISK1=${DISKS%% *} 57function cleanup 58{ 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 65function get_sync 66{ 67 zpool iostat -p -H -v -r $TESTPOOL $1 | \ 68 awk '/[0-9]+$/{s+=$4+$5} END{print s}' 69} 70 71function do_test { 72 # Wait for udev to create symlinks to our zvol 73 block_device_wait $zvolpath 74 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 100 # Create a data file 101 log_must dd if=/dev/urandom of="$datafile1" bs=1M count=5 102 103 # Write the data to our zvol using FUA 104 log_must dd if=$datafile1 of=$zvolpath oflag=dsync,direct bs=1M count=5 105 106 # Extract data from our zvol 107 log_must dd if=$zvolpath of="$datafile2" bs=1M count=5 108 109 # Compare the data we expect with what's on our zvol. diff will return 110 # non-zero if they differ. 111 log_must diff $datafile1 $datafile2 112 113 log_must rm $datafile1 $datafile2 114} 115 116log_assert "Verify that a ZFS volume can do Force Unit Access (FUA)" 117log_onexit cleanup 118 119log_must zfs set compression=off $TESTPOOL/$TESTVOL 120log_must truncate -s 100M $datafile3 121log_must zpool add $TESTPOOL log $datafile3 122 123log_note "Testing without blk-mq" 124 125set_blk_mq 0 126log_must zpool export $TESTPOOL 127log_must zpool import $TESTPOOL 128do_test 129 130set_blk_mq 1 131log_must zpool export $TESTPOOL 132log_must zpool import $TESTPOOL 133do_test 134 135log_pass "ZFS volume FUA works" 136