On Thu, Aug 1, 2024 at 7:38 PM Jan Kara <jack@xxxxxxx> wrote: > > On Thu 25-07-24 14:19:45, Josef Bacik wrote: > > From: Amir Goldstein <amir73il@xxxxxxxxx> > > > > With group class FAN_CLASS_PRE_CONTENT, report offset and length info > > along with FAN_PRE_ACCESS and FAN_PRE_MODIFY permission events. > > > > This information is meant to be used by hierarchical storage managers > > that want to fill partial content of files on first access to range. > > > > Signed-off-by: Amir Goldstein <amir73il@xxxxxxxxx> > > --- > > fs/notify/fanotify/fanotify.h | 8 +++++++ > > fs/notify/fanotify/fanotify_user.c | 38 ++++++++++++++++++++++++++++++ > > include/uapi/linux/fanotify.h | 7 ++++++ > > 3 files changed, 53 insertions(+) > > > > diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h > > index 93598b7d5952..7f06355afa1f 100644 > > --- a/fs/notify/fanotify/fanotify.h > > +++ b/fs/notify/fanotify/fanotify.h > > @@ -448,6 +448,14 @@ static inline bool fanotify_is_perm_event(u32 mask) > > mask & FANOTIFY_PERM_EVENTS; > > } > > > > +static inline bool fanotify_event_has_access_range(struct fanotify_event *event) > > +{ > > + if (!(event->mask & FANOTIFY_PRE_CONTENT_EVENTS)) > > + return false; > > + > > + return FANOTIFY_PERM(event)->ppos; > > +} > > Now I'm a bit confused. Can we have legally NULL ppos for an event from > FANOTIFY_PRE_CONTENT_EVENTS? > Sorry for the very late reply... The short answer is that NULL FANOTIFY_PERM(event)->ppos simply means that fanotify_alloc_perm_event() was called with NULL range, which is the very common case of legacy permission events. The long answer is a bit convoluted, so bare with me. The long answer is to the question whether fsnotify_file_range() can be called with a NULL ppos. This shouldn't be possible AFAIK for regular files and directories, unless some fs that is marked with FS_ALLOW_HSM opens a regular file with FMODE_STREAM, which should not be happening IMO, but then the assertion belongs inside fsnotify_file_range(). However, there was another way to get NULL ppos before I added the patch "fsnotify: generate pre-content permission event on open" Which made this "half intentional" change: static inline int fsnotify_file_perm(struct file *file, int perm_mask) { - return fsnotify_file_area_perm(file, perm_mask, NULL, 0); + return fsnotify_file_area_perm(file, perm_mask, &file->f_pos, 0); } In order to implement: "The event will have a range info of (0..0) to provide an opportunity to fill the entire file content on open." The problem is that do_open() was not the only caller of fsnotify_file_perm(). There is another call from iterate_dir() and the change above causes FS_PRE_ACCESS events on readdir to report the directory f_pos - Do we want that? I think we do, but HSM should be able to tell the difference between opendir() and readdir(), because my HSM only wants to fill dir content on the latter. I think that we need to decide if we want to allow pre-content events with no range reported (e.g. for readdir()) or if pre-content events must report a range, can report (0..-1) or something for "entire range". Thanks, Amir.