4 # This file and its contents are supplied under the terms of the
5 # Common Development and Distribution License ("CDDL"), version 1.0.
6 # You may only use this file in accordance with the terms of version
9 # A full copy of the text of the CDDL should have accompanied this
10 # source. A copy of the CDDL is also available via the Internet at
11 # http://www.illumos.org/license/CDDL.
15 # Copyright (c) 2021 by Delphix. All rights reserved.
16 # Copyright (c) 2023 by Klara, Inc.
19 .
$STF_SUITE/tests
/functional
/cli_root
/zpool_import
/zpool_import.kshlib
23 # A pool that wasn't cleanly exported should not be importable from a cachefile
24 # without force if the local hostid doesn't match the on-disk hostid.
29 # 3. Backup the cachefile.
30 # 4. Simulate the pool being torn down without export:
31 # 4.1. Copy the underlying device state.
32 # 4.2. Export the pool.
33 # 4.3. Restore the device state from the copy.
34 # 5. Change the hostid.
35 # 6. Verify that importing the pool from the cachefile fails.
36 # 7. Verify that importing the pool from the cachefile with force
40 verify_runnable
"global"
42 function custom_cleanup
44 rm -f $HOSTID_FILE $CPATH $CPATHBKP $VDEV0.bak
48 log_onexit custom_cleanup
51 log_must zgenhostid
-f $HOSTID1
54 log_must zpool create
-o cachefile
=$CPATH $TESTPOOL1 $VDEV0
56 # 3. Backup the cachfile.
57 log_must
cp $CPATH $CPATHBKP
59 # 4. Simulate the pool being torn down without export.
60 log_must
cp $VDEV0 $VDEV0.bak
61 log_must zpool
export $TESTPOOL1
62 log_must
cp -f $VDEV0.bak
$VDEV0
63 log_must
rm -f $VDEV0.bak
65 # 5. Change the hostid.
66 log_must zgenhostid
-f $HOSTID2
68 # 6. Verify that importing the pool from the cachefile fails.
69 log_mustnot zpool import
-c $CPATHBKP $TESTPOOL1
71 # 7. Verify that importing the pool from the cachefile with force succeeds.
72 log_must zpool import
-f -c $CPATHBKP $TESTPOOL1
74 log_pass
"zpool import from cachefile requires force if not cleanly " \
75 "exported and hostid changes."