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

https://github.com/adilger/zfs · Korn Shell · 168 lines · 98 code · 19 blank · 51 comment · 10 complexity · f20ea7e9913055aafc8f9b03a36aa1f7 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 2008 Sun Microsystems, Inc. All rights reserved.
  24. # Use is subject to license terms.
  25. #
  26. #
  27. # Copyright (c) 2012, 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. # ZFS will not interfere with devices that are in use by ufsdump or
  34. # ufsrestore.
  35. #
  36. # STRATEGY:
  37. # 1. newfs a disk
  38. # 2. mount the disk
  39. # 3. create files and dirs on disk
  40. # 4. umount the disk
  41. # 5. ufsdump this disk to a backup disk
  42. # 6. Try to create a ZFS pool with same disk (also as a spare device)
  43. # 7. ufsrestore the disk from backup
  44. # 8. try to create a zpool during the ufsrestore
  45. #
  46. verify_runnable "global"
  47. function cleanup
  48. {
  49. poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
  50. poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2
  51. log_note "Kill off ufsdump process if still running"
  52. kill -0 $PIDUFSDUMP > /dev/null 2>&1 && \
  53. log_must kill -9 $PIDUFSDUMP > /dev/null 2>&1
  54. #
  55. # Note: It would appear that ufsdump spawns a number of processes
  56. # which are not killed when the $PIDUFSDUMP is whacked. So best bet
  57. # is to find the rest of the them and deal with them individually.
  58. #
  59. for all in `pgrep ufsdump`
  60. do
  61. kill -9 $all > /dev/null 2>&1
  62. done
  63. log_note "Kill off ufsrestore process if still running"
  64. kill -0 $PIDUFSRESTORE > /dev/null 2>&1 && \
  65. log_must kill -9 $PIDUFSRESTORE > /dev/null 2>&1
  66. ismounted $UFSMP ufs && log_must umount $UFSMP
  67. rm -rf $UFSMP
  68. rm -rf $TESTDIR
  69. #
  70. # Tidy up the disks we used.
  71. #
  72. log_must cleanup_devices $vdisks $sdisks
  73. }
  74. log_assert "Ensure ZFS does not interfere with devices that are in use by " \
  75. "ufsdump or ufsrestore"
  76. log_onexit cleanup
  77. typeset bigdir="${UFSMP}/bigdirectory"
  78. typeset restored_files="${UFSMP}/restored_files"
  79. typeset -i dirnum=0
  80. typeset -i filenum=0
  81. typeset cwd=""
  82. log_note "Make a ufs filesystem on source $rawdisk1"
  83. new_fs $rawdisk1 > /dev/null 2>&1
  84. (($? != 0)) && log_untested "Unable to create ufs filesystem on $rawdisk1"
  85. log_must mkdir -p $UFSMP
  86. log_note "mount source $disk1 on $UFSMP"
  87. log_must mount $disk1 $UFSMP
  88. log_note "Now create some directories and files to be ufsdump'ed"
  89. while (($dirnum <= 2)); do
  90. log_must mkdir $bigdir${dirnum}
  91. while (( $filenum <= 2 )); do
  92. file_write -o create -f $bigdir${dirnum}/file${filenum} \
  93. -b $BLOCK_SIZE -c $BLOCK_COUNT
  94. if [[ $? -ne 0 ]]; then
  95. if [[ $dirnum -lt 3 ]]; then
  96. log_fail "file_write only wrote" \
  97. "<(( $dirnum * 3 + $filenum ))>" \
  98. "files, this is not enough"
  99. fi
  100. fi
  101. ((filenum = filenum + 1))
  102. done
  103. filenum=0
  104. ((dirnum = dirnum + 1))
  105. done
  106. log_must umount $UFSMP
  107. log_note "Start ufsdump in the background"
  108. log_note "ufsdump 0bf 512 $rawdisk0 $disk1"
  109. ufsdump 0bf 512 $rawdisk0 $disk1 &
  110. PIDUFSDUMP=$!
  111. unset NOINUSE_CHECK
  112. log_note "Attempt to zpool the source device in use by ufsdump"
  113. log_mustnot zpool create $TESTPOOL1 "$disk1"
  114. log_mustnot poolexists $TESTPOOL1
  115. log_note "Attempt to take the source device in use by ufsdump as spare device"
  116. log_mustnot zpool create $TESTPOOL1 "$FS_DISK2" spare "$disk1"
  117. log_mustnot poolexists $TESTPOOL1
  118. wait $PIDUFSDUMP
  119. typeset -i retval=$?
  120. (($retval != 0)) && log_fail "ufsdump failed with error code $ret_val"
  121. log_must mount $disk1 $UFSMP
  122. log_must rm -rf $UFSMP/*
  123. log_must mkdir $restored_files
  124. cwd=$PWD
  125. log_must cd $restored_files
  126. log_note "Start ufsrestore in the background from the target device"
  127. log_note "ufsrestore rbf 512 $rawdisk0"
  128. ufsrestore rbf 512 $rawdisk0 &
  129. PIDUFSRESTORE=$!
  130. log_must cd $cwd
  131. log_note "Attempt to zpool the restored device in use by ufsrestore"
  132. log_mustnot zpool create -f $TESTPOOL2 "$disk1"
  133. log_mustnot poolexists $TESTPOOL2
  134. log_note "Attempt to take the restored device in use by ufsrestore as spare" \
  135. "device"
  136. log_mustnot zpool create -f $TESTPOOL2 "$FS_DISK2" spare "$disk1"
  137. log_mustnot poolexists $TESTPOOL2
  138. log_pass "Unable to zpool over a device in use by ufsdump or ufsrestore"