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_007_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#   - Recursively rename the snapshot 3 times.
44#   - Destroy the root.
45#
46#   - Recursively snapshot the root.
47#   - Clone the volume to another name in the root.
48#   - Rename the root.
49#   - Destroy the renamed root.
50#
51#   - Recursively snapshot the root.
52#   - Send|Receive the root to another root.
53#   - Destroy the original and received roots.
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 1)."
70
71ROOTPREFIX=$TESTPOOL/007
72DIRS="dir0 dir1"
73VOLS="vol0 dir0/dvol0 dir1/dvol1"
74
75typeset -i NUM_RENAMES=5
76typeset -i NUM_ITERATIONS=10
77
78function onexit_callback
79{
80	log_must $ZFS list -t all
81	log_note "Char devices in /dev/zvol:"
82	find /dev/zvol -type c
83}
84log_onexit onexit_callback
85
86function root_setup
87{
88	rootds=$1
89
90	log_must $ZFS create $rootds
91	for dir in $DIRS; do
92		log_must $ZFS create $rootds/$dir
93	done
94	for vol in $VOLS; do
95		log_must $ZFS create -V 100M $rootds/$vol
96		log_must test -c /dev/zvol/$rootds/$vol
97	done
98}
99
100typeset -i i=0
101root=""
102while (( i != NUM_ITERATIONS )); do
103	root=${ROOTPREFIX}_iter${i}
104	# Test set 1: Recursive snapshot, recursive rename, and destroy
105	typeset -i cur=0
106	log_mustnot test -e /dev/zvol/$root/vol0
107	root_setup $root
108	log_must $ZFS snapshot -r $root@$cur
109	for vol in $VOLS; do
110		log_must test -c /dev/zvol/$root/$vol@$cur
111	done
112	while ((cur < $NUM_RENAMES)); do
113		((next = cur + 1))
114		log_must $ZFS rename -r $root@$cur $root@$next
115		for vol in $VOLS; do
116			v=$root/$vol
117			log_mustnot test -e /dev/zvol/$v@$cur
118			log_must test -c /dev/zvol/$v@$next
119		done
120		cur=$next
121	done
122	log_must $ZFS destroy -r $root
123	log_mustnot test -e /dev/zvol/$root/vol0
124
125	(( i += 1 ))
126done
127
128log_pass "ZFS volume device nodes are handled properly."
129