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 can expand a device while the pool has a
23#	checkpoint but in the case of a rewind that device rewinds
24#	back to its previous size.
25#
26# STRATEGY:
27#	1. Create pool
28#	2. Populate it
29#	3. Take checkpoint
30#	4. Expand the device and modify some data
31#	   (include at least one destructive change)
32#	5. Rewind to checkpoint
33#	6. Verify that we rewinded successfully and check if the
34#	   device shows up expanded in the vdev list
35#
36
37verify_runnable "global"
38
39EXPSZ=2G
40
41setup_nested_pools
42log_onexit cleanup_nested_pools
43
44populate_nested_pool
45INITSZ=$(zpool list -v | grep "$FILEDISK1" | awk '{print $2}')
46log_must zpool checkpoint $NESTEDPOOL
47
48log_must truncate -s $EXPSZ $FILEDISK1
49log_must zpool online -e $NESTEDPOOL $FILEDISK1
50NEWSZ=$(zpool list -v | grep "$FILEDISK1" | awk '{print $2}')
51nested_change_state_after_checkpoint
52log_mustnot [ "$INITSZ" = "$NEWSZ" ]
53
54log_must zpool export $NESTEDPOOL
55log_must zpool import -d $FILEDISKDIR --rewind-to-checkpoint $NESTEDPOOL
56
57nested_verify_pre_checkpoint_state
58FINSZ=$(zpool list -v | grep "$FILEDISK1" | awk '{print $2}')
59log_must [ "$INITSZ" = "$FINSZ" ]
60
61log_pass "LUN expansion rewinded correctly."
62