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