Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3837804rdg; Wed, 18 Oct 2023 07:29:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhlmiYfBiCgvqD4RIX28jcAD6DdLXubnZ+6UGilxEKBfkVDUSDmyXwWl05wF3qt1BplpYm X-Received: by 2002:a17:902:e5c8:b0:1ca:35cb:dbb with SMTP id u8-20020a170902e5c800b001ca35cb0dbbmr6551559plf.46.1697639385743; Wed, 18 Oct 2023 07:29:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697639385; cv=none; d=google.com; s=arc-20160816; b=k4VjyXHaWHMR69dsDPbignsnfIvV/OslYGdu6nGORg0Llgb7d6hMdTDsoIZchK6ohi zX2X4XHseD78KiFKuliwzryhqTP+1g5QlbFwAlFXjr86rI0vzS+TGCQmw/yHM3yhv2iq Quc3UGV3weB8rIZOu4DumgcWvTqsPovpWl8WI2io1RJKmOlGkWcHyUCIL2nxXsdHddUH FxGhw0uIiJEb3b42eaDPkzQ83UNpSFYGbRbHEQx2G6UhUUqswlyNu6W4ifwMYpi00ER1 vT6k7b5S2YwLV5ystcxOzAtK8RzxBOvCESmpVwDYTTgZKQfnuSa7iSN7kLah4KVnASLq jXuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=ToVU66LFOtqSy5U2cCO/umcVtMP/MDfzI1uRE3dbYGM=; fh=UhF25t0OeCAcCrVXPjAh8OFp6ZzVKN6UmHeNfp8T5po=; b=f4wKMbGHSQdHnmQDlPlNUJfCV0X35BqnF2KpD7q/3Avl3hUz/CDAgJV8yQy1WfKDGu 5d87fXymWfPLQ8WPcYRRRULNLdhLBWSUx+eZbfHx8MOWIZIoANXDHJUf66HyMTRE579n 9q7dxqA8itbzr/DDT3aTIMGUL3Chg8BFZheYnuLUOXg4pO7UqD2aYmGyEzvz0JHMCx9d KjNIYqRpyfEdoSP822vkoJ2r8CmHgjpSHdB09nBeAt9em1lTtlP014LvTxtGfU3p/n4p OsvxkE2bX1SQaZLu/l4L2qXmw7WlcvM64oA3ZZ/BDA5fY9y+ST9go3dinfRE5BV1Rv7V wzzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GgS5BPAx; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id kf15-20020a17090305cf00b001b8ac52a19esi2388198plb.436.2023.10.18.07.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 07:29:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GgS5BPAx; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 3E91180238BB; Wed, 18 Oct 2023 07:29:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345456AbjJRO3Z (ORCPT + 99 others); Wed, 18 Oct 2023 10:29:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345528AbjJRO3P (ORCPT ); Wed, 18 Oct 2023 10:29:15 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 274801BC3 for ; Wed, 18 Oct 2023 07:15:14 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AB27C43395; Wed, 18 Oct 2023 14:15:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697638513; bh=s6aY1ZS/yXo5J/gpAx2yUrzGUVyMMUnsaK92PMe3VII=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=GgS5BPAxJF1KKE3iLdd8lnhjobPqK3vI6/tDryYftWSIb5E+JLWCDk4VbkjZ0NCdz 6MZWMJ8gyzFNFwhJs5EtoaqrvBu0Bxb5O1aVXJe9yl9TcqSKbyLPMsxE8C+crki0Hh bZBdy5Z+VPiSNNoXOBjWJEhEuwihLF3qiyRd/0S9fjQQSPno863UlZkbXjsj5jpesd 3/fXhuQu2Yu2+PdnBqFN4jPTCDt8R4RxbBKeLJ6Yy2P0+I6hBiRy/IpPHiU+v6mhtU c49DbKXVmb/048/8Wp3vK4cJMAhUECdRSVBA6bklHrktJOuqpDalg1BrXCQaDtbUAD xKDVhfVMUfXnw== Message-ID: <59e186df80ae6a841ccfada0369110b301ebbaa2.camel@kernel.org> Subject: Re: [PATCH 2/5] exportfs: add helpers to check if filesystem can encode/decode file handles From: Jeff Layton To: Amir Goldstein , Jan Kara Cc: Chuck Lever , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org Date: Wed, 18 Oct 2023 10:15:11 -0400 In-Reply-To: <20231018100000.2453965-3-amir73il@gmail.com> References: <20231018100000.2453965-1-amir73il@gmail.com> <20231018100000.2453965-3-amir73il@gmail.com> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 18 Oct 2023 07:29:39 -0700 (PDT) On Wed, 2023-10-18 at 12:59 +0300, Amir Goldstein wrote: > The logic of whether filesystem can encode/decode file handles is open > coded in many places. >=20 > In preparation to changing the logic, move the open coded logic into > inline helpers. >=20 > Signed-off-by: Amir Goldstein > --- > fs/exportfs/expfs.c | 8 ++------ > fs/fhandle.c | 6 +----- > fs/nfsd/export.c | 3 +-- > fs/notify/fanotify/fanotify_user.c | 4 ++-- > fs/overlayfs/util.c | 2 +- > include/linux/exportfs.h | 27 +++++++++++++++++++++++++++ > 6 files changed, 34 insertions(+), 16 deletions(-) >=20 > diff --git a/fs/exportfs/expfs.c b/fs/exportfs/expfs.c > index c20704aa21b3..9ee205df8fa7 100644 > --- a/fs/exportfs/expfs.c > +++ b/fs/exportfs/expfs.c > @@ -396,11 +396,7 @@ int exportfs_encode_inode_fh(struct inode *inode, st= ruct fid *fid, > { > const struct export_operations *nop =3D inode->i_sb->s_export_op; > =20 > - /* > - * If a decodeable file handle was requested, we need to make sure that > - * filesystem can decode file handles. > - */ > - if (nop && !(flags & EXPORT_FH_FID) && !nop->fh_to_dentry) > + if (!exportfs_can_encode_fh(nop, flags)) > return -EOPNOTSUPP; > =20 > if (nop && nop->encode_fh) > @@ -456,7 +452,7 @@ exportfs_decode_fh_raw(struct vfsmount *mnt, struct f= id *fid, int fh_len, > /* > * Try to get any dentry for the given file handle from the filesystem. > */ > - if (!nop || !nop->fh_to_dentry) > + if (!exportfs_can_decode_fh(nop)) > return ERR_PTR(-ESTALE); > result =3D nop->fh_to_dentry(mnt->mnt_sb, fid, fh_len, fileid_type); > if (IS_ERR_OR_NULL(result)) > diff --git a/fs/fhandle.c b/fs/fhandle.c > index 6ea8d35a9382..18b3ba8dc8ea 100644 > --- a/fs/fhandle.c > +++ b/fs/fhandle.c > @@ -26,12 +26,8 @@ static long do_sys_name_to_handle(const struct path *p= ath, > /* > * We need to make sure whether the file system support decoding of > * the file handle if decodeable file handle was requested. > - * Otherwise, even empty export_operations are sufficient to opt-in > - * to encoding FIDs. > */ > - if (!path->dentry->d_sb->s_export_op || > - (!(fh_flags & EXPORT_FH_FID) && > - !path->dentry->d_sb->s_export_op->fh_to_dentry)) > + if (!exportfs_can_encode_fh(path->dentry->d_sb->s_export_op, fh_flags)) > return -EOPNOTSUPP; > =20 > if (copy_from_user(&f_handle, ufh, sizeof(struct file_handle))) > diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c > index 11a0eaa2f914..dc99dfc1d411 100644 > --- a/fs/nfsd/export.c > +++ b/fs/nfsd/export.c > @@ -421,8 +421,7 @@ static int check_export(struct path *path, int *flags= , unsigned char *uuid) > return -EINVAL; > } > =20 > - if (!inode->i_sb->s_export_op || > - !inode->i_sb->s_export_op->fh_to_dentry) { > + if (!exportfs_can_decode_fh(inode->i_sb->s_export_op)) { > dprintk("exp_export: export of invalid fs type.\n"); > return -EINVAL; > } > diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fano= tify_user.c > index 537c70beaad0..ce926eb9feea 100644 > --- a/fs/notify/fanotify/fanotify_user.c > +++ b/fs/notify/fanotify/fanotify_user.c > @@ -1595,7 +1595,7 @@ static int fanotify_test_fid(struct dentry *dentry,= unsigned int flags) > * file handles so user can use name_to_handle_at() to compare fids > * reported with events to the file handle of watched objects. > */ > - if (!nop) > + if (!exportfs_can_encode_fid(nop)) > return -EOPNOTSUPP; > =20 > /* > @@ -1603,7 +1603,7 @@ static int fanotify_test_fid(struct dentry *dentry,= unsigned int flags) > * supports decoding file handles, so user has a way to map back the > * reported fids to filesystem objects. > */ > - if (mark_type !=3D FAN_MARK_INODE && !nop->fh_to_dentry) > + if (mark_type !=3D FAN_MARK_INODE && !exportfs_can_decode_fh(nop)) > return -EOPNOTSUPP; > =20 > return 0; > diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c > index 89e0d60d35b6..f0a712214ec2 100644 > --- a/fs/overlayfs/util.c > +++ b/fs/overlayfs/util.c > @@ -55,7 +55,7 @@ int ovl_can_decode_fh(struct super_block *sb) > if (!capable(CAP_DAC_READ_SEARCH)) > return 0; > =20 > - if (!sb->s_export_op || !sb->s_export_op->fh_to_dentry) > + if (!exportfs_can_decode_fh(sb->s_export_op)) > return 0; > =20 > return sb->s_export_op->encode_fh ? -1 : FILEID_INO32_GEN; > diff --git a/include/linux/exportfs.h b/include/linux/exportfs.h > index 11fbd0ee1370..5b3c9f30b422 100644 > --- a/include/linux/exportfs.h > +++ b/include/linux/exportfs.h > @@ -233,6 +233,33 @@ extern int exportfs_encode_inode_fh(struct inode *in= ode, struct fid *fid, > extern int exportfs_encode_fh(struct dentry *dentry, struct fid *fid, > int *max_len, int flags); > =20 > +static inline bool exportfs_can_encode_fid(const struct export_operation= s *nop) > +{ > + return nop; > +} > + > +static inline bool exportfs_can_decode_fh(const struct export_operations= *nop) > +{ > + return nop && nop->fh_to_dentry; > +} > + > +static inline bool exportfs_can_encode_fh(const struct export_operations= *nop, > + int fh_flags) > +{ > + /* > + * If a non-decodeable file handle was requested, we only need to make > + * sure that filesystem can encode file handles. > + */ > + if (fh_flags & EXPORT_FH_FID) > + return exportfs_can_encode_fid(nop); > + > + /* > + * If a decodeable file handle was requested, we need to make sure that > + * filesystem can also decode file handles. > + */ > + return exportfs_can_decode_fh(nop); > +} > + > static inline int exportfs_encode_fid(struct inode *inode, struct fid *f= id, > int *max_len) > { Nice cleanup. Reviewed-by: Jeff Layton