xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/reservation/reservation_022_pos.sh (revision e153cda9f9660e385e8f468253f80e59f5d454d7)
1#!/usr/bin/bash -p
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright 2018 Joyent, Inc.
15#
16
17. $STF_SUITE/include/libtest.shlib
18. $STF_SUITE/tests/functional/reservation/reservation.shlib
19
20#
21# DESCRIPTION:
22#
23# Cloning a volume with -o refreservation=auto creates a thick provisioned
24# volume
25#
26# STRATEGY:
27# 1) Create a sparse volume.
28# 2) Snapshot and clone it, using clone -o refreservation=auto.
29# 3) Verify that the clone has refreservation that matches the size predicted by
30#    volsize_to_reservation().
31# 4) Snapshot this second volume and clone it, using clone -o
32#    refreservation=auto.
33# 5) Verify that the second clone has refreservation that matches the size
34#    predicted by volsize_to_reservation().
35#
36
37verify_runnable "global"
38
39function cleanup
40{
41	if datasetexists $TESTPOOL/$TESTVOL; then
42		# Destroy first vol and descendants in one go.
43		log_must zfs destroy -Rf $TESTPOOL/$TESTVOL
44	fi
45}
46
47log_onexit cleanup
48
49log_assert "Cloning a volume with -o refreservation=auto creates a thick" \
50    "provisioned volume"
51
52space_avail=$(get_prop available $TESTPOOL)
53(( vol_size = (space_avail / 4) & ~(1024 * 1024 - 1) ))
54
55vol=$TESTPOOL/$TESTVOL
56vol2=$TESTPOOL/$TESTVOL2
57vol3=$TESTPOOL/$TESTVOL2-again
58
59# Create sparse vol and verify
60log_must zfs create -s -V $vol_size $vol
61resv=$(get_prop refreservation $vol)
62log_must test $resv -eq 0
63
64# Clone it
65snap=$vol@clone
66log_must zfs snapshot $snap
67log_must zfs clone -o refreservation=auto $snap $vol2
68
69# Verify it is thick provisioned
70resv=$(get_prop refreservation $vol2)
71expected=$(volsize_to_reservation $vol2 $vol_size)
72log_must test $resv -eq $expected
73
74# Clone the thick provisioned volume
75snap=$vol2@clone
76log_must zfs snapshot $snap
77log_must zfs clone -o refreservation=auto $snap $vol3
78
79# Verify new newest clone is also thick provisioned
80resv=$(get_prop refreservation $vol3)
81expected=$(volsize_to_reservation $vol3 $vol_size)
82log_must test $resv -eq $expected
83
84log_pass "Cloning a thick provisioned volume results in a sparse volume"
85