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