From patchwork Thu Nov 21 11:22:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13881876 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 643E4D6ED09 for ; Thu, 21 Nov 2024 11:22:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A1AA86B008A; Thu, 21 Nov 2024 06:22:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 848FD6B0099; Thu, 21 Nov 2024 06:22:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C3726B008A; Thu, 21 Nov 2024 06:22:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D57C16B008A for ; Thu, 21 Nov 2024 06:22:28 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7C519AE95F for ; Thu, 21 Nov 2024 11:22:28 +0000 (UTC) X-FDA: 82809862296.21.5974028 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf08.hostedemail.com (Postfix) with ESMTP id 4E4AE160010 for ; Thu, 21 Nov 2024 11:21:51 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of jack@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732188079; a=rsa-sha256; cv=none; b=vq7J9F5scyA8+zpOwDXTO0Sa5n3dlm3eWN0EaINT8Rsp0ww3VQFLAWsmLW8jPoinqSnLxp HaQpRcmmJjdTKLpv/QqljNvjxGmHjfVWrgro+AGMENwxOaNayB2mUekEzi6I94wBxC0brm 7D/xUBh7bUt6jtsJJd/Uy3qWI0OPbrw= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of jack@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732188079; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bNHgWh2PSAQoFMjnMXAu0jFK5Yl+kb9vf/9ZJ3eAETU=; b=LSkLfzDnMpHMQ7ZMJ1Z8bbUNbBGxNc9m7EiK5HspWFIPwMImtAK7KlFLHTSoLsat0tlWaZ JGxfMKSrTBnutecDJHLOFPv9ubxbPYd7/c5Q1Hbg5q63HeD+qk8CZR2ONGfp8DHqoCgWfD kV4+K7qlN5hidzfzx/7Iqg9aOYu5Jew= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 894C321A03; Thu, 21 Nov 2024 11:22:24 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7DD5D13A7D; Thu, 21 Nov 2024 11:22:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id gve3HvAXP2c4fwAAD6G6ig (envelope-from ); Thu, 21 Nov 2024 11:22:24 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 24BCEA0926; Thu, 21 Nov 2024 12:22:24 +0100 (CET) From: Jan Kara To: Cc: Amir Goldstein , Josef Bacik , brauner@kernel.org, Linus Torvalds , Al Viro , linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, Jan Kara Subject: [PATCH 11/19] fanotify: report file range info with pre-content events Date: Thu, 21 Nov 2024 12:22:10 +0100 Message-Id: <20241121112218.8249-12-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20241121112218.8249-1-jack@suse.cz> References: <20241121112218.8249-1-jack@suse.cz> MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspam-User: X-Rspamd-Queue-Id: 4E4AE160010 X-Rspamd-Server: rspam11 X-Stat-Signature: y6h9pn19ihdftrjsett4dwsh8hmdiuws X-HE-Tag: 1732188111-665458 X-HE-Meta: U2FsdGVkX1/22ROGfy6pv0kCCFDV4lo/SeXn2SPg7Ojw9xinheXwcdFjxB3yXmG3oF6qEP3PYattJ/p/z4tkpWoe6nhQ1J4W4HJoeHzpidIkXx3MRjSC7t+q5ZgCsM8HUw5qsuU+2UptPazJ7IEB8Rgt0AfgnXtqtdLhQqpJeALMOzufNqDF36zuScomwgXhI+FBlSI4bdpgFC0J9anr1Kx49D43G7RY5m55vwdnq918oF9IeenlXbxFsHpRFg+hDQ3GWIq8C7orOZex4pMR9+XsnSXchSIXG/HTS8dkAKHU2V2cAHBaI5JmJVIthHxbhzM+28z3xPoiWzoCuHQcROnY6sWT+GQV9PhBZW5QIXzYDiLFXn9UMwcNjVtJl3B4pHkBmlpf4iVg6LOj2RDdEh1PPcZ1n2VKXiuGBSXtn6rhDOsKnXxN89p751RQnl0IKX7XGaf0WMiO/COpFsEEV1hWPntWz+MTxll7VEYqQeMWnx5x3GwlhLV1wpdO8Od5nYxKPJZ2v7UdKOhUq8uDk0DQKygsao7xsrkm1yl0Eu2DtcTPmcJHJYgyrXHUEl+SApht+iI8g1AqzGznQY6qg9RpLNnCsBqyU9RPMzM5RIkA818PM+Qlb/KJ8JjlldethFvDLrdjkT0O2z4SvihEIVXxeFoK3SLbBXfgZtje1AqYn4Dsd0TEmEBeJgrz9C9eSW4wcXtHtO0LXNCoXn/7sLNEMR+Jd+9CHG0nOvXBXiEyHzRb39NhEZHuQvrmTm24avX7XnGlo4ncYngXsqzMlTm/jCeUyWiVxSfyImRHz9nmGiffjzSin/vVoghrMLB+PVfYkuS0r2QcYpA2RnqIJYEtvPI2aH0FiQEEiChyHymZD004RrIV0IKKInYchfyvKp5qZU/gyEdNgJXPLIuwk9I0oYf2efwZV5X6z2kjr+LSgTJmj65PX/BCLZmf5fVbDJXuS9DhiGaxpes1kKQ AsRuKkrf U1FiQCUla8EeEoMalVwGEtzXqoGTGu05xBUwhL0dAEk4JFljOIASVTZkzY8u5Zhy6xgULVDWdxyfa+jqw6ZDJFId/OJhDRfSBPKnE3UZANG8JWy5oJh08cAbl7k7PnruuvkuR7YFdN97sZBNUfYC9GkJUkXmI9OfbWtyJjo+tbvJRMCGV2+GJ+Is370l3mZP8W0Mmxqx1IdGbQFWYZd2QdRR+KUiVH+lTcKoGd17SKfXC6vSBNrIchhfspECGgUFyPxfY86KM/2SGkCY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein With group class FAN_CLASS_PRE_CONTENT, report offset and length info along with FAN_PRE_ACCESS pre-content events. This information is meant to be used by hierarchical storage managers that want to fill partial content of files on first access to range. Signed-off-by: Amir Goldstein Signed-off-by: Jan Kara Link: https://patch.msgid.link/b90a9e6c809dd3cad5684da90f23ea93ec6ce8c8.1731684329.git.josef@toxicpanda.com --- fs/notify/fanotify/fanotify.h | 8 +++++++ fs/notify/fanotify/fanotify_user.c | 38 ++++++++++++++++++++++++++++++ include/uapi/linux/fanotify.h | 8 +++++++ 3 files changed, 54 insertions(+) diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 93598b7d5952..7f06355afa1f 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -448,6 +448,14 @@ static inline bool fanotify_is_perm_event(u32 mask) mask & FANOTIFY_PERM_EVENTS; } +static inline bool fanotify_event_has_access_range(struct fanotify_event *event) +{ + if (!(event->mask & FANOTIFY_PRE_CONTENT_EVENTS)) + return false; + + return FANOTIFY_PERM(event)->ppos; +} + static inline struct fanotify_event *FANOTIFY_E(struct fsnotify_event *fse) { return container_of(fse, struct fanotify_event, fse); diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index b4dfc8f0d037..61e0f67169e4 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -122,6 +122,8 @@ struct kmem_cache *fanotify_perm_event_cachep __ro_after_init; sizeof(struct fanotify_event_info_pidfd) #define FANOTIFY_ERROR_INFO_LEN \ (sizeof(struct fanotify_event_info_error)) +#define FANOTIFY_RANGE_INFO_LEN \ + (sizeof(struct fanotify_event_info_range)) static int fanotify_fid_info_len(int fh_len, int name_len) { @@ -181,6 +183,9 @@ static size_t fanotify_event_len(unsigned int info_mode, if (info_mode & FAN_REPORT_PIDFD) event_len += FANOTIFY_PIDFD_INFO_LEN; + if (fanotify_event_has_access_range(event)) + event_len += FANOTIFY_RANGE_INFO_LEN; + return event_len; } @@ -517,6 +522,30 @@ static int copy_pidfd_info_to_user(int pidfd, return info_len; } +static size_t copy_range_info_to_user(struct fanotify_event *event, + char __user *buf, int count) +{ + struct fanotify_perm_event *pevent = FANOTIFY_PERM(event); + struct fanotify_event_info_range info = { }; + size_t info_len = FANOTIFY_RANGE_INFO_LEN; + + if (WARN_ON_ONCE(info_len > count)) + return -EFAULT; + + if (WARN_ON_ONCE(!pevent->ppos)) + return -EINVAL; + + info.hdr.info_type = FAN_EVENT_INFO_TYPE_RANGE; + info.hdr.len = info_len; + info.offset = *(pevent->ppos); + info.count = pevent->count; + + if (copy_to_user(buf, &info, info_len)) + return -EFAULT; + + return info_len; +} + static int copy_info_records_to_user(struct fanotify_event *event, struct fanotify_info *info, unsigned int info_mode, int pidfd, @@ -638,6 +667,15 @@ static int copy_info_records_to_user(struct fanotify_event *event, total_bytes += ret; } + if (fanotify_event_has_access_range(event)) { + ret = copy_range_info_to_user(event, buf, count); + if (ret < 0) + return ret; + buf += ret; + count -= ret; + total_bytes += ret; + } + return total_bytes; } diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 7596168c80eb..0636a9c85dd0 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -146,6 +146,7 @@ struct fanotify_event_metadata { #define FAN_EVENT_INFO_TYPE_DFID 3 #define FAN_EVENT_INFO_TYPE_PIDFD 4 #define FAN_EVENT_INFO_TYPE_ERROR 5 +#define FAN_EVENT_INFO_TYPE_RANGE 6 /* Special info types for FAN_RENAME */ #define FAN_EVENT_INFO_TYPE_OLD_DFID_NAME 10 @@ -192,6 +193,13 @@ struct fanotify_event_info_error { __u32 error_count; }; +struct fanotify_event_info_range { + struct fanotify_event_info_header hdr; + __u32 pad; + __u64 offset; + __u64 count; +}; + /* * User space may need to record additional information about its decision. * The extra information type records what kind of information is included.