]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_002_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / zvol / zvol_misc / zvol_misc_002_pos.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 2008 Sun Microsystems, Inc.  All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30 # Copyright 2016 Nexenta Systems, Inc.
31 #
32
33 . $STF_SUITE/include/libtest.shlib
34
35 #
36 # DESCRIPTION:
37 # Verify that ZFS volume snapshot could be fscked
38 #
39 # STRATEGY:
40 # 1. Create a ZFS volume
41 # 2. Copy some files and create snapshot
42 # 3. Verify fsck on the snapshot is OK
43 #
44
45 verify_runnable "global"
46
47 volsize=$(zfs get -H -o value volsize $TESTPOOL/$TESTVOL)
48
49 function cleanup
50 {
51         snapexists $TESTPOOL/$TESTVOL@snap && \
52                 zfs destroy $TESTPOOL/$TESTVOL@snap
53
54         ismounted $TESTDIR $NEWFS_DEFAULT_FS
55         (( $? == 0 )) && log_must umount $TESTDIR
56
57         zfs set volsize=$volsize $TESTPOOL/$TESTVOL
58 }
59
60 log_assert "Verify that ZFS volume snapshot could be fscked"
61 log_onexit cleanup
62
63 TESTVOL='testvol'
64 BLOCKSZ=$(( 1024 * 1024 ))
65 NUM_WRITES=40
66
67 log_must zfs set volsize=128m $TESTPOOL/$TESTVOL
68
69 log_must new_fs ${ZVOL_RDEVDIR}/$TESTPOOL/$TESTVOL
70
71 log_must mount ${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL $TESTDIR
72
73 typeset -i fn=0
74 typeset -i retval=0
75
76 while (( 1 )); do
77         file_write -o create -f $TESTDIR/testfile$$.$fn \
78             -b $BLOCKSZ -c $NUM_WRITES
79         retval=$?
80         if (( $retval != 0 )); then
81                 break
82         fi
83         (( fn = fn + 1 ))
84 done
85
86 if is_linux || is_freebsd ; then
87         log_must sync
88 else
89         log_must lockfs -f $TESTDIR
90 fi
91
92 log_must zfs set snapdev=visible $TESTPOOL/$TESTVOL
93 log_must zfs snapshot $TESTPOOL/$TESTVOL@snap
94 block_device_wait
95
96 fsck -n ${ZVOL_RDEVDIR}/$TESTPOOL/$TESTVOL@snap >/dev/null 2>&1
97 retval=$?
98
99 if [ $retval -ne 0 ] ; then
100         if is_linux ; then
101                 # Linux's fsck returns a different code for this test depending
102                 # on the version:
103                 #
104                 # e2fsprogs-1.43.3 (Fedora 25 and older): returns 4
105                 # e2fsprogs-1.43.4 (Fedora 26): returns 8
106                 #
107                 if [ $retval -ne 4 -a $retval -ne 8 ] ; then
108                         log_fail "fsck exited with wrong value $retval"
109                 fi
110         else
111                 if [ $retval -ne 39 ] ; then
112                         log_fail "fsck exited with wrong value $retval"
113                 fi
114         fi
115 fi
116
117 log_pass "Verify that ZFS volume snapshot could be fscked"