Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp387874rdb; Thu, 19 Oct 2023 07:23:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFRUe/KGb+QAaUd5YOpFPzaebIDoTwENm7SWMXnhZKBErKK6PPJKu5F6mCT1k9OoBcYuRE+ X-Received: by 2002:a17:902:e28b:b0:1c5:f7e2:c5e0 with SMTP id o11-20020a170902e28b00b001c5f7e2c5e0mr1986615plc.51.1697725424548; Thu, 19 Oct 2023 07:23:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697725424; cv=none; d=google.com; s=arc-20160816; b=T1ZD8ut/Dr9FbH+HebJXhBIvTWtYijXLb22Gzd2x4OYOigM7B87x9dko78p2r82XjW bnCGXZceKv0+VymZXI9Toat5jS0Fd3xHxh84/WwxFrgvweCax7xVKCLBNPKrFtHXB+2+ y7o8isTccHNzcxrGQmrozXwoIZAmEhC2lf7yQhMg67i2b0madGCkhm6e86y0SjMBA/wq AZXqzmQnGo12lW2LftW0jqYUtyEq4Xy1UaPqY3a1Nv5ZDvpEvcfj6VUhBfrWQRdT3c4f eOIOmlqPejgyHymFI0I9SLr8oTbj6++euPETCLICb/hdR1QNeQlkhpCEZeWy9C12kliE kscA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=vHVKbvz5KKhBcLpNoYotjBcpsCJS93EZbgmfvvObLpI=; fh=lDiGqg3gPmyeCipTkGF/rKa36svKb+zKwXdWWECJhIc=; b=v0gCFf3AXM7AUq19mgHEEHNmZUuCl4ACzIr5saMfvcd0m9Y/igALIgN+eVCH5uqcrX IKQr3kAQ01Ju9L9sJHpao+SXME/LbcxvjxOJrDjnqMaebfXeV+Cwf5joUy+Jkyz7f1TK ylD7b4pv8o1PM41qB1lqYvsb0c90lUJC3JkqPkEpP/zrHFcC30+2aDxrKb7Ux5T3eYcc 2wBMPJjgmyC3MYw1OMqhbS13CKRaCv+BIevDPPlw2HoSc2gbevtAnYwBFpaMwp/2aQX/ wnli4pK56eUiry9fpRLcqp3PJfC1q1PO9FIttiZLejJzzMRiwQdRzd0NYRMzYB698vmW +sTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=vVR3nSdq; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=w3uMPTFc; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id k15-20020a170902c40f00b001c0c4be62basi2539610plk.617.2023.10.19.07.23.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:23:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=vVR3nSdq; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=w3uMPTFc; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id E487281C0C11; Thu, 19 Oct 2023 07:23:38 -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 S235408AbjJSOXi (ORCPT + 99 others); Thu, 19 Oct 2023 10:23:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235412AbjJSOXi (ORCPT ); Thu, 19 Oct 2023 10:23:38 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32C29119; Thu, 19 Oct 2023 07:23:36 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7843F21A48; Thu, 19 Oct 2023 14:23:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1697725414; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vHVKbvz5KKhBcLpNoYotjBcpsCJS93EZbgmfvvObLpI=; b=vVR3nSdqgJ+JeDlDXdQb2sJdrOxl0PMAGBBcfbKJYJP95A+RRojpl5FujNvF8mPk5jlmRu To8Iy8c0Zoy6ojJl241PwO+B0C+i7HjJzvbFI5TgAiqCTryRZNQQprR2anFxH/FIU+Uf5Z Lxg5CtP777N5jo/UgHPZg1SfOPxVsFo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1697725414; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vHVKbvz5KKhBcLpNoYotjBcpsCJS93EZbgmfvvObLpI=; b=w3uMPTFcTPrXfpqnkdeLtmNuaJ6ylNuS0rD/fQPpp+6RJ57WUfSyCRloZ1x0UxPyxp1ak+ 35PMnX5kf/WgiHDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6B84B139C2; Thu, 19 Oct 2023 14:23:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QO47GuY7MWXRfQAAMHmgww (envelope-from ); Thu, 19 Oct 2023 14:23:34 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id EEBFBA06B0; Thu, 19 Oct 2023 16:23:33 +0200 (CEST) Date: Thu, 19 Oct 2023 16:23:33 +0200 From: Jan Kara To: Amir Goldstein Cc: Jan Kara , Jeff Layton , Chuck Lever , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org Subject: Re: [PATCH 2/5] exportfs: add helpers to check if filesystem can encode/decode file handles Message-ID: <20231019142333.tuao3phsvqqgfqix@quack3> References: <20231018100000.2453965-1-amir73il@gmail.com> <20231018100000.2453965-3-amir73il@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231018100000.2453965-3-amir73il@gmail.com> Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -6.60 X-Spamd-Result: default: False [-6.60 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-3.00)[-1.000]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RCPT_COUNT_SEVEN(0.00)[7]; FREEMAIL_TO(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_NOT_FQDN(0.50)[]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,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]); Thu, 19 Oct 2023 07:23:39 -0700 (PDT) On Wed 18-10-23 12:59:57, Amir Goldstein wrote: > The logic of whether filesystem can encode/decode file handles is open > coded in many places. > > In preparation to changing the logic, move the open coded logic into > inline helpers. > > Signed-off-by: Amir Goldstein Yeah, good cleanup. Feel free to add: Reviewed-by: Jan Kara Honza > --- > 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(-) > > 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, struct fid *fid, > { > const struct export_operations *nop = inode->i_sb->s_export_op; > > - /* > - * 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; > > if (nop && nop->encode_fh) > @@ -456,7 +452,7 @@ exportfs_decode_fh_raw(struct vfsmount *mnt, struct fid *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 = 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 *path, > /* > * 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; > > 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; > } > > - 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/fanotify_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; > > /* > @@ -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 != FAN_MARK_INODE && !nop->fh_to_dentry) > + if (mark_type != FAN_MARK_INODE && !exportfs_can_decode_fh(nop)) > return -EOPNOTSUPP; > > 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; > > - if (!sb->s_export_op || !sb->s_export_op->fh_to_dentry) > + if (!exportfs_can_decode_fh(sb->s_export_op)) > return 0; > > 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 *inode, struct fid *fid, > extern int exportfs_encode_fh(struct dentry *dentry, struct fid *fid, > int *max_len, int flags); > > +static inline bool exportfs_can_encode_fid(const struct export_operations *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 *fid, > int *max_len) > { > -- > 2.34.1 > -- Jan Kara SUSE Labs, CR