1f38cb554SJohn Wren Kennedy#!/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 2009 Sun Microsystems, Inc. All rights reserved. 25f38cb554SJohn Wren Kennedy# Use is subject to license terms. 26f38cb554SJohn Wren Kennedy# 27f38cb554SJohn Wren Kennedy 28f38cb554SJohn Wren Kennedy 29f38cb554SJohn Wren Kennedy# 30*1d32ba66SJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved. 31f38cb554SJohn Wren Kennedy# 32f38cb554SJohn Wren Kennedy 33f38cb554SJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib 34f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/snapshot/snapshot.cfg 35f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib 36f38cb554SJohn Wren Kennedy 37f38cb554SJohn Wren Kennedy# 38f38cb554SJohn Wren Kennedy# DESCRIPTION: 39f38cb554SJohn Wren Kennedy# Verify snapshot can be created or destroy via mkdir or rm 40f38cb554SJohn Wren Kennedy# in .zfs/snapshot. 41f38cb554SJohn Wren Kennedy# 42f38cb554SJohn Wren Kennedy# STRATEGY: 43f38cb554SJohn Wren Kennedy# 1. Verify make directories only successfully in .zfs/snapshot. 44f38cb554SJohn Wren Kennedy# 2. Verify snapshot can be created and destroy via mkdir and remove 45f38cb554SJohn Wren Kennedy# directories in .zfs/snapshot. 46f38cb554SJohn Wren Kennedy# 3. Verify rollback to previous snapshot can succeed. 47f38cb554SJohn Wren Kennedy# 4. Verify remove directory in snapdir can destroy snapshot. 48f38cb554SJohn Wren Kennedy# 49f38cb554SJohn Wren Kennedy 50f38cb554SJohn Wren Kennedyverify_runnable "both" 51f38cb554SJohn Wren Kennedy 52f38cb554SJohn Wren Kennedyfunction cleanup 53f38cb554SJohn Wren Kennedy{ 54f38cb554SJohn Wren Kennedy typeset -i i=0 55f38cb554SJohn Wren Kennedy while ((i < snap_cnt)); do 56f38cb554SJohn Wren Kennedy typeset snap=$fs@snap.$i 57*1d32ba66SJohn Wren Kennedy datasetexists $snap && log_must zfs destroy -f $snap 58f38cb554SJohn Wren Kennedy 59f38cb554SJohn Wren Kennedy ((i += 1)) 60f38cb554SJohn Wren Kennedy done 61f38cb554SJohn Wren Kennedy} 62f38cb554SJohn Wren Kennedy 63*1d32ba66SJohn Wren Kennedyzfs 2>&1 | grep "allow" > /dev/null 64f38cb554SJohn Wren Kennedy(($? != 0)) && log_unsupported 65f38cb554SJohn Wren Kennedy 66f38cb554SJohn Wren Kennedylog_assert "Verify snapshot can be created via mkdir in .zfs/snapshot." 67f38cb554SJohn Wren Kennedylog_onexit cleanup 68f38cb554SJohn Wren Kennedy 69f38cb554SJohn Wren Kennedyfs=$TESTPOOL/$TESTFS 70f38cb554SJohn Wren Kennedy# Verify all the other directories are readonly. 71f38cb554SJohn Wren Kennedymntpnt=$(get_prop mountpoint $fs) 72f38cb554SJohn Wren Kennedysnapdir=$mntpnt/.zfs 73f38cb554SJohn Wren Kennedyset -A ro_dirs "$snapdir" "$snapdir/snap" "$snapdir/snapshot" 74f38cb554SJohn Wren Kennedyfor dir in ${ro_dirs[@]}; do 75f38cb554SJohn Wren Kennedy if [[ -d $dir ]]; then 76*1d32ba66SJohn Wren Kennedy log_mustnot rm -rf $dir 77*1d32ba66SJohn Wren Kennedy log_mustnot touch $dir/testfile 78f38cb554SJohn Wren Kennedy else 79*1d32ba66SJohn Wren Kennedy log_mustnot mkdir $dir 80f38cb554SJohn Wren Kennedy fi 81f38cb554SJohn Wren Kennedydone 82f38cb554SJohn Wren Kennedy 83f38cb554SJohn Wren Kennedy# Verify snapshot can be created via mkdir in .zfs/snapshot 84f38cb554SJohn Wren Kennedytypeset -i snap_cnt=5 85f38cb554SJohn Wren Kennedytypeset -i cnt=0 86f38cb554SJohn Wren Kennedywhile ((cnt < snap_cnt)); do 87f38cb554SJohn Wren Kennedy testfile=$mntpnt/testfile.$cnt 88*1d32ba66SJohn Wren Kennedy log_must mkfile 1M $testfile 89*1d32ba66SJohn Wren Kennedy log_must mkdir $snapdir/snapshot/snap.$cnt 90f38cb554SJohn Wren Kennedy if ! datasetexists $fs@snap.$cnt ; then 91f38cb554SJohn Wren Kennedy log_fail "ERROR: $fs@snap.$cnt should exists." 92f38cb554SJohn Wren Kennedy fi 93f38cb554SJohn Wren Kennedy 94f38cb554SJohn Wren Kennedy ((cnt += 1)) 95f38cb554SJohn Wren Kennedydone 96f38cb554SJohn Wren Kennedy 97f38cb554SJohn Wren Kennedy# Verify rollback to previous snapshot succeed. 98f38cb554SJohn Wren Kennedy((cnt = RANDOM % snap_cnt)) 99*1d32ba66SJohn Wren Kennedylog_must zfs rollback -r $fs@snap.$cnt 100f38cb554SJohn Wren Kennedy 101f38cb554SJohn Wren Kennedytypeset -i i=0 102f38cb554SJohn Wren Kennedywhile ((i < snap_cnt)); do 103f38cb554SJohn Wren Kennedy testfile=$mntpnt/testfile.$i 104f38cb554SJohn Wren Kennedy if ((i <= cnt)); then 105f38cb554SJohn Wren Kennedy if [[ ! -f $testfile ]]; then 106f38cb554SJohn Wren Kennedy log_fail "ERROR: $testfile should exists." 107f38cb554SJohn Wren Kennedy fi 108f38cb554SJohn Wren Kennedy else 109f38cb554SJohn Wren Kennedy if [[ -f $testfile ]]; then 110f38cb554SJohn Wren Kennedy log_fail "ERROR: $testfile should not exists." 111f38cb554SJohn Wren Kennedy fi 112f38cb554SJohn Wren Kennedy fi 113f38cb554SJohn Wren Kennedy 114f38cb554SJohn Wren Kennedy ((i += 1)) 115f38cb554SJohn Wren Kennedydone 116f38cb554SJohn Wren Kennedy 117f38cb554SJohn Wren Kennedy# Verify remove directory in snapdir can destroy snapshot. 118*1d32ba66SJohn Wren Kennedylog_must rmdir $snapdir/snapshot/snap.$cnt 119f38cb554SJohn Wren Kennedylog_mustnot datasetexists $fs@snap.$cnt 120f38cb554SJohn Wren Kennedy 121f38cb554SJohn Wren Kennedylog_pass "Verify snapshot can be created via mkdir in .zfs/snapshot passed." 122