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