fanotify: no external fh buffer in fanotify_name_event
authorAmir Goldstein <amir73il@gmail.com>
Thu, 16 Jul 2020 08:42:18 +0000 (11:42 +0300)
committerJan Kara <jack@suse.cz>
Mon, 27 Jul 2020 19:23:37 +0000 (21:23 +0200)
commitf35c41567867e06bb0a1d6b74c5bf323be1026e5
treebeb4aab78dfae5cc44cd128df0d4b23ebd388e2b
parentf454fa610a69b93e7ed4de739e736f988d95c2d2
fanotify: no external fh buffer in fanotify_name_event

The fanotify_fh struct has an inline buffer of size 12 which is enough
to store the most common local filesystem file handles (e.g. ext4, xfs).
For file handles that do not fit in the inline buffer (e.g. btrfs), an
external buffer is allocated to store the file handle.

When allocating a variable size fanotify_name_event, there is no point
in allocating also an external fh buffer when file handle does not fit
in the inline buffer.

Check required size for encoding fh, preallocate an event buffer
sufficient to contain both file handle and name and store the name after
the file handle.

At this time, when not reporting name in event, we still allocate
the fixed size fanotify_fid_event and an external buffer for large
file handles, but fanotify_alloc_name_event() has already been prepared
to accept a NULL file_name.

Link: https://lore.kernel.org/r/20200716084230.30611-11-amir73il@gmail.com
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
fs/notify/fanotify/fanotify.c
fs/notify/fanotify/fanotify.h