Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3871716pxy; Mon, 26 Apr 2021 11:45:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7PsNbrHg18aI1Cathfd9uXrC0BFO0VXPbf+rfl1fOkJo4nHKFnLOViZm/MU0PaDcI0WIK X-Received: by 2002:a50:f395:: with SMTP id g21mr107455edm.238.1619462744248; Mon, 26 Apr 2021 11:45:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619462744; cv=none; d=google.com; s=arc-20160816; b=jaN/WN1BDMaZnbFIu0FTLNxk+MBJ2PW94a0bPB+HzxnSR+Pnsz378l77YKzfWHLZNE EUHX6GG0O8KYt7SjeZjuQgOfFovCyGY+g/gxOMYM8v0Dp93FGtobMpBK8NkUkoeHoJ0V owxspRw8LiStg0yIZyoajxvSXnwY7kSYB8a+a8bjI65IXDW3NzBzDCkphLB/daMcYMFG i6/4BglW5z1yi4sWEIqYaUw+N7NkzkXyZ7dRS+7Zg+l4AoOVI+AGDLliSSzQM9z0+cyJ OOVPGLZm7Q59nOhWdfFyc5qAcH3vqNhEUC/d8jzLulzqEZrvCiLIo7eqksog7GgrXc6b 6kQw== 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=aOdaJlMsFgRdXZjZhWd3FrINOb9UwB218YJZRM/B7mI=; b=ACAe2XQ3/nvCRS7Mvmqk33yH0q+px10EZ2oPtwp7j/VMBK5A6ZyEMAEHDmT0nu0u4h GPdoGSuCreSUb6hvVA4+k1H/y/9fW0pgwJX56F2rBduGNNhWILsR2VTNSpAnciwgOruF 4ZJ96V/PryxTpAMHxKwhIu5tOP11cY6ZWRVumUFdnJP3RV04Sool31LeaxJr022SbtbV 6ppOZPrvxbrUb0/5OD8LJBLNdUyFbeqJaKIqCUoDrz3yEWyNVK6X+IGxRo8Ern474Ulg 73Ep7Hj4319l4itEve/iclN93bvfw4t/i6a0g5HSzEhepjo9tXBRsSet8lbBsUEAME9L E9mw== 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 m9si15293674ejj.645.2021.04.26.11.45.21; Mon, 26 Apr 2021 11:45:44 -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 S238653AbhDZSpw (ORCPT + 99 others); Mon, 26 Apr 2021 14:45:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239506AbhDZSn4 (ORCPT ); Mon, 26 Apr 2021 14:43:56 -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 EE4D0C06175F; Mon, 26 Apr 2021 11:43:13 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 92ECC1F422D6 From: Gabriel Krisman Bertazi To: amir73il@gmail.com, tytso@mit.edu, djwong@kernel.org Cc: david@fromorbit.com, jack@suse.com, dhowells@redhat.com, khazhy@google.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH RFC 13/15] ext4: Send notifications on error Date: Mon, 26 Apr 2021 14:41:59 -0400 Message-Id: <20210426184201.4177978-14-krisman@collabora.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210426184201.4177978-1-krisman@collabora.com> References: <20210426184201.4177978-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Send a FS_ERROR message via fsnotify to a userspace monitoring tool whenever a ext4 error condition is triggered. This follows the existing error conditions in ext4, so it is hooked to the ext4_error* functions. It also follows the current dmesg reporting in the format. The filesystem message is composed mostly by the string that would be otherwise printed in dmesg. A new ext4 specific record format is exposed in the uapi, such that a monitoring tool knows what to expect when listening errors of an ext4 filesystem. Signed-off-by: Gabriel Krisman Bertazi --- fs/ext4/super.c | 60 ++++++++++++++++++++++++-------- include/uapi/linux/ext4-notify.h | 17 +++++++++ 2 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 include/uapi/linux/ext4-notify.h diff --git a/fs/ext4/super.c b/fs/ext4/super.c index b9693680463a..032e29e7ff6a 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -46,6 +46,8 @@ #include #include #include +#include +#include #include "ext4.h" #include "ext4_extents.h" /* Needed for trace points definition */ @@ -727,6 +729,22 @@ static void flush_stashed_error_work(struct work_struct *work) ext4_commit_super(sbi->s_sb); } +static void ext4_fsnotify_error(int error, struct inode *inode, __u64 block, + const char *func, int line, + const char *desc, struct va_format *vaf) +{ + struct ext4_error_inode_report report; + + if (inode->i_sb->s_fsnotify_marks) { + report.inode = inode ? inode->i_ino : -1L; + report.block = block ? block : -1L; + + snprintf(report.desc, EXT4_FSN_DESC_LEN, "%s%pV\n", desc?:"", vaf); + + fsnotify_error_event(error, inode, func, line, &report, sizeof(report)); + } +} + #define ext4_error_ratelimit(sb) \ ___ratelimit(&(EXT4_SB(sb)->s_err_ratelimit_state), \ "EXT4-fs error") @@ -742,15 +760,18 @@ void __ext4_error(struct super_block *sb, const char *function, return; trace_ext4_error(sb, function, line); + + va_start(args, fmt); + vaf.fmt = fmt; + vaf.va = &args; if (ext4_error_ratelimit(sb)) { - va_start(args, fmt); - vaf.fmt = fmt; - vaf.va = &args; printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: comm %s: %pV\n", sb->s_id, function, line, current->comm, &vaf); - va_end(args); + } + ext4_fsnotify_error(error, sb->s_root->d_inode, block, function, line, NULL, &vaf); + va_end(args); ext4_handle_error(sb, force_ro, error, 0, block, function, line); } @@ -765,10 +786,10 @@ void __ext4_error_inode(struct inode *inode, const char *function, return; trace_ext4_error(inode->i_sb, function, line); + va_start(args, fmt); + vaf.fmt = fmt; + vaf.va = &args; if (ext4_error_ratelimit(inode->i_sb)) { - va_start(args, fmt); - vaf.fmt = fmt; - vaf.va = &args; if (block) printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: " "inode #%lu: block %llu: comm %s: %pV\n", @@ -779,8 +800,11 @@ void __ext4_error_inode(struct inode *inode, const char *function, "inode #%lu: comm %s: %pV\n", inode->i_sb->s_id, function, line, inode->i_ino, current->comm, &vaf); - va_end(args); } + + ext4_fsnotify_error(error, inode, block, function, line, NULL, &vaf); + va_end(args); + ext4_handle_error(inode->i_sb, false, error, inode->i_ino, block, function, line); } @@ -798,13 +822,16 @@ void __ext4_error_file(struct file *file, const char *function, return; trace_ext4_error(inode->i_sb, function, line); + + path = file_path(file, pathname, sizeof(pathname)); + if (IS_ERR(path)) + path = "(unknown)"; + + va_start(args, fmt); + vaf.fmt = fmt; + vaf.va = &args; + if (ext4_error_ratelimit(inode->i_sb)) { - path = file_path(file, pathname, sizeof(pathname)); - if (IS_ERR(path)) - path = "(unknown)"; - va_start(args, fmt); - vaf.fmt = fmt; - vaf.va = &args; if (block) printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: inode #%lu: " @@ -817,8 +844,10 @@ void __ext4_error_file(struct file *file, const char *function, "comm %s: path %s: %pV\n", inode->i_sb->s_id, function, line, inode->i_ino, current->comm, path, &vaf); - va_end(args); } + ext4_fsnotify_error(EFSCORRUPTED, inode, block, function, line, NULL, &vaf); + va_end(args); + ext4_handle_error(inode->i_sb, false, EFSCORRUPTED, inode->i_ino, block, function, line); } @@ -886,6 +915,7 @@ void __ext4_std_error(struct super_block *sb, const char *function, printk(KERN_CRIT "EXT4-fs error (device %s) in %s:%d: %s\n", sb->s_id, function, line, errstr); } + ext4_fsnotify_error(errno, NULL, -1L, function, line, errstr, NULL); ext4_handle_error(sb, false, -errno, 0, 0, function, line); } diff --git a/include/uapi/linux/ext4-notify.h b/include/uapi/linux/ext4-notify.h new file mode 100644 index 000000000000..31a3bbcafd13 --- /dev/null +++ b/include/uapi/linux/ext4-notify.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +/* + * Copyright 2021, Collabora Ltd. + */ + +#ifndef EXT4_NOTIFY_H +#define EXT4_NOTIFY_H + +#define EXT4_FSN_DESC_LEN 256 + +struct ext4_error_inode_report { + u64 inode; + u64 block; + char desc[EXT4_FSN_DESC_LEN]; +}; + +#endif -- 2.31.0