PageRenderTime 21ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_001_pos.ksh

http://github.com/zfsonlinux/zfs
Korn Shell | 174 lines | 95 code | 21 blank | 58 comment | 26 complexity | 19a50c296338832c251ce2575e7c537e 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) 2016 by Delphix. All rights reserved.
  28. #
  29. . $STF_SUITE/include/libtest.shlib
  30. . $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib
  31. #
  32. # DESCRIPTION:
  33. # 'zfs rollback -r|-rf|-R|-Rf' will recursively destroy any snapshots
  34. # more recent than the one specified.
  35. #
  36. # STRATEGY:
  37. # 1. Create pool, fs & volume.
  38. # 2. Separately create three snapshots or clones for fs & volume
  39. # 3. Roll back to the second snapshot and check the results.
  40. # 4. Create the third snapshot or clones for fs & volume again.
  41. # 5. Roll back to the first snapshot and check the results.
  42. # 6. Separately create two snapshots for fs & volume.
  43. # 7. Roll back to the first snapshot and check the results.
  44. #
  45. verify_runnable "both"
  46. log_assert "'zfs rollback -r|-rf|-R|-Rf' will recursively destroy any " \
  47. "snapshots more recent than the one specified."
  48. log_onexit cleanup_env
  49. #
  50. # Create suitable test environment and run 'zfs rollback', then compare with
  51. # expected value to check the system status.
  52. #
  53. # $1 option.
  54. # $2 the number of snapshots or clones.
  55. # $3 the number of snapshot point which we want to rollback.
  56. #
  57. function test_n_check #opt num_snap_clone num_rollback
  58. {
  59. typeset opt=$1
  60. typeset -i cnt=$2
  61. typeset -i pointcnt=$3
  62. typeset dtst
  63. (( cnt > 3 || pointcnt > cnt )) && \
  64. log_fail "Unsupported testing condition."
  65. # Clean up the test environment
  66. if pgrep -x dd 2>/dev/null; then
  67. pkill -x dd
  68. fi
  69. datasetexists $FS && log_must zfs destroy -Rf $FS
  70. if datasetexists $VOL; then
  71. if ismounted $TESTDIR1 $NEWFS_DEFAULT_FS; then
  72. log_must umount -f $TESTDIR1
  73. fi
  74. log_must zfs destroy -Rf $VOL
  75. fi
  76. # Create specified test environment
  77. case $opt in
  78. *r*) setup_snap_env $cnt ;;
  79. *R*) setup_clone_env $cnt ;;
  80. esac
  81. all_snap="$TESTSNAP $TESTSNAP1 $TESTSNAP2"
  82. all_clone="$TESTCLONE $TESTCLONE1 $TESTCLONE2"
  83. typeset snap_point
  84. typeset exist_snap
  85. typeset exist_clone
  86. case $pointcnt in
  87. 1) snap_point=$TESTSNAP
  88. exist_snap=$TESTSNAP
  89. [[ $opt == *R* ]] && exist_clone=$TESTCLONE
  90. ;;
  91. 2) snap_point=$TESTSNAP1
  92. exist_snap="$TESTSNAP $TESTSNAP1"
  93. [[ $opt == *R* ]] && exist_clone="$TESTCLONE $TESTCLONE1"
  94. ;;
  95. esac
  96. typeset snap
  97. for dtst in $FS $VOL; do
  98. # Volume is not available in Local Zone.
  99. if [[ $dtst == $VOL ]]; then
  100. if ! is_global_zone; then
  101. break
  102. fi
  103. fi
  104. if [[ $opt == *f* ]]; then
  105. # To write data to the mountpoint directory,
  106. write_mountpoint_dir $dtst
  107. opt=${opt%f}
  108. fi
  109. if [[ $dtst == $VOL ]]; then
  110. if ismounted $TESTDIR1 $NEWFS_DEFAULT_FS; then
  111. log_must umount -f $TESTDIR1
  112. fi
  113. log_must zfs rollback $opt $dtst@$snap_point
  114. log_must mount \
  115. $ZVOL_DEVDIR/$TESTPOOL/$TESTVOL $TESTDIR1
  116. else
  117. log_must zfs rollback $opt $dtst@$snap_point
  118. fi
  119. for snap in $all_snap; do
  120. if [[ " $exist_snap " == *" $snap "* ]]; then
  121. log_must datasetexists $dtst@$snap
  122. else
  123. log_must datasetnonexists $dtst@$snap
  124. fi
  125. done
  126. for clone in $all_clone; do
  127. if [[ " $exist_clone " == *" $clone "* ]]; then
  128. log_must datasetexists $dtst$clone
  129. else
  130. log_must datasetnonexists $dtst$clone
  131. fi
  132. done
  133. check_files $dtst@$snap_point
  134. done
  135. }
  136. typeset opt
  137. for opt in "-r" "-rf" "-R" "-Rf"; do
  138. #
  139. # Currently, the test case was limited to create and rollback
  140. # in three snapshots
  141. #
  142. log_note "Create 3 snapshots, rollback to the 2nd snapshot " \
  143. "using $opt."
  144. test_n_check "$opt" 3 2
  145. log_note "Create 3 snapshots and rollback to the 1st snapshot " \
  146. "using $opt."
  147. test_n_check "$opt" 3 1
  148. log_note "Create 2 snapshots and rollback to the 1st snapshot " \
  149. "using $opt."
  150. test_n_check "$opt" 2 1
  151. done
  152. log_pass "'zfs rollback -r|-rf|-R|-Rf' recursively destroy any snapshots more "\
  153. "recent than the one specified passed."