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# Copyright 2019 Joyent, Inc. 17# 18 19. $STF_SUITE/tests/functional/alloc_class/alloc_class.kshlib 20 21# 22# DESCRIPTION: 23# Removing a special device from a pool succeeds. 24# 25 26verify_runnable "global" 27 28# 29# Verify the file identified by the input <inode> is written on a special vdev 30# According to the pool layout used in this test vdev_id 3 and 4 are special 31# XXX: move this function to libtest.shlib once we get "Vdev Properties" 32# 33function file_in_special_vdev # <dataset> <inode> 34{ 35 typeset dataset="$1" 36 typeset inum="$2" 37 38 zdb -dddddd $dataset $inum | nawk '{ 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] < 3) { 54 exit 1; 55 } 56 } 57 } 58}}' 59} 60 61claim="Removing a special device from a pool succeeds." 62 63log_assert $claim 64log_onexit cleanup 65 66# 67# Create a non-raidz pool so we can remove top-level vdevs 68# 69log_must disk_setup 70log_must zpool create $TESTPOOL $ZPOOL_DISK0 $ZPOOL_DISK1 $ZPOOL_DISK2 \ 71 special $CLASS_DISK0 special $CLASS_DISK1 72log_must display_status "$TESTPOOL" 73 74# 75# Generate some metadata and small blocks in the special class before removal 76# 77typeset -l i=1 78typeset -l blocks=25 79 80log_must zfs create -o special_small_blocks=32K -o recordsize=32K \ 81 $TESTPOOL/$TESTFS 82for i in 1 2 3 4; do 83 log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/testfile.$i bs=1M \ 84 count=$blocks 85 ((blocks = blocks + 25)) 86done 87sync_pool $TESTPOOL 88log_must zpool list -v $TESTPOOL 89 90# Verify the files were written in the special class vdevs 91for i in 1 2 3 4; do 92 dataset="$TESTPOOL/$TESTFS" 93 inum="$(stat -c '%i' /$TESTPOOL/$TESTFS/testfile.$i)" 94 log_must file_in_special_vdev $dataset $inum 95done 96 97# 98# remove a special allocation vdev and force a remapping 99# 100log_must zpool remove $TESTPOOL $CLASS_DISK0 101log_must zfs remap $TESTPOOL/$TESTFS 102 103sleep 5 104sync_pool $TESTPOOL 105sleep 1 106 107log_must zdb -bbcc $TESTPOOL 108log_must zpool list -v $TESTPOOL 109log_must zpool destroy -f "$TESTPOOL" 110 111log_pass $claim 112