1f38cb554SJohn Wren Kennedy#!/usr/bin/ksh -p 2f38cb554SJohn Wren Kennedy# 3f38cb554SJohn Wren Kennedy# CDDL HEADER START 4f38cb554SJohn Wren Kennedy# 5f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the 6f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License"). 7f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License. 8f38cb554SJohn Wren Kennedy# 9f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing. 11f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions 12f38cb554SJohn Wren Kennedy# and limitations under the License. 13f38cb554SJohn Wren Kennedy# 14f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each 15f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the 17f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying 18f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner] 19f38cb554SJohn Wren Kennedy# 20f38cb554SJohn Wren Kennedy# CDDL HEADER END 21f38cb554SJohn Wren Kennedy# 22f38cb554SJohn Wren Kennedy 23f38cb554SJohn Wren Kennedy# 24f38cb554SJohn Wren Kennedy# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 25f38cb554SJohn Wren Kennedy# Use is subject to license terms. 26f38cb554SJohn Wren Kennedy# 27f38cb554SJohn Wren Kennedy 28f38cb554SJohn Wren Kennedy# 29*1d32ba66SJohn Wren Kennedy# Copyright (c) 2012, 2016 by Delphix. All rights reserved. 30f38cb554SJohn Wren Kennedy# 31f38cb554SJohn Wren Kennedy 32f38cb554SJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib 33f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/inuse/inuse.cfg 34f38cb554SJohn Wren Kennedy 35f38cb554SJohn Wren Kennedy# 36f38cb554SJohn Wren Kennedy# DESCRIPTION: 37f38cb554SJohn Wren Kennedy# ZFS will not interfere with devices that are in use by ufsdump or 38f38cb554SJohn Wren Kennedy# ufsrestore. 39f38cb554SJohn Wren Kennedy# 40f38cb554SJohn Wren Kennedy# STRATEGY: 41f38cb554SJohn Wren Kennedy# 1. newfs a disk 42f38cb554SJohn Wren Kennedy# 2. mount the disk 43f38cb554SJohn Wren Kennedy# 3. create files and dirs on disk 44f38cb554SJohn Wren Kennedy# 4. umount the disk 45f38cb554SJohn Wren Kennedy# 5. ufsdump this disk to a backup disk 46f38cb554SJohn Wren Kennedy# 6. Try to create a ZFS pool with same disk (also as a spare device) 47f38cb554SJohn Wren Kennedy# 7. ufsrestore the disk from backup 48f38cb554SJohn Wren Kennedy# 8. try to create a zpool during the ufsrestore 49f38cb554SJohn Wren Kennedy# 50f38cb554SJohn Wren Kennedy 51f38cb554SJohn Wren Kennedyverify_runnable "global" 52f38cb554SJohn Wren Kennedy 53f38cb554SJohn Wren Kennedyfunction cleanup 54f38cb554SJohn Wren Kennedy{ 55f38cb554SJohn Wren Kennedy poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 56f38cb554SJohn Wren Kennedy 57f38cb554SJohn Wren Kennedy poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2 58f38cb554SJohn Wren Kennedy 59f38cb554SJohn Wren Kennedy log_note "Kill off ufsdump process if still running" 60*1d32ba66SJohn Wren Kennedy kill -0 $PIDUFSDUMP > /dev/null 2>&1 && \ 61*1d32ba66SJohn Wren Kennedy log_must kill -9 $PIDUFSDUMP > /dev/null 2>&1 62f38cb554SJohn Wren Kennedy # 63f38cb554SJohn Wren Kennedy # Note: It would appear that ufsdump spawns a number of processes 64f38cb554SJohn Wren Kennedy # which are not killed when the $PIDUFSDUMP is whacked. So best bet 65f38cb554SJohn Wren Kennedy # is to find the rest of the them and deal with them individually. 66f38cb554SJohn Wren Kennedy # 67*1d32ba66SJohn Wren Kennedy for all in `pgrep ufsdump` 68f38cb554SJohn Wren Kennedy do 69*1d32ba66SJohn Wren Kennedy kill -9 $all > /dev/null 2>&1 70f38cb554SJohn Wren Kennedy done 71f38cb554SJohn Wren Kennedy 72f38cb554SJohn Wren Kennedy log_note "Kill off ufsrestore process if still running" 73*1d32ba66SJohn Wren Kennedy kill -0 $PIDUFSRESTORE > /dev/null 2>&1 && \ 74*1d32ba66SJohn Wren Kennedy log_must kill -9 $PIDUFSRESTORE > /dev/null 2>&1 75f38cb554SJohn Wren Kennedy 76*1d32ba66SJohn Wren Kennedy ismounted $UFSMP ufs && log_must umount $UFSMP 77f38cb554SJohn Wren Kennedy 78*1d32ba66SJohn Wren Kennedy rm -rf $UFSMP 79*1d32ba66SJohn Wren Kennedy rm -rf $TESTDIR 80f38cb554SJohn Wren Kennedy 81f38cb554SJohn Wren Kennedy # 82f38cb554SJohn Wren Kennedy # Tidy up the disks we used. 83f38cb554SJohn Wren Kennedy # 84f38cb554SJohn Wren Kennedy log_must cleanup_devices $vdisks $sdisks 85f38cb554SJohn Wren Kennedy} 86f38cb554SJohn Wren Kennedy 87f38cb554SJohn Wren Kennedylog_assert "Ensure ZFS does not interfere with devices that are in use by " \ 88f38cb554SJohn Wren Kennedy "ufsdump or ufsrestore" 89f38cb554SJohn Wren Kennedy 90f38cb554SJohn Wren Kennedylog_onexit cleanup 91f38cb554SJohn Wren Kennedy 92f38cb554SJohn Wren Kennedytypeset bigdir="${UFSMP}/bigdirectory" 93f38cb554SJohn Wren Kennedytypeset restored_files="${UFSMP}/restored_files" 94f38cb554SJohn Wren Kennedytypeset -i dirnum=0 95f38cb554SJohn Wren Kennedytypeset -i filenum=0 96f38cb554SJohn Wren Kennedytypeset cwd="" 97f38cb554SJohn Wren Kennedy 98f38cb554SJohn Wren Kennedyfor num in 0 1 2; do 99f38cb554SJohn Wren Kennedy eval typeset slice=\${FS_SIDE$num} 100f38cb554SJohn Wren Kennedy disk=${slice%s*} 101f38cb554SJohn Wren Kennedy slice=${slice##*s} 1029498083eSYuri Pankov log_must set_partition $slice "" $FS_SIZE $disk 103f38cb554SJohn Wren Kennedydone 104f38cb554SJohn Wren Kennedy 105f38cb554SJohn Wren Kennedylog_note "Make a ufs filesystem on source $rawdisk1" 106*1d32ba66SJohn Wren Kennedyecho "y" | newfs -v $rawdisk1 > /dev/null 2>&1 107f38cb554SJohn Wren Kennedy(($? != 0)) && log_untested "Unable to create ufs filesystem on $rawdisk1" 108f38cb554SJohn Wren Kennedy 109*1d32ba66SJohn Wren Kennedylog_must mkdir -p $UFSMP 110f38cb554SJohn Wren Kennedy 111f38cb554SJohn Wren Kennedylog_note "mount source $disk1 on $UFSMP" 112*1d32ba66SJohn Wren Kennedylog_must mount $disk1 $UFSMP 113f38cb554SJohn Wren Kennedy 114f38cb554SJohn Wren Kennedylog_note "Now create some directories and files to be ufsdump'ed" 115f38cb554SJohn Wren Kennedywhile (($dirnum <= 2)); do 116*1d32ba66SJohn Wren Kennedy log_must mkdir $bigdir${dirnum} 117f38cb554SJohn Wren Kennedy while (( $filenum <= 2 )); do 118*1d32ba66SJohn Wren Kennedy file_write -o create -f $bigdir${dirnum}/file${filenum} \ 119f38cb554SJohn Wren Kennedy -b $BLOCK_SIZE -c $BLOCK_COUNT 120f38cb554SJohn Wren Kennedy if [[ $? -ne 0 ]]; then 121f38cb554SJohn Wren Kennedy if [[ $dirnum -lt 3 ]]; then 122*1d32ba66SJohn Wren Kennedy log_fail "file_write only wrote" \ 123f38cb554SJohn Wren Kennedy "<(( $dirnum * 3 + $filenum ))>" \ 124f38cb554SJohn Wren Kennedy "files, this is not enough" 125f38cb554SJohn Wren Kennedy fi 126f38cb554SJohn Wren Kennedy fi 127f38cb554SJohn Wren Kennedy ((filenum = filenum + 1)) 128f38cb554SJohn Wren Kennedy done 129f38cb554SJohn Wren Kennedy filenum=0 130f38cb554SJohn Wren Kennedy ((dirnum = dirnum + 1)) 131f38cb554SJohn Wren Kennedydone 132f38cb554SJohn Wren Kennedy 133*1d32ba66SJohn Wren Kennedylog_must umount $UFSMP 134f38cb554SJohn Wren Kennedy 135f38cb554SJohn Wren Kennedylog_note "Start ufsdump in the background" 136*1d32ba66SJohn Wren Kennedylog_note "ufsdump 0bf 512 $rawdisk0 $disk1" 137*1d32ba66SJohn Wren Kennedyufsdump 0bf 512 $rawdisk0 $disk1 & 138f38cb554SJohn Wren KennedyPIDUFSDUMP=$! 139f38cb554SJohn Wren Kennedy 140447b1e1fSJohn Wren Kennedyunset NOINUSE_CHECK 141f38cb554SJohn Wren Kennedylog_note "Attempt to zpool the source device in use by ufsdump" 142*1d32ba66SJohn Wren Kennedylog_mustnot zpool create $TESTPOOL1 "$disk1" 143f38cb554SJohn Wren Kennedylog_mustnot poolexists $TESTPOOL1 144f38cb554SJohn Wren Kennedy 145f38cb554SJohn Wren Kennedylog_note "Attempt to take the source device in use by ufsdump as spare device" 146*1d32ba66SJohn Wren Kennedylog_mustnot zpool create $TESTPOOL1 "$FS_SIDE2" spare "$disk1" 147f38cb554SJohn Wren Kennedylog_mustnot poolexists $TESTPOOL1 148f38cb554SJohn Wren Kennedy 149f38cb554SJohn Wren Kennedywait $PIDUFSDUMP 150f38cb554SJohn Wren Kennedytypeset -i retval=$? 151*1d32ba66SJohn Wren Kennedy(($retval != 0)) && log_fail "ufsdump failed with error code $ret_val" 152f38cb554SJohn Wren Kennedy 153*1d32ba66SJohn Wren Kennedylog_must mount $disk1 $UFSMP 154f38cb554SJohn Wren Kennedy 155*1d32ba66SJohn Wren Kennedylog_must rm -rf $UFSMP/* 156*1d32ba66SJohn Wren Kennedylog_must mkdir $restored_files 157f38cb554SJohn Wren Kennedy 158f38cb554SJohn Wren Kennedycwd=$PWD 159f38cb554SJohn Wren Kennedylog_must cd $restored_files 160f38cb554SJohn Wren Kennedylog_note "Start ufsrestore in the background from the target device" 161*1d32ba66SJohn Wren Kennedylog_note "ufsrestore rbf 512 $rawdisk0" 162*1d32ba66SJohn Wren Kennedyufsrestore rbf 512 $rawdisk0 & 163f38cb554SJohn Wren KennedyPIDUFSRESTORE=$! 164f38cb554SJohn Wren Kennedylog_must cd $cwd 165f38cb554SJohn Wren Kennedy 166f38cb554SJohn Wren Kennedylog_note "Attempt to zpool the restored device in use by ufsrestore" 167*1d32ba66SJohn Wren Kennedylog_mustnot zpool create -f $TESTPOOL2 "$disk1" 168f38cb554SJohn Wren Kennedylog_mustnot poolexists $TESTPOOL2 169f38cb554SJohn Wren Kennedy 170f38cb554SJohn Wren Kennedylog_note "Attempt to take the restored device in use by ufsrestore as spare" \ 171f38cb554SJohn Wren Kennedy "device" 172*1d32ba66SJohn Wren Kennedylog_mustnot zpool create -f $TESTPOOL2 "$FS_SIDE2" spare "$disk1" 173f38cb554SJohn Wren Kennedylog_mustnot poolexists $TESTPOOL2 174f38cb554SJohn Wren Kennedy 175f38cb554SJohn Wren Kennedylog_pass "Unable to zpool over a device in use by ufsdump or ufsrestore" 176