Skip to content

RFC File system wide monitoring

Gabriel Krisman Bertazi linux-ext4 linux-fsdevel oe-kbuild-all 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest15 patches 21 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/15fanotify: Fold event size calculation to its own functionfs/notify/fanotify/fanotify_user.c+23 -171 reply
2/15fanotify: Split fsid check from other fid mode checksfs/notify/fanotify/fanotify_user.c+22 -131 reply
3/15fsnotify: Wire flags field on group allocationfs/notify/dnotify/dnotify.c fs/notify/fanotify/fanotify_user.c fs/notify/group.c +5 more+20 -141 reply
4/15fsnotify: Wire up group information on event initializationfs/notify/fanotify/fanotify.c fs/notify/fanotify/fanotify.h fs/notify/fanotify/fanotify_user.c +3 more+11 -90 replies
5/15fsnotify: Support event submission through ring bufferfs/notify/Makefile fs/notify/group.c fs/notify/notification.c +2 more+255 -52 replies
6/15fanotify: Support submission through ring bufferfs/notify/fanotify/fanotify.c fs/notify/fanotify/fanotify_user.c include/linux/fanotify.h +1 more+105 -592 replies
7/15fsnotify: Support FS_ERROR event typefs/notify/fsnotify.c include/linux/fsnotify_backend.h+17 -11 reply
8/15fsnotify: Introduce helpers to send error_eventsinclude/linux/fsnotify.h+15 -01 reply
9/15fanotify: Introduce generic error recordfs/notify/fanotify/fanotify.h fs/notify/fanotify/fanotify_user.c include/uapi/linux/fanotify.h+54 -01 reply
10/15fanotify: Introduce code location recordfs/notify/fanotify/fanotify.h fs/notify/fanotify/fanotify_user.c include/uapi/linux/fanotify.h+48 -03 replies
11/15fanotify: Introduce filesystem specific data recordfs/notify/fanotify/fanotify_user.c include/uapi/linux/fanotify.h+35 -21 reply
12/15fanotify: Introduce the FAN_ERROR markfs/notify/fanotify/fanotify.c fs/notify/fanotify/fanotify.h fs/notify/fanotify/fanotify_user.c +2 more+120 -101 reply
13/15ext4: Send notifications on errorfs/ext4/super.c include/uapi/linux/ext4-notify.h+62 -152 replies
14/15samples: Add fs error monitoring examplesamples/Kconfig samples/Makefile samples/fanotify/Makefile +1 more+146 -00 replies
15/15Documentation: Document the FAN_ERROR frameworkDocumentation/admin-guide/filesystem-monitoring.rst Documentation/admin-guide/index.rst+104 -00 replies

Reviews trailers per patch

1 of 15 patches has a Reviewed-by or Acked-by.

PatchAmir Goldstein
1/15R-b
2/15
3/15
4/15
5/15
6/15
7/15
8/15
9/15
10/15
11/15
12/15
13/15
14/15
15/15

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH RFC 00/15] File system wide monitoring

Hi,

In an attempt to consolidate some of the feedback from the previous proposals, I wrote a new attempt to solve the file system error reporting problem. Before I spend more time polishing it, I'd like to hear your feedback if I'm going in the wrong direction, in particular with the modifications to fsnotify.

This RFC follows up on my previous proposals which attempted to leverage watch_queue[1] and fsnotify[2] to provide a mechanism for file systems to push error notifications to user space. This proposal starts by, as suggested by Darrick, limiting the scope of what I'm trying to do to an interface for administrators to monitor the health of a file system, instead of a generic inteface for file errors. Therefore, this doesn't solve the problem of writeback errors or the need to watch a specific subsystem.

* Format

The feature is implemented on top of fanotify, as a new type of fanotify mark, FAN_ERROR, which a file system monitoring tool can register to receive notifications. A notification is split in three parts, and only the first is guaranteed to exist for any given error event:

- FS generic data: A file system agnostic structure that has a generic error code and identifies the filesystem. Basically, it let's userspace know something happen on a monitored filesystem.

- FS location data: Identifies where in the code the problem happened. (This is important for the use case of analysing frequent error points that we discussed earlier).

- FS specific data: A detailed error report in a filesystem specific format that details what the error is. Ideally, a capable monitoring tool can use the information here for error recovery. For instance, xfs can put the xfs_scrub structures here, ext4 can send its error reports, etc. An example of usage is done in the ext4 patch of this series.

