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 that interleaving reads from different readers does not affect the
32# results that are returned.
33#
34# STRATEGY:
35# 1. Make sure a few debug messages have been logged.
36# 2. Open the procfs file and start reading from it.
37# 3. Open the file again, and read its entire contents.
38# 4. Resume reading from the first instance.
39# 5. Check that the contents read by the two instances are identical.
40#
41
42function cleanup
43{
44	[[ -z $msgs1 ]] || log_must rm $msgs1
45	[[ -z $msgs2 ]] || log_must rm $msgs2
46	datasetexists $FS && log_must zfs destroy -r $FS
47}
48
49typeset -r ZFS_DBGMSG=/proc/spl/kstat/zfs/dbgmsg
50typeset -r FS=$TESTPOOL/fs
51typeset msgs1 msgs2
52
53log_onexit cleanup
54
55# Clear out old messages
56echo 0 >$ZFS_DBGMSG || log_fail "failed to write to $ZFS_DBGMSG"
57
58# Add some new messages
59log_must zfs create $FS
60for i in {1..20}; do
61	log_must zfs snapshot "$FS@testsnapshot$i"
62done
63log_must zpool sync $TESTPOOL
64
65msgs1=$(mktemp) || log_fail
66msgs2=$(mktemp) || log_fail
67
68#
69# Start reading file, pause and read it from another process, and then finish
70# reading.
71#
72{ dd bs=512 count=4; cat $ZFS_DBGMSG >$msgs1; cat; } <$ZFS_DBGMSG >$msgs2
73
74#
75# Truncate the result of the read that completed second in case it picked up an
76# extra message that was logged after the first read completed.
77#
78log_must truncate -s $(stat_size $msgs1) $msgs2
79
80log_must diff $msgs1 $msgs2
81
82log_pass "Concurrent readers receive identical results"
83