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