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 | xargs) 37 38 zdb -dddddd $dataset $inum | awk -v d=$num_normal '{ 39# find DVAs from string "offset level dva" only for L0 (data) blocks 40if (match($0,"L0 [0-9]+")) { 41 dvas[0]=$3 42 dvas[1]=$4 43 dvas[2]=$5 44 for (i = 0; i < 3; ++i) { 45 if (match(dvas[i],"([^:]+):.*")) { 46 dva = substr(dvas[i], RSTART, RLENGTH); 47 # parse DVA from string "vdev:offset:asize" 48 if (split(dva,arr,":") != 3) { 49 print "Error parsing DVA: <" dva ">"; 50 exit 1; 51 } 52 # verify vdev is "special" 53 if (arr[1] < d) { 54 exit 1; 55 } 56 } 57 } 58}}' 59} 60 61# 62# Check that device removal works for special class vdevs 63# 64function check_removal 65{ 66 # 67 # Create a non-raidz pool so we can remove top-level vdevs 68 # 69 log_must disk_setup 70 log_must zpool create $TESTPOOL $ZPOOL_DISKS \ 71 special $CLASS_DISK0 special $CLASS_DISK1 72 log_must display_status "$TESTPOOL" 73 74 # 75 # Generate some metadata and small blocks in the special class vdev 76 # before removal 77 # 78 typeset -l i=1 79 typeset -l blocks=25 80 81 log_must zfs create -o special_small_blocks=32K -o recordsize=32K \ 82 $TESTPOOL/$TESTFS 83 for i in 1 2 3 4; do 84 log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/testfile.$i \ 85 bs=1M count=$blocks 86 ((blocks = blocks + 25)) 87 done 88 log_must sync_pool $TESTPOOL 89 log_must zpool list -v $TESTPOOL 90 91 # Verify the files were written in the special class vdevs 92 for i in 1 2 3 4; do 93 dataset="$TESTPOOL/$TESTFS" 94 inum="$(get_objnum /$TESTPOOL/$TESTFS/testfile.$i)" 95 log_must file_in_special_vdev $dataset $inum 96 done 97 98 log_must zpool remove $TESTPOOL $CLASS_DISK0 99 100 sleep 5 101 log_must sync_pool $TESTPOOL 102 sleep 1 103 104 log_must zdb -bbcc $TESTPOOL 105 log_must zpool list -v $TESTPOOL 106 log_must zpool destroy -f "$TESTPOOL" 107 log_must disk_cleanup 108} 109 110claim="Removing a special device from a pool succeeds." 111 112log_assert $claim 113log_onexit cleanup 114 115typeset CLASS_DEVSIZE=$CLASS_DEVSIZE 116for CLASS_DEVSIZE in $CLASS_DEVSIZE $ZPOOL_DEVSIZE; do 117 typeset ZPOOL_DISKS=$ZPOOL_DISKS 118 for ZPOOL_DISKS in "$ZPOOL_DISKS" $ZPOOL_DISK0; do 119 check_removal 120 done 121done 122 123log_pass $claim 124