1f38cb554SJohn Wren Kennedy#!/bin/ksh -p
2f38cb554SJohn Wren Kennedy#
3f38cb554SJohn Wren Kennedy# CDDL HEADER START
4f38cb554SJohn Wren Kennedy#
5f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the
6f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License").
7f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License.
8f38cb554SJohn Wren Kennedy#
9f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing.
11f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions
12f38cb554SJohn Wren Kennedy# and limitations under the License.
13f38cb554SJohn Wren Kennedy#
14f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
15f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
17f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
18f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
19f38cb554SJohn Wren Kennedy#
20f38cb554SJohn Wren Kennedy# CDDL HEADER END
21f38cb554SJohn Wren Kennedy#
22f38cb554SJohn Wren Kennedy
23f38cb554SJohn Wren Kennedy#
24f38cb554SJohn Wren Kennedy# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25f38cb554SJohn Wren Kennedy# Use is subject to license terms.
26f38cb554SJohn Wren Kennedy#
27f38cb554SJohn Wren Kennedy
28f38cb554SJohn Wren Kennedy#
29*1d32ba66SJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30f38cb554SJohn Wren Kennedy#
31f38cb554SJohn Wren Kennedy
32f38cb554SJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib
33f38cb554SJohn Wren Kennedy
34f38cb554SJohn Wren Kennedy#
35f38cb554SJohn Wren Kennedy# DESCRIPTION:
36f38cb554SJohn Wren Kennedy#
37f38cb554SJohn Wren Kennedy# Test that a set of valid names can be used to create pools. Further
38f38cb554SJohn Wren Kennedy# verify that the created pools can be destroyed.
39f38cb554SJohn Wren Kennedy#
40f38cb554SJohn Wren Kennedy# STRATEGY:
41f38cb554SJohn Wren Kennedy# 1) For each valid character in the character set, try to create
42f38cb554SJohn Wren Kennedy# and destroy the pool.
43f38cb554SJohn Wren Kennedy# 2) Given a list of valid pool names, try to create and destroy
44f38cb554SJohn Wren Kennedy# pools with the given names.
45f38cb554SJohn Wren Kennedy#
46f38cb554SJohn Wren Kennedy
47f38cb554SJohn Wren Kennedyverify_runnable "global"
48f38cb554SJohn Wren Kennedy
49f38cb554SJohn Wren Kennedylog_assert "Ensure that pool names can use the ASCII subset of UTF-8"
50f38cb554SJohn Wren Kennedy
51f38cb554SJohn Wren Kennedyfunction cleanup
52f38cb554SJohn Wren Kennedy{
53f38cb554SJohn Wren Kennedy	if [[ -n $name ]] && poolexists $name ; then
54*1d32ba66SJohn Wren Kennedy		log_must zpool destroy $name
55f38cb554SJohn Wren Kennedy	fi
56f38cb554SJohn Wren Kennedy
57f38cb554SJohn Wren Kennedy	if [[ -d $TESTDIR ]]; then
58*1d32ba66SJohn Wren Kennedy		log_must rm -rf $TESTDIR
59f38cb554SJohn Wren Kennedy	fi
60f38cb554SJohn Wren Kennedy
61f38cb554SJohn Wren Kennedy}
62f38cb554SJohn Wren Kennedy
63f38cb554SJohn Wren Kennedylog_onexit cleanup
64f38cb554SJohn Wren Kennedy
65f38cb554SJohn Wren KennedyDISK=${DISKS%% *}
66f38cb554SJohn Wren Kennedyif [[ ! -e $TESTDIR ]]; then
67*1d32ba66SJohn Wren Kennedy	log_must mkdir $TESTDIR
68f38cb554SJohn Wren Kennedyfi
69f38cb554SJohn Wren Kennedy
70f38cb554SJohn Wren Kennedylog_note "Ensure letters of the alphabet are allowable"
71f38cb554SJohn Wren Kennedy
72f38cb554SJohn Wren Kennedytypeset name=""
73f38cb554SJohn Wren Kennedy
74f38cb554SJohn Wren Kennedyfor name in A B C D E F G H I J K L M \
75f38cb554SJohn Wren Kennedy    N O P Q R S T U V W X Y Z \
76f38cb554SJohn Wren Kennedy    a b c d e f g h i j k l m \
77f38cb554SJohn Wren Kennedy    n o p q r s t u v w x y z
78f38cb554SJohn Wren Kennedydo
79*1d32ba66SJohn Wren Kennedy	log_must zpool create -m $TESTDIR $name $DISK
80f38cb554SJohn Wren Kennedy	if ! poolexists $name; then
81f38cb554SJohn Wren Kennedy		log_fail "Could not create a pool called '$name'"
82f38cb554SJohn Wren Kennedy	fi
83f38cb554SJohn Wren Kennedy
84*1d32ba66SJohn Wren Kennedy	log_must zpool destroy $name
85f38cb554SJohn Wren Kennedydone
86f38cb554SJohn Wren Kennedy
87f38cb554SJohn Wren Kennedylog_note "Ensure a variety of unusual names passes"
88f38cb554SJohn Wren Kennedy
89f38cb554SJohn Wren Kennedyname=""
90f38cb554SJohn Wren Kennedy
91f38cb554SJohn Wren Kennedyfor name in "a.............................." "a_" "a-" "a:" \
92f38cb554SJohn Wren Kennedy    "a." "a123456" "bc0t0d0" "m1rr0r_p00l" "ra1dz_p00l" \
93f38cb554SJohn Wren Kennedy    "araidz2" "C0t2d0" "cc0t0" "raid2:-_." "mirr_:-." \
94f38cb554SJohn Wren Kennedy    "m1rr0r-p00l" "ra1dz-p00l" "spar3_p00l" \
95f38cb554SJohn Wren Kennedy    "spar3-p00l" "hiddenmirrorpool" "hiddenraidzpool" \
96f38cb554SJohn Wren Kennedy    "hiddensparepool"
97f38cb554SJohn Wren Kennedydo
98*1d32ba66SJohn Wren Kennedy	log_must zpool create -m $TESTDIR $name $DISK
99f38cb554SJohn Wren Kennedy	if ! poolexists $name; then
100f38cb554SJohn Wren Kennedy		log_fail "Could not create a pool called '$name'"
101f38cb554SJohn Wren Kennedy	fi
102f38cb554SJohn Wren Kennedy
103f38cb554SJohn Wren Kennedy	#
104f38cb554SJohn Wren Kennedy	# Since the naming convention applies to datasets too,
105f38cb554SJohn Wren Kennedy	# create datasets with the same names as above.
106f38cb554SJohn Wren Kennedy	#
107*1d32ba66SJohn Wren Kennedy	log_must zfs create $name/$name
108*1d32ba66SJohn Wren Kennedy	log_must zfs snapshot $name/$name@$name
109*1d32ba66SJohn Wren Kennedy	log_must zfs clone $name/$name@$name $name/clone_$name
110*1d32ba66SJohn Wren Kennedy	log_must zfs create -V 150m $name/$name/$name
111f38cb554SJohn Wren Kennedy
112*1d32ba66SJohn Wren Kennedy	log_must zpool destroy $name
113f38cb554SJohn Wren Kennedydone
114f38cb554SJohn Wren Kennedy
115f38cb554SJohn Wren Kennedylog_pass "Valid pool names were accepted correctly."
116