1#!/bin/ksh -p 2# SPDX-License-Identifier: CDDL-1.0 3# 4# CDDL HEADER START 5# 6# The contents of this file are subject to the terms of the 7# Common Development and Distribution License (the "License"). 8# You may not use this file except in compliance with the License. 9# 10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11# or https://opensource.org/licenses/CDDL-1.0. 12# See the License for the specific language governing permissions 13# and limitations under the License. 14# 15# When distributing Covered Code, include this CDDL HEADER in each 16# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17# If applicable, add the following below this CDDL HEADER, with the 18# fields enclosed by brackets "[]" replaced with your own identifying 19# information: Portions Copyright [yyyy] [name of copyright owner] 20# 21# CDDL HEADER END 22# 23 24# 25# Copyright (c) 2018 by Delphix. All rights reserved. 26# 27 28. $STF_SUITE/include/libtest.shlib 29 30# 31# DESCRIPTION: 32# Make sure errors caused by messages being dropped from the list backing the 33# procfs file are handled gracefully. 34# 35# STRATEGY: 36# 1. Make sure a few entries have been logged. 37# 2. Open the procfs file and start reading from it. 38# 3. Write to the file to cause its contents to be dropped. 39# 4. Resume reading from the first instance, and check that the expected 40# error is received. 41# 5. Repeat steps 1-4, except instead of dropping all the messages by writing 42# to the file, cause enough new messages to be written that the old messages 43# are dropped. 44# 45 46function cleanup 47{ 48 echo $default_max_entries >$MAX_ENTRIES_PARAM || log_fail 49} 50 51function sync_n 52{ 53 for i in {1..$1}; do 54 sync_pool $TESTPOOL 55 done 56 return 0 57} 58 59function do_test 60{ 61 typeset cmd=$1 62 63 # Clear out old entries 64 echo 0 >$TXG_HIST || log_fail 65 66 # Add some new entries 67 sync_n 20 68 69 # Confirm that there actually is something in the file. 70 [[ $(wc -l <$TXG_HIST) -ge 20 ]] || log_fail "expected more entries" 71 72 # 73 # Start reading file, pause and run a command that will cause the 74 # current offset into the file to become invalid, and then try to 75 # finish reading. 76 # 77 { 78 log_must eval "dd bs=512 count=4 >/dev/null" 79 log_must eval "$cmd" 80 log_must eval 'cat 2>&1 >/dev/null | grep "Input/output error"' 81 } <$TXG_HIST 82} 83 84typeset -r TXG_HIST=/proc/spl/kstat/zfs/$TESTPOOL/txgs 85typeset MAX_ENTRIES_PARAM=/sys/module/zfs/parameters/zfs_txg_history 86typeset default_max_entries 87 88log_onexit cleanup 89 90default_max_entries=$(<$MAX_ENTRIES_PARAM) || log_fail 91echo 50 >$MAX_ENTRIES_PARAM || log_fail 92 93# Clear all of the existing entries. 94do_test "echo 0 >$TXG_HIST" 95 96# Add enough new entries to the list that all of the old ones are dropped. 97do_test "sync_n 60" 98 99log_pass "Attempting to read dropped message returns expected error" 100