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 2009 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) 2013, 2016 by Delphix. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy. $STF_SUITE/tests/functional/rsend/rsend.kshlib
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# DESCRIPTION:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Changes made by 'zfs inherit' can be properly received.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# STRATEGY:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 1. Inherit property for filesystem and volume
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 2. Send and restore them in the target pool
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 3. Verify all the datasets can be properly backup and receive
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_runnable "both"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction cleanup
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy{
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy export __ZFS_POOL_RESTRICT="$POOL $POOL2"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs unmount -a
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy unset __ZFS_POOL_RESTRICT
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must cleanup_pool $POOL
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must cleanup_pool $POOL2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must setup_test_model $POOL
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_assert "Verify changes made by 'zfs inherit' can be properly received."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_onexit cleanup
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Setting all the $FS properties as local value,
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfor prop in $(fs_inherit_prop); do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy value=$(get_prop $prop $POOL/$FS)
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs set $prop=$value $POOL/$FS
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedydone
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Inherit propertes in sub-datasets
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfor ds in "$POOL/$FS/fs1" "$POOL/$FS/fs1/fs2" "$POOL/$FS/fs1/fclone" ; do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy for prop in $(fs_inherit_prop) ; do
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy zfs inherit $prop $ds
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if (($? !=0 )); then
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_fail "zfs inherit $prop $ds"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy done
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedydone
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif is_global_zone ; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy for prop in $(vol_inherit_prop) ; do
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy zfs inherit $prop $POOL/$FS/vol
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if (($? !=0 )); then
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_fail "zfs inherit $prop $POOL/$FS/vol"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy done
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Verify datasets can be backup and restore correctly
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Unmount $POOL/$FS to avoid two fs mount in the same mountpoint
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must eval "zfs send -R $POOL@final > $BACKDIR/pool-R"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must zfs unmount -f $POOL/$FS
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must eval "zfs receive -d -F $POOL2 < $BACKDIR/pool-R"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedydstds=$(get_dst_ds $POOL $POOL2)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Define all the POOL/POOL2 datasets pair
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyset -A pair "$POOL" "$dstds" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$POOL/$FS" "$dstds/$FS" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$POOL/$FS/fs1" "$dstds/$FS/fs1" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$POOL/$FS/fs1/fs2" "$dstds/$FS/fs1/fs2" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$POOL/pclone" "$dstds/pclone" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$POOL/$FS/fs1/fclone" "$dstds/$FS/fs1/fclone"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif is_global_zone ; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i n=${#pair[@]}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy pair[((n))]="$POOL/vol"; pair[((n+1))]="$dstds/vol"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy pair[((n+2))]="$POOL/$FS/vol" pair[((n+3))]="$dstds/$FS/vol"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Verify all the sub-datasets can be properly received.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_must cmp_ds_subs $POOL $dstds
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedytypeset -i i=0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedywhile ((i < ${#pair[@]})); do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_must cmp_ds_prop ${pair[$i]} ${pair[((i+1))]}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy ((i += 2))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedydone
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_pass "Changes made by 'zfs inherit' can be properly received."