Re: [PATCH v8 27/32] fanotify: Report fid info for file related file system errors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Oct 19, 2021 at 3:04 AM Gabriel Krisman Bertazi
<krisman@xxxxxxxxxxxxx> wrote:
>
> Plumb the pieces to add a FID report to error records.  Since all error
> event memory must be pre-allocated, we pre-allocate the maximum file
> handle size possible, such that it should always fit.
>
> For errors that don't expose a file handle report it with an invalid
> FID.
>
> Signed-off-by: Gabriel Krisman Bertazi <krisman@xxxxxxxxxxxxx>
>
Reviewed-by: Amir Goldstein <amir73il@xxxxxxxxx>

with minor nit below..

> ---
> Changes since v7:
>   - Move WARN_ON to separate patch (Amir)
>   - Avoid duplication in the structure definition (Amir)
> Changes since v6:
>   - pass fsid from handle_events
> Changes since v5:
>   - Use preallocated MAX_HANDLE_SZ FH buffer
>   - Report superblock errors with a zerolength INVALID FID (jan, amir)
> ---
>  fs/notify/fanotify/fanotify.c | 10 ++++++++++
>  fs/notify/fanotify/fanotify.h | 11 +++++++++++
>  2 files changed, 21 insertions(+)
>
> diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
> index 45df610debbe..335ce8f88eb8 100644
> --- a/fs/notify/fanotify/fanotify.c
> +++ b/fs/notify/fanotify/fanotify.c
> @@ -609,7 +609,9 @@ static struct fanotify_event *fanotify_alloc_error_event(
>  {
>         struct fs_error_report *report =
>                         fsnotify_data_error_report(data, data_type);
> +       struct inode *inode = report->inode;
>         struct fanotify_error_event *fee;
> +       int fh_len;
>
>         if (WARN_ON_ONCE(!report))
>                 return NULL;
> @@ -622,6 +624,14 @@ static struct fanotify_event *fanotify_alloc_error_event(
>         fee->err_count = 1;
>         fee->fsid = *fsid;
>
> +       fh_len = fanotify_encode_fh_len(inode);
> +
> +       /* Bad fh_len. Fallback to using an invalid fh. Should never happen. */
> +       if (!fh_len && inode)
> +               inode = NULL;
> +
> +       fanotify_encode_fh(&fee->object_fh, inode, fh_len, NULL, 0);
> +
>         *hash ^= fanotify_hash_fsid(fsid);
>
>         return &fee->fae;
> diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h
> index bdf01ad4f9bf..4246a34667b5 100644
> --- a/fs/notify/fanotify/fanotify.h
> +++ b/fs/notify/fanotify/fanotify.h
> @@ -209,6 +209,9 @@ struct fanotify_error_event {
>         u32 err_count; /* Suppressed errors count */
>
>         __kernel_fsid_t fsid; /* FSID this error refers to. */
> +
> +       /* This must be the last element of the structure. */
> +       FANOTIFY_INLINE_FH(MAX_HANDLE_SZ);

Does not really have to be last but certainly doesn't hurt

Thanks,
Amir.



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux