1#!/bin/ksh -p 2# 3# This file and its contents are supplied under the terms of the 4# Common Development and Distribution License ("CDDL"), version 1.0. 5# You may only use this file in accordance with the terms of version 6# 1.0 of the CDDL. 7# 8# A full copy of the text of the CDDL should have accompanied this 9# source. A copy of the CDDL is also available via the Internet at 10# http://www.illumos.org/license/CDDL. 11# 12 13# 14# Copyright (c) 2018 by Delphix. All rights reserved. 15# 16 17# DESCRIPTION 18# Verify that livelists tracking remapped blocks can be 19# properly condensed. 20 21# STRATEGY 22# 1. Create a pool with disk1 and create a filesystem, snapshot 23# and clone. Create two files for the first livelist entry and 24# pause condensing. 25# 2. Add disk2 to the pool and then remove disk1, triggering a 26# remap of the blkptrs tracked in the livelist. 27# 3. Overwrite the first file several times to trigger a condense, 28# overwrite the second file once and resume condensing, now with 29# extra blkptrs added during the remap 30# 4. Check that the test added new ALLOC blkptrs mid-condense using 31# a variable set in that code path 32 33. $STF_SUITE/include/libtest.shlib 34. $STF_SUITE/tests/functional/removal/removal.kshlib 35. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg 36 37function cleanup 38{ 39 poolexists $TESTPOOL2 && zpool destroy $TESTPOOL2 40 # reset livelist max size 41 set_tunable64 LIVELIST_MAX_ENTRIES $ORIGINAL_MAX 42 [[ -f $VIRTUAL_DISK1 ]] && log_must rm $VIRTUAL_DISK1 43 [[ -f $VIRTUAL_DISK2 ]] && log_must rm $VIRTUAL_DISK2 44} 45 46log_onexit cleanup 47 48ORIGINAL_MAX=$(get_tunable LIVELIST_MAX_ENTRIES) 49set_tunable64 LIVELIST_MAX_ENTRIES 20 50 51VIRTUAL_DISK1=$TEST_BASE_DIR/disk1 52VIRTUAL_DISK2=$TEST_BASE_DIR/disk2 53log_must truncate -s $(($MINVDEVSIZE * 8)) $VIRTUAL_DISK1 54log_must truncate -s $(($MINVDEVSIZE * 16)) $VIRTUAL_DISK2 55 56log_must zpool create -O compression=off $TESTPOOL2 $VIRTUAL_DISK1 57log_must poolexists $TESTPOOL2 58 59log_must zfs create $TESTPOOL2/$TESTFS 60log_must mkfile 100m /$TESTPOOL2/$TESTFS/atestfile 61log_must zfs snapshot $TESTPOOL2/$TESTFS@snap 62 63log_must zfs clone $TESTPOOL2/$TESTFS@snap $TESTPOOL2/$TESTCLONE 64 65# Create initial files and pause condense zthr on next execution 66log_must mkfile 10m /$TESTPOOL2/$TESTCLONE/A 67log_must mkfile 1m /$TESTPOOL2/$TESTCLONE/B 68sync_pool $TESTPOOL2 69set_tunable32 LIVELIST_CONDENSE_SYNC_PAUSE 1 70 71# Add a new dev and remove the old one 72log_must zpool add $TESTPOOL2 $VIRTUAL_DISK2 73log_must zpool remove $TESTPOOL2 $VIRTUAL_DISK1 74wait_for_removal $TESTPOOL2 75 76set_tunable32 LIVELIST_CONDENSE_NEW_ALLOC 0 77# Trigger a condense 78log_must mkfile 10m /$TESTPOOL2/$TESTCLONE/A 79sync_pool $TESTPOOL2 80log_must mkfile 10m /$TESTPOOL2/$TESTCLONE/A 81sync_pool $TESTPOOL2 82# Write remapped blkptrs which will modify the livelist mid-condense 83log_must mkfile 1m /$TESTPOOL2/$TESTCLONE/B 84 85# Resume condense thr 86set_tunable32 LIVELIST_CONDENSE_SYNC_PAUSE 0 87sync_pool $TESTPOOL2 88# Check that we've added new ALLOC blkptrs during the condense 89[[ "0" < "$(get_tunable LIVELIST_CONDENSE_NEW_ALLOC)" ]] || \ 90 log_fail "removal/condense test failed" 91 92log_must zfs destroy $TESTPOOL2/$TESTCLONE 93log_pass "Clone with the livelist feature and remapped blocks," \ 94 "can be condensed." 95