1eda14cbcSMatt Macy#!/bin/ksh -p 2eda14cbcSMatt Macy# 3eda14cbcSMatt Macy# This file and its contents are supplied under the terms of the 4eda14cbcSMatt Macy# Common Development and Distribution License ("CDDL"), version 1.0. 5eda14cbcSMatt Macy# You may only use this file in accordance with the terms of version 6eda14cbcSMatt Macy# 1.0 of the CDDL. 7eda14cbcSMatt Macy# 8eda14cbcSMatt Macy# A full copy of the text of the CDDL should have accompanied this 9eda14cbcSMatt Macy# source. A copy of the CDDL is also available via the Internet at 10eda14cbcSMatt Macy# http://www.illumos.org/license/CDDL. 11eda14cbcSMatt Macy# 12eda14cbcSMatt Macy 13eda14cbcSMatt Macy# 14eda14cbcSMatt Macy# Copyright (c) 2018 by Delphix. All rights reserved. 15eda14cbcSMatt Macy# 16eda14cbcSMatt Macy 17eda14cbcSMatt Macy. $STF_SUITE/include/libtest.shlib 18eda14cbcSMatt Macy. $STF_SUITE/tests/functional/cli_root/zpool_wait/zpool_wait.kshlib 19eda14cbcSMatt Macy 20eda14cbcSMatt Macy# 21eda14cbcSMatt Macy# DESCRIPTION: 22eda14cbcSMatt Macy# 'zpool wait' works when waiting for background freeing to complete. 23eda14cbcSMatt Macy# 24eda14cbcSMatt Macy# STRATEGY: 25eda14cbcSMatt Macy# 1. Create a pool. 26eda14cbcSMatt Macy# 2. Modify tunables to make sure freeing is slow enough to observe. 27eda14cbcSMatt Macy# 3. Create a file system with some data. 28eda14cbcSMatt Macy# 4. Destroy the file system and call 'zpool wait'. 29eda14cbcSMatt Macy# 5. Monitor the waiting process to make sure it returns neither too soon nor 30eda14cbcSMatt Macy# too late. 31eda14cbcSMatt Macy# 6. Repeat 3-5, except destroy a snapshot instead of a filesystem. 32eda14cbcSMatt Macy# 7. Repeat 3-5, except destroy a clone. 33eda14cbcSMatt Macy# 34eda14cbcSMatt Macy 35eda14cbcSMatt Macyfunction cleanup 36eda14cbcSMatt Macy{ 37eda14cbcSMatt Macy log_must set_tunable64 ASYNC_BLOCK_MAX_BLOCKS $default_async_block_max_blocks 38eda14cbcSMatt Macy log_must set_tunable64 LIVELIST_MAX_ENTRIES $default_max_livelist_entries 39eda14cbcSMatt Macy log_must set_tunable64 LIVELIST_MIN_PERCENT_SHARED $default_min_pct_shared 40eda14cbcSMatt Macy 41eda14cbcSMatt Macy poolexists $TESTPOOL && destroy_pool $TESTPOOL 42eda14cbcSMatt Macy kill_if_running $pid 43eda14cbcSMatt Macy} 44eda14cbcSMatt Macy 45eda14cbcSMatt Macyfunction test_wait 46eda14cbcSMatt Macy{ 47eda14cbcSMatt Macy log_bkgrnd zpool wait -t free $TESTPOOL 48eda14cbcSMatt Macy pid=$! 49eda14cbcSMatt Macy check_while_waiting $pid '[[ $(get_pool_prop freeing $TESTPOOL) != "0" ]]' 50eda14cbcSMatt Macy} 51eda14cbcSMatt Macy 52eda14cbcSMatt Macytypeset -r FS="$TESTPOOL/$TESTFS1" 53eda14cbcSMatt Macytypeset -r SNAP="$FS@snap1" 54eda14cbcSMatt Macytypeset -r CLONE="$TESTPOOL/clone" 55eda14cbcSMatt Macytypeset pid default_max_livelist_entries default_min_pct_shared 56eda14cbcSMatt Macytypeset default_async_block_max_blocks 57eda14cbcSMatt Macy 58eda14cbcSMatt Macylog_onexit cleanup 59eda14cbcSMatt Macy 60eda14cbcSMatt Macylog_must zpool create $TESTPOOL $DISK1 61eda14cbcSMatt Macy 62eda14cbcSMatt Macy# 63eda14cbcSMatt Macy# Limit the number of blocks that can be freed in a single txg. This slows down 64eda14cbcSMatt Macy# freeing so that we actually have something to wait for. 65eda14cbcSMatt Macy# 66eda14cbcSMatt Macydefault_async_block_max_blocks=$(get_tunable ASYNC_BLOCK_MAX_BLOCKS) 67eda14cbcSMatt Macylog_must set_tunable64 ASYNC_BLOCK_MAX_BLOCKS 8 68eda14cbcSMatt Macy# 69eda14cbcSMatt Macy# Space from clones gets freed one livelist per txg instead of being controlled 70eda14cbcSMatt Macy# by zfs_async_block_max_blocks. Limit the rate at which space is freed by 71eda14cbcSMatt Macy# limiting the size of livelists so that we end up with a number of them. 72eda14cbcSMatt Macy# 73eda14cbcSMatt Macydefault_max_livelist_entries=$(get_tunable LIVELIST_MAX_ENTRIES) 74eda14cbcSMatt Macylog_must set_tunable64 LIVELIST_MAX_ENTRIES 16 75eda14cbcSMatt Macy# Don't disable livelists, no matter how much clone diverges from snapshot 76eda14cbcSMatt Macydefault_min_pct_shared=$(get_tunable LIVELIST_MIN_PERCENT_SHARED) 77eda14cbcSMatt Macylog_must set_tunable64 LIVELIST_MIN_PERCENT_SHARED -1 78eda14cbcSMatt Macy 79eda14cbcSMatt Macy# 80eda14cbcSMatt Macy# Test waiting for space from destroyed filesystem to be freed 81eda14cbcSMatt Macy# 82eda14cbcSMatt Macylog_must zfs create "$FS" 83eda14cbcSMatt Macylog_must dd if=/dev/zero of="/$FS/testfile" bs=1M count=128 84eda14cbcSMatt Macylog_must zfs destroy "$FS" 85eda14cbcSMatt Macytest_wait 86eda14cbcSMatt Macy 87eda14cbcSMatt Macy# 88eda14cbcSMatt Macy# Test waiting for space from destroyed snapshot to be freed 89eda14cbcSMatt Macy# 90eda14cbcSMatt Macylog_must zfs create "$FS" 91eda14cbcSMatt Macylog_must dd if=/dev/zero of="/$FS/testfile" bs=1M count=128 92eda14cbcSMatt Macylog_must zfs snapshot "$SNAP" 93eda14cbcSMatt Macy# Make sure bulk of space is unique to snapshot 94eda14cbcSMatt Macylog_must rm "/$FS/testfile" 95eda14cbcSMatt Macylog_must zfs destroy "$SNAP" 96eda14cbcSMatt Macytest_wait 97eda14cbcSMatt Macy 98eda14cbcSMatt Macy# 99eda14cbcSMatt Macy# Test waiting for space from destroyed clone to be freed 100eda14cbcSMatt Macy# 101eda14cbcSMatt Macylog_must zfs snapshot "$SNAP" 102eda14cbcSMatt Macylog_must zfs clone "$SNAP" "$CLONE" 103eda14cbcSMatt Macy# Add some data to the clone 104eda14cbcSMatt Macyfor i in {1..50}; do 105eda14cbcSMatt Macy log_must dd if=/dev/urandom of="/$CLONE/testfile$i" bs=1k count=512 106eda14cbcSMatt Macy # Force each new file to be tracked by a new livelist 107*e92ffd9bSMartin Matuska sync_pool $TESTPOOL 108eda14cbcSMatt Macydone 109eda14cbcSMatt Macylog_must zfs destroy "$CLONE" 110eda14cbcSMatt Macytest_wait 111eda14cbcSMatt Macy 112eda14cbcSMatt Macylog_pass "'zpool wait -t freeing' works." 113