PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/sys/cddl/zfs/tests/snapshot/clone_001_pos.ksh

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 143 lines | 52 code | 24 blank | 67 comment | 7 complexity | a6e59c1208a82c91df4b3470594e8319 MD5 | raw file
  1. #! /usr/local/bin/ksh93 -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. # $FreeBSD$
  23. #
  24. # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
  25. # Use is subject to license terms.
  26. #
  27. # ident "@(#)clone_001_pos.ksh 1.6 09/06/22 SMI"
  28. #
  29. . $STF_SUITE/include/libtest.kshlib
  30. ################################################################################
  31. #
  32. # __stc_assertion_start
  33. #
  34. # ID: clone_001_pos
  35. #
  36. # DESCRIPTION:
  37. # Create a snapshot from regular filesystem, volume,
  38. # or filesystem upon volume, Build a clone file system
  39. # from the snapshot and verify new files can be written.
  40. #
  41. # STRATEGY:
  42. # 1. Create snapshot use 3 combination:
  43. # - Regular filesystem
  44. # - Regular volume
  45. # - Filesystem upon volume
  46. # 2. Clone a new file system from the snapshot
  47. # 3. Verify the cloned file system is writable
  48. #
  49. # TESTABILITY: explicit
  50. #
  51. # TEST_AUTOMATION_LEVEL: automated
  52. #
  53. # CODING_STATUS: COMPLETED (2005-08-25)
  54. #
  55. # __stc_assertion_end
  56. #
  57. ################################################################################
  58. verify_runnable "both"
  59. # Setup array, 4 elements as a group, refer to:
  60. # i+0: name of a snapshot
  61. # i+1: mountpoint of the snapshot
  62. # i+2: clone created from the snapshot
  63. # i+3: mountpoint of the clone
  64. set -A args "$SNAPFS" "$SNAPDIR" "$TESTPOOL/$TESTCLONE" "$TESTDIR.0" \
  65. "$SNAPFS1" "$SNAPDIR3" "$TESTPOOL/$TESTCLONE1" "" \
  66. "$SNAPFS2" "$SNAPDIR2" "$TESTPOOL1/$TESTCLONE2" "$TESTDIR.2"
  67. function setup_all
  68. {
  69. create_pool $TESTPOOL1 /dev/zvol/$TESTPOOL/$TESTVOL
  70. log_must $ZFS create $TESTPOOL1/$TESTFS
  71. log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL1/$TESTFS
  72. return 0
  73. }
  74. function cleanup_all
  75. {
  76. destroy_pool $TESTPOOL1
  77. [[ -d $TESTDIR2 ]] && \
  78. log_must $RM -rf $TESTDIR2
  79. return 0
  80. }
  81. log_assert "Verify a cloned file system is writable."
  82. log_onexit cleanup_all
  83. setup_all
  84. [[ -n $TESTDIR ]] && \
  85. log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
  86. typeset -i COUNT=10
  87. for mtpt in $TESTDIR $TESTDIR2 ; do
  88. log_note "Populate the $mtpt directory (prior to snapshot)"
  89. populate_dir $mtpt/before_file $COUNT $NUM_WRITES $BLOCKSZ ITER
  90. done
  91. typeset -i i=0
  92. while (( i < ${#args[*]} )); do
  93. #
  94. # Take a snapshot of the test file system.
  95. #
  96. log_must $ZFS snapshot ${args[i]}
  97. #
  98. # Clone a new file system from the snapshot
  99. #
  100. log_must $ZFS clone ${args[i]} ${args[i+2]}
  101. if [[ -n ${args[i+3]} ]] ; then
  102. log_must $ZFS set mountpoint=${args[i+3]} ${args[i+2]}
  103. FILE_COUNT=`$LS -Al ${args[i+3]} | $GREP -v "total" | wc -l`
  104. if [[ $FILE_COUNT -ne $COUNT ]]; then
  105. $LS -Al ${args[i+3]}
  106. log_fail "AFTER: ${args[i+3]} contains $FILE_COUNT files(s)."
  107. fi
  108. log_note "Verify the ${args[i+3]} directory is writable"
  109. populate_dir ${args[i+3]}/after_file $COUNT $NUM_WRITES \
  110. $BLOCKSZ ITER
  111. FILE_COUNT=`$LS -Al ${args[i+3]}/after* | $GREP -v "total" | wc -l`
  112. if [[ $FILE_COUNT -ne $COUNT ]]; then
  113. $LS -Al ${args[i+3]}
  114. log_fail "${args[i+3]} contains $FILE_COUNT after* files(s)."
  115. fi
  116. fi
  117. (( i = i + 4 ))
  118. done
  119. log_pass "The clone file system is writable."