]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/openzfs/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_fua.ksh
zfs: merge openzfs/zfs@deb121309
[FreeBSD/FreeBSD.git] / sys / contrib / openzfs / tests / zfs-tests / tests / functional / zvol / zvol_misc / zvol_misc_fua.ksh
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 http://www.opensolaris.org/os/licensing.
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
40 verify_runnable "global"
41
42 if ! is_physical_device $DISKS; then
43         log_unsupported "This directory cannot be run on raw files."
44 fi
45
46 if ! is_linux ; then
47         log_unsupported "Only linux supports dd with oflag=dsync for FUA writes"
48 fi
49
50 typeset datafile1="$(mktemp zvol_misc_fua1.XXXXXX)"
51 typeset datafile2="$(mktemp zvol_misc_fua2.XXXXXX)"
52 typeset zvolpath=${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL
53
54 function cleanup
55 {
56        rm "$datafile1" "$datafile2"
57 }
58
59 function 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
79 log_assert "Verify that a ZFS volume can do Force Unit Access (FUA)"
80 log_onexit cleanup
81
82 log_must zfs set compression=off $TESTPOOL/$TESTVOL
83
84 log_note "Testing without blk-mq"
85
86 set_blk_mq 0
87 log_must zpool export $TESTPOOL
88 log_must zpool import $TESTPOOL
89 do_test
90
91 set_blk_mq 1
92 log_must zpool export $TESTPOOL
93 log_must zpool import $TESTPOOL
94 do_test
95
96 log_pass "ZFS volume FUA works"