nocache_eof.sh 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/sh
  2. # Ensure dd invalidates to EOF when appropriate
  3. # Copyright (C) 2017-2018 Free Software Foundation, Inc.
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  15. print_ver_ dd
  16. require_strace_ fadvise64,fadvise64_64
  17. head -c1234567 /dev/zero > in.f || framework_failure_
  18. # Check basic operation or skip.
  19. # We could check for 'Operation not supported' error here,
  20. # but that was seen to be brittle. HPUX returns ENOTTY for example.
  21. # So assume that if this basic operation fails, it's due to lack
  22. # of support by the system.
  23. dd if=in.f iflag=nocache count=0 ||
  24. skip_ 'this file system lacks support for posix_fadvise()'
  25. strace_dd() {
  26. strace -o dd.strace -e fadvise64,fadvise64_64 dd status=none "$@" || fail=1
  27. }
  28. advised_to_eof() {
  29. grep -F ' 0, POSIX_FADV_DONTNEED' dd.strace >/dev/null
  30. }
  31. # The commented fadvise64 calls are what are expected with
  32. # a 4KiB page size and 128KiB IO_BUFSIZE.
  33. strace_dd if=in.f of=out.f bs=1M oflag=nocache,sync
  34. #fadvise64(1, 0, 1048576, POSIX_FADV_DONTNEED) = 0
  35. #fadvise64(1, 1048576, 131072, POSIX_FADV_DONTNEED) = 0
  36. #fadvise64(1, 1179648, 0, POSIX_FADV_DONTNEED) = 0
  37. advised_to_eof || fail=1
  38. strace_dd if=in.f count=0 iflag=nocache
  39. #fadvise64(0, 0, 0, POSIX_FADV_DONTNEED) = 0
  40. advised_to_eof || fail=1
  41. strace_dd if=in.f of=/dev/null iflag=nocache skip=10 count=300
  42. #fadvise64(0, 5120, 131072, POSIX_FADV_DONTNEED) = 0
  43. #fadvise64(0, 136192, 22528, POSIX_FADV_DONTNEED) = 0
  44. returns_ 1 advised_to_eof || fail=1
  45. strace_dd if=in.f of=/dev/null iflag=nocache bs=1M count=3000
  46. #fadvise64(0, 0, 1048576, POSIX_FADV_DONTNEED) = 0
  47. #fadvise64(0, 1048576, 131072, POSIX_FADV_DONTNEED) = 0
  48. #fadvise64(0, 1179648, 0, POSIX_FADV_DONTNEED) = 0
  49. advised_to_eof || fail=1
  50. strace_dd if=in.f of=/dev/null bs=1M count=1 iflag=nocache
  51. #fadvise64(0, 0, 1048576, POSIX_FADV_DONTNEED) = 0
  52. returns_ 1 advised_to_eof || fail=1
  53. strace_dd if=in.f of=out.f bs=1M iflag=nocache oflag=nocache,sync
  54. #fadvise64(0, 0, 1048576, POSIX_FADV_DONTNEED) = 0
  55. #fadvise64(1, 0, 1048576, POSIX_FADV_DONTNEED) = 0
  56. #fadvise64(0, 1048576, 131072, POSIX_FADV_DONTNEED) = 0
  57. #fadvise64(1, 1048576, 131072, POSIX_FADV_DONTNEED) = 0
  58. #fadvise64(0, 1179648, 0, POSIX_FADV_DONTNEED) = 0
  59. #fadvise64(1, 1179648, 0, POSIX_FADV_DONTNEED) = 0
  60. advised_to_eof || fail=1
  61. # Ensure sub page size offsets are handled.
  62. # I.e., only page aligned offsets are sent to fadvise.
  63. if ! strace -o dd.strace -e fadvise64,fadvise64_64 dd status=none \
  64. if=in.f of=out.f bs=1M oflag=direct seek=512 oflag=seek_bytes; then
  65. warn_ '512 byte aligned O_DIRECT is not supported on this (file) system'
  66. # The current file system may not support O_DIRECT,
  67. # or older XFS had a page size alignment requirement
  68. else
  69. #The first call is redundant but inconsequential
  70. #fadvise64(1, 1048576, 0, POSIX_FADV_DONTNEED) = 0
  71. #fadvise64(1, 1048576, 0, POSIX_FADV_DONTNEED) = 0
  72. advised_to_eof || fail=1
  73. strace_dd if=in.f of=out.f bs=1M oflag=direct
  74. #fadvise64(1, 1048576, 0, POSIX_FADV_DONTNEED) = 0
  75. #fadvise64(1, 1048576, 0, POSIX_FADV_DONTNEED) = 0
  76. advised_to_eof || fail=1
  77. fi
  78. Exit $fail