/tests/zfs-tests/tests/functional/reservation/reservation_022_pos.ksh

https://github.com/adilger/zfs · Korn Shell · 82 lines · 31 code · 15 blank · 36 comment · 0 complexity · a344b6833605ad776c10871e02f7a0d5 MD5 · raw file

  1. #!/bin/ksh -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. # Copyright 2018 Joyent, Inc.
  14. #
  15. . $STF_SUITE/include/libtest.shlib
  16. . $STF_SUITE/tests/functional/reservation/reservation.shlib
  17. #
  18. # DESCRIPTION:
  19. #
  20. # Cloning a volume with -o refreservation=auto creates a thick provisioned
  21. # volume
  22. #
  23. # STRATEGY:
  24. # 1) Create a sparse volume.
  25. # 2) Snapshot and clone it, using clone -o refreservation=auto.
  26. # 3) Verify that the clone has refreservation that matches the size predicted by
  27. # volsize_to_reservation().
  28. # 4) Snapshot this second volume and clone it, using clone -o
  29. # refreservation=auto.
  30. # 5) Verify that the second clone has refreservation that matches the size
  31. # predicted by volsize_to_reservation().
  32. #
  33. verify_runnable "global"
  34. function cleanup
  35. {
  36. # Destroy first vol and descendants in one go.
  37. destroy_dataset "$TESTPOOL/$TESTVOL" "-Rf"
  38. }
  39. log_onexit cleanup
  40. log_assert "Cloning a volume with -o refreservation=auto creates a thick" \
  41. "provisioned volume"
  42. space_avail=$(get_prop available $TESTPOOL)
  43. (( vol_size = (space_avail / 4) & ~(1024 * 1024 - 1) ))
  44. vol=$TESTPOOL/$TESTVOL
  45. vol2=$TESTPOOL/$TESTVOL2
  46. vol3=$TESTPOOL/$TESTVOL2-again
  47. # Create sparse vol and verify
  48. log_must zfs create -s -V $vol_size $vol
  49. resv=$(get_prop refreservation $vol)
  50. log_must test $resv -eq 0
  51. # Clone it
  52. snap=$vol@clone
  53. log_must zfs snapshot $snap
  54. log_must zfs clone -o refreservation=auto $snap $vol2
  55. # Verify it is thick provisioned
  56. resv=$(get_prop refreservation $vol2)
  57. expected=$(volsize_to_reservation $vol2 $vol_size)
  58. log_must test $resv -eq $expected
  59. # Clone the thick provisioned volume
  60. snap=$vol2@clone
  61. log_must zfs snapshot $snap
  62. log_must zfs clone -o refreservation=auto $snap $vol3
  63. # Verify new newest clone is also thick provisioned
  64. resv=$(get_prop refreservation $vol3)
  65. expected=$(volsize_to_reservation $vol3 $vol_size)
  66. log_must test $resv -eq $expected
  67. log_pass "Cloning a thick provisioned volume results in a sparse volume"