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 duplicate writes to a clone are accounted as new data if the 24d583b39bSJohn Wren Kennedy# prerequisites for nopwrite are not met. 25d583b39bSJohn Wren Kennedy# 26d583b39bSJohn Wren Kennedy# Scenarios: 27d583b39bSJohn Wren Kennedy# 1. The file in the origin ds is written without compression or sha256. 28d583b39bSJohn Wren Kennedy# 2. The file in the origin ds is written before sha256 checksum is turned on. 29d583b39bSJohn Wren Kennedy# 3. The clone does not have compression. 30d583b39bSJohn Wren Kennedy# 4. The clone does not have the appropriate checksum. 31d583b39bSJohn Wren Kennedy# 32d583b39bSJohn Wren Kennedy 33d583b39bSJohn Wren Kennedyverify_runnable "global" 34d583b39bSJohn Wren Kennedyorigin="$TESTPOOL/$TESTFS" 35d583b39bSJohn Wren Kennedylog_onexit cleanup 36d583b39bSJohn Wren Kennedy 37d583b39bSJohn Wren Kennedyfunction cleanup 38d583b39bSJohn Wren Kennedy{ 39*1d32ba66SJohn Wren Kennedy datasetexists $origin && log_must zfs destroy -R $origin 40*1d32ba66SJohn Wren Kennedy log_must zfs create -o mountpoint=$TESTDIR $origin 41d583b39bSJohn Wren Kennedy} 42d583b39bSJohn Wren Kennedy 43d583b39bSJohn Wren Kennedylog_assert "nopwrite isn't enabled without the prerequisites" 44d583b39bSJohn Wren Kennedy 45d583b39bSJohn Wren Kennedy# Data written into origin fs without compression or sha256 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 of $TESTDIR/file failed." 48*1d32ba66SJohn Wren Kennedyzfs snapshot $origin@a || log_fail "zfs snap failed" 49*1d32ba66SJohn Wren Kennedylog_must zfs clone -o compress=on $origin@a $origin/clone 50*1d32ba66SJohn Wren Kennedylog_must zfs set checksum=sha256 $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 54*1d32ba66SJohn Wren Kennedyzfs destroy -R $origin@a || log_fail "zfs destroy failed" 55*1d32ba66SJohn Wren Kennedylog_must rm -f $TESTDIR/file 56d583b39bSJohn Wren Kennedy 57d583b39bSJohn Wren Kennedy# Data written to origin fs before checksum enabled 58*1d32ba66SJohn Wren Kennedylog_must zfs set compress=on $origin 59*1d32ba66SJohn Wren Kennedydd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \ 60d583b39bSJohn Wren Kennedy >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed." 61*1d32ba66SJohn Wren Kennedylog_must zfs set checksum=sha256 $origin 62*1d32ba66SJohn Wren Kennedyzfs snapshot $origin@a || log_fail "zfs snap failed" 63*1d32ba66SJohn Wren Kennedylog_must zfs clone $origin@a $origin/clone 64*1d32ba66SJohn Wren Kennedydd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \ 65d583b39bSJohn Wren Kennedy conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." 66d583b39bSJohn Wren Kennedylog_mustnot verify_nopwrite $origin $origin@a $origin/clone 67*1d32ba66SJohn Wren Kennedyzfs destroy -R $origin@a || log_fail "zfs destroy failed" 68*1d32ba66SJohn Wren Kennedylog_must rm -f $TESTDIR/file 69d583b39bSJohn Wren Kennedy 70d583b39bSJohn Wren Kennedy# Clone with compression=off 71*1d32ba66SJohn Wren Kennedydd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \ 72d583b39bSJohn Wren Kennedy >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed." 73*1d32ba66SJohn Wren Kennedyzfs snapshot $origin@a || log_fail "zfs snap failed" 74*1d32ba66SJohn Wren Kennedylog_must zfs clone -o compress=off $origin@a $origin/clone 75*1d32ba66SJohn Wren Kennedydd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \ 76d583b39bSJohn Wren Kennedy conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." 77d583b39bSJohn Wren Kennedylog_mustnot verify_nopwrite $origin $origin@a $origin/clone 78*1d32ba66SJohn Wren Kennedyzfs destroy -R $origin@a || log_fail "zfs destroy failed" 79*1d32ba66SJohn Wren Kennedylog_must rm -f $TESTDIR/file 80d583b39bSJohn Wren Kennedy 81d583b39bSJohn Wren Kennedy# Clone with fletcher4, rather than sha256 82*1d32ba66SJohn Wren Kennedydd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \ 83d583b39bSJohn Wren Kennedy >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed." 84*1d32ba66SJohn Wren Kennedyzfs snapshot $origin@a || log_fail "zfs snap failed" 85*1d32ba66SJohn Wren Kennedylog_must zfs clone -o checksum=fletcher4 $origin@a $origin/clone 86*1d32ba66SJohn Wren Kennedydd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \ 87d583b39bSJohn Wren Kennedy conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." 88d583b39bSJohn Wren Kennedylog_mustnot verify_nopwrite $origin $origin@a $origin/clone 89d583b39bSJohn Wren Kennedy 90d583b39bSJohn Wren Kennedylog_pass "nopwrite isn't enabled without the prerequisites" 91