f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#!/bin/ksh -p
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER START
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The contents of this file are subject to the terms of the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Common Development and Distribution License (the "License").
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You may not use this file except in compliance with the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# or http://www.opensolaris.org/os/licensing.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# See the License for the specific language governing permissions
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# and limitations under the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER END
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Use is subject to license terms.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy. $STF_SUITE/tests/functional/cli_root/zfs_promote/zfs_promote.cfg
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy. $STF_SUITE/include/libtest.shlib
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# DESCRIPTION:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 'zfs promote' can deal with multi-point snapshots.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# STRATEGY:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 1. Create multiple snapshots and a clone to a middle point snapshot
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 2. Promote the clone filesystem
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 3. Verify the origin filesystem and promoted filesystem include
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# correct datasets seperated by the clone point.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_runnable "both"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction cleanup
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy{
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if snapexists ${csnap[2]}; then
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs promote $fs
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset ds
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset data
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy for ds in ${snap[*]}; do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snapexists $ds && \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must zfs destroy -rR $ds
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy done
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy for data in ${file[*]}; do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy [[ -e $data ]] && rm -f $data
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy done
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_assert "'zfs promote' can deal with multi-point snapshots."
log_onexit cleanup
fs=$TESTPOOL/$TESTFS
clone=$TESTPOOL/$TESTCLONE
# Define some arrays here to use loop to reduce code amount
# Array which stores the origin snapshots created in the origin filesystem
set -A snap "${fs}@$TESTSNAP" "${fs}@$TESTSNAP1" "${fs}@$TESTSNAP2" "${fs}@$TESTSNAP3"
# Array which stores the snapshots existing in the clone after promote operation
set -A csnap "${clone}@$TESTSNAP" "${clone}@$TESTSNAP1" "${clone}@$TESTSNAP2" \
"${clone}@$TESTSNAP3"
# The data will inject into the origin filesystem
set -A file "$TESTDIR/$TESTFILE0" "$TESTDIR/$TESTFILE1" "$TESTDIR/$TESTFILE2" \
"$TESTDIR/$TESTFILE3"
snapdir=$TESTDIR/.zfs/snapshot
# The data which will exist in the snapshot after creation of snapshot
set -A snapfile "$snapdir/$TESTSNAP/$TESTFILE0" "$snapdir/$TESTSNAP1/$TESTFILE1" \
"$snapdir/$TESTSNAP2/$TESTFILE2" "$snapdir/$TESTSNAP3/$TESTFILE3"
csnapdir=/$clone/.zfs/snapshot
# The data which will exist in the snapshot of clone filesystem after promote
set -A csnapfile "${csnapdir}/$TESTSNAP/$TESTFILE0" "${csnapdir}/$TESTSNAP1/$TESTFILE1" \
"${csnapdir}/$TESTSNAP2/$TESTFILE2"
# setup for promote testing
typeset -i i=0
while (( i < 4 )); do
log_must mkfile $FILESIZE ${file[i]}
(( i>0 )) && log_must rm -f ${file[((i-1))]}
log_must zfs snapshot ${snap[i]}
(( i = i + 1 ))
done
log_must zfs clone ${snap[2]} $clone
log_must mkfile $FILESIZE /$clone/$CLONEFILE
log_must rm -f /$clone/$TESTFILE2
log_must zfs snapshot ${csnap[3]}
log_must zfs promote $clone
# verify the 'promote' operation
for ds in ${snap[3]} ${csnap[*]}; do
! snapexists $ds && \
log_fail "The snapshot $ds disappear after zfs promote."
done
for data in ${csnapfile[*]} $TESTDIR/$TESTFILE3 /$clone/$CLONEFILE; do
[[ ! -e $data ]] && \
log_fail "The data file $data loses after zfs promote."
done
for ds in ${snap[0]} ${snap[1]} ${snap[2]}; do
snapexists $ds && \
log_fail "zfs promote cannot promote the snapshot $ds."
done
for data in ${snapfile[0]} ${snapfile[1]} ${snapfile[2]}; do
[[ -e $data ]] && \
log_fail "zfs promote cannot promote the data $data."
done
origin_prop=$(get_prop origin $fs)
[[ "$origin_prop" != "${csnap[2]}" ]] && \
log_fail "The dependency is not correct for $fs after zfs promote."
origin_prop=$(get_prop origin $clone)
[[ "$origin_prop" != "-" ]] && \
log_fail "The dependency is not correct for $clone after zfs promote."
log_pass "'zfs promote' deal with multi-point snapshots as expected."