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) 2019 by Lawrence Livermore National Security, LLC.
19#
20
21# DESCRIPTION:
22#	Verify the hostid file can reside on a ZFS dataset.
23#
24# STRATEGY:
25#	1. Create a non-redundant pool
26#	2. Create an 'etc' dataset containing a valid hostid file
27#	3. Create a file so the pool will have some contents
28#	4. Verify multihost cannot be enabled until the /etc/hostid is linked
29#	5. Verify vdevs may be attached and detached
30#	6. Verify normal, cache, log and special vdevs can be added
31#	7. Verify normal, cache, and log vdevs can be removed
32#
33
34. $STF_SUITE/include/libtest.shlib
35. $STF_SUITE/tests/functional/mmp/mmp.cfg
36. $STF_SUITE/tests/functional/mmp/mmp.kshlib
37
38verify_runnable "both"
39
40function cleanup
41{
42	default_cleanup_noexit
43	log_must rm $MMP_DIR/file.{0,1,2,3,4,5}
44	log_must rmdir $MMP_DIR
45	log_must mmp_clear_hostid
46	if [[ -L $HOSTID_FILE ]]; then
47		rm -f $HOSTID_FILE
48	fi
49}
50
51log_assert "Verify hostid file can reside on a ZFS dataset"
52log_onexit cleanup
53
54log_must mkdir -p $MMP_DIR
55log_must truncate -s $MINVDEVSIZE $MMP_DIR/file.{0,1,2,3,4,5}
56
57# 1. Create a non-redundant pool
58log_must zpool create $MMP_POOL $MMP_DIR/file.0
59
60# 2. Create an 'etc' dataset containing a valid hostid file; caching is
61#    disabled on the dataset to force the hostid to be read from disk.
62log_must zfs create -o primarycache=none -o secondarycache=none $MMP_POOL/etc
63mntpnt_etc=$(get_prop mountpoint $MMP_POOL/etc)
64log_must mmp_set_hostid $HOSTID1
65log_must mv $HOSTID_FILE $mntpnt_etc/hostid
66
67# 3. Create a file so the pool will have some contents
68log_must zfs create $MMP_POOL/fs
69mntpnt_fs=$(get_prop mountpoint $MMP_POOL/fs)
70log_must mkfile 1M $mntpnt_fs/file
71
72# 4. Verify multihost cannot be enabled until the /etc/hostid is linked
73log_mustnot zpool set multihost=on $MMP_POOL
74log_mustnot ls -l $HOSTID_FILE
75log_must ln -s $mntpnt_etc/hostid $HOSTID_FILE
76log_must zpool set multihost=on $MMP_POOL
77
78# 5. Verify vdevs may be attached and detached
79log_must zpool attach $MMP_POOL $MMP_DIR/file.0 $MMP_DIR/file.1
80log_must zpool detach $MMP_POOL $MMP_DIR/file.1
81
82# 6. Verify normal, cache, log and special vdevs can be added
83log_must zpool add $MMP_POOL $MMP_DIR/file.1
84log_must zpool add $MMP_POOL $MMP_DIR/file.2
85log_must zpool add $MMP_POOL cache $MMP_DIR/file.3
86log_must zpool add $MMP_POOL log $MMP_DIR/file.4
87log_must zpool add $MMP_POOL special $MMP_DIR/file.5
88
89# 7. Verify normal, cache, and log vdevs can be removed
90log_must zpool remove $MMP_POOL $MMP_DIR/file.2
91log_must zpool remove $MMP_POOL $MMP_DIR/file.3
92log_must zpool remove $MMP_POOL $MMP_DIR/file.4
93
94log_pass "Verify hostid file can reside on a ZFS dataset."
95