From patchwork Mon Nov 11 20:18:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871229 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 04D4AD3ABF5 for ; Mon, 11 Nov 2024 20:19:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A2128D0008; Mon, 11 Nov 2024 15:19:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 953558D0001; Mon, 11 Nov 2024 15:19:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A7B58D0008; Mon, 11 Nov 2024 15:19:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 563718D0001 for ; Mon, 11 Nov 2024 15:19:30 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 14D23160D5C for ; Mon, 11 Nov 2024 20:19:30 +0000 (UTC) X-FDA: 82774927200.07.E604E60 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by imf27.hostedemail.com (Postfix) with ESMTP id 88A3C40013 for ; Mon, 11 Nov 2024 20:18:46 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=nEnJB7Dw; spf=none (imf27.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.175) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731356280; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mxzNxKWQS223qRTjvLG5E3r4Xe02F6POoSVqC+sjeek=; b=yBwGFdEHNlpZAlmUC2vkXI0HmjJ54Cmv9b14O1aZN5lJmPeQFhTwyduZJg10UUraOzcYxS 7afL6YXAzi+DEQ9Nos71QAZhLYzlWT6mzatK5U8vMyZF7TK+5phirnXJ9XkRkOQnkdP4Hf W06xxwlsJ3u0FcGmhibXhTm3K6Z5DsU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356280; a=rsa-sha256; cv=none; b=g53tq6xE1O3P1uV3MrFEV6aUrJDbD4e2Qa4PSwAYt9xGLzEUGFqbf/EGjC8cDHcxzN/cIO M2e2m9/DQ65c0U6ZvxXfcTm2wzG6ZosEF4HRKo8TLvoaQbiSWU2ByLxwAH7pgE3t6H/4G8 iYRlWJBURCTJZcMnakO6RaQHCymFsuk= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=nEnJB7Dw; spf=none (imf27.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.175) smtp.mailfrom=josef@toxicpanda.com; dmarc=none Received: by mail-qt1-f175.google.com with SMTP id d75a77b69052e-460ad0440ddso33609131cf.3 for ; Mon, 11 Nov 2024 12:19:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356367; x=1731961167; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=mxzNxKWQS223qRTjvLG5E3r4Xe02F6POoSVqC+sjeek=; b=nEnJB7Dw48uWmt5g8UCTF+vKKSe9j/UQM26b9leQR2ka1aSF9q12sXzhFMqsWWjs6l B14rJUNM6UcQV+pIUsQYkRDt9tpzRWxMX4HrBh7nH9ShW1TsmhRhgtA+UvDX9AWOwfg0 TDcT3iccwZUDom4XwAkmsgJLzhvyqJ0rF6gHDvDyLpiekOfcnEOhsYaOTzlQIkF20W35 uUamkyboFFK3u8VIXG3A67m82qZqP+oPOshk+Sk8ZKTvfbNxFcnDm1NIoSk/84pvCUCC q7yLToULDS/ONURWX/nC/oWlMcreZVMHT8KRxPOYFvgOoEHGtgtfhW0ilO0jV4e0uxBd QKBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356367; x=1731961167; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mxzNxKWQS223qRTjvLG5E3r4Xe02F6POoSVqC+sjeek=; b=VfUVXQfqviBfpcM+81OZSKC0BbBdn/0GVM350YNbW4xy3LAuCQSQzVw7hXCy00MGxE a6sqz8wgo0ks6LwGqiNMchojZ+JlZNJmbhkUzpF1GRY1XBUL9biaqGoaDQKpzxtHC+gi yQb2BqgAoq3NUjpe+6AW3z1kvGdkKCBMGXOVJzMBLI9YlLfqojQG0Td8Sjj6KQLDSviB XBhrH5Uu+mYgcF2VUSH4Lr9AYPtDRVcMMsCXZo+U3Gw/Y3ArOwo1X1Crcu3NNjumr2jc GbJCBojWMxJ+EzRxCzxI+9sbNE8ZxLe7cAYScC6RevTd5lVGXaE9H0uc1pFoDH8nmwji hoLw== X-Forwarded-Encrypted: i=1; AJvYcCUmWwLwA0/ecStuDtETenFMWawgOJTFnZlda+q1tR/BoailHp8urDgtWHLYSrYzgfrAB+qF3RXnDQ==@kvack.org X-Gm-Message-State: AOJu0Yyso3GRDnxqjqQwdlZM+Gc0bYH4VaDy+EzUE2KyuZ4WBKt/VCF0 QJk0ZrNhZSHwv4iCeG1DMZ/DUoPiHbQZzsqowvp0vA8CiwpE3FiHUrkCxOv/cRA= X-Google-Smtp-Source: AGHT+IErujsxQUzTbV6poIIfui4YaoHywzZ9+iKLxxl+cBzfLZ4qZlTFt050wM/IYDovGmekQNr9vg== X-Received: by 2002:a05:622a:8d:b0:460:8d16:e8cc with SMTP id d75a77b69052e-46309331aa3mr187305441cf.16.1731356367498; Mon, 11 Nov 2024 12:19:27 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ff580e2asm66683971cf.67.2024.11.11.12.19.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:26 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v6 11/17] fanotify: add a helper to check for pre content events Date: Mon, 11 Nov 2024 15:18:00 -0500 Message-ID: <0b76f68806fefceae2618e5f135765e429b23025.1731355931.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Stat-Signature: 955gj4yx5essrexpwehfhh9gysfuey1p X-Rspamd-Queue-Id: 88A3C40013 X-Rspam-User: X-HE-Tag: 1731356326-487729 X-HE-Meta: U2FsdGVkX1/cydl7R3buJM8KjVovTqRBtDuE+bDmxwMmzHQFPgOIImiU8JnS6I97/vmQDniGtCwI3YKrFkuJL62+ejI9kEdYdyPSXLiGC8aSQG7ToCsExakkCgE3NY0SWL1WxqrtB/OvVs41n0WM66YMeYKGnfFv7C0wpr6/9VbbX8o/qTI+23mIvJGS8TTnhkWLESvxBmRE1KEQw/nQ0/EKfR87AdouieP8cw9caBvkAJDXlYPOy8oX0cBVrqlCIcX5+u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gFWwvrk/nCG7BnVag2kF8icr1H4izT0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000308, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We want to emit events during page fault, and calling into fanotify could be expensive, so add a helper to allow us to skip calling into fanotify from page fault. This will also be used to disable readahead for content watched files which will be handled in a subsequent patch. Reviewed-by: Christian Brauner Signed-off-by: Josef Bacik --- fs/notify/fsnotify.c | 16 ++++++++++++++++ include/linux/fsnotify_backend.h | 14 ++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 0696c1771b2a..a49c42c6ce01 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -203,6 +203,22 @@ static inline bool fsnotify_object_watched(struct inode *inode, __u32 mnt_mask, return mask & marks_mask & ALL_FSNOTIFY_EVENTS; } +#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS +bool fsnotify_file_has_pre_content_watches(struct file *file) +{ + struct inode *inode = file_inode(file); + __u32 mnt_mask = real_mount(file->f_path.mnt)->mnt_fsnotify_mask; + + if (!(inode->i_sb->s_iflags & SB_I_ALLOW_HSM)) + return false; + + return fsnotify_object_watched(inode, mnt_mask, + FSNOTIFY_PRE_CONTENT_EVENTS); +} +EXPORT_SYMBOL_GPL(fsnotify_file_has_pre_content_watches); +#endif + + /* * Notify this dentry's parent about a child's events with child name info * if parent is watching or if inode/sb/mount are interested in events with diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index abd292edb48c..e3a4a8e06fa0 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -896,6 +896,15 @@ static inline void fsnotify_init_event(struct fsnotify_event *event) INIT_LIST_HEAD(&event->list); } +#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS +bool fsnotify_file_has_pre_content_watches(struct file *file); +#else +static inline bool fsnotify_file_has_pre_content_watches(struct file *file) +{ + return false; +} +#endif /* CONFIG_FANOTIFY_ACCESS_PERMISSIONS */ + #else static inline int fsnotify(__u32 mask, const void *data, int data_type, @@ -934,6 +943,11 @@ static inline u32 fsnotify_get_cookie(void) static inline void fsnotify_unmount_inodes(struct super_block *sb) {} +static inline bool fsnotify_file_has_pre_content_watches(struct file *file) +{ + return false; +} + #endif /* CONFIG_FSNOTIFY */ #endif /* __KERNEL __ */