From patchwork Tue Jul 20 15:59:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 1507659 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4GTkHv6mDgz9sRR for ; Wed, 21 Jul 2021 02:12:11 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236362AbhGTPan (ORCPT ); Tue, 20 Jul 2021 11:30:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240517AbhGTPUm (ORCPT ); Tue, 20 Jul 2021 11:20:42 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AFA0C061574; Tue, 20 Jul 2021 09:00:41 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id E01E41F43149 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, Gabriel Krisman Bertazi , kernel@collabora.com, Jan Kara Subject: [PATCH v4 12/16] fsnotify: Introduce helpers to send error_events Date: Tue, 20 Jul 2021 11:59:40 -0400 Message-Id: <20210720155944.1447086-13-krisman@collabora.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210720155944.1447086-1-krisman@collabora.com> References: <20210720155944.1447086-1-krisman@collabora.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Introduce helpers for filesystems interested in reporting FS_ERROR events. When notifying errors, the file system might not have an inode to report on the error. To support this, allow the caller to specify the superblock to which the error applies. Reviewed-by: Amir Goldstein Reviewed-by: Jan Kara Signed-off-by: Gabriel Krisman Bertazi --- Changes since v2: - Drop reference to s_fnotify_marks and guards (Amir) Changes since v1: - Use the inode argument (Amir) - Protect s_fsnotify_marks with ifdef guard --- fs/notify/fsnotify.c | 2 +- include/linux/fsnotify.h | 13 +++++++++++++ include/linux/fsnotify_backend.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 7c783c9df1dd..f66dff6e2d4e 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -487,7 +487,7 @@ int __fsnotify(__u32 mask, const struct fsnotify_event_info *event_info) */ parent = event_info->dir; } - sb = inode->i_sb; + sb = event_info->sb ?: inode->i_sb; /* * Optimization: srcu_read_lock() has a memory barrier which can diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index f8acddcf54fb..f118e20a9926 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -317,4 +317,17 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid) fsnotify_dentry(dentry, mask); } +static inline int fsnotify_sb_error(struct super_block *sb, struct inode *inode, + int error) +{ + struct fs_error_report report = { + .error = error, + .inode = inode, + }; + + return __fsnotify(FS_ERROR, &(struct fsnotify_event_info) { + .data = &report, .data_type = FSNOTIFY_EVENT_ERROR, + .sb = sb}); +} + #endif /* _LINUX_FS_NOTIFY_H */ diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 33988fdf391a..fa1303b8c599 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -138,6 +138,7 @@ struct fsnotify_event_info { struct inode *dir; const struct qstr *name; struct inode *inode; + struct super_block *sb; u32 cookie; };