/tests/zfs-tests/tests/functional/cli_root/zfs_bookmark/zfs_bookmark_cliargs.ksh

https://github.com/adilger/zfs · Korn Shell · 238 lines · 151 code · 20 blank · 67 comment · 3 complexity · 88dfd5a9d59aa19674e55f487452b7d3 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 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
  24. # Copyright 2019, 2020 by Christian Schwarz. All rights reserved.
  25. #
  26. . $STF_SUITE/include/libtest.shlib
  27. #
  28. # DESCRIPTION:
  29. # 'zfs bookmark' should work with both full and short arguments.
  30. #
  31. # STRATEGY:
  32. # 1. Create initial snapshot
  33. #
  34. # 2. Verify we can create a bookmark specifying snapshot and bookmark full paths
  35. # 3. Verify we can create a bookmark specifying the short snapshot name
  36. # 4. Verify we can create a bookmark specifying the short bookmark name
  37. # 5. Verify at least a full dataset path is required and both snapshot and
  38. # bookmark name must be valid
  39. #
  40. # 6. Verify we can copy a bookmark by specifying the source bookmark and new
  41. # bookmark full paths.
  42. # 7. Verify we can copy a bookmark specifying the short source name
  43. # 8. Verify we can copy a bookmark specifying the short new name
  44. # 9. Verify two short paths are not allowed, and test empty paths
  45. # 10. Verify we cannot copy a bookmark if the new bookmark already exists
  46. # 11. Verify that copying a bookmark only works if new and source name
  47. # have the same dataset
  48. #
  49. verify_runnable "both"
  50. function cleanup
  51. {
  52. if snapexists "$DATASET@$TESTSNAP"; then
  53. log_must zfs destroy "$DATASET@$TESTSNAP"
  54. fi
  55. if bkmarkexists "$DATASET#$TESTBM"; then
  56. log_must zfs destroy "$DATASET#$TESTBM"
  57. fi
  58. if bkmarkexists "$DATASET#$TESTBMCOPY"; then
  59. log_must zfs destroy "$DATASET#$TESTBMCOPY"
  60. fi
  61. }
  62. log_assert "'zfs bookmark' should work only when passed valid arguments."
  63. log_onexit cleanup
  64. DATASET="$TESTPOOL/$TESTFS"
  65. DATASET_TWO="$TESTPOOL/${TESTFS}_two"
  66. TESTSNAP='snapshot'
  67. TESTSNAP2='snapshot2'
  68. TESTBM='bookmark'
  69. TESTBMCOPY='bookmark_copy'
  70. # Create initial snapshot
  71. log_must zfs snapshot "$DATASET@$TESTSNAP"
  72. #
  73. # Bookmark creation tests
  74. #
  75. # Verify we can create a bookmark specifying snapshot and bookmark full paths
  76. log_must zfs bookmark "$DATASET@$TESTSNAP" "$DATASET#$TESTBM"
  77. log_must eval "bkmarkexists $DATASET#$TESTBM"
  78. log_must zfs destroy "$DATASET#$TESTBM"
  79. # Verify we can create a bookmark specifying the snapshot name
  80. log_must zfs bookmark "@$TESTSNAP" "$DATASET#$TESTBM"
  81. log_must eval "bkmarkexists $DATASET#$TESTBM"
  82. log_must zfs destroy "$DATASET#$TESTBM"
  83. # Verify we can create a bookmark specifying the bookmark name
  84. log_must zfs bookmark "$DATASET@$TESTSNAP" "#$TESTBM"
  85. log_must eval "bkmarkexists $DATASET#$TESTBM"
  86. log_must zfs destroy "$DATASET#$TESTBM"
  87. # Verify at least a full dataset path is required and both snapshot and
  88. # bookmark name must be valid
  89. log_mustnot zfs bookmark "@$TESTSNAP" "#$TESTBM"
  90. log_mustnot zfs bookmark "$TESTSNAP" "#$TESTBM"
  91. log_mustnot zfs bookmark "@$TESTSNAP" "$TESTBM"
  92. log_mustnot zfs bookmark "$TESTSNAP" "$TESTBM"
  93. log_mustnot zfs bookmark "$TESTSNAP" "$DATASET#$TESTBM"
  94. log_mustnot zfs bookmark "$DATASET" "$TESTBM"
  95. log_mustnot zfs bookmark "$DATASET@" "$TESTBM"
  96. log_mustnot zfs bookmark "$DATASET" "#$TESTBM"
  97. log_mustnot zfs bookmark "$DATASET@" "#$TESTBM"
  98. log_mustnot zfs bookmark "$DATASET@$TESTSNAP" "$TESTBM"
  99. log_mustnot zfs bookmark "@" "#$TESTBM"
  100. log_mustnot zfs bookmark "@" "#"
  101. log_mustnot zfs bookmark "@$TESTSNAP" "#"
  102. log_mustnot zfs bookmark "@$TESTSNAP" "$DATASET#"
  103. log_mustnot zfs bookmark "@$TESTSNAP" "$DATASET"
  104. log_mustnot zfs bookmark "$TESTSNAP" "$DATASET#"
  105. log_mustnot zfs bookmark "$TESTSNAP" "$DATASET"
  106. log_mustnot eval "bkmarkexists $DATASET#$TESTBM"
  107. # Verify that we can create a bookmarks on another origin filesystem
  108. log_must zfs clone "$DATASET@$TESTSNAP" "$DATASET_TWO"
  109. log_must zfs bookmark "$DATASET@$TESTSNAP" "$DATASET_TWO#$TESTBM"
  110. log_must eval "destroy_dataset $DATASET_TWO"
  111. # Verify that we can cannot create bookmarks on a non-origin filesystem
  112. log_must zfs create "$DATASET_TWO"
  113. log_mustnot_expect "source is not an ancestor of the new bookmark's dataset" zfs bookmark "$DATASET@$TESTSNAP" "$DATASET_TWO#$TESTBM"
  114. log_must zfs destroy "$DATASET_TWO"
  115. # Verify that we can create bookmarks of snapshots on the pool dataset
  116. log_must zfs snapshot "$TESTPOOL@$TESTSNAP"
  117. log_must zfs bookmark "$TESTPOOL@$TESTSNAP" "$TESTPOOL#$TESTBM"
  118. log_must zfs destroy "$TESTPOOL#$TESTBM"
  119. log_must zfs destroy "$TESTPOOL@$TESTSNAP"
  120. #
  121. # Bookmark copying tests
  122. #
  123. # create the source bookmark
  124. log_must zfs bookmark "$DATASET@$TESTSNAP" "$DATASET#$TESTBM"
  125. # Verify we can copy a bookmark by specifying the source bookmark
  126. # and new bookmark full paths.
  127. log_must eval "bkmarkexists $DATASET#$TESTBM"
  128. log_must zfs bookmark "$DATASET#$TESTBM" "$DATASET#$TESTBMCOPY"
  129. log_must eval "bkmarkexists $DATASET#$TESTBMCOPY"
  130. ## validate destroy once (should be truly independent bookmarks)
  131. log_must zfs destroy "$DATASET#$TESTBM"
  132. log_mustnot eval "bkmarkexists $DATASET#$TESTBM"
  133. log_must eval "bkmarkexists $DATASET#$TESTBMCOPY"
  134. log_must zfs destroy "$DATASET#$TESTBMCOPY"
  135. log_mustnot eval "bkmarkexists $DATASET#$TESTBMCOPY"
  136. log_mustnot eval "bkmarkexists $DATASET#$TESTBM"
  137. ## recreate the source bookmark
  138. log_must zfs bookmark "$DATASET@$TESTSNAP" "$DATASET#$TESTBM"
  139. # Verify we can copy a bookmark specifying the short source name
  140. log_must zfs bookmark "#$TESTBM" "$DATASET#$TESTBMCOPY"
  141. log_must eval "bkmarkexists $DATASET#$TESTBMCOPY"
  142. log_must zfs destroy "$DATASET#$TESTBMCOPY"
  143. # Verify we can copy a bookmark specifying the short bookmark name
  144. log_must zfs bookmark "$DATASET#$TESTBM" "#$TESTBMCOPY"
  145. log_must eval "bkmarkexists $DATASET#$TESTBMCOPY"
  146. log_must zfs destroy "$DATASET#$TESTBMCOPY"
  147. # Verify two short paths are not allowed, and test empty paths
  148. log_mustnot zfs bookmark "#$TESTBM" "#$TESTBMCOPY"
  149. log_mustnot zfs bookmark "#$TESTBM" "#"
  150. log_mustnot zfs bookmark "#" "#$TESTBMCOPY"
  151. log_mustnot zfs bookmark "#" "#"
  152. log_mustnot zfs bookmark "#" ""
  153. log_mustnot zfs bookmark "" "#"
  154. log_mustnot zfs bookmark "" ""
  155. # Verify that we can copy bookmarks on another origin filesystem
  156. log_must zfs clone "$DATASET@$TESTSNAP" "$DATASET_TWO"
  157. log_must zfs bookmark "$DATASET#$TESTBM" "$DATASET_TWO#$TESTBMCOPY"
  158. log_must zfs destroy "$DATASET_TWO"
  159. # Verify that we can cannot create bookmarks on another non-origin filesystem
  160. log_must zfs create "$DATASET_TWO"
  161. log_mustnot_expect "source is not an ancestor of the new bookmark's dataset" zfs bookmark "$DATASET#$TESTBM" "$DATASET_TWO#$TESTBMCOPY"
  162. log_must zfs destroy "$DATASET_TWO"
  163. # Verify that we can copy bookmarks on the pool dataset
  164. log_must zfs snapshot "$TESTPOOL@$TESTSNAP"
  165. log_must zfs bookmark "$TESTPOOL@$TESTSNAP" "$TESTPOOL#$TESTBM"
  166. log_must zfs bookmark "$TESTPOOL#$TESTBM" "$TESTPOOL#$TESTBMCOPY"
  167. log_must zfs destroy "$TESTPOOL#$TESTBM"
  168. log_must zfs destroy "$TESTPOOL#$TESTBMCOPY"
  169. log_must zfs destroy "$TESTPOOL@$TESTSNAP"
  170. # Verify that copied 'normal' bookmarks are independent of the source bookmark
  171. log_must zfs bookmark "$DATASET#$TESTBM" "$DATASET#$TESTBMCOPY"
  172. log_must zfs destroy "$DATASET#$TESTBM"
  173. log_must eval "zfs send $DATASET@$TESTSNAP > $TEST_BASE_DIR/zfstest_datastream.$$"
  174. log_must eval "destroy_dataset $TESTPOOL/$TESTFS/recv"
  175. log_must eval "zfs recv -o mountpoint=none $TESTPOOL/$TESTFS/recv < $TEST_BASE_DIR/zfstest_datastream.$$"
  176. log_must zfs snapshot "$DATASET@$TESTSNAP2"
  177. log_must eval "zfs send -i \#$TESTBMCOPY $DATASET@$TESTSNAP2 > $TEST_BASE_DIR/zfstest_datastream.$$"
  178. log_must eval "zfs recv $TESTPOOL/$TESTFS/recv < $TEST_BASE_DIR/zfstest_datastream.$$"
  179. # cleanup
  180. log_must eval "destroy_dataset $DATASET@$TESTSNAP2"
  181. log_must zfs destroy "$DATASET#$TESTBMCOPY"
  182. log_must zfs bookmark "$DATASET@$TESTSNAP" "$DATASET#$TESTBM"
  183. # Verify that copied redaction bookmarks are independent of the source bookmark
  184. ## create redaction bookmark
  185. log_must zfs destroy "$DATASET#$TESTBM"
  186. log_must zfs destroy "$DATASET@$TESTSNAP"
  187. log_must eval "echo secret > $TESTDIR/secret"
  188. log_must zfs snapshot "$DATASET@$TESTSNAP"
  189. log_must eval "echo redacted > $TESTDIR/secret"
  190. log_must zfs snapshot "$DATASET@$TESTSNAP2" # TESTSNAP2 is the redaction snapshot
  191. log_must zfs list -t all -o name,createtxg,guid,mountpoint,written
  192. log_must zfs redact "$DATASET@$TESTSNAP" "$TESTBM" "$DATASET@$TESTSNAP2"
  193. # ensure our primitive for testing whether a bookmark is a redaction bookmark works
  194. log_must eval "zfs get all $DATASET#$TESTBM | grep redact_snaps"
  195. ## copy the redaction bookmark
  196. log_must zfs bookmark "$DATASET#$TESTBM" "#$TESTBMCOPY"
  197. log_mustnot eval "zfs get all $DATASET#$TESTBMCOPY | grep redact_snaps"
  198. log_must eval "zfs send --redact "$TESTBMCOPY" -i $DATASET@$TESTSNAP $DATASET@$TESTSNAP2 2>&1 | head -n 100 | grep 'not a redaction bookmark'"
  199. # try the above again after destroying the source bookmark, preventive measure for future work
  200. log_must zfs destroy "$DATASET#$TESTBM"
  201. log_mustnot eval "zfs get all $DATASET#$TESTBMCOPY | grep redact_snaps"
  202. log_must eval "zfs send --redact "$TESTBMCOPY" -i $DATASET@$TESTSNAP $DATASET@$TESTSNAP2 2>&1 | head -n 100 | grep 'not a redaction bookmark'"
  203. ## cleanup
  204. log_must eval "destroy_dataset $DATASET@$TESTSNAP2"
  205. log_must zfs destroy "$DATASET#$TESTBMCOPY"
  206. log_must eval "destroy_dataset $DATASET@$TESTSNAP"
  207. log_must zfs snapshot "$DATASET@$TESTSNAP"
  208. log_must zfs bookmark "$DATASET@$TESTSNAP" "$DATASET#$TESTBM"
  209. log_pass "'zfs bookmark' works as expected"