1#!/usr/local/bin/ksh93 -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# $FreeBSD$
24
25#
26# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)link_count_001.ksh	1.2	07/01/09 SMI"
30#
31. $STF_SUITE/include/libtest.kshlib
32
33################################################################################
34#
35# __stc_assertion_start
36#
37# ID: link_count_001
38#
39# DESCRIPTION:
40# Verify file link count is zero on zfs
41#
42# STRATEGY:
43# 1. Make sure this test executes on multi-processes system
44# 2. Make zero size files and remove them in the background
45# 3. Call the binary
46# 4. Make sure the files can be removed successfully
47#
48# TESTABILITY: explicit
49#
50# TEST_AUTOMATION_LEVEL: automated
51#
52# CODING_STATUS: COMPLETED (2006-07-13)
53#
54# __stc_assertion_end
55#
56################################################################################
57
58verify_runnable "both"
59
60log_assert "Verify file link count is zero on zfs"
61
62# Detect and make sure this test must be executed on a multi-process system
63NCPUS=`sysctl -n kern.smp.cpus`
64#NCPUS=`sysctl -a | awk -F '"' '/cpu count="[0-9+]"/ {print $2; exit}'`
65if [[ $? -ne 0 || -z "$NCPUS" || "$NCPUS" -le 1 ]]; then
66	log_unsupported "This test must be executed on a multi-processor system."
67fi
68
69log_must $MKDIR -p ${TESTDIR}/tmp
70
71typeset -i i=0
72while [ $i -lt $NUMFILES ]; do
73        (( i = i + 1 ))
74        $TOUCH ${TESTDIR}/tmp/x$i > /dev/null 2>&1
75done
76
77sleep 3
78
79$RM -f ${TESTDIR}/tmp/x* >/dev/null 2>&1
80
81$RM_LNKCNT_ZERO_FILE ${TESTDIR}/tmp/test${TESTCASE_ID} > /dev/null 2>&1 &
82PID=$!
83log_note "$RM_LNKCNT_ZERO_FILE ${TESTDIR}/tmp/test${TESTCASE_ID} pid: $PID"
84
85i=0
86while [ $i -lt $ITERS ]; do
87	if ! $PGREP $RM_LNKCNT_ZERO_FILE > /dev/null ; then
88		log_note "$RM_LNKCNT_ZERO_FILE completes"
89		break
90	fi
91	log_must $SLEEP 10
92	(( i = i + 1 ))
93done
94
95if $PGREP $RM_LNKCNT_ZERO_FILE > /dev/null; then
96	log_must $KILL -9 $PID
97	log_fail "file link count is zero"
98fi
99
100log_must $RM -f ${TESTDIR}/tmp/test${TESTCASE_ID}*
101
102log_pass "Verify file link count is zero on zfs"
103