1#!/usr/bin/ksh -p
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) 2017 by Delphix. All rights reserved.
16#
17
18. $STF_SUITE/tests/functional/pool_checkpoint/pool_checkpoint.kshlib
19
20#
21# DESCRIPTION:
22#	Ensure that we don't reuse checkpointed blocks when the
23#	pool hits ENOSPC errors because of the slop space limit.
24#	This test also ensures that the DSL layer correctly takes
25#	into account the space used by the checkpoint when deciding
26#	whether to allow operations based on the reserved slop
27#	space.
28#
29# STRATEGY:
30#	1. Create pool with one disk of 1G size
31#	2. Create a file with random data of 700M in size.
32#	   leaving ~200M left in pool capacity.
33#	3. Checkpoint the pool
34#	4. Remove the file. All of its blocks should stay around
35#	   in ZFS as they are part of the checkpoint.
36#	5. Create a new empty file and attempt to write ~300M
37#	   of data to it. This should fail, as the reserved
38#	   SLOP space for the pool should be ~128M, and we should
39#	   be hitting that limit getting ENOSPC.
40#	6. Use zdb to traverse and checksum all the checkpointed
41#	   data to ensure its integrity.
42#	7. Export the pool and rewind to ensure that everything
43#	   is actually there as expected.
44#
45
46function test_cleanup
47{
48	poolexists $NESTEDPOOL && destroy_pool $NESTEDPOOL
49	cleanup_test_pool
50}
51
52verify_runnable "global"
53
54setup_test_pool
55log_onexit test_cleanup
56
57log_must zfs create $DISKFS
58
59log_must mkfile $FILEDISKSIZE $FILEDISK1
60log_must zpool create $NESTEDPOOL $FILEDISK1
61
62log_must zfs create -o compression=lz4 -o recordsize=8k $NESTEDFS0
63log_must dd if=/dev/urandom of=$NESTEDFS0FILE bs=700M count=1
64FILE0INTRO=$(head -c 100 $NESTEDFS0FILE)
65
66log_must zpool checkpoint $NESTEDPOOL
67log_must rm $NESTEDFS0FILE
68
69#
70# only for debugging purposes
71#
72log_must zpool list $NESTEDPOOL
73
74log_mustnot dd if=/dev/urandom of=$NESTEDFS0FILE bs=300M count=1
75
76#
77# only for debugging purposes
78#
79log_must zpool list $NESTEDPOOL
80
81log_must zdb -kc $NESTEDPOOL
82
83log_must zpool export $NESTEDPOOL
84log_must zpool import -d $FILEDISKDIR --rewind-to-checkpoint $NESTEDPOOL
85
86log_must [ "$(head -c 100 $NESTEDFS0FILE)" = "$FILE0INTRO" ]
87
88log_must zdb $NESTEDPOOL
89
90log_pass "Do not reuse checkpointed space at low capacity."
91