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