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 https://opensource.org/licenses/CDDL-1.0.
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 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33
34#
35# DESCRIPTION:
36# Verify file link count is zero on zfs
37#
38# STRATEGY:
39# 1. Make sure this test executes on multi-processes system
40# 2. Make zero size files and remove them in the background
41# 3. Call the binary
42# 4. Make sure the files can be removed successfully
43#
44
45verify_runnable "both"
46
47log_assert "Verify file link count is zero on zfs"
48
49export ITERS=10
50export NUMFILES=10000
51
52if is_freebsd; then
53	log_unsupported "Not applicable on FreeBSD"
54fi
55
56# Detect and make sure this test must be executed on a multi-process system
57if ! is_mp; then
58	log_unsupported "This test requires a multi-processor system."
59fi
60
61log_must mkdir -p ${TESTDIR}/tmp
62
63typeset -i i=0
64while [ $i -lt $NUMFILES ]; do
65        (( i = i + 1 ))
66        touch ${TESTDIR}/tmp/x$i > /dev/null 2>&1
67done
68
69sleep 3
70
71rm -f ${TESTDIR}/tmp/x* >/dev/null 2>&1
72
73rm_lnkcnt_zero_file ${TESTDIR}/tmp/test$$ > /dev/null 2>&1 &
74PID=$!
75log_note "rm_lnkcnt_zero_file ${TESTDIR}/tmp/test$$ pid: $PID"
76
77i=0
78while [ $i -lt $ITERS ]; do
79	if ! pgrep rm_lnkcnt_zero_file > /dev/null ; then
80		log_note "rm_lnkcnt_zero_file completes"
81		break
82	fi
83	log_must sleep 10
84	(( i = i + 1 ))
85done
86
87if pgrep rm_lnkcnt_zero_file > /dev/null; then
88	log_must kill -TERM $PID
89	log_fail "file link count is zero"
90fi
91
92log_must kill -TERM $PID
93log_must rm -f ${TESTDIR}/tmp/test$$*
94
95log_pass "Verify file link count is zero on zfs"
96