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