]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_006_pos.ksh
Add the ZFS Test Suite
[mirror_zfs.git] / tests / zfs-tests / tests / functional / zvol / zvol_swap / zvol_swap_006_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 by Delphix. All rights reserved.
30 #
31
32 . $STF_SUITE/include/libtest.shlib
33 . $STF_SUITE/tests/functional/zvol/zvol_common.shlib
34
35 #
36 # DESCRIPTION:
37 # A volume can be added as several segments, but overlapping segments
38 # are not allowed.
39 #
40 # STRATEGY:
41 # 1. Figure out three groups swaplow and swaplen.
42 # 2. Verify different volume segments can be added correctly.
43 # 3. Verify overlapping swap volume are not allowed.
44 #
45
46 verify_runnable "global"
47
48 function cleanup
49 {
50 typeset -i i=0
51
52 while ((count > 0)); do
53 log_must $SWAP -d $swapname ${swap_opt[$i]}
54
55 ((i += 2))
56 ((count -= 1))
57 done
58 }
59
60 log_assert "Verify volume can be add as several segments, but overlapping " \
61 "are not allowed."
62 log_onexit cleanup
63
64 # swap -a won't allow the use of multiple segments of the same volume unless
65 # libdiskmgmt is disabled with the environment variable below.
66 typeset -x NOINUSE_CHECK=1
67
68 typeset vol=$TESTPOOL/$TESTVOL
69 typeset -i pageblocks volblocks
70 ((pageblocks = $($PAGESIZE) / 512))
71 ((volblocks = $(get_prop volsize $vol) / 512))
72
73 log_note "Verify volume can be add as several segments."
74
75 #
76 # swaplow swaplen
77 set -A swap_opt $((pageblocks)) \
78 $((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \
79 $((volblocks / 3)) \
80 $((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \
81 $((volblocks / 2)) \
82 $((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \
83 $(((volblocks*2) / 3)) \
84 $((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) ))
85
86 swapname=${ZVOL_DEVDIR}/$vol
87 typeset -i i=0 count=0
88
89 if is_swap_inuse $swapname ; then
90 log_must $SWAP -d $swapname
91 fi
92
93 while ((i < ${#swap_opt[@]})); do
94 log_must $SWAP -a $swapname ${swap_opt[$i]} ${swap_opt[((i+1))]}
95
96 ((i += 2))
97 ((count += 1))
98 done
99
100 log_note "Verify overlapping swap volume are not allowed"
101 i=0
102 while ((i < ${#swap_opt[@]})); do
103 log_mustnot $SWAP -a $swapname ${swap_opt[$i]}
104
105 ((i += 2))
106 done
107
108 log_pass "Verify volume can be added as several segments passed."