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

/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_007_pos.ksh

http://github.com/zfsonlinux/zfs
Korn Shell | 155 lines | 107 code | 11 blank | 37 comment | 4 complexity | 9cd7eec3fffbdea2deaef9f0d471162a 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/include/libtest.shlib
  30. . $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib
  31. #
  32. # DESCRIPTION:
  33. # Rename dataset, verify that the data haven't changed.
  34. #
  35. # STRATEGY:
  36. # 1. Create random data and copy to dataset.
  37. # 2. Perform renaming commands.
  38. # 3. Verify that the data haven't changed.
  39. #
  40. verify_runnable "both"
  41. function cleanup
  42. {
  43. if datasetexists $TESTPOOL/$TESTFS ; then
  44. log_must zfs destroy -Rf $TESTPOOL/$TESTFS
  45. fi
  46. log_must zfs create $TESTPOOL/$TESTFS
  47. log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
  48. rm -f $SRC_FILE $DST_FILE
  49. }
  50. function target_obj
  51. {
  52. typeset dtst=$1
  53. typeset obj
  54. typeset type=$(get_prop type $dtst)
  55. if [[ $type == "filesystem" ]]; then
  56. obj=$(get_prop mountpoint $dtst)/${SRC_FILE##*/}
  57. elif [[ $type == "volume" ]]; then
  58. obj=$ZVOL_DEVDIR/$dtst
  59. fi
  60. echo $obj
  61. }
  62. log_assert "Rename dataset, verify that the data haven't changed."
  63. log_onexit cleanup
  64. # Generate random data
  65. #
  66. BS=512 ; CNT=2048
  67. SRC_FILE=$TESTDIR/srcfile.$$
  68. DST_FILE=$TESTDIR/dstfile.$$
  69. log_must dd if=/dev/urandom of=$SRC_FILE bs=$BS count=$CNT
  70. fs=$TESTPOOL/$TESTFS/fs.$$
  71. fsclone=$TESTPOOL/$TESTFS/fsclone.$$
  72. log_must zfs create $fs
  73. obj=$(target_obj $fs)
  74. log_must cp $SRC_FILE $obj
  75. snap=${fs}@snap.$$
  76. log_must zfs snapshot $snap
  77. log_must zfs clone $snap $fsclone
  78. # Rename dataset & clone
  79. #
  80. log_must zfs rename $fs ${fs}-new
  81. log_must zfs rename $fsclone ${fsclone}-new
  82. # Compare source file and target file
  83. #
  84. obj=$(target_obj ${fs}-new)
  85. log_must diff $SRC_FILE $obj
  86. obj=$(target_obj ${fsclone}-new)
  87. log_must diff $SRC_FILE $obj
  88. # Rename snapshot and re-clone dataset
  89. #
  90. log_must zfs rename ${fs}-new $fs
  91. log_must zfs rename $snap ${snap}-new
  92. log_must zfs clone ${snap}-new $fsclone
  93. # Compare source file and target file
  94. #
  95. obj=$(target_obj $fsclone)
  96. log_must diff $SRC_FILE $obj
  97. if is_global_zone; then
  98. vol=$TESTPOOL/$TESTFS/vol.$$ ; volclone=$TESTPOOL/$TESTFS/volclone.$$
  99. log_must zfs create -V 100M $vol
  100. block_device_wait
  101. obj=$(target_obj $vol)
  102. log_must dd if=$SRC_FILE of=$obj bs=$BS count=$CNT
  103. snap=${vol}@snap.$$
  104. log_must zfs snapshot $snap
  105. log_must zfs clone $snap $volclone
  106. block_device_wait
  107. # Rename dataset & clone
  108. log_must zfs rename $vol ${vol}-new
  109. log_must zfs rename $volclone ${volclone}-new
  110. block_device_wait
  111. # Compare source file and target file
  112. obj=$(target_obj ${vol}-new)
  113. log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT
  114. log_must diff $SRC_FILE $DST_FILE
  115. obj=$(target_obj ${volclone}-new)
  116. log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT
  117. log_must diff $SRC_FILE $DST_FILE
  118. # Rename snapshot and re-clone dataset
  119. log_must zfs rename ${vol}-new $vol
  120. log_must zfs rename $snap ${snap}-new
  121. log_must zfs clone ${snap}-new $volclone
  122. block_device_wait
  123. # Compare source file and target file
  124. obj=$(target_obj $volclone)
  125. log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT
  126. log_must diff $SRC_FILE $DST_FILE
  127. fi
  128. log_pass "Rename dataset, the data haven't changed passed."