]> git.proxmox.com Git - mirror_zfs.git/blame - tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_002_pos.ksh
ZTS: normalize on use of `sync_pool` and `sync_all_pools`
[mirror_zfs.git] / tests / zfs-tests / tests / functional / zvol / zvol_misc / zvol_misc_002_pos.ksh
CommitLineData
6bb24f4d
BB
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#
c1d9abf9 29# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
43bd43f9 30# Copyright 2016 Nexenta Systems, Inc.
6bb24f4d
BB
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
45verify_runnable "global"
46
c1d9abf9 47volsize=$(zfs get -H -o value volsize $TESTPOOL/$TESTVOL)
3d3fe9f9 48
6bb24f4d
BB
49function cleanup
50{
51 snapexists $TESTPOOL/$TESTVOL@snap && \
90b77a03 52 destroy_dataset $TESTPOOL/$TESTVOL@snap
6bb24f4d 53
8c54ddd3 54 ismounted $TESTDIR $NEWFS_DEFAULT_FS
c1d9abf9 55 (( $? == 0 )) && log_must umount $TESTDIR
6bb24f4d 56
c1d9abf9 57 zfs set volsize=$volsize $TESTPOOL/$TESTVOL
6bb24f4d
BB
58}
59
60log_assert "Verify that ZFS volume snapshot could be fscked"
61log_onexit cleanup
62
63TESTVOL='testvol'
64BLOCKSZ=$(( 1024 * 1024 ))
65NUM_WRITES=40
66
c1d9abf9 67log_must zfs set volsize=128m $TESTPOOL/$TESTVOL
3d3fe9f9 68
7839c4b5 69log_must new_fs ${ZVOL_RDEVDIR}/$TESTPOOL/$TESTVOL
6bb24f4d 70
c1d9abf9 71log_must mount ${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL $TESTDIR
6bb24f4d
BB
72
73typeset -i fn=0
74typeset -i retval=0
75
76while (( 1 )); do
ea8c83fd
YP
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 ))
6bb24f4d
BB
84done
85
7839c4b5 86if is_linux || is_freebsd ; then
7454275a 87 sync_all_pools
8c54ddd3 88else
8c54ddd3
BB
89 log_must lockfs -f $TESTDIR
90fi
91
92log_must zfs set snapdev=visible $TESTPOOL/$TESTVOL
c1d9abf9 93log_must zfs snapshot $TESTPOOL/$TESTVOL@snap
8c54ddd3 94block_device_wait
6bb24f4d 95
8c54ddd3 96fsck -n ${ZVOL_RDEVDIR}/$TESTPOOL/$TESTVOL@snap >/dev/null 2>&1
6bb24f4d 97retval=$?
c89a02a2
TH
98
99if [ $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 #
c89a02a2
TH
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
8c54ddd3 115fi
6bb24f4d
BB
116
117log_pass "Verify that ZFS volume snapshot could be fscked"