/tests/zfs-tests/tests/functional/inuse/inuse_008_pos.ksh

https://github.com/adilger/zfs · Korn Shell · 97 lines · 36 code · 19 blank · 42 comment · 7 complexity · 51007ba5e69307554b235576c860a7e0 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 2009 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. . $STF_SUITE/tests/functional/inuse/inuse.cfg
  31. #
  32. # DESCRIPTION:
  33. # Newfs will interfere with devices and spare devices that are in use
  34. # by exported pool.
  35. #
  36. # STRATEGY:
  37. # 1. Create a regular|mirror|raidz|raidz2 pool with the given disk
  38. # 2. Export the pool
  39. # 3. Try to newfs against the disk, verify it succeeds as expect.
  40. #
  41. verify_runnable "global"
  42. if ! is_physical_device $FS_DISK0; then
  43. log_unsupported "This directory cannot be run on raw files."
  44. fi
  45. function cleanup
  46. {
  47. poolexists $TESTPOOL1 || zpool import $TESTPOOL1 >/dev/null 2>&1
  48. poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
  49. #
  50. # Tidy up the disks we used.
  51. #
  52. cleanup_devices $vdisks $sdisks
  53. }
  54. function verify_assertion # disks
  55. {
  56. typeset targets=$1
  57. for t in $targets; do
  58. if ! new_fs $t; then
  59. log_fail "newfs over exported pool " \
  60. "fails unexpectedly."
  61. fi
  62. done
  63. return 0
  64. }
  65. log_assert "Verify newfs over exported pool succeed."
  66. log_onexit cleanup
  67. set -A vdevs "" "mirror" "raidz" "raidz1" "raidz2"
  68. typeset -i i=0
  69. while (( i < ${#vdevs[*]} )); do
  70. typeset spare="spare $sdisks"
  71. # If this is for raidz2, use 3 disks for the pool.
  72. [[ ${vdevs[i]} = "raidz2" ]] && spare="$sdisks"
  73. create_pool $TESTPOOL1 ${vdevs[i]} $vdisks $spare
  74. log_must zpool export $TESTPOOL1
  75. verify_assertion "$rawtargets"
  76. (( i = i + 1 ))
  77. done
  78. log_pass "Newfs over exported pool succeed."