1*5cabbc6bSPrashanth Sreenivasa#! /bin/ksh -p 2*5cabbc6bSPrashanth Sreenivasa# 3*5cabbc6bSPrashanth Sreenivasa# CDDL HEADER START 4*5cabbc6bSPrashanth Sreenivasa# 5*5cabbc6bSPrashanth Sreenivasa# This file and its contents are supplied under the terms of the 6*5cabbc6bSPrashanth Sreenivasa# Common Development and Distribution License ("CDDL"), version 1.0. 7*5cabbc6bSPrashanth Sreenivasa# You may only use this file in accordance with the terms of version 8*5cabbc6bSPrashanth Sreenivasa# 1.0 of the CDDL. 9*5cabbc6bSPrashanth Sreenivasa# 10*5cabbc6bSPrashanth Sreenivasa# A full copy of the text of the CDDL should have accompanied this 11*5cabbc6bSPrashanth Sreenivasa# source. A copy of the CDDL is also available via the Internet at 12*5cabbc6bSPrashanth Sreenivasa# http://www.illumos.org/license/CDDL. 13*5cabbc6bSPrashanth Sreenivasa# 14*5cabbc6bSPrashanth Sreenivasa# CDDL HEADER END 15*5cabbc6bSPrashanth Sreenivasa# 16*5cabbc6bSPrashanth Sreenivasa 17*5cabbc6bSPrashanth Sreenivasa# 18*5cabbc6bSPrashanth Sreenivasa# Copyright (c) 2015, 2016 by Delphix. All rights reserved. 19*5cabbc6bSPrashanth Sreenivasa# 20*5cabbc6bSPrashanth Sreenivasa 21*5cabbc6bSPrashanth Sreenivasa. $STF_SUITE/include/libtest.shlib 22*5cabbc6bSPrashanth Sreenivasa. $STF_SUITE/tests/functional/removal/removal.kshlib 23*5cabbc6bSPrashanth Sreenivasa 24*5cabbc6bSPrashanth Sreenivasadefault_setup_noexit "$DISKS" 25*5cabbc6bSPrashanth Sreenivasa 26*5cabbc6bSPrashanth Sreenivasa 27*5cabbc6bSPrashanth Sreenivasafunction cleanup 28*5cabbc6bSPrashanth Sreenivasa{ 29*5cabbc6bSPrashanth Sreenivasa log_must set_min_bytes 131072 30*5cabbc6bSPrashanth Sreenivasa default_cleanup_noexit 31*5cabbc6bSPrashanth Sreenivasa} 32*5cabbc6bSPrashanth Sreenivasa 33*5cabbc6bSPrashanth Sreenivasalog_onexit cleanup 34*5cabbc6bSPrashanth Sreenivasa 35*5cabbc6bSPrashanth Sreenivasalog_must set_min_bytes 1 36*5cabbc6bSPrashanth Sreenivasa 37*5cabbc6bSPrashanth Sreenivasalog_must zfs set recordsize=512 $TESTPOOL/$TESTFS 38*5cabbc6bSPrashanth Sreenivasa 39*5cabbc6bSPrashanth Sreenivasa# 40*5cabbc6bSPrashanth Sreenivasa# Create a large file so that we know some of the blocks will be on the 41*5cabbc6bSPrashanth Sreenivasa# removed device, and hence eligible for remapping. 42*5cabbc6bSPrashanth Sreenivasa# 43*5cabbc6bSPrashanth Sreenivasalog_must dd if=/dev/urandom of=$TESTDIR/file bs=$((2**12)) count=$((2**9)) 44*5cabbc6bSPrashanth Sreenivasa 45*5cabbc6bSPrashanth Sreenivasa# 46*5cabbc6bSPrashanth Sreenivasa# Randomly rewrite some of blocks in the file so that there will be holes and 47*5cabbc6bSPrashanth Sreenivasa# we will not be able to remap the entire file in a few huge chunks. 48*5cabbc6bSPrashanth Sreenivasa# 49*5cabbc6bSPrashanth Sreenivasafor i in $(seq $((2**12))); do 50*5cabbc6bSPrashanth Sreenivasa # 51*5cabbc6bSPrashanth Sreenivasa # We have to sync periodically so that all the writes don't end up in 52*5cabbc6bSPrashanth Sreenivasa # the same txg. If they were all in the same txg, only the last write 53*5cabbc6bSPrashanth Sreenivasa # would go through and we would not have as many allocations to 54*5cabbc6bSPrashanth Sreenivasa # fragment the file. 55*5cabbc6bSPrashanth Sreenivasa # 56*5cabbc6bSPrashanth Sreenivasa ((i % 100 > 0 )) || sync || log_fail "Could not sync." 57*5cabbc6bSPrashanth Sreenivasa random_write $TESTDIR/file $((2**9)) || \ 58*5cabbc6bSPrashanth Sreenivasa log_fail "Could not random write." 59*5cabbc6bSPrashanth Sreenivasadone 60*5cabbc6bSPrashanth Sreenivasa 61*5cabbc6bSPrashanth Sreenivasa# 62*5cabbc6bSPrashanth Sreenivasa# Remap should quietly succeed as a noop before a removal. 63*5cabbc6bSPrashanth Sreenivasa# 64*5cabbc6bSPrashanth Sreenivasalog_must zfs remap $TESTPOOL/$TESTFS 65*5cabbc6bSPrashanth Sreenivasaremaptxg_before=$(zfs get -H -o value remaptxg $TESTPOOL/$TESTFS) 66*5cabbc6bSPrashanth Sreenivasa(( $? == 0 )) || log_fail "Could not get remaptxg." 67*5cabbc6bSPrashanth Sreenivasa[[ $remaptxg_before == "-" ]] || \ 68*5cabbc6bSPrashanth Sreenivasa log_fail "remaptxg ($remaptxg_before) had value before a removal" 69*5cabbc6bSPrashanth Sreenivasa 70*5cabbc6bSPrashanth Sreenivasalog_must zpool remove $TESTPOOL $REMOVEDISK 71*5cabbc6bSPrashanth Sreenivasalog_must wait_for_removal $TESTPOOL 72*5cabbc6bSPrashanth Sreenivasalog_mustnot vdevs_in_pool $TESTPOOL $REMOVEDISK 73*5cabbc6bSPrashanth Sreenivasa 74*5cabbc6bSPrashanth Sreenivasa# 75*5cabbc6bSPrashanth Sreenivasa# remaptxg should not be set if we haven't done a remap. 76*5cabbc6bSPrashanth Sreenivasa# 77*5cabbc6bSPrashanth Sreenivasaremaptxg_before=$(zfs get -H -o value remaptxg $TESTPOOL/$TESTFS) 78*5cabbc6bSPrashanth Sreenivasa(( $? == 0 )) || log_fail "Could not get remaptxg." 79*5cabbc6bSPrashanth Sreenivasa[[ $remaptxg_before == "-" ]] || \ 80*5cabbc6bSPrashanth Sreenivasa log_fail "remaptxg ($remaptxg_before) had value before a removal" 81*5cabbc6bSPrashanth Sreenivasa 82*5cabbc6bSPrashanth Sreenivasamapping_size_before=$(indirect_vdev_mapping_size $TESTPOOL) 83*5cabbc6bSPrashanth Sreenivasalog_must zfs remap $TESTPOOL/$TESTFS 84*5cabbc6bSPrashanth Sreenivasa 85*5cabbc6bSPrashanth Sreenivasa# Try to wait for a condense to finish. 86*5cabbc6bSPrashanth Sreenivasafor i in {1..5}; do 87*5cabbc6bSPrashanth Sreenivasa sleep 5 88*5cabbc6bSPrashanth Sreenivasa sync 89*5cabbc6bSPrashanth Sreenivasadone 90*5cabbc6bSPrashanth Sreenivasamapping_size_after=$(indirect_vdev_mapping_size $TESTPOOL) 91*5cabbc6bSPrashanth Sreenivasa 92*5cabbc6bSPrashanth Sreenivasa# 93*5cabbc6bSPrashanth Sreenivasa# After the remap, there should not be very many blocks referenced. The reason 94*5cabbc6bSPrashanth Sreenivasa# why our threshold is as high as 512 is because our ratio of metadata to 95*5cabbc6bSPrashanth Sreenivasa# user data is relatively high, with only 64M of user data on the file system. 96*5cabbc6bSPrashanth Sreenivasa# 97*5cabbc6bSPrashanth Sreenivasa(( mapping_size_after < mapping_size_before )) || \ 98*5cabbc6bSPrashanth Sreenivasa log_fail "Mapping size did not decrease after remap: " \ 99*5cabbc6bSPrashanth Sreenivasa "$mapping_size_before before to $mapping_size_after after." 100*5cabbc6bSPrashanth Sreenivasa(( mapping_size_after < 512 )) || \ 101*5cabbc6bSPrashanth Sreenivasa log_fail "Mapping size not small enough after remap: " \ 102*5cabbc6bSPrashanth Sreenivasa "$mapping_size_before before to $mapping_size_after after." 103*5cabbc6bSPrashanth Sreenivasa 104*5cabbc6bSPrashanth Sreenivasa# 105*5cabbc6bSPrashanth Sreenivasa# After a remap, the remaptxg should be set to a non-zero value. 106*5cabbc6bSPrashanth Sreenivasa# 107*5cabbc6bSPrashanth Sreenivasaremaptxg_after=$(zfs get -H -o value remaptxg $TESTPOOL/$TESTFS) 108*5cabbc6bSPrashanth Sreenivasa(( $? == 0 )) || log_fail "Could not get remaptxg." 109*5cabbc6bSPrashanth Sreenivasalog_note "remap txg after remap is $remaptxg_after" 110*5cabbc6bSPrashanth Sreenivasa(( remaptxg_after > 0 )) || log_fail "remaptxg not increased" 111*5cabbc6bSPrashanth Sreenivasa 112*5cabbc6bSPrashanth Sreenivasa# 113*5cabbc6bSPrashanth Sreenivasa# Remap should quietly succeed as a noop if there have been no removals since 114*5cabbc6bSPrashanth Sreenivasa# the last remap. 115*5cabbc6bSPrashanth Sreenivasa# 116*5cabbc6bSPrashanth Sreenivasalog_must zfs remap $TESTPOOL/$TESTFS 117*5cabbc6bSPrashanth Sreenivasaremaptxg_again=$(zfs get -H -o value remaptxg $TESTPOOL/$TESTFS) 118*5cabbc6bSPrashanth Sreenivasa(( $? == 0 )) || log_fail "Could not get remaptxg." 119*5cabbc6bSPrashanth Sreenivasalog_note "remap txg after second remap is $remaptxg_again" 120*5cabbc6bSPrashanth Sreenivasa(( remaptxg_again == remaptxg_after )) || \ 121*5cabbc6bSPrashanth Sreenivasa log_fail "remap not noop if there has been no removal" 122*5cabbc6bSPrashanth Sreenivasa 123*5cabbc6bSPrashanth Sreenivasalog_pass "Remapping a fs caused mapping size to decrease." 124