Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3502349pxb; Mon, 18 Oct 2021 17:03:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTucK4kXymS6ZFTNh52SnsOHB8v+DjZuvC23bG6C+dMOr6x8uECh88VXT0O6s56dPRk7vy X-Received: by 2002:a17:906:b208:: with SMTP id p8mr34360603ejz.477.1634601828139; Mon, 18 Oct 2021 17:03:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634601828; cv=none; d=google.com; s=arc-20160816; b=UfXiascxhC949wUvgZe3T66JiA+zNbX5K6B94hPmC6RzudmAkpP6lEy/a/eM0POpfJ rlWO/utVgbI3cVX1clQFGpqAKRjgdDX+NcdHHIPH5RBugehgVeM/eVsFVY3mz9Dvs/lP QSp2cvd6hbvtsx6it0H3WV0Gs+oMUZ76ZDQtfSewMLZ10DBq3jryeUA+lA7H7lFadO47 upVgxbs7RSd0vwC6iZmiQU1KKHdzk6bYP/jQ26BM4jd7vj4UZ0kQQCGtllai3Tljv5hD oU6Kr1Bt7zwOj7PgLjROeE1vFZY6HW/3je68RHRg5sdO+zZqpX3uYCnSpbKIt6dTybS9 /oLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ZHbka87j0mSBT28Ca2vaxML2+UT3UfybhJVhK14NfEY=; b=hN9Gsal3gW9ZfCqsed6YREBMZlulmByUrlKlmSHsa0CvUYGMOYdthuJ47suvt1HWLU fWmmkzFyQ/4oPgxOe1VWESF5lbLtmVGXP12Vor24S6h+2u/4K8AfZqVGoYBDsQJbL3jZ 2Hb3Dnr/B6y67rrRZ1NlgsDQsEIuD8epk5l38zmQQ1rVPj9M+wX4o9SLjUQN/c/sfh1f aOhZstbFWdIFxqYVJPwT8DIRw0woKYN4XDqrihzKPK2Uc95blGoqmaOe2mrdK9qIr60T STSD1/+1wrp6tMz1dTpYA8Za4WDamPNd6p0OM++C39MfSwu5RKICgQHWVtbgtXq7nFsS Sxnw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m10si3040982edd.467.2021.10.18.17.03.24; Mon, 18 Oct 2021 17:03:48 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234037AbhJSAF2 (ORCPT + 99 others); Mon, 18 Oct 2021 20:05:28 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:40936 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229710AbhJSAFZ (ORCPT ); Mon, 18 Oct 2021 20:05:25 -0400 Received: from localhost (unknown [IPv6:2804:14c:124:8a08::1007]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: krisman) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 1B5E31F411B7; Tue, 19 Oct 2021 01:03:11 +0100 (BST) From: Gabriel Krisman Bertazi To: jack@suse.com, amir73il@gmail.com Cc: djwong@kernel.org, tytso@mit.edu, david@fromorbit.com, dhowells@redhat.com, khazhy@google.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-api@vger.kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com, Jan Kara Subject: [PATCH v8 21/32] fanotify: Support enqueueing of error events Date: Mon, 18 Oct 2021 21:00:04 -0300 Message-Id: <20211019000015.1666608-22-krisman@collabora.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211019000015.1666608-1-krisman@collabora.com> References: <20211019000015.1666608-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Once an error event is triggered, enqueue it in the notification group, similarly to what is done for other events. FAN_FS_ERROR is not handled specially, since the memory is now handled by a preallocated mempool. For now, make the event unhashed. A future patch implements merging of this kind of event. Reviewed-by: Jan Kara Signed-off-by: Gabriel Krisman Bertazi --- Changes since v7: - WARN_ON -> WARN_ON_ONCE (Amir) --- fs/notify/fanotify/fanotify.c | 35 +++++++++++++++++++++++++++++++++++ fs/notify/fanotify/fanotify.h | 6 ++++++ 2 files changed, 41 insertions(+) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 01d68dfc74aa..1f195c95dfcd 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -574,6 +574,27 @@ static struct fanotify_event *fanotify_alloc_name_event(struct inode *id, return &fne->fae; } +static struct fanotify_event *fanotify_alloc_error_event( + struct fsnotify_group *group, + __kernel_fsid_t *fsid, + const void *data, int data_type) +{ + struct fs_error_report *report = + fsnotify_data_error_report(data, data_type); + struct fanotify_error_event *fee; + + if (WARN_ON_ONCE(!report)) + return NULL; + + fee = mempool_alloc(&group->fanotify_data.error_events_pool, GFP_NOFS); + if (!fee) + return NULL; + + fee->fae.type = FANOTIFY_EVENT_TYPE_FS_ERROR; + + return &fee->fae; +} + static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, u32 mask, const void *data, int data_type, struct inode *dir, @@ -641,6 +662,9 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, if (fanotify_is_perm_event(mask)) { event = fanotify_alloc_perm_event(path, gfp); + } else if (fanotify_is_error_event(mask)) { + event = fanotify_alloc_error_event(group, fsid, data, + data_type); } else if (name_event && (file_name || child)) { event = fanotify_alloc_name_event(id, fsid, file_name, child, &hash, gfp); @@ -850,6 +874,14 @@ static void fanotify_free_name_event(struct fanotify_event *event) kfree(FANOTIFY_NE(event)); } +static void fanotify_free_error_event(struct fsnotify_group *group, + struct fanotify_event *event) +{ + struct fanotify_error_event *fee = FANOTIFY_EE(event); + + mempool_free(fee, &group->fanotify_data.error_events_pool); +} + static void fanotify_free_event(struct fsnotify_group *group, struct fsnotify_event *fsn_event) { @@ -873,6 +905,9 @@ static void fanotify_free_event(struct fsnotify_group *group, case FANOTIFY_EVENT_TYPE_OVERFLOW: kfree(event); break; + case FANOTIFY_EVENT_TYPE_FS_ERROR: + fanotify_free_error_event(group, event); + break; default: WARN_ON_ONCE(1); } diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index a577e87fac2b..ebef952481fa 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -298,6 +298,11 @@ static inline struct fanotify_event *FANOTIFY_E(struct fsnotify_event *fse) return container_of(fse, struct fanotify_event, fse); } +static inline bool fanotify_is_error_event(u32 mask) +{ + return mask & FAN_FS_ERROR; +} + static inline bool fanotify_event_has_path(struct fanotify_event *event) { return event->type == FANOTIFY_EVENT_TYPE_PATH || @@ -327,6 +332,7 @@ static inline struct path *fanotify_event_path(struct fanotify_event *event) static inline bool fanotify_is_hashed_event(u32 mask) { return !(fanotify_is_perm_event(mask) || + fanotify_is_error_event(mask) || fsnotify_is_overflow_event(mask)); } -- 2.33.0