1#! /bin/ksh -p 2# 3# CDDL HEADER START 4# 5# This file and its contents are supplied under the terms of the 6# Common Development and Distribution License ("CDDL"), version 1.0. 7# You may only use this file in accordance with the terms of version 8# 1.0 of the CDDL. 9# 10# A full copy of the text of the CDDL should have accompanied this 11# source. A copy of the CDDL is also available via the Internet at 12# http://www.illumos.org/license/CDDL. 13# 14# CDDL HEADER END 15# 16 17# 18# Copyright (c) 2019 by Delphix. All rights reserved. 19# 20 21. $STF_SUITE/include/libtest.shlib 22 23# 24# DESCRIPTION: 25# Log spacemaps are generally destroyed at export in order to 26# not induce performance overheads at import time. As a result, 27# the log spacemap codepaths that read the logs in import times 28# are not tested outside of ztest and pools with DEBUG bits doing 29# many imports/exports while running the test suite. 30# 31# This test uses an internal tunable and forces ZFS to keep the 32# log spacemaps at export, and then re-imports the pool, thus 33# providing explicit testing of those codepaths. It also uses 34# another tunable to load all the metaslabs when the pool is 35# re-imported so more assertions and verifications will be hit. 36# 37# STRATEGY: 38# 1. Create pool. 39# 2. Do a couple of writes to generate some data for spacemap logs. 40# 3. Set tunable to keep logs after export. 41# 4. Export pool and verify that there are logs with zdb. 42# 5. Set tunable to load all metaslabs at import. 43# 6. Import pool. 44# 7. Reset tunables. 45# 46 47verify_runnable "global" 48 49function cleanup 50{ 51 log_must set_tunable64 KEEP_LOG_SPACEMAPS_AT_EXPORT 0 52 log_must set_tunable64 METASLAB_DEBUG_LOAD 0 53 if poolexists $LOGSM_POOL; then 54 log_must zpool destroy -f $LOGSM_POOL 55 fi 56} 57log_onexit cleanup 58 59LOGSM_POOL="logsm_import" 60TESTDISK="$(echo $DISKS | cut -d' ' -f1)" 61 62log_must zpool create -o cachefile=none -f $LOGSM_POOL $TESTDISK 63log_must zfs create $LOGSM_POOL/fs 64 65log_must dd if=/dev/urandom of=/$LOGSM_POOL/fs/00 bs=128k count=10 66log_must sync 67log_must dd if=/dev/urandom of=/$LOGSM_POOL/fs/00 bs=128k count=10 68log_must sync 69 70log_must set_tunable64 KEEP_LOG_SPACEMAPS_AT_EXPORT 1 71log_must zpool export $LOGSM_POOL 72 73LOGSM_COUNT=$(zdb -m -e $LOGSM_POOL | grep "Log Spacemap object" | wc -l) 74if (( LOGSM_COUNT == 0 )); then 75 log_fail "Pool does not have any log spacemaps after being exported" 76fi 77 78log_must set_tunable64 METASLAB_DEBUG_LOAD 1 79log_must zpool import $LOGSM_POOL 80 81log_pass "Log spacemaps imported with no errors" 82