Print this page
12181 zvol swap tests should avoid grep -w
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/test/zfs-tests/tests/functional/zvol/zvol_common.shlib
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_common.shlib
1 1 #
2 2 # CDDL HEADER START
3 3 #
4 4 # The contents of this file are subject to the terms of the
5 5 # Common Development and Distribution License (the "License").
6 6 # You may not use this file except in compliance with the License.
7 7 #
8 8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 # or http://www.opensolaris.org/os/licensing.
10 10 # See the License for the specific language governing permissions
11 11 # and limitations under the License.
12 12 #
13 13 # When distributing Covered Code, include this CDDL HEADER in each
14 14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 # If applicable, add the following below this CDDL HEADER, with the
16 16 # fields enclosed by brackets "[]" replaced with your own identifying
17 17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 18 #
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
19 19 # CDDL HEADER END
20 20 #
21 21
22 22 #
23 23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 24 # Use is subject to license terms.
25 25 #
26 26
27 27 #
28 28 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
29 +# Copyright 2020 Joyent, Inc.
29 30 #
30 31
31 32 . $STF_SUITE/include/libtest.shlib
32 33 . $STF_SUITE/tests/functional/zvol/zvol.cfg
33 34
34 35 #
35 36 # Create a simple zvol volume
36 37 #
37 38 # Where disk_device: is the name of the disk to be used
38 39 # volume_size: is the size of the volume, e.g. 2G
39 40 #
40 41 function default_zvol_setup # disk_device volume_size
41 42 {
42 43 typeset disk=$1
43 44 typeset size=$2
44 45 typeset savedumpdev
45 46 typeset -i output
46 47
47 48 create_pool $TESTPOOL "$disk"
48 49
49 50 log_must zfs create -V $size $TESTPOOL/$TESTVOL
50 51 }
51 52
52 53 #
53 54 # Destroy the default zvol which was setup using
54 55 # default_zvol_setup().
55 56 #
56 57 function default_zvol_cleanup
57 58 {
58 59 if datasetexists $TESTPOOL/$TESTVOL ; then
59 60 log_must zfs destroy $TESTPOOL/$TESTVOL
60 61 fi
61 62
62 63 destroy_pool $TESTPOOL
63 64 }
64 65
65 66 function get_dumpdevice
66 67 {
67 68 typeset ret=$(dumpadm | grep "Dump device:" | awk '{print $3}')
68 69 echo $ret
69 70 }
70 71
71 72 function set_dumpsize
72 73 {
73 74 typeset volume=$1
74 75
75 76 if [[ -z $volume ]] ; then
76 77 log_note "No volume specified."
77 78 return 1
78 79 fi
79 80
80 81 log_must zfs set volsize=64m $volume
81 82
82 83 output=$(dumpadm -d /dev/zvol/dsk/$volume 2>&1 | \
83 84 tail -1 | awk '{print $3}')
84 85
85 86 if [[ -n $output ]]; then
86 87 (( output = output / 1024 / 1024 ))
87 88 (( output = output + output / 5 ))
88 89 log_must zfs set volsize=${output}m $volume
89 90 fi
90 91 return 0
91 92 }
92 93
93 94 function safe_dumpadm
94 95 {
95 96 typeset device=$1
96 97
97 98 if [[ -z $device || $device == "none" ]] ; then
98 99 log_note "No dump device volume specified."
99 100 return 1
100 101 fi
101 102 if [[ $device == "/dev/zvol/dsk/"* ]] ; then
102 103 typeset volume=${device#/dev/zvol/dsk/}
103 104 set_dumpsize $volume
104 105 log_must dumpadm -d $device
105 106 else
106 107 log_must swapadd
107 108 if ! is_swap_inuse $device ; then
108 109 log_must swap -a $device
109 110 fi
110 111 log_must dumpadm -d swap
111 112 fi
112 113 }
113 114
114 115 function is_zvol_dumpified
115 116 {
116 117 typeset volume=$1
117 118
118 119 if [[ -z $volume ]] ; then
119 120 log_note "No volume specified."
120 121 return 1
121 122 fi
122 123
123 124 zdb -dddd $volume 2 | grep "dumpsize" > /dev/null 2>&1
124 125 return $?
125 126 }
↓ open down ↓ |
87 lines elided |
↑ open up ↑ |
126 127
127 128 function is_swap_inuse
128 129 {
129 130 typeset device=$1
130 131
131 132 if [[ -z $device ]] ; then
132 133 log_note "No device specified."
133 134 return 1
134 135 fi
135 136
136 - swap -l | grep -w $device > /dev/null 2>&1
137 + swap -l | awk 'NR > 1 { print $1 }' | \
138 + grep "^$device\$" > /dev/null 2>&1
137 139 return $?
138 140 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX