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"
48else
49	if [[ $(linux_version) -gt $(linux_version "6.2") ]]; then
50		log_unsupported "Disabled while issue #14872 is being worked"
51	fi
52
53	# Disabled for the CentOS 9 kernel
54	if [[ $(linux_version) -eq $(linux_version "5.14") ]]; then
55		log_unsupported "Disabled while issue #14872 is being worked"
56	fi
57fi
58
59typeset datafile1="$(mktemp zvol_misc_fua1.XXXXXX)"
60typeset datafile2="$(mktemp zvol_misc_fua2.XXXXXX)"
61typeset zvolpath=${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL
62
63function cleanup
64{
65       rm "$datafile1" "$datafile2"
66}
67
68function do_test {
69	# Wait for udev to create symlinks to our zvol
70	block_device_wait $zvolpath
71
72	# Create a data file
73	log_must dd if=/dev/urandom of="$datafile1" bs=1M count=5
74
75	# Write the data to our zvol using FUA
76	log_must dd if=$datafile1 of=$zvolpath oflag=dsync,direct bs=1M count=5
77
78	# Extract data from our zvol
79	log_must dd if=$zvolpath of="$datafile2" bs=1M count=5
80
81	# Compare the data we expect with what's on our zvol.  diff will return
82	# non-zero if they differ.
83	log_must diff $datafile1 $datafile2
84
85	log_must rm $datafile1 $datafile2
86}
87
88log_assert "Verify that a ZFS volume can do Force Unit Access (FUA)"
89log_onexit cleanup
90
91log_must zfs set compression=off $TESTPOOL/$TESTVOL
92
93log_note "Testing without blk-mq"
94
95set_blk_mq 0
96log_must zpool export $TESTPOOL
97log_must zpool import $TESTPOOL
98do_test
99
100set_blk_mq 1
101log_must zpool export $TESTPOOL
102log_must zpool import $TESTPOOL
103do_test
104
105log_pass "ZFS volume FUA works"
106