PageRenderTime 25ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_004_pos.ksh

http://github.com/zfsonlinux/zfs
Korn Shell | 140 lines | 73 code | 21 blank | 46 comment | 22 complexity | e9599e6f958796342161410231581648 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 2007 Sun Microsystems, Inc. All rights reserved.
  24. # Use is subject to license terms.
  25. #
  26. #
  27. # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
  28. #
  29. . $STF_SUITE/tests/functional/cli_root/zfs_promote/zfs_promote.cfg
  30. . $STF_SUITE/include/libtest.shlib
  31. #
  32. # DESCRIPTION:
  33. # 'zfs promote' can deal with multi-level clones.
  34. #
  35. # STRATEGY:
  36. # 1. Create multiple snapshots and multi-level clones
  37. # 2. Promote a clone filesystem
  38. # 3. Verify the dataset dependency relationships are correct after promotion.
  39. #
  40. verify_runnable "both"
  41. function cleanup
  42. {
  43. if snapexists ${c1snap[1]}; then
  44. log_must zfs promote $clone
  45. fi
  46. typeset ds
  47. typeset data
  48. for ds in ${snap[*]}; do
  49. snapexists $ds && \
  50. log_must zfs destroy -rR $ds
  51. done
  52. for data in ${file[*]}; do
  53. [[ -e $data ]] && rm -f $data
  54. done
  55. }
  56. log_assert "'zfs promote' can deal with multi-level clone."
  57. log_onexit cleanup
  58. fs=$TESTPOOL/$TESTFS
  59. clone=$TESTPOOL/$TESTCLONE
  60. clone1=$TESTPOOL/$TESTCLONE1
  61. # Define some arrays here to use loop to reduce code amount
  62. # Array which stores the origin snapshots created in the origin filesystem
  63. set -A snap "${fs}@$TESTSNAP" "${fs}@$TESTSNAP1" "${fs}@$TESTSNAP2" "${fs}@$TESTSNAP3"
  64. # Array which stores the snapshots existing in the first clone
  65. set -A csnap "${clone}@$TESTSNAP3" "${clone}@$TESTSNAP4" "${clone}@$TESTSNAP5"
  66. # Array which stores the snapshots existing in the second clone after promote operation
  67. set -A c1snap "${clone1}@$TESTSNAP3" "${clone1}@$TESTSNAP4" "${clone1}@$TESTSNAP5"
  68. # The data will inject into the origin filesystem
  69. set -A file "$TESTDIR/$TESTFILE0" "$TESTDIR/$TESTFILE1" "$TESTDIR/$TESTFILE2" \
  70. "$TESTDIR/$TESTFILE3"
  71. cdir=/$TESTPOOL/$TESTCLONE
  72. # The data will inject into the first clone
  73. set -A cfile "${cdir}/$CLONEFILE" "${cdir}/$CLONEFILE1" "${cdir}/$CLONEFILE2"
  74. c1snapdir=/$TESTPOOL/$TESTCLONE1/.zfs/snapshot
  75. # The data which will exist in the snapshot of the second clone filesystem after promote
  76. set -A c1snapfile "${c1snapdir}/$TESTSNAP3/$CLONEFILE" \
  77. "${c1snapdir}/$TESTSNAP4/$CLONEFILE1" \
  78. "${c1snapdir}/$TESTSNAP5/$CLONEFILE2"
  79. # setup for promote testing
  80. typeset -i i=0
  81. while (( i < 4 )); do
  82. log_must mkfile $FILESIZE ${file[i]}
  83. (( i>0 )) && log_must rm -f ${file[((i-1))]}
  84. log_must zfs snapshot ${snap[i]}
  85. (( i = i + 1 ))
  86. done
  87. log_must zfs clone ${snap[2]} $clone
  88. log_must rm -f /$clone/$TESTFILE2
  89. i=0
  90. while (( i < 3 )); do
  91. log_must mkfile $FILESIZE ${cfile[i]}
  92. (( i>0 )) && log_must rm -f ${cfile[(( i-1 ))]}
  93. log_must zfs snapshot ${csnap[i]}
  94. (( i = i + 1 ))
  95. done
  96. log_must zfs clone ${csnap[1]} $clone1
  97. log_must mkfile $FILESIZE /$clone1/$CLONEFILE2
  98. log_must rm -f /$clone1/$CLONEFILE1
  99. log_must zfs snapshot ${c1snap[2]}
  100. log_must zfs promote $clone1
  101. # verify the 'promote' operation
  102. for ds in ${snap[*]} ${csnap[2]} ${c1snap[*]}; do
  103. ! snapexists $ds && \
  104. log_fail "The snapshot $ds disappear after zfs promote."
  105. done
  106. for data in ${c1snapfile[*]}; do
  107. [[ ! -e $data ]] && \
  108. log_fail "The data file $data loses after zfs promote."
  109. done
  110. origin_prop=$(get_prop origin $fs)
  111. [[ "$origin_prop" != "-" ]] && \
  112. log_fail "The dependency is not correct for $fs after zfs promote."
  113. origin_prop=$(get_prop origin $clone)
  114. [[ "$origin_prop" != "${c1snap[1]}" ]] && \
  115. log_fail "The dependency is not correct for $clone after zfs promote."
  116. origin_prop=$(get_prop origin $clone1)
  117. [[ "$origin_prop" != "${snap[2]}" ]] && \
  118. log_fail "The dependency is not correct for $clone1 after zfs promote."
  119. log_pass "'zfs promote' deal with multi-level clones as expected."