/tests/zfs-tests/tests/functional/removal/removal_resume_export.ksh

https://github.com/adilger/zfs · Korn Shell · 100 lines · 21 code · 16 blank · 63 comment · 0 complexity · 0744f443bc3869e3060982f27eb0d9f3 MD5 · raw file

  1. #! /bin/ksh -p
  2. #
  3. # CDDL HEADER START
  4. #
  5. # This file and its contents are supplied under the terms of the
  6. # Common Development and Distribution License ("CDDL"), version 1.0.
  7. # You may only use this file in accordance with the terms of version
  8. # 1.0 of the CDDL.
  9. #
  10. # A full copy of the text of the CDDL should have accompanied this
  11. # source. A copy of the CDDL is also available via the Internet at
  12. # http://www.illumos.org/license/CDDL.
  13. #
  14. # CDDL HEADER END
  15. #
  16. #
  17. # Copyright (c) 2017 by Delphix. All rights reserved.
  18. #
  19. . $STF_SUITE/include/libtest.shlib
  20. . $STF_SUITE/tests/functional/removal/removal.kshlib
  21. #
  22. # DESCRIPTION:
  23. #
  24. # When a pool has an ongoing removal and it is exported ZFS
  25. # suspends the removal thread beforehand. This test ensures
  26. # that ZFS restarts the removal thread if the export fails
  27. # for some reason.
  28. #
  29. # STRATEGY:
  30. #
  31. # 1. Create a pool with one vdev and do some writes on it.
  32. # 2. Add a new vdev to the pool and start the removal of
  33. # the first vdev.
  34. # 3. Inject a fault in the pool and attempt to export (it
  35. # should fail).
  36. # 4. After the export fails ensure that the removal thread
  37. # was restarted and the process complete successfully.
  38. #
  39. function cleanup
  40. {
  41. zinject -c all
  42. default_cleanup_noexit
  43. }
  44. function callback
  45. {
  46. #
  47. # Inject an error so export fails after having just suspended
  48. # the removal thread. [spa_inject_ref gets incremented]
  49. #
  50. log_must zinject -d $REMOVEDISK -D 10:1 $TESTPOOL
  51. #
  52. # Because of the above error export should fail.
  53. #
  54. log_mustnot zpool export $TESTPOOL
  55. #
  56. # Let the removal finish.
  57. #
  58. log_must zinject -c all
  59. return 0
  60. }
  61. log_onexit cleanup
  62. #
  63. # Create pool with one disk.
  64. #
  65. log_must default_setup_noexit "$REMOVEDISK"
  66. #
  67. # Turn off compression to raise capacity as much as possible
  68. # for the little time that this test runs.
  69. #
  70. log_must zfs set compression=off $TESTPOOL/$TESTFS
  71. #
  72. # Write some data that will be evacuated from the device when
  73. # we start the removal.
  74. #
  75. log_must dd if=/dev/urandom of=$TESTDIR/$TESTFILE0 bs=64M count=32
  76. #
  77. # Add second device where all the data will be evacuated.
  78. #
  79. log_must zpool add -f $TESTPOOL $NOTREMOVEDISK
  80. #
  81. # Attempt the export with errors injected.
  82. #
  83. log_must attempt_during_removal $TESTPOOL $REMOVEDISK callback
  84. log_pass "Device removal thread resumes after failed export"