Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4256069pxy; Tue, 27 Apr 2021 00:02:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwisfgrLwK8edyS6aghhE1GKpZQZTvQum0WRC6WzdnXnycrUEMxq1OZ6FVCdJWNQNoWd4mj X-Received: by 2002:a17:90b:907:: with SMTP id bo7mr9360361pjb.114.1619506950832; Tue, 27 Apr 2021 00:02:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619506950; cv=none; d=google.com; s=arc-20160816; b=GUNC/lvIUXyzeZ9wiS0aA2a5O1jiTA74xS40fZbJQOTw4m3xoytKCZBw4p7AAGIDRe xffUG3WBhQHX3yfvr6pkMbCIEiqwQ/csjbgASOSW26hwcAZqUbnLCKnmE5zafx/e7c7V 01ywvSWfWJ3kS3DsY8AVo5qdr/xuBWvHwzn1diUbIrnyNimd4Yfh5h1dF2153hneequK KfsQDs4n3wXOOaVQGnwrCj1WXLI8mQULGyxpLkwcI2uxuwbtRfm4W6dtewnLeYki6ZFc SB7SQJwZFdY0e+1UWiocjHMwMN3mLvOmMq0oOIt9hSdXzVI8rPoKuTZXRoomvUD7MgY4 kVVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=y9Qt/PNIUM76w/s8A28x+xnbjsoSLCqkK9LFTkFb2Fg=; b=dTnrwK4vJEb7NPvSiSoqDosn6eSVYd8BPWqKy63fEKvQE4oZ8eVFUUExwoj1B8x5U1 dDd638lkcf4hSLD0xnhXgfBv+jLQEAIGkNToKUHgNzoMQXq0eCJ0M9yE0hmH+pygrx4b TpmltZM/REHTu41jfAvUJwWpPV2vo1YHV14S41abFQKvEOYI/K5NdPfISsQ7eBXBfhHo WL+W/KwUhtTji6H8ABvU/hj90ozUvrRx/Ffg4WBKcF+tcYNRe9JhcDYXABjScUQOqLG+ 0INrAYSHCO7hH4rNUA6r05He/igC1skJwzqKoJrLX5QzoFB5Mwglk2W9YRDU0y46t9R6 jjhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kOIffbVJ; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p20si129456plo.260.2021.04.27.00.02.14; Tue, 27 Apr 2021 00:02:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kOIffbVJ; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229578AbhD0HCo (ORCPT + 99 others); Tue, 27 Apr 2021 03:02:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbhD0HCo (ORCPT ); Tue, 27 Apr 2021 03:02:44 -0400 Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E891C061574; Tue, 27 Apr 2021 00:02:00 -0700 (PDT) Received: by mail-il1-x134.google.com with SMTP id c3so2590127ils.5; Tue, 27 Apr 2021 00:02:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=y9Qt/PNIUM76w/s8A28x+xnbjsoSLCqkK9LFTkFb2Fg=; b=kOIffbVJLsU9r/e7FuE9jHiTShXXgAbuhlah1ljNuns7Q1BuNdmdeRR3lPIectKiII S936ruOGRvBvMIyveGJgOE7XHEcmaYaHG2HXTlGkpICKp0iiXg/0NyN0GhjAVaCeNE0L REcvy/G16GmGeL7bgXOl+5ZCIqdGl04Aq18v2yI6qcjR/jH54AC6D+TRch1ZlMlEodKJ AnbTPsIVpnofxq+CeaGbu45gQE24gxLkk63Fea1k6NLZcRZv5slUuAG4AX0I1Ljj0SYw QffwIs4ZUmV9YOnQLVsXCKV/2OJZt5w8N5P6lJcs1PUL1wTcs4m7IHh9O64Ks2GmgbTs uqjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=y9Qt/PNIUM76w/s8A28x+xnbjsoSLCqkK9LFTkFb2Fg=; b=t9+kfZupKjiaYZCeEUa2LFYAYEZ6GkuUFAyKhT+gXR7P54PmqHHA8EK1QBCTSaOHEg JcZBhAJpzZC3NdtPJnwO2LFQlYyIKB998hj/M6ad95jtLUpjPX2HKujVk3tAnP2XJZK8 rJZhVx+iotvRXlwCPP9FYjXo/g21YkyhgEfZLslh8vGjpSYO8fFMVGl8omdV0jTUkluV Cl0w4GXbajtQi546ExcAJhWqj4pkyoY83DXrZUBUKzGdDuCFKDBlFcLyFPLaUj03Dtzl r++bsR0oue5T1wRCLn4vqZBpNDPajNKSnkbpMb2A+PqgxQ+SqLXWnR2g1w4THOrXXWlU CINA== X-Gm-Message-State: AOAM531YhEbqlnxcJ0nbNxnBcEI5cEjLrFQ2bMXWPXe54+jPx4M7XeVd N5DoRNsycOG8dg2A/ZxQBM8SkABKxMhrvcItkdA= X-Received: by 2002:a92:c548:: with SMTP id a8mr16895976ilj.137.1619506919767; Tue, 27 Apr 2021 00:01:59 -0700 (PDT) MIME-Version: 1.0 References: <20210426184201.4177978-1-krisman@collabora.com> <20210426184201.4177978-10-krisman@collabora.com> In-Reply-To: <20210426184201.4177978-10-krisman@collabora.com> From: Amir Goldstein Date: Tue, 27 Apr 2021 10:01:48 +0300 Message-ID: Subject: Re: [PATCH RFC 09/15] fanotify: Introduce generic error record To: Gabriel Krisman Bertazi Cc: Theodore Tso , "Darrick J. Wong" , Dave Chinner , Jan Kara , David Howells , Khazhismel Kumykov , linux-fsdevel , Ext4 , kernel@collabora.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Mon, Apr 26, 2021 at 9:42 PM Gabriel Krisman Bertazi wrote: > > This record describes a fs error in a fs agnostic way. It will be send > back to userspace in response to a FSNOTIFY_EVENT_ERROR for groups with > the FAN_ERROR mark. It's not a mark, it's an event, so: "...for groups with the FAN_ERROR event in their mark mask" > > Signed-off-by: Gabriel Krisman Bertazi > --- > fs/notify/fanotify/fanotify.h | 16 ++++++++++++++++ > fs/notify/fanotify/fanotify_user.c | 28 ++++++++++++++++++++++++++++ > include/uapi/linux/fanotify.h | 10 ++++++++++ > 3 files changed, 54 insertions(+) > > diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h > index 47299e3d6efd..4cb9dd31f084 100644 > --- a/fs/notify/fanotify/fanotify.h > +++ b/fs/notify/fanotify/fanotify.h > @@ -179,6 +179,22 @@ FANOTIFY_NE(struct fanotify_event *event) > return container_of(event, struct fanotify_name_event, fae); > } > > +struct fanotify_error_event { > + struct fanotify_event fae; > + int error; > + __kernel_fsid_t fsid; > + > + int fs_data_size; > + /* Must be the last item in the structure */ > + char fs_data[0]; > +}; > + > +static inline struct fanotify_error_event * > +FANOTIFY_EE(struct fanotify_event *event) > +{ > + return container_of(event, struct fanotify_error_event, fae); > +} > + > static inline __kernel_fsid_t *fanotify_event_fsid(struct fanotify_event *event) > { > if (event->type == FANOTIFY_EVENT_TYPE_FID) > diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c > index 5031198bf7db..21162d347bd1 100644 > --- a/fs/notify/fanotify/fanotify_user.c > +++ b/fs/notify/fanotify/fanotify_user.c > @@ -64,6 +64,11 @@ static int fanotify_fid_info_len(int fh_len, int name_len) > return roundup(FANOTIFY_INFO_HDR_LEN + info_len, FANOTIFY_EVENT_ALIGN); > } > > +static size_t fanotify_error_info_len(struct fanotify_error_event *fee) > +{ > + return sizeof(struct fanotify_event_info_error); > +} > + > static size_t fanotify_event_len(struct fanotify_event *event, > unsigned int fid_mode) > { > @@ -232,6 +237,29 @@ static int process_access_response(struct fsnotify_group *group, > return -ENOENT; > } > > +static size_t copy_error_info_to_user(struct fanotify_error_event *fee, > + char __user *buf, int count) > +{ > + struct fanotify_event_info_error info; > + > + info.hdr.info_type = FAN_EVENT_INFO_TYPE_ERROR; > + info.hdr.pad = 0; > + info.hdr.len = fanotify_error_info_len(fee); > + > + if (WARN_ON(count < info.hdr.len)) > + return -EFAULT; > + > + info.version = FANOTIFY_EVENT_INFO_ERROR_VERS_1; > + info.error = fee->error; > + info.fsid = fee->fsid; > + > + if (copy_to_user(buf, &info, sizeof(info))) > + return -EFAULT; > + > + return info.hdr.len; > + > +} > + > static int copy_info_to_user(__kernel_fsid_t *fsid, struct fanotify_fh *fh, > int info_type, const char *name, size_t name_len, > char __user *buf, size_t count) > diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h > index b283531549f1..cc9a1fa80e30 100644 > --- a/include/uapi/linux/fanotify.h > +++ b/include/uapi/linux/fanotify.h > @@ -124,6 +124,7 @@ struct fanotify_event_metadata { > #define FAN_EVENT_INFO_TYPE_FID 1 > #define FAN_EVENT_INFO_TYPE_DFID_NAME 2 > #define FAN_EVENT_INFO_TYPE_DFID 3 > +#define FAN_EVENT_INFO_TYPE_ERROR 4 > > /* Variable length info record following event metadata */ > struct fanotify_event_info_header { > @@ -149,6 +150,15 @@ struct fanotify_event_info_fid { > unsigned char handle[0]; > }; > > +#define FANOTIFY_EVENT_INFO_ERROR_VERS_1 1 Honestly, this struct is too simple to have a 'version'. The format of this simple struct is already defined by FAN_EVENT_INFO_TYPE_ERROR and if we want to change the reported info in the future, we can use FAN_EVENT_INFO_TYPE_ERROR_V2. In fact, I suggest to name the type FAN_EVENT_INFO_TYPE_FS_ERROR to differentiate from a future FAN_EVENT_INFO_TYPE_WB_ERROR > + > +struct fanotify_event_info_error { > + struct fanotify_event_info_header hdr; > + int version; > + int error; > + __kernel_fsid_t fsid; > +}; I suggest to put an error seq counter in this struct. The per-sb seq counter can be provided by the filesystem or by fsnotify. Thanks, Amir.