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

https://github.com/adilger/zfs · Korn Shell · 109 lines · 64 code · 17 blank · 28 comment · 11 complexity · 1cb3019272a8d0e1094cefc90c4a25cb 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. . $STF_SUITE/include/properties.shlib
  17. #
  18. # Description:
  19. # Verify that compressed streams can contain embedded blocks.
  20. #
  21. # Strategy:
  22. # 1. Create a filesystem with compressible data and embedded blocks.
  23. # 2. Verify the created streams can be received correctly.
  24. # 3. Verify the presence / absence of embedded blocks in the compressed stream,
  25. # as well as the receiving file system.
  26. #
  27. verify_runnable "both"
  28. log_assert "Verify that compressed streams can contain embedded blocks."
  29. log_onexit cleanup_pool $POOL2
  30. typeset objs obj recsize
  31. typeset sendfs=$POOL2/sendfs
  32. typeset recvfs=$POOL2/recvfs
  33. typeset stream=$BACKDIR/stream
  34. typeset dump=$BACKDIR/dump
  35. typeset recvfs2=$POOL2/recvfs2
  36. typeset stream2=$BACKDIR/stream2
  37. typeset dump2=$BACKDIR/dump2
  38. log_must zfs create -o compress=lz4 $sendfs
  39. log_must zfs create -o compress=lz4 $recvfs
  40. log_must zfs create -o compress=lz4 $recvfs2
  41. typeset dir=$(get_prop mountpoint $sendfs)
  42. # Populate the send dataset with compressible data and embedded block files.
  43. write_compressible $dir 16m
  44. for recsize in "${recsize_prop_vals[@]}"; do
  45. # For lz4, this method works for blocks up to 16k, but not larger
  46. [[ $recsize -eq $((32 * 1024)) ]] && break
  47. if is_linux || is_freebsd; then
  48. log_must truncate -s $recsize $dir/$recsize
  49. log_must dd if=/dev/urandom of=$dir/$recsize \
  50. seek=$((recsize - 8)) bs=1 count=8 conv=notrunc
  51. else
  52. log_must mkholes -h 0:$((recsize - 8)) -d $((recsize - 8)):8 \
  53. $dir/$recsize
  54. fi
  55. done
  56. # Generate the streams and zstreamdump output.
  57. log_must zfs snapshot $sendfs@now
  58. log_must eval "zfs send -c $sendfs@now >$stream"
  59. log_must eval "zstreamdump -v <$stream >$dump"
  60. log_must eval "zfs recv -d $recvfs <$stream"
  61. cmp_ds_cont $sendfs $recvfs
  62. verify_stream_size $stream $sendfs
  63. log_mustnot stream_has_features $stream embed_data
  64. log_must eval "zfs send -c -e $sendfs@now >$stream2"
  65. log_must eval "zstreamdump -v <$stream2 >$dump2"
  66. log_must eval "zfs recv -d $recvfs2 <$stream2"
  67. cmp_ds_cont $sendfs $recvfs2
  68. verify_stream_size $stream2 $sendfs
  69. log_must stream_has_features $stream2 embed_data
  70. # Verify embedded blocks are present only when expected.
  71. for recsize in "${recsize_prop_vals[@]}"; do
  72. [[ $recsize -eq $((32 * 1024)) ]] && break
  73. typeset send_obj=$(get_objnum $(get_prop mountpoint $sendfs)/$recsize)
  74. typeset recv_obj=$(get_objnum \
  75. $(get_prop mountpoint $recvfs/sendfs)/$recsize)
  76. typeset recv2_obj=$(get_objnum \
  77. $(get_prop mountpoint $recvfs2/sendfs)/$recsize)
  78. log_must eval "zdb -ddddd $sendfs $send_obj >$BACKDIR/sendfs.zdb"
  79. log_must eval "zdb -ddddd $recvfs/sendfs $recv_obj >$BACKDIR/recvfs.zdb"
  80. log_must eval "zdb -ddddd $recvfs2/sendfs $recv2_obj >$BACKDIR/recvfs2.zdb"
  81. grep -q "EMBEDDED" $BACKDIR/sendfs.zdb || \
  82. log_fail "Obj $send_obj not embedded in $sendfs"
  83. grep -q "EMBEDDED" $BACKDIR/recvfs.zdb || \
  84. log_fail "Obj $recv_obj not embedded in $recvfs"
  85. grep -q "EMBEDDED" $BACKDIR/recvfs2.zdb || \
  86. log_fail "Obj $recv2_obj not embedded in $recvfs2"
  87. grep -q "WRITE_EMBEDDED object = $send_obj offset = 0" $dump && \
  88. log_fail "Obj $obj embedded in zstreamdump output"
  89. grep -q "WRITE_EMBEDDED object = $send_obj offset = 0" $dump2 || \
  90. log_fail "Obj $obj not embedded in zstreamdump output"
  91. done
  92. log_pass "Compressed streams can contain embedded blocks."