/tests/zfs-tests/tests/functional/link_count/link_count_001.ksh

https://github.com/adilger/zfs · Korn Shell · 95 lines · 38 code · 18 blank · 39 comment · 6 complexity · 3fdc4005d143f641951683cad40b54a1 MD5 · raw file

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