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 # A sparse volume can be made dense with 'zfs set refreservation=auto'.
  24 #
  25 # STRATEGY:
  26 # 1) Create a sparse value.
  27 # 2) Use zfs set refreservation=auto to make it dense.
  28 # 3) Verify that refreservation is now the size predicted by
  29 # volsize_to_reservation().
  30 #
  31 
  32 verify_runnable "global"
  33 
  34 function cleanup
  35 {
  36         if datasetexists $TESTPOOL/$TESTVOL; then
  37                 log_must zfs destroy -f $TESTPOOL/$TESTVOL
  38         fi
  39 }
  40 
  41 log_onexit cleanup
  42 
  43 log_assert "A sparse volume can be made non-sparse with" \
  44         "'zfs set refreservation=auto'"
  45 
  46 space_avail=$(get_prop available $TESTPOOL)
  47 (( vol_size = (space_avail / 2) & ~(1024 * 1024 - 1) ))
  48 
  49 vol=$TESTPOOL/$TESTVOL
  50 
  51 # Create sparse vol and verify
  52 log_must zfs create -V $vol_size -s $vol
  53 resv=$(get_prop refreservation $vol)
  54 log_must test $resv -eq 0
  55 
  56 # Set refreservation
  57 log_must zfs set refreservation=auto $vol
  58 
  59 # Verify
  60 resv=$(get_prop refreservation $vol)
  61 expected=$(volsize_to_reservation $vol $vol_size)
  62 log_must test $resv -eq $expected
  63 
  64 log_pass "Setting refreservation=auto set refreservation to expected value"