162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci==================================== 462306a36Sopenharmony_ciFile system Monitoring with fanotify 562306a36Sopenharmony_ci==================================== 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciFile system Error Reporting 862306a36Sopenharmony_ci=========================== 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciFanotify supports the FAN_FS_ERROR event type for file system-wide error 1162306a36Sopenharmony_cireporting. It is meant to be used by file system health monitoring 1262306a36Sopenharmony_cidaemons, which listen for these events and take actions (notify 1362306a36Sopenharmony_cisysadmin, start recovery) when a file system problem is detected. 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciBy design, a FAN_FS_ERROR notification exposes sufficient information 1662306a36Sopenharmony_cifor a monitoring tool to know a problem in the file system has happened. 1762306a36Sopenharmony_ciIt doesn't necessarily provide a user space application with semantics 1862306a36Sopenharmony_cito verify an IO operation was successfully executed. That is out of 1962306a36Sopenharmony_ciscope for this feature. Instead, it is only meant as a framework for 2062306a36Sopenharmony_ciearly file system problem detection and reporting recovery tools. 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ciWhen a file system operation fails, it is common for dozens of kernel 2362306a36Sopenharmony_cierrors to cascade after the initial failure, hiding the original failure 2462306a36Sopenharmony_cilog, which is usually the most useful debug data to troubleshoot the 2562306a36Sopenharmony_ciproblem. For this reason, FAN_FS_ERROR tries to report only the first 2662306a36Sopenharmony_cierror that occurred for a file system since the last notification, and 2762306a36Sopenharmony_ciit simply counts additional errors. This ensures that the most 2862306a36Sopenharmony_ciimportant pieces of information are never lost. 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ciFAN_FS_ERROR requires the fanotify group to be setup with the 3162306a36Sopenharmony_ciFAN_REPORT_FID flag. 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ciAt the time of this writing, the only file system that emits FAN_FS_ERROR 3462306a36Sopenharmony_cinotifications is Ext4. 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ciA FAN_FS_ERROR Notification has the following format:: 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci :: 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci [ Notification Metadata (Mandatory) ] 4162306a36Sopenharmony_ci [ Generic Error Record (Mandatory) ] 4262306a36Sopenharmony_ci [ FID record (Mandatory) ] 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ciThe order of records is not guaranteed, and new records might be added 4562306a36Sopenharmony_ciin the future. Therefore, applications must not rely on the order and 4662306a36Sopenharmony_cimust be prepared to skip over unknown records. Please refer to 4762306a36Sopenharmony_ci``samples/fanotify/fs-monitor.c`` for an example parser. 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ciGeneric error record 5062306a36Sopenharmony_ci-------------------- 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ciThe generic error record provides enough information for a file system 5362306a36Sopenharmony_ciagnostic tool to learn about a problem in the file system, without 5462306a36Sopenharmony_ciproviding any additional details about the problem. This record is 5562306a36Sopenharmony_ciidentified by ``struct fanotify_event_info_header.info_type`` being set 5662306a36Sopenharmony_cito FAN_EVENT_INFO_TYPE_ERROR. 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci :: 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci struct fanotify_event_info_error { 6162306a36Sopenharmony_ci struct fanotify_event_info_header hdr; 6262306a36Sopenharmony_ci __s32 error; 6362306a36Sopenharmony_ci __u32 error_count; 6462306a36Sopenharmony_ci }; 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ciThe `error` field identifies the type of error using errno values. 6762306a36Sopenharmony_ci`error_count` tracks the number of errors that occurred and were 6862306a36Sopenharmony_cisuppressed to preserve the original error information, since the last 6962306a36Sopenharmony_cinotification. 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ciFID record 7262306a36Sopenharmony_ci---------- 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ciThe FID record can be used to uniquely identify the inode that triggered 7562306a36Sopenharmony_cithe error through the combination of fsid and file handle. A file system 7662306a36Sopenharmony_cispecific application can use that information to attempt a recovery 7762306a36Sopenharmony_ciprocedure. Errors that are not related to an inode are reported with an 7862306a36Sopenharmony_ciempty file handle of type FILEID_INVALID. 79