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