1eda14cbcSMatt Macy#!/bin/ksh -p
2eda14cbcSMatt Macy
3eda14cbcSMatt Macy#
4eda14cbcSMatt Macy# This file and its contents are supplied under the terms of the
5eda14cbcSMatt Macy# Common Development and Distribution License ("CDDL"), version 1.0.
6eda14cbcSMatt Macy# You may only use this file in accordance with the terms of version
7eda14cbcSMatt Macy# 1.0 of the CDDL.
8eda14cbcSMatt Macy#
9eda14cbcSMatt Macy# A full copy of the text of the CDDL should have accompanied this
10eda14cbcSMatt Macy# source.  A copy of the CDDL is also available via the Internet at
11eda14cbcSMatt Macy# http://www.illumos.org/license/CDDL.
12eda14cbcSMatt Macy#
13eda14cbcSMatt Macy
14eda14cbcSMatt Macy#
15eda14cbcSMatt Macy# Copyright (c) 2017 by Delphix. All rights reserved.
16eda14cbcSMatt Macy#
17eda14cbcSMatt Macy
18eda14cbcSMatt Macy. $STF_SUITE/tests/functional/pool_checkpoint/pool_checkpoint.kshlib
19eda14cbcSMatt Macy
20eda14cbcSMatt Macy#
21eda14cbcSMatt Macy# DESCRIPTION:
22eda14cbcSMatt Macy#	Ensure that we don't reuse checkpointed blocks when the
23eda14cbcSMatt Macy#	pool hits ENOSPC errors because of the slop space limit.
24eda14cbcSMatt Macy#	This test also ensures that the DSL layer correctly takes
25eda14cbcSMatt Macy#	into account the space used by the checkpoint when deciding
26eda14cbcSMatt Macy#	whether to allow operations based on the reserved slop
27eda14cbcSMatt Macy#	space.
28eda14cbcSMatt Macy#
29eda14cbcSMatt Macy# STRATEGY:
30eda14cbcSMatt Macy#	1. Create pool with one disk of 1G size
31eda14cbcSMatt Macy#	2. Create a file with random data of 700M in size.
32eda14cbcSMatt Macy#	   leaving ~200M left in pool capacity.
33eda14cbcSMatt Macy#	3. Checkpoint the pool
34eda14cbcSMatt Macy#	4. Remove the file. All of its blocks should stay around
35eda14cbcSMatt Macy#	   in ZFS as they are part of the checkpoint.
36eda14cbcSMatt Macy#	5. Create a new empty file and attempt to write ~300M
37eda14cbcSMatt Macy#	   of data to it. This should fail, as the reserved
38eda14cbcSMatt Macy#	   SLOP space for the pool should be ~128M, and we should
39eda14cbcSMatt Macy#	   be hitting that limit getting ENOSPC.
40eda14cbcSMatt Macy#	6. Use zdb to traverse and checksum all the checkpointed
41eda14cbcSMatt Macy#	   data to ensure its integrity.
42eda14cbcSMatt Macy#	7. Export the pool and rewind to ensure that everything
43eda14cbcSMatt Macy#	   is actually there as expected.
44eda14cbcSMatt Macy#
45eda14cbcSMatt Macy
46eda14cbcSMatt Macyfunction test_cleanup
47eda14cbcSMatt Macy{
48eda14cbcSMatt Macy	poolexists $NESTEDPOOL && destroy_pool $NESTEDPOOL
49eda14cbcSMatt Macy	set_tunable32 SPA_ASIZE_INFLATION 24
50eda14cbcSMatt Macy	cleanup_test_pool
51eda14cbcSMatt Macy}
52eda14cbcSMatt Macy
53eda14cbcSMatt Macyverify_runnable "global"
54eda14cbcSMatt Macy
55eda14cbcSMatt Macysetup_test_pool
56eda14cbcSMatt Macylog_onexit test_cleanup
57eda14cbcSMatt Macylog_must set_tunable32 SPA_ASIZE_INFLATION 4
58eda14cbcSMatt Macy
59eda14cbcSMatt Macylog_must zfs create $DISKFS
60eda14cbcSMatt Macy
61eda14cbcSMatt Macylog_must mkfile $FILEDISKSIZE $FILEDISK1
62eda14cbcSMatt Macylog_must zpool create $NESTEDPOOL $FILEDISK1
63eda14cbcSMatt Macy
64eda14cbcSMatt Macylog_must zfs create -o compression=lz4 -o recordsize=8k $NESTEDFS0
65eda14cbcSMatt Macylog_must dd if=/dev/urandom of=$NESTEDFS0FILE bs=1M count=700
66eda14cbcSMatt MacyFILE0INTRO=$(head -c 100 $NESTEDFS0FILE)
67eda14cbcSMatt Macy
68eda14cbcSMatt Macylog_must zpool checkpoint $NESTEDPOOL
69eda14cbcSMatt Macylog_must rm $NESTEDFS0FILE
70eda14cbcSMatt Macy
71eda14cbcSMatt Macy#
72eda14cbcSMatt Macy# only for debugging purposes
73eda14cbcSMatt Macy#
74eda14cbcSMatt Macylog_must zpool list $NESTEDPOOL
75eda14cbcSMatt Macy
76eda14cbcSMatt Macylog_mustnot dd if=/dev/urandom of=$NESTEDFS0FILE bs=1M count=300
77eda14cbcSMatt Macy
78eda14cbcSMatt Macy#
79eda14cbcSMatt Macy# only for debugging purposes
80eda14cbcSMatt Macy#
81eda14cbcSMatt Macylog_must zpool list $NESTEDPOOL
82eda14cbcSMatt Macy
83eda14cbcSMatt Macylog_must zpool export $NESTEDPOOL
84*16038816SMartin Matuskalog_must zdb -e -p $FILEDISKDIR -kc $NESTEDPOOL
85*16038816SMartin Matuska
86eda14cbcSMatt Macylog_must zpool import -d $FILEDISKDIR --rewind-to-checkpoint $NESTEDPOOL
87eda14cbcSMatt Macy
88eda14cbcSMatt Macylog_must [ "$(head -c 100 $NESTEDFS0FILE)" = "$FILE0INTRO" ]
89eda14cbcSMatt Macy
90*16038816SMartin Matuskalog_must zpool export $NESTEDPOOL
91*16038816SMartin Matuskalog_must zdb -e -p $FILEDISKDIR $NESTEDPOOL
92eda14cbcSMatt Macy
93eda14cbcSMatt Macylog_pass "Do not reuse checkpointed space at low capacity."
94