1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or https://opensource.org/licenses/CDDL-1.0. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22 23# 24# Copyright (c) 2022 by Lawrence Livermore National Security, LLC. 25# 26 27. $STF_SUITE/include/libtest.shlib 28. $STF_SUITE/tests/functional/zvol/zvol_common.shlib 29 30# 31# DESCRIPTION: 32# Verify that a zvol Force Unit Access (FUA) write works. 33# 34# STRATEGY: 35# 1. dd write 5MB of data with "oflag=dsync,direct" to a zvol. Those flags 36# together do a FUA write. 37# 3. Verify the data is correct. 38# 3. Repeat 1-2 for both the blk-mq and non-blk-mq cases. 39 40verify_runnable "global" 41 42if ! is_physical_device $DISKS; then 43 log_unsupported "This directory cannot be run on raw files." 44fi 45 46if ! is_linux ; then 47 log_unsupported "Only linux supports dd with oflag=dsync for FUA writes" 48fi 49 50typeset datafile1="$(mktemp zvol_misc_fua1.XXXXXX)" 51typeset datafile2="$(mktemp zvol_misc_fua2.XXXXXX)" 52typeset zvolpath=${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL 53 54function cleanup 55{ 56 rm "$datafile1" "$datafile2" 57} 58 59function do_test { 60 # Wait for udev to create symlinks to our zvol 61 block_device_wait $zvolpath 62 63 # Create a data file 64 log_must dd if=/dev/urandom of="$datafile1" bs=1M count=5 65 66 # Write the data to our zvol using FUA 67 log_must dd if=$datafile1 of=$zvolpath oflag=dsync,direct bs=1M count=5 68 69 # Extract data from our zvol 70 log_must dd if=$zvolpath of="$datafile2" bs=1M count=5 71 72 # Compare the data we expect with what's on our zvol. diff will return 73 # non-zero if they differ. 74 log_must diff $datafile1 $datafile2 75 76 log_must rm $datafile1 $datafile2 77} 78 79log_assert "Verify that a ZFS volume can do Force Unit Access (FUA)" 80log_onexit cleanup 81 82log_must zfs set compression=off $TESTPOOL/$TESTVOL 83 84log_note "Testing without blk-mq" 85 86set_blk_mq 0 87log_must zpool export $TESTPOOL 88log_must zpool import $TESTPOOL 89do_test 90 91set_blk_mq 1 92log_must zpool export $TESTPOOL 93log_must zpool import $TESTPOOL 94do_test 95 96log_pass "ZFS volume FUA works" 97