1#! /usr/local/bin/ksh93 -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"@(#)zvol_misc_008_pos.ksh	1.3	08/05/14 SMI"
28#
29
30. $STF_SUITE/include/libtest.kshlib
31. $STF_SUITE/tests/zvol/zvol_common.kshlib
32
33###############################################################################
34#
35# __stc_assertion_start
36#
37# ID: zvol_misc_008_pos
38#
39# DESCRIPTION:
40# Verify that device nodes are modified appropriately during zfs command
41# operations on volumes.
42#
43# STRATEGY:
44# For a certain number of iterations, with root setup for each test set:
45#   - Recursively snapshot the root.
46#   - Clone the volume to another name in the root.
47#   - Promote the clone.
48#   - Demote the original clone.
49#   - Snapshot & clone the clone.
50#   - Rename the root.
51#   - Destroy the renamed root.
52#
53# At each stage, the device nodes are checked to match the expectations.
54#
55# TESTABILITY: explicit
56#
57# TEST_AUTOMATION_LEVEL: automated
58#
59# CODING_STATUS: COMPLETED (2008-03-04)
60#
61# __stc_assertion_end
62#
63################################################################################
64
65verify_runnable "global"
66
67log_assert "Verify that ZFS volume device nodes are handled properly (part 2)."
68
69ROOTPREFIX=$TESTPOOL/008
70DIRS="dir0 dir1"
71VOLS="vol0 dir0/dvol0 dir1/dvol1"
72
73typeset -i NUM_ITERATIONS=10
74
75function onexit_callback
76{
77	log_must $ZFS list -t all
78	log_note "Char devices in /dev/zvol:"
79	find /dev/zvol -type c
80}
81log_onexit onexit_callback
82
83function root_setup
84{
85	rootds=$1
86
87	log_must $ZFS create $rootds
88	for dir in $DIRS; do
89		log_must $ZFS create $rootds/$dir
90	done
91	for vol in $VOLS; do
92		log_must $ZFS create -V 100M $rootds/$vol
93		log_must test -c /dev/zvol/$rootds/$vol
94	done
95}
96
97function test_exists
98{
99	for zvolds in $*; do
100		log_must test -c /dev/zvol/${zvolds}
101	done
102}
103
104function test_notexists
105{
106	for zvolds in $*; do
107		log_mustnot test -e /dev/zvol/${zvolds}
108	done
109}
110
111typeset -i i=0
112while (( i != NUM_ITERATIONS )); do
113	root=${ROOTPREFIX}_iter${i}
114	# Test set 2: Recursive snapshot, cloning/promoting, and root-rename
115	root_setup $root
116	log_must $ZFS snapshot -r $root@snap
117	log_must $ZFS clone $root/vol0@snap $root/vol1
118	test_exists $root/vol1
119	test_notexists $root/vol1@snap
120
121	log_must $ZFS promote $root/vol1
122	test_exists $root/vol0 $root/vol1 $root/vol1@snap
123	test_notexists $root/vol0@snap
124
125	# Re-promote the original volume.
126	log_must $ZFS promote $root/vol0
127	test_exists $root/vol0 $root/vol1 $root/vol0@snap
128	test_notexists $root/vol1@snap
129
130	# Clone a clone's snapshot.
131	log_must $ZFS snapshot $root/vol1@newsnap
132	log_must $ZFS clone $root/vol1@newsnap $root/vol2
133	test_exists $root/vol2
134	test_notexists $root/vol2@snap
135
136	# Now promote *that* clone.
137	log_must $ZFS promote $root/vol2
138	test_exists $root/vol0 $root/vol0@snap \
139		$root/vol1 $root/vol2 $root/vol2@newsnap
140	test_notexists $root/vol1@snap $root/vol1@newsnap
141
142	renamed=${root}_renamed
143	log_must $ZFS rename $root $renamed
144	# Ensure that the root rename applies to clones and promoted clones.
145	test_exists $renamed/vol1 $renamed/vol2 $renamed/vol2@newsnap
146	test_notexists $root/vol1 $renamed/vol1@snap $renamed/vol1@newsnap
147	for vol in $VOLS; do
148		test_notexists $root/$vol $root/$vol@snap
149		test_exists $renamed/$vol $renamed/$vol@snap
150	done
151
152	log_must $ZFS destroy -r $renamed
153	test_notexists $renamed/vol0 $renamed/vol1 $renamed/vol2
154
155	(( i += 1 ))
156done
157log_pass "ZFS volume device nodes are handled properly (part 2)."
158