xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/link_count/link_count_001.ksh (revision f985abb4a2473d3c04b086f7c9fab177e368ffef)
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 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2013 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
52# Detect and make sure this test must be executed on a multi-process system
53is_mp || log_fail "This test requires a multi-processor system."
54
55log_must $MKDIR -p ${TESTDIR}/tmp
56
57typeset -i i=0
58while [ $i -lt $NUMFILES ]; do
59        (( i = i + 1 ))
60        $TOUCH ${TESTDIR}/tmp/x$i > /dev/null 2>&1
61done
62
63sleep 3
64
65$RM -f ${TESTDIR}/tmp/x* >/dev/null 2>&1
66
67$RM_LNKCNT_ZERO_FILE ${TESTDIR}/tmp/test$$ > /dev/null 2>&1 &
68PID=$!
69log_note "$RM_LNKCNT_ZERO_FILE ${TESTDIR}/tmp/test$$ pid: $PID"
70
71i=0
72while [ $i -lt $ITERS ]; do
73	if ! $PGREP $RM_LNKCNT_ZERO_FILE > /dev/null ; then
74		log_note "$RM_LNKCNT_ZERO_FILE completes"
75		break
76	fi
77	log_must $SLEEP 10
78	(( i = i + 1 ))
79done
80
81if $PGREP $RM_LNKCNT_ZERO_FILE > /dev/null; then
82	log_must $KILL -TERM $PID
83	log_fail "file link count is zero"
84fi
85
86log_must $KILL -TERM $PID
87log_must $RM -f ${TESTDIR}/tmp/test$$*
88
89log_pass "Verify file link count is zero on zfs"
90