1#!/bin/ksh -p 2 3# 4# This file and its contents are supplied under the terms of the 5# Common Development and Distribution License ("CDDL"), version 1.0. 6# You may only use this file in accordance with the terms of version 7# 1.0 of the CDDL. 8# 9# A full copy of the text of the CDDL should have accompanied this 10# source. A copy of the CDDL is also available via the Internet at 11# http://www.illumos.org/license/CDDL. 12# 13 14# 15# Copyright (c) 2018 by Delphix. All rights reserved. 16# 17 18. $STF_SUITE/tests/functional/alloc_class/alloc_class.kshlib 19 20# 21# DESCRIPTION: 22# Removing a special device from a pool succeeds. 23# 24 25verify_runnable "global" 26 27# 28# Verify the file identified by the input <inode> is written on a special vdev 29# According to the pool layout used in this test vdev_id 3 and 4 are special 30# XXX: move this function to libtest.shlib once we get "Vdev Properties" 31# 32function file_in_special_vdev # <dataset> <inode> 33{ 34 typeset dataset="$1" 35 typeset inum="$2" 36 typeset num_normal=$(echo $ZPOOL_DISKS | wc -w) 37 num_normal=${num_normal##* } 38 39 zdb -dddddd $dataset $inum | awk -v d=$num_normal '{ 40# find DVAs from string "offset level dva" only for L0 (data) blocks 41if (match($0,"L0 [0-9]+")) { 42 dvas[0]=$3 43 dvas[1]=$4 44 dvas[2]=$5 45 for (i = 0; i < 3; ++i) { 46 if (match(dvas[i],"([^:]+):.*")) { 47 dva = substr(dvas[i], RSTART, RLENGTH); 48 # parse DVA from string "vdev:offset:asize" 49 if (split(dva,arr,":") != 3) { 50 print "Error parsing DVA: <" dva ">"; 51 exit 1; 52 } 53 # verify vdev is "special" 54 if (arr[1] < d) { 55 exit 1; 56 } 57 } 58 } 59}}' 60} 61 62# 63# Check that device removal works for special class vdevs 64# 65function check_removal 66{ 67 # 68 # Create a non-raidz pool so we can remove top-level vdevs 69 # 70 log_must disk_setup 71 log_must zpool create $TESTPOOL $ZPOOL_DISKS \ 72 special $CLASS_DISK0 special $CLASS_DISK1 73 log_must display_status "$TESTPOOL" 74 75 # 76 # Generate some metadata and small blocks in the special class vdev 77 # before removal 78 # 79 typeset -l i=1 80 typeset -l blocks=25 81 82 log_must zfs create -o special_small_blocks=32K -o recordsize=32K \ 83 $TESTPOOL/$TESTFS 84 for i in 1 2 3 4; do 85 log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/testfile.$i \ 86 bs=1M count=$blocks 87 ((blocks = blocks + 25)) 88 done 89 sync_pool $TESTPOOL 90 log_must zpool list -v $TESTPOOL 91 92 # Verify the files were written in the special class vdevs 93 for i in 1 2 3 4; do 94 dataset="$TESTPOOL/$TESTFS" 95 inum="$(get_objnum /$TESTPOOL/$TESTFS/testfile.$i)" 96 log_must file_in_special_vdev $dataset $inum 97 done 98 99 log_must zpool remove $TESTPOOL $CLASS_DISK0 100 101 sleep 5 102 sync_pool $TESTPOOL 103 sleep 1 104 105 log_must zdb -bbcc $TESTPOOL 106 log_must zpool list -v $TESTPOOL 107 log_must zpool destroy -f "$TESTPOOL" 108 log_must disk_cleanup 109} 110 111claim="Removing a special device from a pool succeeds." 112 113log_assert $claim 114log_onexit cleanup 115 116typeset CLASS_DEVSIZE=$CLASS_DEVSIZE 117for CLASS_DEVSIZE in $CLASS_DEVSIZE $ZPOOL_DEVSIZE; do 118 typeset ZPOOL_DISKS=$ZPOOL_DISKS 119 for ZPOOL_DISKS in "$ZPOOL_DISKS" $ZPOOL_DISK0; do 120 check_removal 121 done 122done 123 124log_pass $claim 125