Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp5106733pxb; Thu, 14 Oct 2021 19:37:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjO6IG/+CVsJRvmdloTF1QEinEGkk9Gv1WJiBbXvIInbHPLxcb+sNWQ5+oEq3UUHanNEnd X-Received: by 2002:a50:da4e:: with SMTP id a14mr13931780edk.154.1634265477242; Thu, 14 Oct 2021 19:37:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634265477; cv=none; d=google.com; s=arc-20160816; b=sYtDGpi2ZfoqwvINehT7r7TpS0Ed5Pzu1+RA+Cg2ODmyS/Tzf3+jzb91jd9QABZ6Ly xL++GT1theQ686CStUq0D2w2q+cMHzTx2Hhvc17Ryoa6QKprOVllnxraU/D+tlLUTWez CiG+HvVVq1YfFEc7KuYk39g+yffiQhAubnInum7bFRycg5+vErYXMFdJVHc1OKsb29X6 GsTDBdaaWRNBoiLQUocv3lTcC7PoifLOFQ3wWs6/aPCPXM2zAH5Kge/Ve5TiChYQ2BtW vxYpFpPIVRExxidArDT+UtXRBLc0/pl55r1W3XnsbevEvZq6yhL3XyLSnDHPFEo2yA53 V5Hg== 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=acCmNPjLyowdNlCaHT3nneUe31ehfOxQa/pbxwjwvzw=; b=RJDj+sr7ZknSuoIdybxtRV0fhy46e08uVlnCTrhPyfH7YvsEJSF2jBFohLlt4jWE2A ipej0SDtVV2RuBwHHsnlBnyWm2lX/zDz3bmfp27zIj8p8Y1mQQ6SFdYzV/j/S9yvAw4u siZkkXixjxBje/hiD8RSou2k1lbEaAnBlStImYFu5n56Hm+xRLs9EXEUucAXJM7wYhRi 2EkhTBM06vAhkP91NCqxzOVAfqyen08X0m94o2gOmQgPTBY5ZXgSUY8IyNti+b9yXHAM bdhJlN4Vv+UDFbtEtHT3+rbnKK9Jp18nCY1Kg2IOWrrXPNT3inA2j06uX+xZZVraDl/H fz3g== 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 u27si6130732ejg.412.2021.10.14.19.37.20; Thu, 14 Oct 2021 19:37:57 -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 S231171AbhJNVl4 (ORCPT + 99 others); Thu, 14 Oct 2021 17:41:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230434AbhJNVlz (ORCPT ); Thu, 14 Oct 2021 17:41:55 -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 52C82C061570; Thu, 14 Oct 2021 14:39:50 -0700 (PDT) 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 835101F415A6; Thu, 14 Oct 2021 22:39:48 +0100 (BST) From: Gabriel Krisman Bertazi To: jack@suse.com, amir73il@gmail.com Cc: djwong@kernel.org, tytso@mit.edu, dhowells@redhat.com, khazhy@google.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-api@vger.kernel.org, repnop@google.com, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH v7 24/28] fanotify: Emit generic error info for error event Date: Thu, 14 Oct 2021 18:36:42 -0300 Message-Id: <20211014213646.1139469-25-krisman@collabora.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211014213646.1139469-1-krisman@collabora.com> References: <20211014213646.1139469-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org The error info is a record sent to users on FAN_FS_ERROR events documenting the type of error. It also carries an error count, documenting how many errors were observed since the last reporting. Signed-off-by: Gabriel Krisman Bertazi --- Changes since v6: - Rebase on top of pidfd patches Changes since v5: - Move error code here --- fs/notify/fanotify/fanotify.c | 1 + fs/notify/fanotify/fanotify.h | 1 + fs/notify/fanotify/fanotify_user.c | 35 ++++++++++++++++++++++++++++++ include/uapi/linux/fanotify.h | 7 ++++++ 4 files changed, 44 insertions(+) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 8a60c96f5fb2..47e28f418711 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -623,6 +623,7 @@ static struct fanotify_event *fanotify_alloc_error_event( return NULL; fee->fae.type = FANOTIFY_EVENT_TYPE_FS_ERROR; + fee->error = report->error; fee->err_count = 1; fee->fsid = *fsid; diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index b58400926f92..a0897425df07 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -199,6 +199,7 @@ FANOTIFY_NE(struct fanotify_event *event) struct fanotify_error_event { struct fanotify_event fae; + s32 error; /* Error reported by the Filesystem. */ u32 err_count; /* Suppressed errors count */ __kernel_fsid_t fsid; /* FSID this error refers to. */ diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 39cf8ba4a6ce..8f7c2f4ce674 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -115,6 +115,8 @@ struct kmem_cache *fanotify_perm_event_cachep __read_mostly; (sizeof(struct fanotify_event_info_fid) + sizeof(struct file_handle)) #define FANOTIFY_PIDFD_INFO_HDR_LEN \ sizeof(struct fanotify_event_info_pidfd) +#define FANOTIFY_ERROR_INFO_LEN \ + (sizeof(struct fanotify_event_info_error)) static int fanotify_fid_info_len(int fh_len, int name_len) { @@ -149,6 +151,9 @@ static size_t fanotify_event_len(unsigned int info_mode, if (!info_mode) return event_len; + if (fanotify_is_error_event(event->mask)) + event_len += FANOTIFY_ERROR_INFO_LEN; + info = fanotify_event_info(event); dir_fh_len = fanotify_event_dir_fh_len(event); fh_len = fanotify_event_object_fh_len(event); @@ -333,6 +338,28 @@ static int process_access_response(struct fsnotify_group *group, return -ENOENT; } +static size_t copy_error_info_to_user(struct fanotify_event *event, + char __user *buf, int count) +{ + struct fanotify_event_info_error info; + struct fanotify_error_event *fee = FANOTIFY_EE(event); + + info.hdr.info_type = FAN_EVENT_INFO_TYPE_ERROR; + info.hdr.pad = 0; + info.hdr.len = FANOTIFY_ERROR_INFO_LEN; + + if (WARN_ON(count < info.hdr.len)) + return -EFAULT; + + info.error = fee->error; + info.error_count = fee->err_count; + + if (copy_to_user(buf, &info, sizeof(info))) + return -EFAULT; + + return info.hdr.len; +} + static int copy_fid_info_to_user(__kernel_fsid_t *fsid, struct fanotify_fh *fh, int info_type, const char *name, size_t name_len, @@ -540,6 +567,14 @@ static int copy_info_records_to_user(struct fanotify_event *event, total_bytes += ret; } + if (fanotify_is_error_event(event->mask)) { + ret = copy_error_info_to_user(event, buf, count); + if (ret < 0) + return ret; + buf += ret; + count -= ret; + } + return total_bytes; } diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 2990731ddc8b..bd1932c2074d 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -126,6 +126,7 @@ struct fanotify_event_metadata { #define FAN_EVENT_INFO_TYPE_DFID_NAME 2 #define FAN_EVENT_INFO_TYPE_DFID 3 #define FAN_EVENT_INFO_TYPE_PIDFD 4 +#define FAN_EVENT_INFO_TYPE_ERROR 5 /* Variable length info record following event metadata */ struct fanotify_event_info_header { @@ -160,6 +161,12 @@ struct fanotify_event_info_pidfd { __s32 pidfd; }; +struct fanotify_event_info_error { + struct fanotify_event_info_header hdr; + __s32 error; + __u32 error_count; +}; + struct fanotify_response { __s32 fd; __u32 response; -- 2.33.0