/tests/zfs-tests/tests/functional/rsend/send_encrypted_truncated_files.ksh

https://github.com/adilger/zfs · Korn Shell · 126 lines · 61 code · 18 blank · 47 comment · 7 complexity · 89b010e80a497f8f9b2388a7d9e3ac7d MD5 · raw file

  1. #!/bin/ksh -p
  2. #
  3. # CDDL HEADER START
  4. #
  5. # This file and its contents are supplied under the terms of the
  6. # Common Development and Distribution License ("CDDL"), version 1.0.
  7. # You may only use this file in accordance with the terms of version
  8. # 1.0 of the CDDL.
  9. #
  10. # A full copy of the text of the CDDL should have accompanied this
  11. # source. A copy of the CDDL is also available via the Internet at
  12. # http://www.illumos.org/license/CDDL.
  13. #
  14. # CDDL HEADER END
  15. #
  16. #
  17. # Copyright (c) 2018 by Datto Inc. All rights reserved.
  18. #
  19. . $STF_SUITE/tests/functional/rsend/rsend.kshlib
  20. #
  21. # DESCRIPTION:
  22. #
  23. #
  24. # STRATEGY:
  25. # 1. Create a new encrypted filesystem
  26. # 2. Add a 4 files that are to be truncated later
  27. # 3. Take a snapshot of the filesystem
  28. # 4. Truncate one of the files from 32M to 128k
  29. # 5. Truncate one of the files from 512k to 384k
  30. # 6. Truncate one of the files from 512k to 0 to 384k via reallocation
  31. # 7. Truncate one of the files from 1k to 0 to 512b via reallocation
  32. # 8. Take another snapshot of the filesystem
  33. # 9. Send and receive both snapshots
  34. # 10. Mount the filesystem and check the contents
  35. #
  36. verify_runnable "both"
  37. function cleanup
  38. {
  39. datasetexists $TESTPOOL/$TESTFS2 && \
  40. log_must zfs destroy -r $TESTPOOL/$TESTFS2
  41. datasetexists $TESTPOOL/recv && \
  42. log_must zfs destroy -r $TESTPOOL/recv
  43. [[ -f $keyfile ]] && log_must rm $keyfile
  44. [[ -f $sendfile ]] && log_must rm $sendfile
  45. }
  46. log_onexit cleanup
  47. function recursive_cksum
  48. {
  49. case "$(uname)" in
  50. FreeBSD)
  51. find $1 -type f -exec sha256 -q {} \; | \
  52. sort | sha256digest
  53. ;;
  54. *)
  55. find $1 -type f -exec sha256sum {} \; | \
  56. sort -k 2 | awk '{ print $1 }' | sha256digest
  57. ;;
  58. esac
  59. }
  60. log_assert "Verify 'zfs send -w' works with many different file layouts"
  61. typeset keyfile=/$TESTPOOL/pkey
  62. typeset sendfile=/$TESTPOOL/sendfile
  63. typeset sendfile2=/$TESTPOOL/sendfile2
  64. # Create an encrypted dataset
  65. log_must eval "echo 'password' > $keyfile"
  66. log_must zfs create -o encryption=on -o keyformat=passphrase \
  67. -o keylocation=file://$keyfile $TESTPOOL/$TESTFS2
  68. # Explicitly set the recordsize since the truncation sizes below depend on
  69. # this value being 128k. This is currently same as the default recordsize.
  70. log_must zfs set recordsize=128k $TESTPOOL/$TESTFS2
  71. # Create files with varied layouts on disk
  72. log_must mkfile 32M /$TESTPOOL/$TESTFS2/truncated
  73. log_must mkfile 524288 /$TESTPOOL/$TESTFS2/truncated2
  74. log_must mkfile 524288 /$TESTPOOL/$TESTFS2/truncated3
  75. log_must mkfile 1024 /$TESTPOOL/$TESTFS2/truncated4
  76. log_must zfs snapshot $TESTPOOL/$TESTFS2@snap1
  77. #
  78. # Truncate files created in the first snapshot. The first tests
  79. # truncating a large file to a single block. The second tests
  80. # truncating one block off the end of a file without changing
  81. # the required nlevels to hold it. The third tests handling
  82. # of a maxblkid that is dropped and then raised again. The
  83. # fourth tests an object that is truncated from a single block
  84. # to a smaller single block.
  85. #
  86. log_must truncate -s 131072 /$TESTPOOL/$TESTFS2/truncated
  87. log_must truncate -s 393216 /$TESTPOOL/$TESTFS2/truncated2
  88. log_must rm -f /$TESTPOOL/$TESTFS2/truncated3
  89. log_must rm -f /$TESTPOOL/$TESTFS2/truncated4
  90. log_must zpool sync $TESTPOOL
  91. log_must zfs umount $TESTPOOL/$TESTFS2
  92. log_must zfs mount $TESTPOOL/$TESTFS2
  93. log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS2/truncated3 \
  94. bs=128k count=3 iflag=fullblock
  95. log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS2/truncated4 \
  96. bs=512 count=1 iflag=fullblock
  97. log_must zfs snapshot $TESTPOOL/$TESTFS2@snap2
  98. expected_cksum=$(recursive_cksum /$TESTPOOL/$TESTFS2)
  99. log_must eval "zfs send -wp $TESTPOOL/$TESTFS2@snap1 > $sendfile"
  100. log_must eval "zfs send -wp -i @snap1 $TESTPOOL/$TESTFS2@snap2 > $sendfile2"
  101. log_must eval "zfs recv -F $TESTPOOL/recv < $sendfile"
  102. log_must eval "zfs recv -F $TESTPOOL/recv < $sendfile2"
  103. log_must zfs load-key $TESTPOOL/recv
  104. log_must zfs mount -a
  105. actual_cksum=$(recursive_cksum /$TESTPOOL/recv)
  106. [[ "$expected_cksum" != "$actual_cksum" ]] && \
  107. log_fail "Recursive checksums differ ($expected_cksum != $actual_cksum)"
  108. log_pass "Verified 'zfs send -w' works with many different file layouts"