1#!/bin/ksh 2 3# 4# This file and its contents are supplied under the terms of the 5# Common Development and Distribution License ("CDDL"), version 1.0. 6# You may only use this file in accordance with the terms of version 7# 1.0 of the CDDL. 8# 9# A full copy of the text of the CDDL should have accompanied this 10# source. A copy of the CDDL is also available via the Internet at 11# http://www.illumos.org/license/CDDL. 12# 13 14# 15# Copyright (c) 2018 by Delphix. All rights reserved. 16# 17 18. $STF_SUITE/tests/functional/redacted_send/redacted.kshlib 19 20# 21# Description: 22# Verify that received redacted datasets are not mounted by default, but 23# can still be mounted after setting ALLOW_REDACTED_DATASET_MOUNT. 24# 25# Strategy: 26# 1. Verify a received redacted stream isn't mounted by default. 27# 2. Set ALLOW_REDACTED_DATASET_MOUNT and verify it can't be mounted 28# without the -f flag, but can with -f. 29# 3. Receive a redacted volume. 30# 4. Verify the device file isn't present until the kernel variable is set. 31# 5. Verify the files in the send fs are also present in the recv fs. 32# 33 34typeset ds_name="mounts" 35typeset sendfs="$POOL/$ds_name" 36typeset sendvol="$sendfs/vol" 37typeset recvfs="$POOL2/$ds_name" 38typeset recvvol="$POOL2/vol" 39typeset clone="$POOL/${ds_name}_clone" 40typeset clonevol="${sendvol}_clone" 41typeset tmpdir="$(get_prop mountpoint $POOL)/tmp" 42typeset stream=$(mktemp $tmpdir/stream.XXXX) 43setup_dataset $ds_name '' setup_mounts 44typeset clone_mnt="$(get_prop mountpoint $clone)" 45typeset send_mnt="$(get_prop mountpoint $sendfs)" 46typeset recv_mnt="/$POOL2/$ds_name" 47typeset recv_vol_file="/dev/zvol/$recvvol" 48 49log_onexit redacted_cleanup $sendfs $recvfs $recvvol 50 51log_must rm $clone_mnt/empty $clone_mnt/contents1 52log_must dd if=/dev/urandom of=$clone_mnt/contents2 bs=512 count=1 conv=notrunc 53log_must rm $clone_mnt/dir1/contents1 54log_must rm -rf $clone_mnt/dir1/dir2 55log_must dd if=/dev/urandom of=$clone_mnt/dir1/contents2 bs=512 count=1 \ 56 conv=notrunc 57log_must dd if=/dev/urandom of=$clone_mnt/dir1/empty bs=512 count=1 58log_must zfs snapshot $clone@snap1 59 60log_must zfs redact $sendfs@snap book1 $clone@snap 61log_must eval "zfs send --redact book1 $sendfs@snap >$stream" 62log_must eval "zfs receive $recvfs <$stream" 63log_mustnot ismounted $recvfs 64log_mustnot mount_redacted $recvfs 65log_mustnot ismounted $recvfs 66log_must mount_redacted -f $recvfs 67log_must ismounted $recvfs 68 69# Verify that the send and recv fs both have the same files under their 70# mountpoints by comparing find output with the name of the mountpoint 71# deleted. 72contents=$(log_must find $recv_mnt) 73contents_orig=$(log_must find $send_mnt) 74log_must diff <(echo ${contents//$recv_mnt/}) \ 75 <(echo ${contents_orig//$send_mnt/}) 76log_must zfs redact $sendvol@snap book2 $clonevol@snap 77log_must eval "zfs send --redact book2 $sendvol@snap >$stream" 78log_must eval "zfs receive $recvvol <$stream" 79is_disk_device $recv_vol_file && log_fail "Volume device file should not exist." 80log_must set_tunable32 ALLOW_REDACTED_DATASET_MOUNT 1 81log_must zpool export $POOL2 82log_must zpool import $POOL2 83udevadm settle 84 85# The device file isn't guaranteed to show up right away. 86if ! is_disk_device $recv_vol_file; then 87 udevadm settle 88 for t in 10 5 3 2 1; do 89 log_note "Polling $t seconds for device file." 90 udevadm settle 91 sleep $t 92 is_disk_device $recv_vol_file && break 93 done 94fi 95is_disk_device $recv_vol_file || log_fail "Volume device file should exist." 96 97log_must dd if=/dev/urandom of=$send_mnt/dir1/contents1 bs=512 count=2 98log_must rm $send_mnt/dir1/dir2/empty 99log_must zfs snapshot $sendfs@snap2 100log_must eval "zfs send -i $sendfs#book1 $sendfs@snap2 >$stream" 101log_must eval "zfs receive $recvfs <$stream" 102log_must mount_redacted -f $recvfs 103log_must ismounted $recvfs 104contents=$(log_must find $recv_mnt) 105contents_orig=$(log_must find $send_mnt) 106log_must diff <(echo ${contents//$recv_mnt/}) \ 107 <(echo ${contents_orig//$send_mnt/}) 108 109log_pass "Received redacted streams can be mounted." 110