1d583b39bSJohn Wren Kennedy#!/usr/bin/ksh
2d583b39bSJohn Wren Kennedy
3d583b39bSJohn Wren Kennedy#
4d583b39bSJohn Wren Kennedy# This file and its contents are supplied under the terms of the
5d583b39bSJohn Wren Kennedy# Common Development and Distribution License ("CDDL"), version 1.0.
6d583b39bSJohn Wren Kennedy# You may only use this file in accordance with the terms of version
7d583b39bSJohn Wren Kennedy# 1.0 of the CDDL.
8d583b39bSJohn Wren Kennedy#
9d583b39bSJohn Wren Kennedy# A full copy of the text of the CDDL should have accompanied this
10d583b39bSJohn Wren Kennedy# source.  A copy of the CDDL is also available via the Internet at
11d583b39bSJohn Wren Kennedy# http://www.illumos.org/license/CDDL.
12d583b39bSJohn Wren Kennedy#
13d583b39bSJohn Wren Kennedy
14d583b39bSJohn Wren Kennedy#
15*1d32ba66SJohn Wren Kennedy# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
16d583b39bSJohn Wren Kennedy#
17d583b39bSJohn Wren Kennedy
18d583b39bSJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib
19d583b39bSJohn Wren Kennedy. $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib
20d583b39bSJohn Wren Kennedy
21d583b39bSJohn Wren Kennedy#
22d583b39bSJohn Wren Kennedy# Description:
23d583b39bSJohn Wren Kennedy# Verify that nopwrite is not enabled if the copies property changes
24d583b39bSJohn Wren Kennedy#
25d583b39bSJohn Wren Kennedy# Strategy:
26d583b39bSJohn Wren Kennedy# 1. Create a clone with copies set higher than the origin fs
27d583b39bSJohn Wren Kennedy# 2. Verify that nopwrite is in use.
28d583b39bSJohn Wren Kennedy# 3. Repeat with the number of copies decreased.
29d583b39bSJohn Wren Kennedy#
30d583b39bSJohn Wren Kennedy
31d583b39bSJohn Wren Kennedyverify_runnable "global"
32d583b39bSJohn Wren Kennedyorigin="$TESTPOOL/$TESTFS"
33d583b39bSJohn Wren Kennedylog_onexit cleanup
34d583b39bSJohn Wren Kennedy
35d583b39bSJohn Wren Kennedyfunction cleanup
36d583b39bSJohn Wren Kennedy{
37*1d32ba66SJohn Wren Kennedy	datasetexists $origin && log_must zfs destroy -R $origin
38*1d32ba66SJohn Wren Kennedy	log_must zfs create -o mountpoint=$TESTDIR $origin
39d583b39bSJohn Wren Kennedy}
40d583b39bSJohn Wren Kennedy
41d583b39bSJohn Wren Kennedylog_assert "nopwrite requires copies property to remain constant"
42d583b39bSJohn Wren Kennedy
43d583b39bSJohn Wren Kennedy# Verify nopwrite is disabled with increased redundancy
44*1d32ba66SJohn Wren Kennedylog_must zfs set compress=on $origin
45*1d32ba66SJohn Wren Kennedylog_must zfs set checksum=sha256 $origin
46*1d32ba66SJohn Wren Kennedydd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \
47d583b39bSJohn Wren Kennedy    >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed."
48*1d32ba66SJohn Wren Kennedyzfs snapshot $origin@a || log_fail "zfs snap failed"
49*1d32ba66SJohn Wren Kennedylog_must zfs clone $origin@a $origin/clone
50*1d32ba66SJohn Wren Kennedyzfs set copies=3 $origin/clone
51*1d32ba66SJohn Wren Kennedydd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \
52d583b39bSJohn Wren Kennedy    conv=notrunc >/dev/null 2>&1 || log_fail "dd failed."
53d583b39bSJohn Wren Kennedylog_mustnot verify_nopwrite $origin $origin@a $origin/clone
54d583b39bSJohn Wren Kennedy
55d583b39bSJohn Wren Kennedy# Verify nopwrite is disabled with decreased redundancy
56*1d32ba66SJohn Wren Kennedyzfs destroy -R $origin || log_fail "Couldn't destroy $origin"
57*1d32ba66SJohn Wren Kennedyzfs create -o mountpoint=$TESTDIR $origin || \
58d583b39bSJohn Wren Kennedy    log_fail "Couldn't recreate $origin"
59*1d32ba66SJohn Wren Kennedylog_must zfs set compress=on $origin
60*1d32ba66SJohn Wren Kennedylog_must zfs set copies=3 $origin
61*1d32ba66SJohn Wren Kennedylog_must zfs set checksum=sha256 $origin
62*1d32ba66SJohn Wren Kennedydd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \
63d583b39bSJohn Wren Kennedy    >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed."
64*1d32ba66SJohn Wren Kennedyzfs snapshot $origin@a || log_fail "zfs snap failed"
65*1d32ba66SJohn Wren Kennedylog_must zfs clone $origin@a $origin/clone
66*1d32ba66SJohn Wren Kennedyzfs set copies=1 $origin/clone
67*1d32ba66SJohn Wren Kennedydd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \
68d583b39bSJohn Wren Kennedy    conv=notrunc >/dev/null 2>&1 || log_fail "dd failed."
69d583b39bSJohn Wren Kennedylog_mustnot verify_nopwrite $origin $origin@a $origin/clone
70d583b39bSJohn Wren Kennedy
71d583b39bSJohn Wren Kennedylog_pass "nopwrite requires copies property to remain constant"
72