PageRenderTime 23ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_004_pos.ksh

http://github.com/zfsonlinux/zfs
Korn Shell | 117 lines | 52 code | 25 blank | 40 comment | 7 complexity | 6f1572d9ad375786415dfbeba3fc4dd2 MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception
  1. #!/bin/ksh -p
  2. #
  3. # CDDL HEADER START
  4. #
  5. # The contents of this file are subject to the terms of the
  6. # Common Development and Distribution License (the "License").
  7. # You may not use this file except in compliance with the License.
  8. #
  9. # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10. # or http://www.opensolaris.org/os/licensing.
  11. # See the License for the specific language governing permissions
  12. # and limitations under the License.
  13. #
  14. # When distributing Covered Code, include this CDDL HEADER in each
  15. # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16. # If applicable, add the following below this CDDL HEADER, with the
  17. # fields enclosed by brackets "[]" replaced with your own identifying
  18. # information: Portions Copyright [yyyy] [name of copyright owner]
  19. #
  20. # CDDL HEADER END
  21. #
  22. #
  23. # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
  24. # Use is subject to license terms.
  25. #
  26. #
  27. # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
  28. # Copyright 2016 Nexenta Systems, Inc.
  29. #
  30. . $STF_SUITE/include/libtest.shlib
  31. . $STF_SUITE/tests/functional/zvol/zvol_common.shlib
  32. #
  33. # DESCRIPTION:
  34. # Verify the ability to take snapshots of zvols used as dump or swap.
  35. #
  36. # STRATEGY:
  37. # 1. Create a ZFS volume
  38. # 2. Set the volume as dump or swap
  39. # 3. Verify creating a snapshot of the zvol succeeds.
  40. #
  41. verify_runnable "global"
  42. if ! is_physical_device $DISKS; then
  43. log_unsupported "This directory cannot be run on raw files."
  44. fi
  45. volsize=$(zfs get -H -o value volsize $TESTPOOL/$TESTVOL)
  46. function cleanup
  47. {
  48. typeset dumpdev=$(get_dumpdevice)
  49. if [[ $dumpdev != $savedumpdev ]] ; then
  50. safe_dumpadm $savedumpdev
  51. fi
  52. swap -l | grep -w $voldev > /dev/null 2>&1
  53. if (( $? == 0 )); then
  54. log_must swap -d $voldev
  55. fi
  56. typeset snap
  57. for snap in snap0 snap1 ; do
  58. if datasetexists $TESTPOOL/$TESTVOL@$snap ; then
  59. log_must zfs destroy $TESTPOOL/$TESTVOL@$snap
  60. fi
  61. done
  62. zfs set volsize=$volsize $TESTPOOL/$TESTVOL
  63. }
  64. function verify_snapshot
  65. {
  66. typeset volume=$1
  67. log_must zfs snapshot $volume@snap0
  68. log_must zfs snapshot $volume@snap1
  69. log_must datasetexists $volume@snap0 $volume@snap1
  70. log_must zfs destroy $volume@snap1
  71. log_must zfs snapshot $volume@snap1
  72. log_mustnot zfs rollback -r $volume@snap0
  73. log_must datasetexists $volume@snap0
  74. log_must zfs destroy -r $volume@snap0
  75. }
  76. log_assert "Verify the ability to take snapshots of zvols used as dump or swap."
  77. log_onexit cleanup
  78. voldev=${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL
  79. savedumpdev=$(get_dumpdevice)
  80. # create snapshot over dump zvol
  81. safe_dumpadm $voldev
  82. log_must is_zvol_dumpified $TESTPOOL/$TESTVOL
  83. verify_snapshot $TESTPOOL/$TESTVOL
  84. safe_dumpadm $savedumpdev
  85. log_mustnot is_zvol_dumpified $TESTPOOL/$TESTVOL
  86. # create snapshot over swap zvol
  87. log_must swap -a $voldev
  88. log_mustnot is_zvol_dumpified $TESTPOOL/$TESTVOL
  89. verify_snapshot $TESTPOOL/$TESTVOL
  90. log_must swap -d $voldev
  91. log_mustnot is_zvol_dumpified $TESTPOOL/$TESTVOL
  92. log_pass "Creating snapshots from dump/swap zvols succeeds."