filesystem-monitoring.rst 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ====================================
  3. File system Monitoring with fanotify
  4. ====================================
  5. File system Error Reporting
  6. ===========================
  7. Fanotify supports the FAN_FS_ERROR event type for file system-wide error
  8. reporting. It is meant to be used by file system health monitoring
  9. daemons, which listen for these events and take actions (notify
  10. sysadmin, start recovery) when a file system problem is detected.
  11. By design, a FAN_FS_ERROR notification exposes sufficient information
  12. for a monitoring tool to know a problem in the file system has happened.
  13. It doesn't necessarily provide a user space application with semantics
  14. to verify an IO operation was successfully executed. That is out of
  15. scope for this feature. Instead, it is only meant as a framework for
  16. early file system problem detection and reporting recovery tools.
  17. When a file system operation fails, it is common for dozens of kernel
  18. errors to cascade after the initial failure, hiding the original failure
  19. log, which is usually the most useful debug data to troubleshoot the
  20. problem. For this reason, FAN_FS_ERROR tries to report only the first
  21. error that occurred for a file system since the last notification, and
  22. it simply counts additional errors. This ensures that the most
  23. important pieces of information are never lost.
  24. FAN_FS_ERROR requires the fanotify group to be setup with the
  25. FAN_REPORT_FID flag.
  26. At the time of this writing, the only file system that emits FAN_FS_ERROR
  27. notifications is Ext4.
  28. A FAN_FS_ERROR Notification has the following format::
  29. ::
  30. [ Notification Metadata (Mandatory) ]
  31. [ Generic Error Record (Mandatory) ]
  32. [ FID record (Mandatory) ]
  33. The order of records is not guaranteed, and new records might be added
  34. in the future. Therefore, applications must not rely on the order and
  35. must be prepared to skip over unknown records. Please refer to
  36. ``samples/fanotify/fs-monitor.c`` for an example parser.
  37. Generic error record
  38. --------------------
  39. The generic error record provides enough information for a file system
  40. agnostic tool to learn about a problem in the file system, without
  41. providing any additional details about the problem. This record is
  42. identified by ``struct fanotify_event_info_header.info_type`` being set
  43. to FAN_EVENT_INFO_TYPE_ERROR.
  44. ::
  45. struct fanotify_event_info_error {
  46. struct fanotify_event_info_header hdr;
  47. __s32 error;
  48. __u32 error_count;
  49. };
  50. The `error` field identifies the type of error using errno values.
  51. `error_count` tracks the number of errors that occurred and were
  52. suppressed to preserve the original error information, since the last
  53. notification.
  54. FID record
  55. ----------
  56. The FID record can be used to uniquely identify the inode that triggered
  57. the error through the combination of fsid and file handle. A file system
  58. specific application can use that information to attempt a recovery
  59. procedure. Errors that are not related to an inode are reported with an
  60. empty file handle of type FILEID_INVALID.