Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp207695pxt; Wed, 4 Aug 2021 09:07:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwb1Hprt8fy97KQ6X5vxO5HlgHB+Q/YgFlZnmnd0kRF1sjvAHyFwm0xokY0VJbhfvpCXGqR X-Received: by 2002:a6b:1642:: with SMTP id 63mr107610iow.68.1628093273285; Wed, 04 Aug 2021 09:07:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628093273; cv=none; d=google.com; s=arc-20160816; b=SJSyOdjhe4iaJ+HGN7LeZsTE2qDYMGu60TAKHH9RNlGD1Ae05R/pul2Z0iMpNV7Pev H5Zt2dyG8NUnbFG1B/xaQ5wQsA1KN8rj45iOG6GCans2j52vHCEVGYAmXAFKdOBGVts6 Z4PTjY/GWBdUf/Z6QJadfn8AUlSYxT8sI33x8Ua/7aEAetFk77jDWrQaI+N/7Vgc34xY m+q5RH87wyfBHhFxSDlKDIvdaeexw2GGJmAQl9Rw3s1k2An1yH0BCUvoslIYry6pv7kS 4DQW63rcDuVoMFK/BbbwLG4cMjqM4brs4J9RDSsjMEYlPGlpQe6pgyIW1sIaLWC5DQBm WSwA== 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=LzEyYhqF/6UYColmtmU+xaZ+3Kp/CCFrUT2UquoJjL4=; b=VBuTnIhW2ME91DnVkmAuACIV2O7mWrJ1bAnjIq2iTHY+tSxqrRDcJuggBd7xyJnMGZ WgHvm7GXO3U7zWiR+RTXkXYYc6/BbAC50ScDudp5ez3yZKJ93yof4ECSO2vSIdbW1rPV LQN0pWVEp+4iCz2vArRR4d73BKzqvBrpKVqW7NafxY5OncKjrN7jeuZvJ7HW77taeoKD J5V5ieGwhY16lKXNHpzQkt4aCxm2yqwAkImQ9WVO0Vp8bnaNldp4ayC1nmz2+nGO4Xzu QVlIpY7Wi20T5COVUDTNx5zKgvc4/ut1C0wF1BthfSkvuLPievqur1GUCBEiUEjUvizE mZQA== 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 j30si2439274ila.56.2021.08.04.09.07.41; Wed, 04 Aug 2021 09:07:53 -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 S231396AbhHDQGy (ORCPT + 99 others); Wed, 4 Aug 2021 12:06:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbhHDQGw (ORCPT ); Wed, 4 Aug 2021 12:06:52 -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 CD0F6C0613D5; Wed, 4 Aug 2021 09:06:39 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 738EE1F4080F 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, Jan Kara Subject: [PATCH v5 03/23] fanotify: Split fsid check from other fid mode checks Date: Wed, 4 Aug 2021 12:05:52 -0400 Message-Id: <20210804160612.3575505-4-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 FAN_FS_ERROR will require fsid, but not necessarily require the filesystem to expose a file handle. Split those checks into different functions, so they can be used separately when setting up an event. While there, update a comment about tmpfs having 0 fsid, which is no longer true. Reviewed-by: Amir Goldstein Reviewed-by: Jan Kara Signed-off-by: Gabriel Krisman Bertazi --- Changes since v2: - FAN_ERROR -> FAN_FS_ERROR (Amir) - Update comment (Amir) Changes since v1: (Amir) - Sort hunks to simplify diff. Changes since RFC: (Amir) - Rename fanotify_check_path_fsid -> fanotify_test_fsid. - Use dentry directly instead of path. --- fs/notify/fanotify/fanotify_user.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 68a53d3534f8..67b18dfe0025 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1192,16 +1192,15 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) return fd; } -/* Check if filesystem can encode a unique fid */ -static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) +static int fanotify_test_fsid(struct dentry *dentry, __kernel_fsid_t *fsid) { __kernel_fsid_t root_fsid; int err; /* - * Make sure path is not in filesystem with zero fsid (e.g. tmpfs). + * Make sure dentry is not of a filesystem with zero fsid (e.g. fuse). */ - err = vfs_get_fsid(path->dentry, fsid); + err = vfs_get_fsid(dentry, fsid); if (err) return err; @@ -1209,10 +1208,10 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) return -ENODEV; /* - * Make sure path is not inside a filesystem subvolume (e.g. btrfs) + * Make sure dentry is not of a filesystem subvolume (e.g. btrfs) * which uses a different fsid than sb root. */ - err = vfs_get_fsid(path->dentry->d_sb->s_root, &root_fsid); + err = vfs_get_fsid(dentry->d_sb->s_root, &root_fsid); if (err) return err; @@ -1220,6 +1219,12 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) root_fsid.val[1] != fsid->val[1]) return -EXDEV; + return 0; +} + +/* Check if filesystem can encode a unique fid */ +static int fanotify_test_fid(struct dentry *dentry) +{ /* * We need to make sure that the file system supports at least * encoding a file handle so user can use name_to_handle_at() to @@ -1227,8 +1232,8 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) * objects. However, name_to_handle_at() requires that the * filesystem also supports decoding file handles. */ - if (!path->dentry->d_sb->s_export_op || - !path->dentry->d_sb->s_export_op->fh_to_dentry) + if (!dentry->d_sb->s_export_op || + !dentry->d_sb->s_export_op->fh_to_dentry) return -EOPNOTSUPP; return 0; @@ -1379,7 +1384,11 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, } if (fid_mode) { - ret = fanotify_test_fid(&path, &__fsid); + ret = fanotify_test_fsid(path.dentry, &__fsid); + if (ret) + goto path_put_and_out; + + ret = fanotify_test_fid(path.dentry); if (ret) goto path_put_and_out; -- 2.32.0