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, 2016 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# block_size: is the block size of the volume 40# 41function default_zvol_setup # disk_device volume_size block_size 42{ 43 typeset disk=$1 44 typeset size=$2 45 typeset blocksize=$3 46 typeset savedumpdev 47 typeset -i output 48 typeset create_args 49 50 create_pool $TESTPOOL "$disk" 51 52 if [ -n "$blocksize" ]; then 53 create_args="-b $blocksize" 54 fi 55 56 log_must zfs create $create_args -V $size $TESTPOOL/$TESTVOL 57 block_device_wait 58} 59 60# 61# Destroy the default zvol which was setup using 62# default_zvol_setup(). 63# 64function default_zvol_cleanup 65{ 66 if datasetexists $TESTPOOL/$TESTVOL ; then 67 log_must zfs destroy $TESTPOOL/$TESTVOL 68 fi 69 70 destroy_pool $TESTPOOL 71} 72 73function get_dumpdevice 74{ 75 typeset ret=$(dumpadm | grep "Dump device:" | awk '{print $3}') 76 echo $ret 77} 78 79function set_dumpsize 80{ 81 typeset volume=$1 82 83 if [[ -z $volume ]] ; then 84 log_note "No volume specified." 85 return 1 86 fi 87 88 log_must zfs set volsize=64m $volume 89 90 output=$(dumpadm -d /dev/zvol/dsk/$volume 2>&1 | \ 91 tail -1 | awk '{print $3}') 92 93 if [[ -n $output ]]; then 94 (( output = output / 1024 / 1024 )) 95 (( output = output + output / 5 )) 96 log_must zfs set volsize=${output}m $volume 97 fi 98 99 return 0 100} 101 102function safe_dumpadm 103{ 104 typeset device=$1 105 106 if [[ -z $device || $device == "none" ]] ; then 107 log_note "No dump device volume specified." 108 return 1 109 fi 110 if [[ $device == "${ZVOL_DEVDIR}/"* ]] ; then 111 typeset volume=${device#${ZVOL_DEVDIR}/} 112 set_dumpsize $volume 113 log_must dumpadm -d $device 114 else 115 log_must swapadd 116 if ! is_swap_inuse $device ; then 117 log_must swap -a $device 118 fi 119 log_must dumpadm -d swap 120 fi 121} 122 123function is_zvol_dumpified 124{ 125 typeset volume=$1 126 127 if [[ -z $volume ]] ; then 128 log_note "No volume specified." 129 return 1 130 fi 131 132 zdb -dddd $volume 2 | grep "dumpsize" > /dev/null 2>&1 133 return $? 134} 135