More details on the information in each record can be found on the documentation introduced in patch 15.

* Using fanotify

Using fanotify for this kind of thing is slightly tricky because we want to guarantee delivery in some complicated conditions, for instance, the file system might want to send an error while holding several locks.

Instead of working around file system constraints at the file system level, this proposal tries to make the FAN_ERROR submission safe in those contexts. This is done with a new mode in fsnotify that preallocates the memory at group creation to be used for the notification submission.

This new mode in fsnotify introduces a ring buffer to queue notifications, which eliminates the allocation path in fsnotify. From what I saw, the allocation is the only problem in fsnotify for filesystems to submit errors in constrained situations.

* Visibility

Since the usecase is limited to a tool for whole file system monitoring, errors are associated with the superblock and visible filesystem-wide. It is assumed and required that userspace has CAP_SYS_ADMIN.

* Testing

This was tested with corrupted ext4 images in a few scenarios, which caused errors to be triggered and monitored with the sample tool provided in the next to final patch.

* patches

Patches 1-4 massage fanotify attempt to refactor fanotify a bit for the patches to come. Patch 5 introduce the ring buffer interface to fsnotify, while patch 6 enable this support in fanotify. Patch 7, 8 wire the FS_ERROR event type, which will be used by filesystems. In sequennce, patches 9-12 implement the FAN_ERROR record types and create the new event. Patch 13 is an ext4 example implementation supporting this feature. Finally, patches 14 and 15 document and provide examples of a userspace tool that uses this feature.

I also pushed the full series to:

https://gitlab.collabora.com/krisman/linux -b fanotify-notifications

[1] https://lwn.net/Articles/839310/
[2] https://www.spinics.net/lists/linux-fsdevel/msg187075.html

Gabriel Krisman Bertazi (15):
fanotify: Fold event size calculation to its own function
fanotify: Split fsid check from other fid mode checks
fsnotify: Wire flags field on group allocation
fsnotify: Wire up group information on event initialization
fsnotify: Support event submission through ring buffer
fanotify: Support submission through ring buffer
fsnotify: Support FS_ERROR event type
fsnotify: Introduce helpers to send error_events
fanotify: Introduce generic error record
fanotify: Introduce code location record
fanotify: Introduce filesystem specific data record
fanotify: Introduce the FAN_ERROR mark
ext4: Send notifications on error
samples: Add fs error monitoring example
Documentation: Document the FAN_ERROR framework

 .../admin-guide/filesystem-monitoring.rst     | 103 ++++++
 Documentation/admin-guide/index.rst           |   1 +
 fs/ext4/super.c                               |  60 +++-
 fs/notify/Makefile                            |   2 +-
 fs/notify/dnotify/dnotify.c                   |   2 +-
 fs/notify/fanotify/fanotify.c                 | 127 +++++--
 fs/notify/fanotify/fanotify.h                 |  35 +-
 fs/notify/fanotify/fanotify_user.c            | 319 ++++++++++++++----
 fs/notify/fsnotify.c                          |   2 +-
 fs/notify/group.c                             |  25 +-
 fs/notify/inotify/inotify_fsnotify.c          |   2 +-
 fs/notify/inotify/inotify_user.c              |   4 +-
 fs/notify/notification.c                      |  10 +
 fs/notify/ring.c                              | 199 +++++++++++
 include/linux/fanotify.h                      |  12 +-
 include/linux/fsnotify.h                      |  15 +
 include/linux/fsnotify_backend.h              |  63 +++-
 include/uapi/linux/ext4-notify.h              |  17 +
 include/uapi/linux/fanotify.h                 |  26 ++
 kernel/audit_fsnotify.c                       |   2 +-
 kernel/audit_tree.c                           |   2 +-
 kernel/audit_watch.c                          |   2 +-
 samples/Kconfig                               |   7 +
 samples/Makefile                              |   1 +
 samples/fanotify/Makefile                     |   3 +
 samples/fanotify/fs-monitor.c                 | 135 ++++++++
 26 files changed, 1034 insertions(+), 142 deletions(-)
 create mode 100644 Documentation/admin-guide/filesystem-monitoring.rst
 create mode 100644 fs/notify/ring.c
 create mode 100644 include/uapi/linux/ext4-notify.h
 create mode 100644 samples/fanotify/Makefile
 create mode 100644 samples/fanotify/fs-monitor.c
Signature · 1 line
2.31.0