Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3870190pxy; Mon, 26 Apr 2021 11:43:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQUK90Fhz7CLgGYdrqaDGgwohseebFabIfcOffm5JiGl34P50CcpNSAEOKJYPRA7kk0ZAn X-Received: by 2002:a50:bb27:: with SMTP id y36mr54651ede.365.1619462592166; Mon, 26 Apr 2021 11:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619462592; cv=none; d=google.com; s=arc-20160816; b=KvsLF7D8hlm/jsalms/70oXYlJJAjHs5zU69nAPqQ6OhRLhQc1cGc+/qKMtAX2gxsa 3xOdbNt0uz9ImYSsNXheVzbHiXHjzd7hpaPgmcMCYANaWh53lrLvabWXvm654tKqVu1b e4CppdQ522unfSGLMT+Y+o0o0nuU/y37CnRBzpCjINqWAj5dVVIF3tqFCx2ruzeV+GTR s+5lPQMtLAxYP2Hx4Fk7mWSpLzbvO8hv6uIKhTWUd+nkuWdgjx3PSAJ8hlN02hqF4bk2 hEGFrYX9hlJMAKvOHHtzaXMRtHkcV4DE3jo6OGjXHtwBITzIwLhhpUn2+stDoJVqR7Jh Jv9A== 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=2G7D+l2HQecO1LDp+O/ek7x2DTWrUgg/9odOrkE9CIg=; b=wx5N54qswSWaqkhaZbhFIwcdmIZ2WCLkNowQm/6RoTbPpiGuN3jInzONfA38KOAks5 ws8SwuCNatLHAvlfmX27MAfGGk8gmwY4nBnJj2Ws/4baSSSRGW+/qySzCTUbzDENMfwb OZBtTIQbtARLqE7pMDy7ArqssCr+EXYf+/Q/wzqLYy6hEYBCkVzWVfJ1JkQrOgExMBnc EFjo83+eHFxrwtEbaFerFahX7mt7/GUZlHgP+TWBQ5JQgaZLq4KJAwPnSGsKIjODpIdU 5TfrXWfgU72tFm3SO3M65QDacNXZJ7yaUn4Ogy/tuZFBNNcPoOylFX1Yd27O6URSgkqN 9oiA== 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 a22si547030edr.40.2021.04.26.11.42.48; Mon, 26 Apr 2021 11:43:12 -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 S239351AbhDZSnV (ORCPT + 99 others); Mon, 26 Apr 2021 14:43:21 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:47414 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239301AbhDZSnK (ORCPT ); Mon, 26 Apr 2021 14:43:10 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 8C38B1F41E27 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 02/15] fanotify: Split fsid check from other fid mode checks Date: Mon, 26 Apr 2021 14:41:48 -0400 Message-Id: <20210426184201.4177978-3-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 FAN_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 creating a mark. Signed-off-by: Gabriel Krisman Bertazi --- fs/notify/fanotify/fanotify_user.c | 35 +++++++++++++++++++----------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 0332c4afeec3..e0d113e3b65c 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1055,7 +1055,23 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) } /* Check if filesystem can encode a unique fid */ -static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) +static int fanotify_test_fid(struct path *path) +{ + /* + * 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 + * compare fid returned with event to the file handle of watched + * 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) + return -EOPNOTSUPP; + + return 0; +} + +static int fanotify_check_path_fsid(struct path *path, __kernel_fsid_t *fsid) { __kernel_fsid_t root_fsid; int err; @@ -1082,17 +1098,6 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) root_fsid.val[1] != fsid->val[1]) return -EXDEV; - /* - * 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 - * compare fid returned with event to the file handle of watched - * 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) - return -EOPNOTSUPP; - return 0; } @@ -1230,7 +1235,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_check_path_fsid(&path, &__fsid); + if (ret) + goto path_put_and_out; + + ret = fanotify_test_fid(&path); if (ret) goto path_put_and_out; -- 2.31.0