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