xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_009_pos.ksh (revision b6805bf78d2bbbeeaea8909a05623587b42d58b3)
1#!/bin/ksh
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright (c) 2012 by Delphix. All rights reserved.
15#
16
17#
18# DESCRIPTION
19# verify 'zfs snapshot <list of snapshots>' works correctly
20#
21# STRATEGY
22# 1. Create multiple datasets
23# 2. Create mutiple snapshots with a list of valid and invalid
24#    snapshot names
25# 3. Verify the valid snpashot creation
26
27. $STF_SUITE/include/libtest.shlib
28
29function cleanup
30{
31	for ds in $datasets; do
32		datasetexists $ds && log_must $ZFS destroy -r $ds
33	done
34	$ZFS destroy -r $TESTPOOL/TESTFS4
35}
36datasets="$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS2
37    $TESTPOOL/$TESTFS3"
38
39invalid_args=("$TESTPOOL/$TESTFS1@now $TESTPOOL/$TESTFS2@now \
40    $TESTPOOL/$TESTFS@blah?" "$TESTPOOL/$TESTFS1@blah* \
41    $TESTPOOL/$TESTFS2@blah? $TESTPOOL/$TESTFS3@blah%" \
42    "$TESTPOOL/$TESTFS1@$($PYTHON -c 'print "x" * 300') $TESTPOOL/$TESTFS2@300 \
43    $TESTPOOL/$TESTFS3@300")
44
45valid_args=("$TESTPOOL/$TESTFS1@snap $TESTPOOL/$TESTFS2@snap \
46    $TESTPOOL/$TESTFS3@snap" "$TESTPOOL/$TESTFS1@$($PYTHON -c 'print "x" * 200')\
47    $TESTPOOL/$TESTFS2@2 $TESTPOOL/$TESTFS3@s")
48
49log_assert "verify zfs supports multiple consistent snapshots"
50log_onexit cleanup
51typeset -i i=1
52test_data=$STF_SUITE/tests/functional/cli_root/zpool_upgrade/blockfiles
53
54log_note "destroy a list of valid snapshots"
55for ds in $datasets; do
56	log_must $ZFS create $ds
57	log_must $CP -r $test_data /$ds
58done
59i=0
60while (( i < ${#valid_args[*]} )); do
61	log_must $ZFS snapshot ${valid_args[i]}
62	for token in ${valid_args[i]}; do
63		log_must snapexists $token && \
64		    log_must $ZFS destroy $token
65	done
66	((i = i + 1))
67done
68log_note "destroy a list of invalid snapshots"
69i=0
70while (( i < ${#invalid_args[*]} )); do
71	log_mustnot $ZFS snapshot ${invalid_args[i]}
72	for token in ${invalid_args[i]}; do
73		log_mustnot snapexists $token
74	done
75	((i = i + 1))
76done
77log_note "verify multiple snapshot transaction group"
78txg_group=$($ZDB -Pd $TESTPOOL | $GREP snap | $AWK '{print $7}')
79for i in 1 2 3; do
80	txg_tag=$($ECHO "$txg_group" | $NAWK -v j=$i 'FNR == j {print}')
81	[[ $txg_tag != $($ECHO "$txg_group" | \
82	    $NAWK -v j=$i 'FNR == j {print}') ]] \
83	    && log_fail "snapshots belong to differnt transaction groups"
84done
85log_note "verify snapshot contents"
86for ds in $datasets; do
87	status=$($DIRCMP /$ds /$ds/.zfs/snapshot/snap | $GREP "different")
88	[[ -z $status ]] || log_fail "snapshot contents are different from" \
89	    "the filesystem"
90done
91
92log_note "verify multiple snapshot with -r option"
93log_must $ZFS create $TESTPOOL/TESTFS4
94log_must $ZFS create -p $TESTPOOL/$TESTFS3/TESTFSA$($PYTHON -c 'print "x" * 210')/TESTFSB
95log_mustnot $ZFS snapshot -r $TESTPOOL/$TESTFS1@snap1 $TESTPOOL/$TESTFS2@snap1 \
96        $TESTPOOL/$TESTFS3@snap1 $TESTPOOL/TESTFS4@snap1
97log_must $ZFS rename  $TESTPOOL/$TESTFS3/TESTFSA$($PYTHON -c 'print "x" * 210') \
98    $TESTPOOL/$TESTFS3/TESTFSA
99log_must $ZFS snapshot -r $TESTPOOL/$TESTFS1@snap1 $TESTPOOL/$TESTFS2@snap1 \
100        $TESTPOOL/$TESTFS3@snap1 $TESTPOOL/TESTFS4@snap1
101
102log_pass "zfs multiple snapshot verified correctly"
103