/tests/zfs-tests/tests/functional/slog/slog_replay_fs_002.ksh

https://github.com/adilger/zfs · Korn Shell · 137 lines · 37 code · 21 blank · 79 comment · 0 complexity · 6289866d9667cfdf9cc7732e0525235b 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 2007 Sun Microsystems, Inc. All rights reserved.
  24. # Use is subject to license terms.
  25. #
  26. . $STF_SUITE/tests/functional/slog/slog.kshlib
  27. #
  28. # DESCRIPTION:
  29. # Verify slog replay correctly when TX_REMOVEs are followed by
  30. # TX_CREATEs.
  31. #
  32. # STRATEGY:
  33. # 1. Create a file system (TESTFS) with a lot of files
  34. # 2. Freeze TESTFS
  35. # 3. Remove all files then create a lot of files
  36. # 4. Copy TESTFS to temporary location (TESTDIR/copy)
  37. # 5. Unmount filesystem
  38. # <at this stage TESTFS is empty again and unfrozen, and the
  39. # intent log contains a complete set of deltas to replay it>
  40. # 6. Remount TESTFS <which replays the intent log>
  41. # 7. Compare TESTFS against the TESTDIR/copy
  42. #
  43. verify_runnable "global"
  44. function cleanup_fs
  45. {
  46. cleanup
  47. }
  48. log_assert "Replay of intent log succeeds."
  49. log_onexit cleanup_fs
  50. log_must setup
  51. #
  52. # 1. Create a file system (TESTFS) with a lot of files
  53. #
  54. log_must zpool create $TESTPOOL $VDEV log mirror $LDEV
  55. log_must zfs set compression=on $TESTPOOL
  56. log_must zfs create $TESTPOOL/$TESTFS
  57. # Prep for the test of TX_REMOVE followed by TX_CREATE
  58. dnsize=(legacy auto 1k 2k 4k 8k 16k)
  59. NFILES=200
  60. log_must mkdir /$TESTPOOL/$TESTFS/dir0
  61. log_must eval 'for i in $(seq $NFILES); do zfs set dnodesize=${dnsize[$RANDOM % ${#dnsize[@]}]} $TESTPOOL/$TESTFS; touch /$TESTPOOL/$TESTFS/dir0/file.$i; done'
  62. #
  63. # Reimport to reset dnode allocation pointer.
  64. # This is to make sure we will have TX_REMOVE and TX_CREATE on same id
  65. #
  66. log_must zpool export $TESTPOOL
  67. log_must zpool import -f -d $VDIR $TESTPOOL
  68. #
  69. # This dd command works around an issue where ZIL records aren't created
  70. # after freezing the pool unless a ZIL header already exists. Create a file
  71. # synchronously to force ZFS to write one out.
  72. #
  73. log_must dd if=/dev/zero of=/$TESTPOOL/$TESTFS/sync \
  74. conv=fdatasync,fsync bs=1 count=1
  75. #
  76. # 2. Freeze TESTFS
  77. #
  78. log_must zpool freeze $TESTPOOL
  79. #
  80. # 3. Remove all files then create a lot of files
  81. #
  82. # TX_REMOVE followed by TX_CREATE
  83. log_must eval 'rm -f /$TESTPOOL/$TESTFS/dir0/*'
  84. log_must eval 'for i in $(seq $NFILES); do zfs set dnodesize=${dnsize[$RANDOM % ${#dnsize[@]}]} $TESTPOOL/$TESTFS; touch /$TESTPOOL/$TESTFS/dir0/file.$i; done'
  85. #
  86. # 4. Copy TESTFS to temporary location (TESTDIR/copy)
  87. #
  88. log_must mkdir -p $TESTDIR/copy
  89. log_must cp -a /$TESTPOOL/$TESTFS/* $TESTDIR/copy/
  90. #
  91. # 5. Unmount filesystem and export the pool
  92. #
  93. # At this stage TESTFS is empty again and frozen, the intent log contains
  94. # a complete set of deltas to replay.
  95. #
  96. log_must zfs unmount /$TESTPOOL/$TESTFS
  97. log_note "Verify transactions to replay:"
  98. log_must zdb -iv $TESTPOOL/$TESTFS
  99. log_must zpool export $TESTPOOL
  100. #
  101. # 6. Remount TESTFS <which replays the intent log>
  102. #
  103. # Import the pool to unfreeze it and claim log blocks. It has to be
  104. # `zpool import -f` because we can't write a frozen pool's labels!
  105. #
  106. log_must zpool import -f -d $VDIR $TESTPOOL
  107. #
  108. # 7. Compare TESTFS against the TESTDIR/copy
  109. #
  110. log_note "Verify current block usage:"
  111. log_must zdb -bcv $TESTPOOL
  112. log_note "Verify number of files"
  113. log_must test "$(ls /$TESTPOOL/$TESTFS/dir0 | wc -l)" -eq $NFILES
  114. log_note "Verify working set diff:"
  115. log_must diff -r /$TESTPOOL/$TESTFS $TESTDIR/copy
  116. log_pass "Replay of intent log succeeds."