/tests/zfs-tests/tests/functional/mmp/mmp_active_import.ksh

https://github.com/adilger/zfs · Korn Shell · 125 lines · 60 code · 20 blank · 45 comment · 7 complexity · f681a13fa2d9f5e16b4164aa1ad55bf2 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 Lawrence Livermore National Security, LLC.
  18. #
  19. # DESCRIPTION:
  20. # Under no circumstances when multihost is active, should an active pool
  21. # with one hostid be importable by a host with a different hostid.
  22. #
  23. # STRATEGY:
  24. # 1. Simulate an active pool on another host with ztest.
  25. # 2. Verify 'zpool import' reports an active pool.
  26. # 3. Verify 'zpool import [-f] $MMP_POOL' cannot import the pool.
  27. # 4. Kill ztest to make pool eligible for import.
  28. # 5. Verify 'zpool import' fails with the expected error message.
  29. # 6. Verify 'zpool import $MMP_POOL' fails with the expected message.
  30. # 7. Verify 'zpool import -f $MMP_POOL' can now import the pool.
  31. # 8. Verify pool may be exported/imported without -f argument.
  32. #
  33. . $STF_SUITE/include/libtest.shlib
  34. . $STF_SUITE/tests/functional/mmp/mmp.cfg
  35. . $STF_SUITE/tests/functional/mmp/mmp.kshlib
  36. verify_runnable "both"
  37. function cleanup
  38. {
  39. mmp_pool_destroy $MMP_POOL $MMP_DIR
  40. log_must mmp_clear_hostid
  41. ZTESTPID=$(pgrep ztest)
  42. if [ -n "$ZTESTPID" ]; then
  43. for pid in $ZTESTPID; do
  44. log_must kill -9 $pid
  45. done
  46. else
  47. # if ztest not running and log present, ztest crashed
  48. if [ -f $MMP_ZTEST_LOG ]; then
  49. log_note "ztest appears to have crashed. Tail of log:"
  50. tail -n 50 $MMP_ZTEST_LOG
  51. fi
  52. fi
  53. }
  54. log_assert "multihost=on|off active pool activity checks"
  55. log_onexit cleanup
  56. # 1. Simulate an active pool on another host with ztest.
  57. mmp_pool_destroy $MMP_POOL $MMP_DIR
  58. mmp_pool_create $MMP_POOL $MMP_DIR
  59. # 2. Verify 'zpool import' reports an active pool.
  60. log_must mmp_set_hostid $HOSTID2
  61. log_must is_pool_imported $MMP_POOL "-d $MMP_DIR"
  62. # 3. Verify 'zpool import [-f] $MMP_POOL' cannot import the pool.
  63. MMP_IMPORTED_MSG="Cannot import '$MMP_POOL': pool is imported"
  64. log_must try_pool_import $MMP_POOL "-d $MMP_DIR" "$MMP_IMPORTED_MSG"
  65. for i in {1..10}; do
  66. log_must try_pool_import $MMP_POOL "-f -d $MMP_DIR" "$MMP_IMPORTED_MSG"
  67. done
  68. log_must try_pool_import $MMP_POOL "-c ${MMP_CACHE}.stale" "$MMP_IMPORTED_MSG"
  69. for i in {1..10}; do
  70. log_must try_pool_import $MMP_POOL "-f -c ${MMP_CACHE}.stale" \
  71. "$MMP_IMPORTED_MSG"
  72. done
  73. # 4. Kill ztest to make pool eligible for import. Poll with 'zpool status'.
  74. ZTESTPID=$(pgrep ztest)
  75. if [ -n "$ZTESTPID" ]; then
  76. log_must kill -9 $ZTESTPID
  77. fi
  78. log_must wait_pool_imported $MMP_POOL "-d $MMP_DIR"
  79. if [ -f $MMP_ZTEST_LOG ]; then
  80. log_must rm $MMP_ZTEST_LOG
  81. fi
  82. # 5. Verify 'zpool import' fails with the expected error message, when
  83. # - hostid=0: - configuration error
  84. # - hostid=matches - safe to import the pool
  85. # - hostid=different - previously imported on a different system
  86. #
  87. log_must mmp_clear_hostid
  88. MMP_IMPORTED_MSG="Set a unique system hostid"
  89. log_must check_pool_import $MMP_POOL "-d $MMP_DIR" "action" "$MMP_IMPORTED_MSG"
  90. log_must mmp_set_hostid $HOSTID1
  91. MMP_IMPORTED_MSG="The pool can be imported"
  92. log_must check_pool_import $MMP_POOL "-d $MMP_DIR" "action" "$MMP_IMPORTED_MSG"
  93. log_must mmp_clear_hostid
  94. log_must mmp_set_hostid $HOSTID2
  95. MMP_IMPORTED_MSG="The pool was last accessed by another system."
  96. log_must check_pool_import $MMP_POOL "-d $MMP_DIR" "status" "$MMP_IMPORTED_MSG"
  97. # 6. Verify 'zpool import $MMP_POOL' fails with the expected message.
  98. MMP_IMPORTED_MSG="pool was previously in use from another system."
  99. log_must try_pool_import $MMP_POOL "-d $MMP_DIR" "$MMP_IMPORTED_MSG"
  100. # 7. Verify 'zpool import -f $MMP_POOL' can now import the pool.
  101. log_must import_activity_check $MMP_POOL "-f -d $MMP_DIR"
  102. # 8 Verify pool may be exported/imported without -f argument.
  103. log_must zpool export $MMP_POOL
  104. log_must import_no_activity_check $MMP_POOL "-d $MMP_DIR"
  105. log_pass "multihost=on|off active pool activity checks passed"