Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp208808pxt; Wed, 4 Aug 2021 09:09:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz97ZIZc09cIRyFCZAtD4PhYB1PX4PPTVmUjpq+NubZpgIHVZIzwxiw8IQJ7Xd1KgeHeQli X-Received: by 2002:a05:6402:35cf:: with SMTP id z15mr573759edc.27.1628093352388; Wed, 04 Aug 2021 09:09:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628093352; cv=none; d=google.com; s=arc-20160816; b=ApPjTDyfeYIM+YHbtvklrnFZy50McvmzY2mZcuVWT+MATigT/brcpdtZFm5mc82kF5 zwEQhArsDOE5Pi+NZk8XZtW9l4sR9i2YjyvHAv+XoBB5zM1jB289NuFColpW62/PFKHY C9IUTGGSgSb/PKQpyfb+fCY6W/tBYxWXGr+x9rorBbg9jSIiKPuLVnZDgvRl0XNJqhsE bBbwFMEI3cVEv41IdHuH98xEdX9PMY/GymVmnF42SL7+Z9UiZhdg/btSQdF+tZicDYXO uecmhzRY78LdC6tYxwmcByj4olNZNSLQo73jNnLz0i7p0nZW5my+4T5l0CmB/D9oeb2E Qk7w== 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=PWjvlZJRbYlJPXzf08FkgtS6AtagbHvVSDO/uNKK+T4=; b=Ewh+3xmr+xGroVhlR3gfBu5isHtSNsEcyx/h71PHY46458aXPkjhfqsDrbX/9qicrR pq3PL7+i4/PvFBaE6QcxZBaEQV55XHSULlybFRLrdU8wsxu6D5LEpTj4w3CmYcsDOQaR +EhzD1ZD8jAuqUwC8DRvW2KbCZGGychDRue4cGJAkhc977VFrlKm4k4UpMzv7Dicw4Dc C+o5yogupShjwMzVscc9CRgTbYefMFpyt8kZHnEjYWRU8+V3atQAfPHJMqthrOcOjqcu EK1GzHRoPHi9ezsMeXN2w1u3iZsXomp45h1Vy6pLOdhXGdaZlRAW1O0IpmDvmdViPKpq 5I0g== 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 m7si2537141edp.272.2021.08.04.09.08.40; Wed, 04 Aug 2021 09:09:12 -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 S232356AbhHDQH2 (ORCPT + 99 others); Wed, 4 Aug 2021 12:07:28 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:42002 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230059AbhHDQHY (ORCPT ); Wed, 4 Aug 2021 12:07:24 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id E8B951F43660 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 Subject: [PATCH v5 11/23] fsnotify: Support FS_ERROR event type Date: Wed, 4 Aug 2021 12:06:00 -0400 Message-Id: <20210804160612.3575505-12-krisman@collabora.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210804160612.3575505-1-krisman@collabora.com> References: <20210804160612.3575505-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Expose a new type of fsnotify event for filesystems to report errors for userspace monitoring tools. fanotify will send this type of notification for FAN_FS_ERROR events. This also introduce a helper for generating the new event. Signed-off-by: Gabriel Krisman Bertazi --- Changes since v3: - Squash patch ("fsnotify: Introduce helpers to send error_events") - Drop reviewed-bys! Changes since v2: - FAN_ERROR->FAN_FS_ERROR (Amir) Changes since v1: - Overload FS_ERROR with FS_IN_IGNORED - Implement support for this type on fsnotify_data_inode (Amir) --- include/linux/fsnotify.h | 12 ++++++++++++ include/linux/fsnotify_backend.h | 17 ++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 39c9dbc46d36..d3f0f5ed8e9e 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -319,4 +319,16 @@ 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, &report, FSNOTIFY_EVENT_ERROR, sb, + NULL, NULL, NULL, 0); +} + #endif /* _LINUX_FS_NOTIFY_H */ diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 4a765edd3b2a..9010e3505f9c 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -42,6 +42,12 @@ #define FS_UNMOUNT 0x00002000 /* inode on umount fs */ #define FS_Q_OVERFLOW 0x00004000 /* Event queued overflowed */ +#define FS_ERROR 0x00008000 /* Filesystem Error (fanotify) */ + +/* + * FS_IN_IGNORED overloads FS_ERROR. It is only used internally by inotify + * which does not support FS_ERROR. + */ #define FS_IN_IGNORED 0x00008000 /* last inotify event here */ #define FS_OPEN_PERM 0x00010000 /* open event in an permission hook */ @@ -95,7 +101,8 @@ #define ALL_FSNOTIFY_EVENTS (ALL_FSNOTIFY_DIRENT_EVENTS | \ FS_EVENTS_POSS_ON_CHILD | \ FS_DELETE_SELF | FS_MOVE_SELF | FS_DN_RENAME | \ - FS_UNMOUNT | FS_Q_OVERFLOW | FS_IN_IGNORED) + FS_UNMOUNT | FS_Q_OVERFLOW | FS_IN_IGNORED | \ + FS_ERROR) /* Extra flags that may be reported with event or control handling of events */ #define ALL_FSNOTIFY_FLAGS (FS_EXCL_UNLINK | FS_ISDIR | FS_IN_ONESHOT | \ @@ -248,6 +255,12 @@ enum fsnotify_data_type { FSNOTIFY_EVENT_NONE, FSNOTIFY_EVENT_PATH, FSNOTIFY_EVENT_INODE, + FSNOTIFY_EVENT_ERROR, +}; + +struct fs_error_report { + int error; + struct inode *inode; }; static inline struct inode *fsnotify_data_inode(const void *data, int data_type) @@ -257,6 +270,8 @@ static inline struct inode *fsnotify_data_inode(const void *data, int data_type) return (struct inode *)data; case FSNOTIFY_EVENT_PATH: return d_inode(((const struct path *)data)->dentry); + case FSNOTIFY_EVENT_ERROR: + return ((struct fs_error_report *)data)->inode; default: return NULL; } -- 2.32.0