1eda14cbcSMatt Macy#! /bin/ksh -p 2eda14cbcSMatt Macy# 3eda14cbcSMatt Macy# CDDL HEADER START 4eda14cbcSMatt Macy# 5eda14cbcSMatt Macy# This file and its contents are supplied under the terms of the 6eda14cbcSMatt Macy# Common Development and Distribution License ("CDDL"), version 1.0. 7eda14cbcSMatt Macy# You may only use this file in accordance with the terms of version 8eda14cbcSMatt Macy# 1.0 of the CDDL. 9eda14cbcSMatt Macy# 10eda14cbcSMatt Macy# A full copy of the text of the CDDL should have accompanied this 11eda14cbcSMatt Macy# source. A copy of the CDDL is also available via the Internet at 12eda14cbcSMatt Macy# http://www.illumos.org/license/CDDL. 13eda14cbcSMatt Macy# 14eda14cbcSMatt Macy# CDDL HEADER END 15eda14cbcSMatt Macy# 16eda14cbcSMatt Macy 17eda14cbcSMatt Macy# 18*bb2d13b6SMartin Matuska# Copyright (c) 2019, 2022 by Delphix. All rights reserved. 19eda14cbcSMatt Macy# 20eda14cbcSMatt Macy 21eda14cbcSMatt Macy. $STF_SUITE/include/libtest.shlib 22eda14cbcSMatt Macy. $STF_SUITE/tests/functional/removal/removal.kshlib 23eda14cbcSMatt Macy. $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib 24eda14cbcSMatt Macy 25eda14cbcSMatt Macydefault_setup_noexit "$DISKS" 26eda14cbcSMatt Macylog_onexit default_cleanup_noexit 27*bb2d13b6SMartin Matuska 28*bb2d13b6SMartin Matuska# 29*bb2d13b6SMartin Matuska# Randomly pick a device to remove 30*bb2d13b6SMartin Matuska# 31*bb2d13b6SMartin MatuskaDISK_TOKENS=( $DISKS ) 32*bb2d13b6SMartin MatuskaDISK_INDEX_TO_REMOVE=$((RANDOM%${#DISK_TOKENS[@]})) 33*bb2d13b6SMartin MatuskaDISK_TO_REMOVE=${DISK_TOKENS[${DISK_INDEX_TO_REMOVE}]} 34eda14cbcSMatt Macy 35eda14cbcSMatt Macyorigin="$TESTPOOL/$TESTFS" 36eda14cbcSMatt Macy 37eda14cbcSMatt Macylog_must zfs set compress=on $origin 38eda14cbcSMatt Macylog_must zfs set checksum=skein $origin 39eda14cbcSMatt Macy 40*bb2d13b6SMartin Matuskalog_must zfs set copies=1 $origin 41eda14cbcSMatt Macylog_must zfs set recordsize=8k $origin 42eda14cbcSMatt Macydd if=/dev/urandom of=$TESTDIR/file_8k bs=1024k count=$MEGS oflag=sync \ 43eda14cbcSMatt Macy conv=notrunc >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed." 44*bb2d13b6SMartin Matuskalog_must zfs set copies=3 $origin 45*bb2d13b6SMartin Matuskadd if=/dev/urandom of=$TESTDIR/file_8k_copies bs=1024k count=$MEGS oflag=sync \ 46*bb2d13b6SMartin Matuska conv=notrunc >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed." 47*bb2d13b6SMartin Matuska 48*bb2d13b6SMartin Matuskalog_must zfs set copies=1 $origin 49eda14cbcSMatt Macylog_must zfs set recordsize=128k $origin 50eda14cbcSMatt Macydd if=/dev/urandom of=$TESTDIR/file_128k bs=1024k count=$MEGS oflag=sync \ 51eda14cbcSMatt Macy conv=notrunc >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed." 52*bb2d13b6SMartin Matuskalog_must zfs set copies=3 $origin 53*bb2d13b6SMartin Matuskadd if=/dev/urandom of=$TESTDIR/file_128k_copies bs=1024k \ 54*bb2d13b6SMartin Matuska count=$MEGS oflag=sync conv=notrunc >/dev/null 2>&1 || \ 55*bb2d13b6SMartin Matuska log_fail "dd into $TESTDIR/file failed." 56eda14cbcSMatt Macy 57eda14cbcSMatt Macyzfs snapshot $origin@a || log_fail "zfs snap failed" 58eda14cbcSMatt Macylog_must zfs clone $origin@a $origin/clone 59eda14cbcSMatt Macy 60eda14cbcSMatt Macy# 61eda14cbcSMatt Macy# Verify that nopwrites work prior to removal 62eda14cbcSMatt Macy# 63*bb2d13b6SMartin Matuskalog_must zfs set copies=1 $origin/clone 64eda14cbcSMatt Macylog_must zfs set recordsize=8k $origin/clone 65eda14cbcSMatt Macydd if=/$TESTDIR/file_8k of=/$TESTDIR/clone/file_8k bs=1024k \ 66eda14cbcSMatt Macy oflag=sync conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." 67eda14cbcSMatt Macylog_must verify_nopwrite $origin $origin@a $origin/clone 68*bb2d13b6SMartin Matuskalog_must zfs set copies=3 $origin/clone 69*bb2d13b6SMartin Matuskadd if=/$TESTDIR/file_8k_copies of=/$TESTDIR/clone/file_8k_copies bs=1024k \ 70*bb2d13b6SMartin Matuska oflag=sync conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." 71*bb2d13b6SMartin Matuskalog_must verify_nopwrite $origin $origin@a $origin/clone 72eda14cbcSMatt Macy 73*bb2d13b6SMartin Matuskalog_must zfs set copies=1 $origin/clone 74eda14cbcSMatt Macylog_must zfs set recordsize=128k $origin/clone 75eda14cbcSMatt Macydd if=/$TESTDIR/file_128k of=/$TESTDIR/clone/file_128k bs=1024k \ 76eda14cbcSMatt Macy oflag=sync conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." 77eda14cbcSMatt Macylog_must verify_nopwrite $origin $origin@a $origin/clone 78*bb2d13b6SMartin Matuskalog_must zfs set copies=3 $origin/clone 79*bb2d13b6SMartin Matuskadd if=/$TESTDIR/file_128k_copies of=/$TESTDIR/clone/file_128k_copies bs=1024k \ 80*bb2d13b6SMartin Matuska oflag=sync conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." 81*bb2d13b6SMartin Matuskalog_must verify_nopwrite $origin $origin@a $origin/clone 82eda14cbcSMatt Macy 83eda14cbcSMatt Macy# 84eda14cbcSMatt Macy# Remove a device before testing nopwrites again 85eda14cbcSMatt Macy# 86*bb2d13b6SMartin Matuskalog_note "Removing: $DISK_TO_REMOVE" 87*bb2d13b6SMartin Matuskalog_must zpool remove $TESTPOOL $DISK_TO_REMOVE 88eda14cbcSMatt Macylog_must wait_for_removal $TESTPOOL 89*bb2d13b6SMartin Matuskalog_mustnot vdevs_in_pool $TESTPOOL $DISK_TO_REMOVE 90eda14cbcSMatt Macy 91eda14cbcSMatt Macy# 92eda14cbcSMatt Macy# Normally, we expect nopwrites to avoid allocating new blocks, but 93eda14cbcSMatt Macy# after a device has been removed the DVAs will get remapped when 94eda14cbcSMatt Macy# a L0's indirect block is written. This will negate the effects 95eda14cbcSMatt Macy# of nopwrite and should result in new allocations. 96eda14cbcSMatt Macy# 97eda14cbcSMatt Macy 98eda14cbcSMatt Macy# 99eda14cbcSMatt Macy# Perform a direct zil nopwrite test 100eda14cbcSMatt Macy# 101*bb2d13b6SMartin Matuskalog_must zfs set copies=1 $origin/clone 102eda14cbcSMatt Macylog_must zfs set recordsize=8k $origin/clone 103eda14cbcSMatt Macydd if=/$TESTDIR/file_8k of=/$TESTDIR/clone/file_8k bs=1024k \ 104eda14cbcSMatt Macy oflag=sync conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." 105eda14cbcSMatt Macylog_mustnot verify_nopwrite $origin $origin@a $origin/clone 106*bb2d13b6SMartin Matuskalog_must zfs set copies=3 $origin/clone 107*bb2d13b6SMartin Matuskadd if=/$TESTDIR/file_8k_copies of=/$TESTDIR/clone/file_8k_copies bs=1024k \ 108*bb2d13b6SMartin Matuska oflag=sync conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." 109*bb2d13b6SMartin Matuskalog_mustnot verify_nopwrite $origin $origin@a $origin/clone 110eda14cbcSMatt Macy 111eda14cbcSMatt Macy# 112eda14cbcSMatt Macy# Perform an indirect zil nopwrite test 113eda14cbcSMatt Macy# 114*bb2d13b6SMartin Matuskalog_must zfs set copies=1 $origin/clone 115eda14cbcSMatt Macylog_must zfs set recordsize=128k $origin/clone 116eda14cbcSMatt Macydd if=/$TESTDIR/file_128k of=/$TESTDIR/clone/file_128k bs=1024k \ 117eda14cbcSMatt Macy oflag=sync conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." 118eda14cbcSMatt Macylog_mustnot verify_nopwrite $origin $origin@a $origin/clone 119*bb2d13b6SMartin Matuskalog_must zfs set copies=3 $origin/clone 120*bb2d13b6SMartin Matuskadd if=/$TESTDIR/file_128k_copies of=/$TESTDIR/clone/file_128k_copies bs=1024k \ 121*bb2d13b6SMartin Matuska oflag=sync conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." 122*bb2d13b6SMartin Matuskalog_mustnot verify_nopwrite $origin $origin@a $origin/clone 123eda14cbcSMatt Macy 124eda14cbcSMatt Macylog_pass "Remove works with nopwrite." 125