/tests/zfs-tests/tests/functional/procfs/procfs_list_basic.ksh

https://github.com/adilger/zfs · Korn Shell · 95 lines · 28 code · 12 blank · 55 comment · 5 complexity · 437a49481e705a68aea9f3989bffe01e 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 (c) 2018 by Delphix. All rights reserved.
  24. #
  25. . $STF_SUITE/include/libtest.shlib
  26. #
  27. # DESCRIPTION:
  28. # Test that we can read from and write to a file in procfs whose contents is
  29. # backed by a linked list.
  30. #
  31. # STRATEGY:
  32. # 1. Take some snapshots of a filesystem, which will cause some messages to be
  33. # written to the zfs dbgmsgs.
  34. # 2. Read the dbgmsgs via procfs and verify that the expected messages are
  35. # present.
  36. # 3. Write to the dbgmsgs file to clear the messages.
  37. # 4. Read the dbgmsgs again, and make sure the messages are no longer present.
  38. #
  39. function cleanup
  40. {
  41. datasetexists $FS && log_must zfs destroy -r $FS
  42. }
  43. function count_snap_cmds
  44. {
  45. typeset expected_count=$1
  46. count=$(grep -E "command: (lt-)?zfs snapshot $FS@testsnapshot" | wc -l)
  47. log_must eval "[[ $count -eq $expected_count ]]"
  48. }
  49. typeset -r ZFS_DBGMSG=/proc/spl/kstat/zfs/dbgmsg
  50. typeset -r FS=$TESTPOOL/fs
  51. typeset snap_msgs
  52. log_onexit cleanup
  53. # Clear out old messages
  54. echo 0 >$ZFS_DBGMSG || log_fail "failed to write to $ZFS_DBGMSG"
  55. log_must zfs create $FS
  56. for i in {1..20}; do
  57. log_must zfs snapshot "$FS@testsnapshot$i"
  58. done
  59. log_must zpool sync $TESTPOOL
  60. #
  61. # Read the debug message file in small chunks to make sure that the read is
  62. # split up into multiple syscalls. This tests that when a syscall begins we
  63. # correctly pick up in the list of messages where the previous syscall left
  64. # off. The size of the read can affect how many bytes the seq_file code has
  65. # left in its internal buffer, which in turn can affect the relative pos that
  66. # the seq_file code picks up at when the next read starts. Try a few
  67. # different size reads to make sure we can handle each case.
  68. #
  69. # Check that the file has the right contents by grepping for some of the
  70. # messages that we expect to be present.
  71. #
  72. for chunk_sz in {1,64,256,1024,4096}; do
  73. dd if=$ZFS_DBGMSG bs=$chunk_sz | count_snap_cmds 20
  74. done
  75. # Clear out old messages and check that they really are gone
  76. echo 0 >$ZFS_DBGMSG || log_fail "failed to write to $ZFS_DBGMSG"
  77. cat $ZFS_DBGMSG | count_snap_cmds 0
  78. #
  79. # Even though we don't expect any messages in the file, reading should still
  80. # succeed.
  81. #
  82. log_must cat $ZFS_DBGMSG
  83. log_pass "Basic reading/writing of procfs file backed by linked list successful"