PageRenderTime 40ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_004_pos.ksh

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 146 lines | 77 code | 22 blank | 47 comment | 3 complexity | 983ef391923a95aa55a2e8f96defecba MD5 | raw file
  1. #!/usr/local/bin/ksh93 -p
  2. #
  3. # Copyright 2015 Spectra Logic Corporation.
  4. #
  5. # $FreeBSD$
  6. . $STF_SUITE/include/libtest.kshlib
  7. ################################################################################
  8. #
  9. # __stc_assertion_start
  10. #
  11. # ID: zpool_destroy_004_pos
  12. #
  13. # DESCRIPTION:
  14. # 'zpool destroy -f <pool>' can forcibly destroy the specified pool,
  15. # even if that pool has running zfs send or receive activity.
  16. #
  17. # STRATEGY:
  18. # 1. Create a storage pool
  19. # 2. For each sleep time in a set:
  20. # 2a. For each destroy type (same pool, sender only, receiver only):
  21. # - Create a dataset with some amount of data
  22. # - Run zfs send | zfs receive in the background.
  23. # - Sleep the amount of time specified for this run.
  24. # - 'zpool destroy -f' the pool.
  25. # - Wait for the send|receive to exit. It must not be killed in
  26. # order to ensure that the destroy takes care of doing so.
  27. # - Verify the pool destroyed successfully
  28. #
  29. # __stc_assertion_end
  30. #
  31. ###############################################################################
  32. verify_runnable "global"
  33. function cleanup
  34. {
  35. poolexists $TESTPOOL && destroy_pool $TESTPOOL
  36. poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
  37. }
  38. function create_sender
  39. {
  40. cleanup
  41. create_pool "$TESTPOOL" "$DISK0"
  42. log_must $ZFS create $TESTPOOL/$TESTFS
  43. log_must $MKDIR -p $TESTDIR
  44. log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
  45. log_must dd if=/dev/zero of=$TESTDIR/f0 bs=1024k count=$datasz
  46. log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap1
  47. }
  48. function create_sender_and_receiver
  49. {
  50. create_sender
  51. create_pool "$TESTPOOL1" "$DISK1"
  52. }
  53. function send_recv_destroy
  54. {
  55. sleeptime=$1
  56. recv=$2
  57. to_destroy=$3
  58. who_to_destroy="$4"
  59. # The pid of this pipe line is that of zfs receive
  60. #
  61. ( $ZFS send -RP $TESTPOOL/$TESTFS@snap1 | $ZFS receive -Fu $recv/d1 ) &
  62. sndrcv_start=$(date '+%s')
  63. rcvpid=$!
  64. sndpid=$(pgrep -P $rcvpid)
  65. log_must sleep $sleeptime
  66. log_note "post sleep: $(ps -p ${sndpid},${rcvpid} -o command)"
  67. destroy_start=$(date '+%s')
  68. log_must $ZPOOL destroy -f $to_destroy
  69. destroy_end=$(date '+%s')
  70. dtime=$((destroy_end - destroy_start))
  71. log_note "Destroy of $who_to_destroy took ${dtime} seconds."
  72. log_note "post destroy: $(ps -p ${sndpid},${rcvpid} -o command)"
  73. # Wait for send and recv to exit.
  74. #
  75. wait $sndpid
  76. snderr=$?
  77. wait $rcvpid
  78. rcverr=$?
  79. wait_end=$(date '+%s')
  80. wtime=$((wait_end - sndrcv_start))
  81. log_note "send|receive took ${wtime} seconds to finish."
  82. # KSH: "wait pid" exit status of 127 means that process never existed
  83. # or already completed; ksh's wait only returns the status of the
  84. # child process if the child was running when the wait was issued.
  85. # Therefore, we can not imply much about the interruption of the
  86. # send | recv by zpool destroy -f
  87. #
  88. # The real test of success is simply that the pool was destroyed.
  89. #
  90. log_note \
  91. "Destruction of ${who_to_destroy}: send ${snderr}, recv ${rcverr}"
  92. log_mustnot $ZPOOL list $to_destroy
  93. }
  94. function run_tests
  95. {
  96. log_note "TEST: send|receive to the same pool"
  97. create_sender
  98. send_recv_destroy $sleeptime $TESTPOOL $TESTPOOL SAME_POOL
  99. log_note "TEST: send|receive to different pools, destroy sender"
  100. create_sender_and_receiver
  101. send_recv_destroy $sleeptime $TESTPOOL1 $TESTPOOL SENDER
  102. log_note "TEST: send|receive to different pools, destroy receiver"
  103. create_sender_and_receiver
  104. send_recv_destroy $sleeptime $TESTPOOL1 $TESTPOOL1 RECEIVER
  105. }
  106. log_assert "'zpool destroy -f <pool>' can force destroy active pool"
  107. log_onexit cleanup
  108. set_disks
  109. # Faster tests using 1GB data size
  110. datasz=1000
  111. log_note "Running fast tests with 1000MB of data"
  112. for sleeptime in 0.1 0.3 0.5 0.75 1 2 3; do
  113. run_tests
  114. done
  115. # A longer test that simulates a more realistic send|receive that exceeds
  116. # the size of arc memory by 1/3 and gets interrupted a decent amount of
  117. # time after the start of the run.
  118. arcmem=$(sysctl -n vfs.zfs.arc_max)
  119. # ARC will use 2xdatasz memory since it caches both the src and dst copies
  120. datasz=$((arcmem / 1048576 * 2 / 3))
  121. log_note "Running longer test with ${datasz}MB of data"
  122. sleeptime=15
  123. run_tests
  124. log_pass "'zpool destroy -f <pool>' successful with active pools."