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_009_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#   - Send|Receive the root to another root.
44#   - Destroy the original and received roots.
45#
46# At each stage, the device nodes are checked to match the expectations.
47#
48# TESTABILITY: explicit
49#
50# TEST_AUTOMATION_LEVEL: automated
51#
52# CODING_STATUS: COMPLETED (2008-03-04)
53#
54# __stc_assertion_end
55#
56################################################################################
57
58verify_runnable "global"
59
60log_assert "Verify that ZFS volume device nodes are handled properly (part 3)."
61
62ROOTPREFIX=$TESTPOOL/009
63DIRS="dir0 dir1"
64VOLS="vol0 dir0/dvol0 dir1/dvol1"
65
66typeset -i NUM_ITERATIONS=5
67
68function onexit_callback
69{
70	log_must $ZFS list -t all
71	log_note "Char devices in /dev/zvol:"
72	find /dev/zvol -type c
73}
74log_onexit onexit_callback
75
76function root_setup
77{
78	rootds=$1
79
80	log_must $ZFS create $rootds
81	for dir in $DIRS; do
82		log_must $ZFS create $rootds/$dir
83	done
84	for vol in $VOLS; do
85		log_must $ZFS create -V 100M $rootds/$vol
86		log_must test -c /dev/zvol/$rootds/$vol
87	done
88}
89
90typeset -i i=0
91while (( i != NUM_ITERATIONS )); do
92	root=${ROOTPREFIX}_iter${i}
93	# Test set 3: send|receive & receive with forced rollback
94	root_setup $root
95	log_must $ZFS snapshot -r $root@snap
96	received=${root}_recv
97	log_must eval "$ZFS send -R $root@snap | $ZFS receive -F ${received}"
98	for vol in $VOLS; do
99		log_must test -c /dev/zvol/${received}/${vol}
100		log_must test -c /dev/zvol/${received}/${vol}@snap
101	done
102	# Re-send with -F, to ensure that actual receive rollback also works.
103	# For good measure, pre-destroy one of the volumes.  Also, destroy
104	# the snapshot we received earlier for this to work.
105	log_must $ZFS destroy -r $received/vol0
106	log_must $ZFS destroy -r $received@snap
107	log_must eval "$ZFS send -R $root@snap | $ZFS receive -F ${received}"
108	for vol in $VOLS; do
109		log_must test -c /dev/zvol/${received}/${vol}
110		log_must test -c /dev/zvol/${received}/${vol}@snap
111	done
112	log_must $ZFS destroy -r ${root}
113	log_mustnot test -e /dev/zvol/${root}/vol0
114	log_mustnot test -e /dev/zvol/${root}/vol0@snap
115	log_must $ZFS destroy -r ${received}
116	log_mustnot test -e /dev/zvol/${received}/vol0
117	log_mustnot test -e /dev/zvol/${received}/vol0@snap
118
119	(( i += 1 ))
120done
121log_pass "ZFS volume device nodes are handled properly (part 3)."
122