/tests/zfs-tests/tests/functional/snapshot/rollback_002_pos.ksh

https://github.com/adilger/zfs · Korn Shell · 133 lines · 62 code · 26 blank · 45 comment · 11 complexity · f1d059150e89b2345bdf708b92674271 MD5 · raw file

  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 2007 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. #
  29. . $STF_SUITE/include/libtest.shlib
  30. . $STF_SUITE/tests/functional/snapshot/snapshot.cfg
  31. #
  32. # DESCRIPTION:
  33. # Verify that rollbacks are with respect to the latest snapshot.
  34. #
  35. # STRATEGY:
  36. # 1. Empty a file system
  37. # 2. Populate the file system
  38. # 3. Take a snapshot of the file system
  39. # 4. Add new files to the file system
  40. # 5. Take a snapshot
  41. # 6. Remove the original files
  42. # 7. Perform a rollback
  43. # 8. Verify the latest snapshot and file system agree
  44. #
  45. verify_runnable "both"
  46. function cleanup
  47. {
  48. snapexists $SNAPFS.1
  49. [[ $? -eq 0 ]] && \
  50. log_must zfs destroy $SNAPFS.1
  51. snapexists $SNAPFS
  52. [[ $? -eq 0 ]] && \
  53. log_must zfs destroy $SNAPFS
  54. [[ -e $TESTDIR ]] && \
  55. log_must rm -rf $TESTDIR/* > /dev/null 2>&1
  56. }
  57. log_assert "Verify rollback is with respect to latest snapshot."
  58. log_onexit cleanup
  59. [[ -n $TESTDIR ]] && \
  60. log_must rm -rf $TESTDIR/* > /dev/null 2>&1
  61. typeset -i COUNT=10
  62. log_note "Populate the $TESTDIR directory (prior to first snapshot)"
  63. typeset -i i=1
  64. while [[ $i -le $COUNT ]]; do
  65. log_must file_write -o create -f $TESTDIR/original_file$i \
  66. -b $BLOCKSZ -c $NUM_WRITES -d $i
  67. (( i = i + 1 ))
  68. done
  69. log_must zfs snapshot $SNAPFS
  70. FILE_COUNT=`ls -Al $SNAPDIR | grep -v "total" | wc -l`
  71. if [[ $FILE_COUNT -ne $COUNT ]]; then
  72. ls -Al $SNAPDIR
  73. log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)."
  74. fi
  75. log_note "Populate the $TESTDIR directory (prior to second snapshot)"
  76. typeset -i i=1
  77. while [[ $i -le $COUNT ]]; do
  78. log_must file_write -o create -f $TESTDIR/afterfirst_file$i \
  79. -b $BLOCKSZ -c $NUM_WRITES -d $i
  80. (( i = i + 1 ))
  81. done
  82. log_must zfs snapshot $SNAPFS.1
  83. log_note "Populate the $TESTDIR directory (Post second snapshot)"
  84. typeset -i i=1
  85. while [[ $i -le $COUNT ]]; do
  86. log_must file_write -o create -f $TESTDIR/aftersecond_file$i \
  87. -b $BLOCKSZ -c $NUM_WRITES -d $i
  88. (( i = i + 1 ))
  89. done
  90. [[ -n $TESTDIR ]] && \
  91. log_must rm -rf $TESTDIR/original_file* > /dev/null 2>&1
  92. #
  93. # Now rollback to latest snapshot
  94. #
  95. log_must zfs rollback $SNAPFS.1
  96. FILE_COUNT=`ls -Al $TESTDIR/aftersecond* 2> /dev/null \
  97. | grep -v "total" | wc -l`
  98. if [[ $FILE_COUNT -ne 0 ]]; then
  99. ls -Al $TESTDIR
  100. log_fail "$TESTDIR contains $FILE_COUNT aftersecond* files(s)."
  101. fi
  102. FILE_COUNT=`ls -Al $TESTDIR/original* $TESTDIR/afterfirst*| grep -v "total" | wc -l`
  103. if [[ $FILE_COUNT -ne 20 ]]; then
  104. ls -Al $TESTDIR
  105. log_fail "$TESTDIR contains $FILE_COUNT original* files(s)."
  106. fi
  107. log_pass "The rollback to the latest snapshot succeeded."