/tests/zfs-tests/tests/functional/rsend/send-cpL_varied_recsize.ksh

https://github.com/adilger/zfs · Korn Shell · 203 lines · 137 code · 11 blank · 55 comment · 10 complexity · 24fe8de87374b64c3782410afd68e7d5 MD5 · raw file

  1. #!/bin/ksh -p
  2. #
  3. # This file and its contents are supplied under the terms of the
  4. # Common Development and Distribution License ("CDDL"), version 1.0.
  5. # You may only use this file in accordance with the terms of version
  6. # 1.0 of the CDDL.
  7. #
  8. # A full copy of the text of the CDDL should have accompanied this
  9. # source. A copy of the CDDL is also available via the Internet at
  10. # http://www.illumos.org/license/CDDL.
  11. #
  12. #
  13. # Copyright (c) 2015 by Delphix. All rights reserved.
  14. #
  15. . $STF_SUITE/tests/functional/rsend/rsend.kshlib
  16. #
  17. # Description:
  18. # Verify compressed send works correctly with datasets of varying recsize.
  19. #
  20. # Strategy:
  21. # 1. Check the recv behavior (into pools with features enabled and disabled)
  22. # of all combinations of -c -p and -L. Verify the stream is compressed,
  23. # and that the recsize property and that of a received file is correct
  24. # according to this matrix:
  25. #
  26. # +---------+--------+------------+------------+-----------+-----------+
  27. # | send | send | received | received | received | received |
  28. # | stream | stream | file bs | prop | file bs | props |
  29. # | recsize | flags | (disabled) | (disabled) | (enabled) | (enabled) |
  30. # +---------+--------+------------+------------+-----------+-----------+
  31. # | 128k | | 128k | 128k | 128k | 128k |
  32. # | 128k | -c | Fails | Fails | 128k | 128k |
  33. # | 128k | -p | 128k | 128k | 128k | 128k |
  34. # | 128k | -L | 128k | 128k | 128k | 128k |
  35. # | 128k | -cp | Fails | Fails | 128k | 128k |
  36. # | 128k | -cL | Fails | Fails | 128k | 128k |
  37. # | 128k | -pL | 128k | 128k | 128k | 128k |
  38. # | 128k | -cpL | Fails | Fails | 128k | 128k |
  39. # | 1m | | Fails | Fails | 128k | 128k |
  40. # | 1m | -c | Fails | Fails | 128k | 128k |
  41. # | 1m | -p | 128k | 128k | 128k | 1m |
  42. # | 1m | -L | Fails | Fails | 1m | 128k |
  43. # | 1m | -cp | Fails | Fails | 128k | 1m |
  44. # | 1m | -cL | Fails | Fails | 1m | 128k |
  45. # | 1m | -pL | Fails | Fails | 1m | 1m |
  46. # | 1m | -cpL | Fails | Fails | 1m | 1m |
  47. # +---------+--------+------------+------------+-----------+-----------+
  48. #
  49. verify_runnable "both"
  50. function cleanup
  51. {
  52. datasetexists $TESTPOOL/128k && log_must_busy zfs destroy $TESTPOOL/128k
  53. datasetexists $TESTPOOL/1m && log_must_busy zfs destroy $TESTPOOL/1m
  54. cleanup_pool $POOL2
  55. destroy_pool $POOL3
  56. }
  57. # For a received stream, verify the recsize (prop and file) match expectations.
  58. function check_recsize
  59. {
  60. typeset recv_ds=$1
  61. typeset expected_file_bs=$2
  62. typeset expected_recsize=$3
  63. typeset file="$(get_prop mountpoint $recv_ds)/testfile"
  64. [[ -f $file ]] || log_fail "file '$file' doesn't exist"
  65. typeset read_recsize=$(get_prop recsize $recv_ds)
  66. if is_freebsd; then
  67. typeset read_file_bs=$(stat -f "%k" $file)
  68. else
  69. typeset read_file_bs=$(stat $file | sed -n \
  70. 's/.*IO Block: \([0-9]*\).*/\1/p')
  71. fi
  72. [[ $read_recsize = $expected_recsize ]] || log_fail \
  73. "read_recsize: $read_recsize expected_recsize: $expected_recsize"
  74. [[ $read_file_bs = $expected_file_bs ]] || log_fail \
  75. "read_file_bs: $read_file_bs expected_file_bs: $expected_file_bs"
  76. }
  77. #
  78. # This function does a zfs send and receive according to the parameters
  79. # below, and verifies the data shown in the strategy section.
  80. #
  81. # -[cpL] flags to pass through to 'zfs send'
  82. # -d Receive into a pool with all features disabled
  83. #
  84. # $1 The recordsize of the send dataset
  85. # $2 Whether or not the recv should work.
  86. # $3 The blocksize expected in a received file (default 128k)
  87. # $4 The recordsize property expected in a received dataset (default 128k)
  88. #
  89. function check
  90. {
  91. typeset recv_pool=$POOL2
  92. typeset flags='-'
  93. while getopts "cdpL" opt; do
  94. case $opt in
  95. c)
  96. flags+='c'
  97. ;;
  98. d)
  99. recv_pool=$POOL3
  100. ;;
  101. p)
  102. flags+='p'
  103. ;;
  104. L)
  105. flags+='L'
  106. ;;
  107. esac
  108. done
  109. shift $(($OPTIND - 1))
  110. [[ ${#flags} -eq 1 ]] && flags=''
  111. typeset recsize=$1
  112. typeset verify=$2
  113. typeset expected_file_bs=${3-131072}
  114. typeset expected_recsize=${4-131072}
  115. typeset send_ds=$TESTPOOL/$recsize
  116. typeset send_snap=$send_ds@snap
  117. typeset recv_ds=$recv_pool/$recsize
  118. typeset stream=$BACKDIR/stream.out
  119. datasetexists $send_ds || log_fail "send ds: $send_ds doesn't exist"
  120. [[ -f $stream ]] && log_must rm $stream
  121. log_must eval "zfs send $flags $send_snap >$stream"
  122. $verify eval "zfs recv $recv_ds <$stream"
  123. typeset stream_size=$(cat $stream | zstreamdump | sed -n \
  124. 's/ Total write size = \(.*\) (0x.*)/\1/p')
  125. #
  126. # Special case: For a send dataset with large blocks, don't try to
  127. # verify the stream size is correct if the compress flag is present
  128. # but the large blocks flag isn't. In these cases, the user data
  129. # isn't compressed in the stream (though metadata is) so the
  130. # verification would fail.
  131. #
  132. typeset do_size_test=true
  133. [[ $recsize = $large && $flags =~ 'c' && ! $flags =~ 'L' ]] && \
  134. do_size_test=false
  135. $do_size_test && verify_stream_size $stream $send_ds
  136. if [[ $verify = "log_mustnot" ]]; then
  137. datasetnonexists $recv_ds || log_fail "$recv_ds shouldn't exist"
  138. return
  139. fi
  140. check_recsize $recv_ds $expected_file_bs $expected_recsize
  141. $do_size_test && verify_stream_size $stream $recv_ds
  142. log_must_busy zfs destroy -r $recv_ds
  143. }
  144. log_assert "Verify compressed send works with datasets of varying recsize."
  145. log_onexit cleanup
  146. typeset recsize opts dir
  147. typeset small=$((128 * 1024))
  148. typeset large=$((1024 * 1024))
  149. # Create POOL3 with features disabled and datasets to create test send streams
  150. datasetexists $POOL3 && log_must zpool destroy $POOL3
  151. log_must zpool create -d $POOL3 $DISK3
  152. write_compressible $BACKDIR 32m
  153. for recsize in $small $large; do
  154. log_must zfs create -o compress=gzip -o recsize=$recsize \
  155. $TESTPOOL/$recsize
  156. dir=$(get_prop mountpoint $TESTPOOL/$recsize)
  157. log_must cp $BACKDIR/file.0 $dir/testfile
  158. log_must zfs snapshot $TESTPOOL/$recsize@snap
  159. done
  160. # Run tests for send streams without large blocks
  161. for opts in '' -d -c -p -dp -L -dL -cp -cL -pL -dpL -cpL; do
  162. check $opts $small log_must
  163. done
  164. for opts in -dc -dcp -dcL -dcpL; do
  165. check $opts $small log_mustnot
  166. done
  167. # Run tests for send streams with large blocks
  168. for opts in '' -d -dp -c; do
  169. check $opts $large log_must
  170. done
  171. for opts in -dc -dL -dcp -dcL -dpL -dcpL; do
  172. check $opts $large log_mustnot
  173. done
  174. check -p $large log_must $small $large
  175. check -L $large log_must $large $small
  176. check -cp $large log_must $small $large
  177. check -cL $large log_must $large $small
  178. check -pL $large log_must $large $large
  179. check -cpL $large log_must $large $large
  180. log_pass "Compressed send works with datasets of varying recsize."