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. $STF_SUITE/include/libtest.kshlib
28. $STF_SUITE/tests/zvol/zvol_common.kshlib
29
30###############################################################################
31#
32# __stc_assertion_start
33#
34# ID: zvol_misc_008_pos
35#
36# DESCRIPTION:
37# Verify that device nodes are modified appropriately during zfs command
38# operations on volumes.
39#
40# STRATEGY:
41# For a certain number of iterations, with root setup for each test set:
42#   - Recursively snapshot the root.
43#   - Clone the volume to another name in the root.
44#   - Promote the clone.
45#   - Demote the original clone.
46#   - Snapshot & clone the clone.
47#   - Rename the root.
48#   - Destroy the renamed root.
49#
50# At each stage, the device nodes are checked to match the expectations.
51#
52# TESTABILITY: explicit
53#
54# TEST_AUTOMATION_LEVEL: automated
55#
56# CODING_STATUS: COMPLETED (2008-03-04)
57#
58# __stc_assertion_end
59#
60################################################################################
61
62verify_runnable "global"
63
64log_assert "Verify that ZFS volume device nodes are handled properly (part 2)."
65
66ROOTPREFIX=$TESTPOOL/008
67DIRS="dir0 dir1"
68VOLS="vol0 dir0/dvol0 dir1/dvol1"
69
70typeset -i NUM_ITERATIONS=10
71
72function onexit_callback
73{
74	log_must $ZFS list -t all
75	log_note "Char devices in /dev/zvol:"
76	find /dev/zvol -type c
77}
78log_onexit onexit_callback
79
80function root_setup
81{
82	rootds=$1
83
84	log_must $ZFS create $rootds
85	for dir in $DIRS; do
86		log_must $ZFS create $rootds/$dir
87	done
88	for vol in $VOLS; do
89		log_must $ZFS create -V 100M $rootds/$vol
90		log_must test -c /dev/zvol/$rootds/$vol
91	done
92}
93
94function test_exists
95{
96	for zvolds in $*; do
97		log_must test -c /dev/zvol/${zvolds}
98	done
99}
100
101function test_notexists
102{
103	for zvolds in $*; do
104		log_mustnot test -e /dev/zvol/${zvolds}
105	done
106}
107
108typeset -i i=0
109while (( i != NUM_ITERATIONS )); do
110	root=${ROOTPREFIX}_iter${i}
111	# Test set 2: Recursive snapshot, cloning/promoting, and root-rename
112	root_setup $root
113	log_must $ZFS snapshot -r $root@snap
114	log_must $ZFS clone $root/vol0@snap $root/vol1
115	test_exists $root/vol1
116	test_notexists $root/vol1@snap
117
118	log_must $ZFS promote $root/vol1
119	test_exists $root/vol0 $root/vol1 $root/vol1@snap
120	test_notexists $root/vol0@snap
121
122	# Re-promote the original volume.
123	log_must $ZFS promote $root/vol0
124	test_exists $root/vol0 $root/vol1 $root/vol0@snap
125	test_notexists $root/vol1@snap
126
127	# Clone a clone's snapshot.
128	log_must $ZFS snapshot $root/vol1@newsnap
129	log_must $ZFS clone $root/vol1@newsnap $root/vol2
130	test_exists $root/vol2
131	test_notexists $root/vol2@snap
132
133	# Now promote *that* clone.
134	log_must $ZFS promote $root/vol2
135	test_exists $root/vol0 $root/vol0@snap \
136		$root/vol1 $root/vol2 $root/vol2@newsnap
137	test_notexists $root/vol1@snap $root/vol1@newsnap
138
139	renamed=${root}_renamed
140	log_must $ZFS rename $root $renamed
141	# Ensure that the root rename applies to clones and promoted clones.
142	test_exists $renamed/vol1 $renamed/vol2 $renamed/vol2@newsnap
143	test_notexists $root/vol1 $renamed/vol1@snap $renamed/vol1@newsnap
144	for vol in $VOLS; do
145		test_notexists $root/$vol $root/$vol@snap
146		test_exists $renamed/$vol $renamed/$vol@snap
147	done
148
149	log_must $ZFS destroy -r $renamed
150	test_notexists $renamed/vol0 $renamed/vol1 $renamed/vol2
151
152	(( i += 1 ))
153done
154log_pass "ZFS volume device nodes are handled properly (part 2)."
155