xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/nopwrite/nopwrite_negative.ksh (revision 6e6545bfaed3bab9ce836ee82d1abd8f2edba89a)
1#!/usr/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) 2012, 2016 by Delphix. All rights reserved.
16#
17
18. $STF_SUITE/include/libtest.shlib
19. $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib
20
21#
22# Description:
23# Verify that duplicate writes to a clone are accounted as new data if the
24# prerequisites for nopwrite are not met.
25#
26# Scenarios:
27# 1. The file in the origin ds is written without compression or sha256.
28# 2. The file in the origin ds is written before sha256 checksum is turned on.
29# 3. The clone does not have compression.
30# 4. The clone does not have the appropriate checksum.
31#
32
33verify_runnable "global"
34origin="$TESTPOOL/$TESTFS"
35log_onexit cleanup
36
37function cleanup
38{
39	datasetexists $origin && log_must zfs destroy -R $origin
40	log_must zfs create -o mountpoint=$TESTDIR $origin
41}
42
43log_assert "nopwrite isn't enabled without the prerequisites"
44
45# Data written into origin fs without compression or sha256
46dd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \
47    >/dev/null 2>&1 || log_fail "dd of $TESTDIR/file failed."
48zfs snapshot $origin@a || log_fail "zfs snap failed"
49log_must zfs clone -o compress=on $origin@a $origin/clone
50log_must zfs set checksum=sha256 $origin/clone
51dd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \
52    conv=notrunc >/dev/null 2>&1 || log_fail "dd failed."
53log_mustnot verify_nopwrite $origin $origin@a $origin/clone
54zfs destroy -R $origin@a || log_fail "zfs destroy failed"
55log_must rm -f $TESTDIR/file
56
57# Data written to origin fs before checksum enabled
58log_must zfs set compress=on $origin
59dd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \
60    >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed."
61log_must zfs set checksum=sha256 $origin
62zfs snapshot $origin@a || log_fail "zfs snap failed"
63log_must zfs clone $origin@a $origin/clone
64dd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \
65    conv=notrunc >/dev/null 2>&1 || log_fail "dd failed."
66log_mustnot verify_nopwrite $origin $origin@a $origin/clone
67zfs destroy -R $origin@a || log_fail "zfs destroy failed"
68log_must rm -f $TESTDIR/file
69
70# Clone with compression=off
71dd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \
72    >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed."
73zfs snapshot $origin@a || log_fail "zfs snap failed"
74log_must zfs clone -o compress=off $origin@a $origin/clone
75dd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \
76    conv=notrunc >/dev/null 2>&1 || log_fail "dd failed."
77log_mustnot verify_nopwrite $origin $origin@a $origin/clone
78zfs destroy -R $origin@a || log_fail "zfs destroy failed"
79log_must rm -f $TESTDIR/file
80
81# Clone with fletcher4, rather than sha256
82dd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \
83    >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed."
84zfs snapshot $origin@a || log_fail "zfs snap failed"
85log_must zfs clone -o checksum=fletcher4 $origin@a $origin/clone
86dd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \
87    conv=notrunc >/dev/null 2>&1 || log_fail "dd failed."
88log_mustnot verify_nopwrite $origin $origin@a $origin/clone
89
90log_pass "nopwrite isn't enabled without the prerequisites"
91