From patchwork Wed Oct 18 09:59:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 13426807 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 990EBCDB483 for ; Wed, 18 Oct 2023 10:00:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229563AbjJRKAL (ORCPT ); Wed, 18 Oct 2023 06:00:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjJRKAK (ORCPT ); Wed, 18 Oct 2023 06:00:10 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A553EBA; Wed, 18 Oct 2023 03:00:08 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-32da4ffd7e5so2462513f8f.0; Wed, 18 Oct 2023 03:00:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697623207; x=1698228007; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qpDN5TJtQWNiSAgsJjoFSpeVl5Mc6XEDfVWBIiGhfG8=; b=mAEvjrQJM3BaQvnHq332ssLG84gfDbky393awp3ZZVzTNxBN6ZcY+XX+i7TOi+zRof 6emDPJzPN6pJUDhi1Ysewt9UrR9zpYI9gxL2soGv0RmhZ8RWLuL1yFO6HUy7cPGZgt94 8UuoNukevrWF25zBjG4wSKDwYyKdQWFmJni2TbgDA0RY02jXpNm6wiOuMYqD39yDnM6T 6VQXOG0axrBztrCm9TgxCry8Q4e1sr6wP9Ru9+AKb7GuNDtCQIuDTJsZOoE1aF9oKqpj sTwe9OpaQGQUjayFRnbdtoNNROjIMwm1xs103Qjg1YpVi4hACNnZq42b3LV62Thq+xCy W9qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697623207; x=1698228007; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qpDN5TJtQWNiSAgsJjoFSpeVl5Mc6XEDfVWBIiGhfG8=; b=oV9NZvWkmlTQLNNe1RAqJyww8LG6EamjEYxB2bimpVPt2F75GxFBWtL+U6yiPBU9qZ a3h/AffuYoaJg2qJ5LSyOLn418m4bo9xmjiBaqnyH+J1fuI6yxLXTP8Pxi5O3voQhKE+ UY1WSLTGuAU3tOo4V05coIQ2Bsa2REsPTh43yWJNOxU0JPvUh6TNEm9DWdnwLs+/iUZh Pwu1MMeBWwdabKdjXl2OL/Bn2oWPSuX0DuudjLXNJyLUG1CmPJcjHdhcoSVRBL2AveWo KDgm8lNiH039qRIMcRVSQQA18LOIP65L6UGDUffIR1WahXr1O7sErX04aLCk3vZ0Uh// 773g== X-Gm-Message-State: AOJu0YzUnPRMIZHVzU9rmxqCQfNpSZs48cmEWdq0S/a89X1O3mPRe4t+ CJCldxpsEV8ZheXEIoYBx1g= X-Google-Smtp-Source: AGHT+IFM57tNvjUDTErp8Tg2QlcT3qIfdSIDjHwtaZ3d9FJgM4lGgPV9+40qcf3qgJdGD0/lB2zbpw== X-Received: by 2002:a5d:46cb:0:b0:32d:c5fd:159b with SMTP id g11-20020a5d46cb000000b0032dc5fd159bmr5028168wrs.4.1697623206794; Wed, 18 Oct 2023 03:00:06 -0700 (PDT) Received: from amir-ThinkPad-T480.lan ([5.29.249.86]) by smtp.gmail.com with ESMTPSA id y34-20020a05600c342200b004063977eccesm1222017wmp.42.2023.10.18.03.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 03:00:06 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Jeff Layton , Chuck Lever , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org Subject: [PATCH 1/5] fanotify: limit reporting of event with non-decodeable file handles Date: Wed, 18 Oct 2023 12:59:56 +0300 Message-Id: <20231018100000.2453965-2-amir73il@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018100000.2453965-1-amir73il@gmail.com> References: <20231018100000.2453965-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Commit a95aef69a740 ("fanotify: support reporting non-decodeable file handles") merged in v6.5-rc1, added the ability to use an fanotify group with FAN_REPORT_FID mode to watch filesystems that do not support nfs export, but do know how to encode non-decodeable file handles, with the newly introduced AT_HANDLE_FID flag. At the time that this commit was merged, there were no filesystems in-tree with those traits. Commit 16aac5ad1fa9 ("ovl: support encoding non-decodable file handles"), merged in v6.6-rc1, added this trait to overlayfs, thus allowing fanotify watching of overlayfs with FAN_REPORT_FID mode. In retrospect, allowing an fanotify filesystem/mount mark on such filesystem in FAN_REPORT_FID mode will result in getting events with file handles, without the ability to resolve the filesystem objects from those file handles (i.e. no open_by_handle_at() support). For v6.6, the safer option would be to allow this mode for inode marks only, where the caller has the opportunity to use name_to_handle_at() at the time of setting the mark. In the future we can revise this decision. Fixes: a95aef69a740 ("fanotify: support reporting non-decodeable file handles") Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify_user.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index f69c451018e3..537c70beaad0 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1585,16 +1585,25 @@ static int fanotify_test_fsid(struct dentry *dentry, __kernel_fsid_t *fsid) } /* Check if filesystem can encode a unique fid */ -static int fanotify_test_fid(struct dentry *dentry) +static int fanotify_test_fid(struct dentry *dentry, unsigned int flags) { + unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; + const struct export_operations *nop = dentry->d_sb->s_export_op; + + /* + * We need to make sure that the filesystem supports encoding of + * 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) + return -EOPNOTSUPP; + /* - * 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, even the relaxed AT_HANDLE_FID flag requires - * at least empty export_operations for ecoding unique file ids. + * For sb/mount mark, we also need to make sure that the filesystem + * supports decoding file handles, so user has a way to map back the + * reported fids to filesystem objects. */ - if (!dentry->d_sb->s_export_op) + if (mark_type != FAN_MARK_INODE && !nop->fh_to_dentry) return -EOPNOTSUPP; return 0; @@ -1812,7 +1821,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, if (ret) goto path_put_and_out; - ret = fanotify_test_fid(path.dentry); + ret = fanotify_test_fid(path.dentry, flags); if (ret) goto path_put_and_out; From patchwork Wed Oct 18 09:59:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 13426808 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 712C5CDB47E for ; Wed, 18 Oct 2023 10:00:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229570AbjJRKAN (ORCPT ); Wed, 18 Oct 2023 06:00:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjJRKAM (ORCPT ); Wed, 18 Oct 2023 06:00:12 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54A4AF7; Wed, 18 Oct 2023 03:00:10 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-405361bb94eso71527805e9.0; Wed, 18 Oct 2023 03:00:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697623209; x=1698228009; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hYD+wgC503kgQ3p5MDhETIjO1ikl1uHN/Qh1ZpMvt48=; b=WM9rKn0souknudtDZASndqY2y3os/DxQq1IthOmIOzmotC2fOg7KqOZy/O/u7kL8wS 59lTC41zZecL+EySrg2PSGZKyRSrSaFhHifjXBG5ojp6ob4Xi0Gg1q6+Sb53ukq3BnXs uu5EYCOKDcahbSAZSDXk7H6vt8z+DyWQINh2T76fb00cVBqjMfmN4L/9JszXgRoDp7eo B1UxVQ8I5lNaQjPksBWZxROPbIkxEESv7h5lpsQbcRsiDbyULJG4k9VV6TYA+2xIxCnl HIlekKqR/gKfCRD5KZf79qUEN/ZvvFWeMfeB+SIvUMTzIpHnuIUxEsgmkTI8RAM/K21s j64w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697623209; x=1698228009; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hYD+wgC503kgQ3p5MDhETIjO1ikl1uHN/Qh1ZpMvt48=; b=l3WO8XdL6L8R9NpICgcVIS3CQBlnnC0Y46Naw6gXdbg2/a32taDKmbbUQNkNSE61G8 Wc5FKOh9WSUaDmk1WszDNggkTrwbO75uTo8OGSFJoO7WpUHkykK8pK5L+RIpkot6bmRq qqGDWKlma5L7bvNpTHPfZcK1Db+sdchInrzRvsOKq5dxoC2o+II73ePzCqD2TrRSUgeC e0D4HkYOKIqjJkf+gofbaKUPl2dG/TstFlFIFitQDWKBI0j4eGluF0xZE20I4B8IK1vi xRbHH7vFuMN/REA5xOWT7ksx+hT/lOUjCKeSOjqRKjFW3QzBu7L4j2XJlMU4Ux78Za7P mNAQ== X-Gm-Message-State: AOJu0Yx8+qOZ82qfWqgsaKcCfqZvzQSwSAw7YEZgGM3caqRW10iUAxX+ vNaGFVVxwdlDUacpEDHcif8= X-Google-Smtp-Source: AGHT+IGYCqCltyFIiCLKUIMDb2fa3mqH0MHEoGRiioyP/M10nwKZ7u5dZ8opR4dmIvF6Xr7jzf+D/Q== X-Received: by 2002:a05:600c:1c88:b0:407:5a7d:45a8 with SMTP id k8-20020a05600c1c8800b004075a7d45a8mr3856101wms.31.1697623208368; Wed, 18 Oct 2023 03:00:08 -0700 (PDT) Received: from amir-ThinkPad-T480.lan ([5.29.249.86]) by smtp.gmail.com with ESMTPSA id y34-20020a05600c342200b004063977eccesm1222017wmp.42.2023.10.18.03.00.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 03:00:07 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Jeff Layton , Chuck Lever , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org Subject: [PATCH 2/5] exportfs: add helpers to check if filesystem can encode/decode file handles Date: Wed, 18 Oct 2023 12:59:57 +0300 Message-Id: <20231018100000.2453965-3-amir73il@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018100000.2453965-1-amir73il@gmail.com> References: <20231018100000.2453965-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org 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 Reviewed-by: Jeff Layton Reviewed-by: Jan Kara --- 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) { From patchwork Wed Oct 18 09:59:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 13426809 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE9C1CDB47E for ; Wed, 18 Oct 2023 10:00:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229605AbjJRKAQ (ORCPT ); Wed, 18 Oct 2023 06:00:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjJRKAP (ORCPT ); Wed, 18 Oct 2023 06:00:15 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B5B3B0; Wed, 18 Oct 2023 03:00:12 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40684f53bfcso58586305e9.0; Wed, 18 Oct 2023 03:00:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697623211; x=1698228011; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bx+RlS47X3pEZGks8fmVGfUUr8kwPiO26j32N14XYVM=; b=iYueOKcxJpZpLiP6Y/XlDJaTsMuHeqjIzzp83J668IqtGff15rCjI4pjurOM/qxhtJ adG/9sGbBcCuVDY/jP7zvby7q1tNmTwCSkSVucRgGPvRoDfokzcVes7cBjdqC2AK0SRn lfk0BIhcpyjJCZTLUNsS5IHkx9zULYQlSEpPsKyQsshlst8Xszk5UziNN1Ul/lhf5LlS reCSRZaAXTfTw/h4FyHU/FkAQqfhnCN8JWw7aqjOxLcD4xG8XlqdwowOBsclsNBDjaX6 ssijJIUvHtt+wrR4bjwVoqM5Hljrd4UkUIWTxsOca6wAlhC4zC7fkxW2bz6BNSJ7Lds/ 7NMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697623211; x=1698228011; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bx+RlS47X3pEZGks8fmVGfUUr8kwPiO26j32N14XYVM=; b=lVJz4YG0tNMTPWgSZ3qSAnqe1APgqpoFoE2gAFdB5oEFpIqJ8afSKpoApNzxUY82MF S50HsewvwjEajOSLxlW5SpnX1kN4U95QIP+xIgCJciYiwluE1r3PqLgZr4xq6vw1nUUt cvrdjtinyj47NOi2qKAqvXZtCnSu7XY7uNnmYGZeBnjgy/zjGgfSgv5A2RMRtV1vQoRv HehS088J7XGlR+VjWOoeXSDOFW9utaOm6cZ0wHrjIShduHSH/1fTmDjOOvEa5CCB5NVz veW3MAzvCW5u+GhYdl3lk6D2XHc90yt5nB5oxNT/nwn7fq5IgCQ4IS+f6l798G+rlbji DRZA== X-Gm-Message-State: AOJu0Yx/Ls5ocps4WFD+UYbaIwV9pta7Lc9Trvw21GHEOkul4eFK5PZ0 NsP2FanoEOWLyWB6WrPOcus= X-Google-Smtp-Source: AGHT+IFJF2E/fGv5Z6ATh11kB/T1HNwWL3eoowF20WT25ghgaRx+hrvHZWA3j5a2HZgCFBcEXoSp3w== X-Received: by 2002:a05:600c:524a:b0:405:3dd0:6ee9 with SMTP id fc10-20020a05600c524a00b004053dd06ee9mr3619088wmb.34.1697623210803; Wed, 18 Oct 2023 03:00:10 -0700 (PDT) Received: from amir-ThinkPad-T480.lan ([5.29.249.86]) by smtp.gmail.com with ESMTPSA id y34-20020a05600c342200b004063977eccesm1222017wmp.42.2023.10.18.03.00.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 03:00:10 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Jeff Layton , Chuck Lever , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, David Sterba , Luis de Bethencourt , Salah Triki , Gao Xiang , Chao Yu , "Theodore Ts'o" , Andreas Dilger , Jaegeuk Kim , OGAWA Hirofumi , Dave Kleikamp , David Woodhouse , Richard Weinberger , Anton Altaparmakov , Konstantin Komarov , Steve French , Phillip Lougher , Evgeniy Dushistov Subject: [PATCH 3/5] exportfs: make ->encode_fh() a mandatory method for NFS export Date: Wed, 18 Oct 2023 12:59:58 +0300 Message-Id: <20231018100000.2453965-4-amir73il@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018100000.2453965-1-amir73il@gmail.com> References: <20231018100000.2453965-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org export_operations ->encode_fh() no longer has a default implementation to encode FILEID_INO32_GEN* file handles. Rename the default helper for encoding FILEID_INO32_GEN* file handles to generic_encode_ino32_fh() and convert the filesystems that used the default implementation to use the generic helper explicitly. This is a step towards allowing filesystems to encode non-decodeable file handles for fanotify without having to implement any export_operations. Signed-off-by: Amir Goldstein Reviewed-by: Jeff Layton Acked-by: Chuck Lever --- Documentation/filesystems/nfs/exporting.rst | 7 ++----- Documentation/filesystems/porting.rst | 9 +++++++++ fs/affs/namei.c | 1 + fs/befs/linuxvfs.c | 1 + fs/efs/super.c | 1 + fs/erofs/super.c | 1 + fs/exportfs/expfs.c | 14 ++++++++------ fs/ext2/super.c | 1 + fs/ext4/super.c | 1 + fs/f2fs/super.c | 1 + fs/fat/nfs.c | 1 + fs/jffs2/super.c | 1 + fs/jfs/super.c | 1 + fs/ntfs/namei.c | 1 + fs/ntfs3/super.c | 1 + fs/smb/client/export.c | 9 +++------ fs/squashfs/export.c | 1 + fs/ufs/super.c | 1 + include/linux/exportfs.h | 4 +++- 19 files changed, 39 insertions(+), 18 deletions(-) diff --git a/Documentation/filesystems/nfs/exporting.rst b/Documentation/filesystems/nfs/exporting.rst index 4b30daee399a..de64d2d002a2 100644 --- a/Documentation/filesystems/nfs/exporting.rst +++ b/Documentation/filesystems/nfs/exporting.rst @@ -122,12 +122,9 @@ are exportable by setting the s_export_op field in the struct super_block. This field must point to a "struct export_operations" struct which has the following members: - encode_fh (optional) + encode_fh (mandatory) Takes a dentry and creates a filehandle fragment which may later be used - to find or create a dentry for the same object. The default - implementation creates a filehandle fragment that encodes a 32bit inode - and generation number for the inode encoded, and if necessary the - same information for the parent. + to find or create a dentry for the same object. fh_to_dentry (mandatory) Given a filehandle fragment, this should find the implied object and diff --git a/Documentation/filesystems/porting.rst b/Documentation/filesystems/porting.rst index 4d05b9862451..197ef78a5014 100644 --- a/Documentation/filesystems/porting.rst +++ b/Documentation/filesystems/porting.rst @@ -1045,3 +1045,12 @@ filesystem type is now moved to a later point when the devices are closed: As this is a VFS level change it has no practical consequences for filesystems other than that all of them must use one of the provided kill_litter_super(), kill_anon_super(), or kill_block_super() helpers. + +--- + +**mandatory** + +export_operations ->encode_fh() no longer has a default implementation to +encode FILEID_INO32_GEN* file handles. +Fillesystems that used the default implementation may use the generic helper +generic_encode_ino32_fh() explicitly. diff --git a/fs/affs/namei.c b/fs/affs/namei.c index 2fe4a5832fcf..d6b9758ee23d 100644 --- a/fs/affs/namei.c +++ b/fs/affs/namei.c @@ -568,6 +568,7 @@ static struct dentry *affs_fh_to_parent(struct super_block *sb, struct fid *fid, } const struct export_operations affs_export_ops = { + .encode_fh = generic_encode_ino32_fh, .fh_to_dentry = affs_fh_to_dentry, .fh_to_parent = affs_fh_to_parent, .get_parent = affs_get_parent, diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c index 9a16a51fbb88..410dcaffd5ab 100644 --- a/fs/befs/linuxvfs.c +++ b/fs/befs/linuxvfs.c @@ -96,6 +96,7 @@ static const struct address_space_operations befs_symlink_aops = { }; static const struct export_operations befs_export_operations = { + .encode_fh = generic_encode_ino32_fh, .fh_to_dentry = befs_fh_to_dentry, .fh_to_parent = befs_fh_to_parent, .get_parent = befs_get_parent, diff --git a/fs/efs/super.c b/fs/efs/super.c index b287f47c165b..f17fdac76b2e 100644 --- a/fs/efs/super.c +++ b/fs/efs/super.c @@ -123,6 +123,7 @@ static const struct super_operations efs_superblock_operations = { }; static const struct export_operations efs_export_ops = { + .encode_fh = generic_encode_ino32_fh, .fh_to_dentry = efs_fh_to_dentry, .fh_to_parent = efs_fh_to_parent, .get_parent = efs_get_parent, diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 3700af9ee173..edbe07a24156 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -626,6 +626,7 @@ static struct dentry *erofs_get_parent(struct dentry *child) } static const struct export_operations erofs_export_ops = { + .encode_fh = generic_encode_ino32_fh, .fh_to_dentry = erofs_fh_to_dentry, .fh_to_parent = erofs_fh_to_parent, .get_parent = erofs_get_parent, diff --git a/fs/exportfs/expfs.c b/fs/exportfs/expfs.c index 9ee205df8fa7..30da4539e257 100644 --- a/fs/exportfs/expfs.c +++ b/fs/exportfs/expfs.c @@ -343,20 +343,21 @@ static int get_name(const struct path *path, char *name, struct dentry *child) } /** - * export_encode_fh - default export_operations->encode_fh function + * generic_encode_ino32_fh - generic export_operations->encode_fh function * @inode: the object to encode - * @fid: where to store the file handle fragment + * @fh: where to store the file handle fragment * @max_len: maximum length to store there * @parent: parent directory inode, if wanted * - * This default encode_fh function assumes that the 32 inode number + * This generic encode_fh function assumes that the 32 inode number * is suitable for locating an inode, and that the generation number * can be used to check that it is still valid. It places them in the * filehandle fragment where export_decode_fh expects to find them. */ -static int export_encode_fh(struct inode *inode, struct fid *fid, - int *max_len, struct inode *parent) +int generic_encode_ino32_fh(struct inode *inode, __u32 *fh, int *max_len, + struct inode *parent) { + struct fid *fid = (void *)fh; int len = *max_len; int type = FILEID_INO32_GEN; @@ -380,6 +381,7 @@ static int export_encode_fh(struct inode *inode, struct fid *fid, *max_len = len; return type; } +EXPORT_SYMBOL_GPL(generic_encode_ino32_fh); /** * exportfs_encode_inode_fh - encode a file handle from inode @@ -402,7 +404,7 @@ int exportfs_encode_inode_fh(struct inode *inode, struct fid *fid, if (nop && nop->encode_fh) return nop->encode_fh(inode, fid->raw, max_len, parent); - return export_encode_fh(inode, fid, max_len, parent); + return -EOPNOTSUPP; } EXPORT_SYMBOL_GPL(exportfs_encode_inode_fh); diff --git a/fs/ext2/super.c b/fs/ext2/super.c index aaf3e3e88cb2..b9f158a34997 100644 --- a/fs/ext2/super.c +++ b/fs/ext2/super.c @@ -397,6 +397,7 @@ static struct dentry *ext2_fh_to_parent(struct super_block *sb, struct fid *fid, } static const struct export_operations ext2_export_ops = { + .encode_fh = generic_encode_ino32_fh, .fh_to_dentry = ext2_fh_to_dentry, .fh_to_parent = ext2_fh_to_parent, .get_parent = ext2_get_parent, diff --git a/fs/ext4/super.c b/fs/ext4/super.c index dbebd8b3127e..c44db1915437 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1646,6 +1646,7 @@ static const struct super_operations ext4_sops = { }; static const struct export_operations ext4_export_ops = { + .encode_fh = generic_encode_ino32_fh, .fh_to_dentry = ext4_fh_to_dentry, .fh_to_parent = ext4_fh_to_parent, .get_parent = ext4_get_parent, diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index a8c8232852bb..60cfa11f65bf 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -3282,6 +3282,7 @@ static struct dentry *f2fs_fh_to_parent(struct super_block *sb, struct fid *fid, } static const struct export_operations f2fs_export_ops = { + .encode_fh = generic_encode_ino32_fh, .fh_to_dentry = f2fs_fh_to_dentry, .fh_to_parent = f2fs_fh_to_parent, .get_parent = f2fs_get_parent, diff --git a/fs/fat/nfs.c b/fs/fat/nfs.c index 3626eb585a98..c52e63e10d35 100644 --- a/fs/fat/nfs.c +++ b/fs/fat/nfs.c @@ -279,6 +279,7 @@ static struct dentry *fat_get_parent(struct dentry *child_dir) } const struct export_operations fat_export_ops = { + .encode_fh = generic_encode_ino32_fh, .fh_to_dentry = fat_fh_to_dentry, .fh_to_parent = fat_fh_to_parent, .get_parent = fat_get_parent, diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c index 7ea37f49f1e1..f99591a634b4 100644 --- a/fs/jffs2/super.c +++ b/fs/jffs2/super.c @@ -150,6 +150,7 @@ static struct dentry *jffs2_get_parent(struct dentry *child) } static const struct export_operations jffs2_export_ops = { + .encode_fh = generic_encode_ino32_fh, .get_parent = jffs2_get_parent, .fh_to_dentry = jffs2_fh_to_dentry, .fh_to_parent = jffs2_fh_to_parent, diff --git a/fs/jfs/super.c b/fs/jfs/super.c index 2e2f7f6d36a0..2cc2632f3c47 100644 --- a/fs/jfs/super.c +++ b/fs/jfs/super.c @@ -896,6 +896,7 @@ static const struct super_operations jfs_super_operations = { }; static const struct export_operations jfs_export_operations = { + .encode_fh = generic_encode_ino32_fh, .fh_to_dentry = jfs_fh_to_dentry, .fh_to_parent = jfs_fh_to_parent, .get_parent = jfs_get_parent, diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c index ab44f2db533b..d7498ddc4a72 100644 --- a/fs/ntfs/namei.c +++ b/fs/ntfs/namei.c @@ -384,6 +384,7 @@ static struct dentry *ntfs_fh_to_parent(struct super_block *sb, struct fid *fid, * and due to using iget() whereas NTFS needs ntfs_iget(). */ const struct export_operations ntfs_export_ops = { + .encode_fh = generic_encode_ino32_fh, .get_parent = ntfs_get_parent, /* Find the parent of a given directory. */ .fh_to_dentry = ntfs_fh_to_dentry, diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 5661a363005e..661ffb5aa1e0 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -789,6 +789,7 @@ static int ntfs_nfs_commit_metadata(struct inode *inode) } static const struct export_operations ntfs_export_ops = { + .encode_fh = generic_encode_ino32_fh, .fh_to_dentry = ntfs_fh_to_dentry, .fh_to_parent = ntfs_fh_to_parent, .get_parent = ntfs3_get_parent, diff --git a/fs/smb/client/export.c b/fs/smb/client/export.c index 37c28415df1e..834e9c9197b4 100644 --- a/fs/smb/client/export.c +++ b/fs/smb/client/export.c @@ -41,13 +41,10 @@ static struct dentry *cifs_get_parent(struct dentry *dentry) } const struct export_operations cifs_export_ops = { + .encode_fh = generic_encode_ino32_fh, .get_parent = cifs_get_parent, -/* Following five export operations are unneeded so far and can default: - .get_dentry = - .get_name = - .find_exported_dentry = - .decode_fh = - .encode_fs = */ +/* Following export operations are mandatory for NFS export support: + .fh_to_dentry = */ }; #endif /* CONFIG_CIFS_NFSD_EXPORT */ diff --git a/fs/squashfs/export.c b/fs/squashfs/export.c index 723763746238..62972f0ff868 100644 --- a/fs/squashfs/export.c +++ b/fs/squashfs/export.c @@ -173,6 +173,7 @@ __le64 *squashfs_read_inode_lookup_table(struct super_block *sb, const struct export_operations squashfs_export_ops = { + .encode_fh = generic_encode_ino32_fh, .fh_to_dentry = squashfs_fh_to_dentry, .fh_to_parent = squashfs_fh_to_parent, .get_parent = squashfs_get_parent diff --git a/fs/ufs/super.c b/fs/ufs/super.c index 23377c1baed9..a480810cd4e3 100644 --- a/fs/ufs/super.c +++ b/fs/ufs/super.c @@ -137,6 +137,7 @@ static struct dentry *ufs_get_parent(struct dentry *child) } static const struct export_operations ufs_export_ops = { + .encode_fh = generic_encode_ino32_fh, .fh_to_dentry = ufs_fh_to_dentry, .fh_to_parent = ufs_fh_to_parent, .get_parent = ufs_get_parent, diff --git a/include/linux/exportfs.h b/include/linux/exportfs.h index 5b3c9f30b422..6b6e01321405 100644 --- a/include/linux/exportfs.h +++ b/include/linux/exportfs.h @@ -235,7 +235,7 @@ extern int exportfs_encode_fh(struct dentry *dentry, struct fid *fid, static inline bool exportfs_can_encode_fid(const struct export_operations *nop) { - return nop; + return nop && nop->encode_fh; } static inline bool exportfs_can_decode_fh(const struct export_operations *nop) @@ -279,6 +279,8 @@ extern struct dentry *exportfs_decode_fh(struct vfsmount *mnt, struct fid *fid, /* * Generic helpers for filesystems. */ +int generic_encode_ino32_fh(struct inode *inode, __u32 *fh, int *max_len, + struct inode *parent); extern struct dentry *generic_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, int fh_type, struct inode *(*get_inode) (struct super_block *sb, u64 ino, u32 gen)); From patchwork Wed Oct 18 09:59:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 13426810 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9811ACDB483 for ; Wed, 18 Oct 2023 10:00:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229482AbjJRKAR (ORCPT ); Wed, 18 Oct 2023 06:00:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229629AbjJRKAQ (ORCPT ); Wed, 18 Oct 2023 06:00:16 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69E4EF7; Wed, 18 Oct 2023 03:00:14 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-407da05f05aso12060155e9.3; Wed, 18 Oct 2023 03:00:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697623213; x=1698228013; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+Qi4Eam5aGrJY9E/N/+2uzFyjTVYPfYz5piRCWTEPBA=; b=dGv4PQOMj1EypfVtWvGp7pUdnXBCrgfHaM2p5adnCt63AfNYh2mx5P8BPDHOtMFYGj VbTqDD4aB8yuWRhKDuuup4cyuw6/9fOV+gAF95KnZwJ+TEMQZzrL2cPSXZKRQo5sL40Y o3Qv0avC5ivIOnETTgI9RAc9iDy3s9LkRnEsqjp7hzblkylCdjbSpEnM1C2t0KADxoVb PfNU4wMns0F/ThvetrXSVudutoCvSangowdIA3c34ACTo909fLde+etpy5KAO0VQA9gL mEyEt8Nq1aZZpKLsUzI1a7VZOtX5a93va9+hiDmoATVnrven7KLs2sEUZx8qyecVV/EH fLlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697623213; x=1698228013; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+Qi4Eam5aGrJY9E/N/+2uzFyjTVYPfYz5piRCWTEPBA=; b=RMaEh6ZHzYEv7BXbZQ4SlUnfqEJh/XKIVWD7kdWsXnYc4D//BbYrdHBIgEcJu/N6GO kuAuOCGtBQKUXpfROMH3JzXLVIbmcElm1qVx/LavUqBVEUIu7Ojr/iApjwdGplWiOXVt zaUHx0DVtpwj9wYggD61mgHaJN5ZQon5OkWp/ZxvEGgqEDlMoy8FKLCzaN295oLFuFVs Ee+ul0VFMgnOftxa+vNcx9QwqfNA4Et2TtHQrwwwczqZNeEjoRIAhShm28R+IzAHlY+K DASSjM7ZtD+OqM2ni1sUTH91meMYjmwLX6kaPJwIAV3AiBJX3WAIb3D+N8gtZWWeitP8 nUaA== X-Gm-Message-State: AOJu0YyVF/KhBA4BQk8uWHuqWGux20YN6Na6sWQZEO73Nh+BvTdIcvj9 +4qMh1gF5BMytUj9kAt85U8= X-Google-Smtp-Source: AGHT+IG61vqYE8SoscH6m48jqjti4rHvc/VWtX153DLhQAC7m2GbXOZywMSf3+/crQjy2LA/wlTk3g== X-Received: by 2002:a05:600c:1ca0:b0:408:3e41:aea with SMTP id k32-20020a05600c1ca000b004083e410aeamr742399wms.1.1697623212464; Wed, 18 Oct 2023 03:00:12 -0700 (PDT) Received: from amir-ThinkPad-T480.lan ([5.29.249.86]) by smtp.gmail.com with ESMTPSA id y34-20020a05600c342200b004063977eccesm1222017wmp.42.2023.10.18.03.00.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 03:00:11 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Jeff Layton , Chuck Lever , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org Subject: [PATCH 4/5] exportfs: define FILEID_INO64_GEN* file handle types Date: Wed, 18 Oct 2023 12:59:59 +0300 Message-Id: <20231018100000.2453965-5-amir73il@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018100000.2453965-1-amir73il@gmail.com> References: <20231018100000.2453965-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Similar to the common FILEID_INO32* file handle types, define common FILEID_INO64* file handle types. The type values of FILEID_INO64_GEN and FILEID_INO64_GEN_PARENT are the values returned by fuse and xfs for 64bit ino encoded file handle types. Note that these type value are filesystem specific and they do not define a universal file handle format, for example: fuse encodes FILEID_INO64_GEN as [ino-hi32,ino-lo32,gen] and xfs encodes FILEID_INO64_GEN as [hostr-order-ino64,gen] (a.k.a xfs_fid64). The FILEID_INO64_GEN fhandle type is going to be used for file ids for fanotify from filesystems that do not support NFS export. Signed-off-by: Amir Goldstein Reviewed-by: Jeff Layton Reviewed-by: Jan Kara --- fs/fuse/inode.c | 7 ++++--- include/linux/exportfs.h | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index 2e4eb7cf26fb..e63f966698a5 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -1002,7 +1002,7 @@ static int fuse_encode_fh(struct inode *inode, u32 *fh, int *max_len, } *max_len = len; - return parent ? 0x82 : 0x81; + return parent ? FILEID_INO64_GEN_PARENT : FILEID_INO64_GEN; } static struct dentry *fuse_fh_to_dentry(struct super_block *sb, @@ -1010,7 +1010,8 @@ static struct dentry *fuse_fh_to_dentry(struct super_block *sb, { struct fuse_inode_handle handle; - if ((fh_type != 0x81 && fh_type != 0x82) || fh_len < 3) + if ((fh_type != FILEID_INO64_GEN && + fh_type != FILEID_INO64_GEN_PARENT) || fh_len < 3) return NULL; handle.nodeid = (u64) fid->raw[0] << 32; @@ -1024,7 +1025,7 @@ static struct dentry *fuse_fh_to_parent(struct super_block *sb, { struct fuse_inode_handle parent; - if (fh_type != 0x82 || fh_len < 6) + if (fh_type != FILEID_INO64_GEN_PARENT || fh_len < 6) return NULL; parent.nodeid = (u64) fid->raw[3] << 32; diff --git a/include/linux/exportfs.h b/include/linux/exportfs.h index 6b6e01321405..21eeb9f6bdbd 100644 --- a/include/linux/exportfs.h +++ b/include/linux/exportfs.h @@ -98,6 +98,17 @@ enum fid_type { */ FILEID_FAT_WITH_PARENT = 0x72, + /* + * 64 bit inode number, 32 bit generation number. + */ + FILEID_INO64_GEN = 0x81, + + /* + * 64 bit inode number, 32 bit generation number, + * 64 bit parent inode number, 32 bit parent generation. + */ + FILEID_INO64_GEN_PARENT = 0x82, + /* * 128 bit child FID (struct lu_fid) * 128 bit parent FID (struct lu_fid) From patchwork Wed Oct 18 10:00:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 13426811 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAF4BCDB47E for ; Wed, 18 Oct 2023 10:00:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229720AbjJRKAT (ORCPT ); Wed, 18 Oct 2023 06:00:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbjJRKAS (ORCPT ); Wed, 18 Oct 2023 06:00:18 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA573FA; Wed, 18 Oct 2023 03:00:15 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2c4fe37f166so80706581fa.1; Wed, 18 Oct 2023 03:00:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697623214; x=1698228014; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9l5t0OpbtbVMsdsvL20hfPgYiDYZf4mDCwLUlENNJ70=; b=XioeH3B+XJDORhKMlvzI7A4cMvrt4DVNnidaOetwy1EhWYGwn/q33Mpm46yUIrtHxH iDSMPr0SIEPqqMXprvamedomsmeCOB5phoe5q8je29b4YaRAZMqME/Iruje3AD1cDhx5 KHD9rKIajmwXt4WxyO232QYQhENZbkMCxV9wI3j73H8Ap401spjYWsIUKwpfhhAMyTyC 0XFSLXQMSDpmmC8UjUj10j3ttfFW83wdmCPIM7ACham6gF5nEdscUpz+FNuNiBC3pURP OL/ap6yJJEQLx4WMeKA8cGakX84fx3W8NLu+Dz1SFFr+RHC0GJG/bG2rX3gPkdjdtK4z DTew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697623214; x=1698228014; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9l5t0OpbtbVMsdsvL20hfPgYiDYZf4mDCwLUlENNJ70=; b=crVBTgws95WPzE7K/O5L+K9KSWomWzp5xytJXwSZb4s8WIrMTfem8ROvDJjh974D6f JhnW/SImz20UVnoHfkj4sVPJ/4Es7F4WViaNYh6VM2vcoGqeTf4TeQL9KIsfCHLgW+he 43PYZCOnWMePwNxO3p9argFkwwV3T/LLY3dgOpSK2GcuuPzRYFryrXxNy5qI5Fqw1DEU D6NWhnw2fYo5/7ZBdl9F2lRuve3ys4/K9zrRUNs9r3FDkW8yWDvenKlRsK51HCGX0GTB CVQUYc9kIoMQaBTem2iuiZS3KPsx/ElaV8iICEp4Se0WKs3B/u1MK9b9OrGeHsfkXLmS kbjg== X-Gm-Message-State: AOJu0YzJvrtTd+tB36RrDIeL0y7luZpOco3fziMx1rNAfbLIi1L4SYOK hMZzl1NdnE17AZJ1CZ8/DbOcV8BKDH0= X-Google-Smtp-Source: AGHT+IFyfA82o+JXQwx40P1ZbvHycg61RAP4gsafsuMAfIN60tD6EMZeYbQOxfX7iiMQ33z1H+P+FQ== X-Received: by 2002:a2e:9bd3:0:b0:2bf:e9e8:de23 with SMTP id w19-20020a2e9bd3000000b002bfe9e8de23mr3239029ljj.16.1697623213998; Wed, 18 Oct 2023 03:00:13 -0700 (PDT) Received: from amir-ThinkPad-T480.lan ([5.29.249.86]) by smtp.gmail.com with ESMTPSA id y34-20020a05600c342200b004063977eccesm1222017wmp.42.2023.10.18.03.00.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 03:00:13 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Jeff Layton , Chuck Lever , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org Subject: [PATCH 5/5] exportfs: support encoding non-decodeable file handles by default Date: Wed, 18 Oct 2023 13:00:00 +0300 Message-Id: <20231018100000.2453965-6-amir73il@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018100000.2453965-1-amir73il@gmail.com> References: <20231018100000.2453965-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org AT_HANDLE_FID was added as an API for name_to_handle_at() that request the encoding of a file id, which is not intended to be decoded. This file id is used by fanotify to describe objects in events. So far, overlayfs is the only filesystem that supports encoding non-decodeable file ids, by providing export_operations with an ->encode_fh() method and without a ->decode_fh() method. Add support for encoding non-decodeable file ids to all the filesystems that do not provide export_operations, by encoding a file id of type FILEID_INO64_GEN from { i_ino, i_generation }. A filesystem may that does not support NFS export, can opt-out of encoding non-decodeable file ids for fanotify by defining an empty export_operations struct (i.e. with a NULL ->encode_fh() method). This allows the use of fanotify events with file ids on filesystems like 9p which do not support NFS export to bring fanotify in feature parity with inotify on those filesystems. Note that fanotify also requires that the filesystems report a non-null fsid. Currently, many simple filesystems that have support for inotify (e.g. debugfs, tracefs, sysfs) report a null fsid, so can still not be used with fanotify in file id reporting mode. Signed-off-by: Amir Goldstein --- fs/exportfs/expfs.c | 30 +++++++++++++++++++++++++++--- include/linux/exportfs.h | 10 +++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/fs/exportfs/expfs.c b/fs/exportfs/expfs.c index 30da4539e257..34e7d835d4ef 100644 --- a/fs/exportfs/expfs.c +++ b/fs/exportfs/expfs.c @@ -383,6 +383,30 @@ int generic_encode_ino32_fh(struct inode *inode, __u32 *fh, int *max_len, } EXPORT_SYMBOL_GPL(generic_encode_ino32_fh); +/** + * exportfs_encode_ino64_fid - encode non-decodeable 64bit ino file id + * @inode: the object to encode + * @fid: where to store the file handle fragment + * @max_len: maximum length to store there + * + * This generic function is used to encode a non-decodeable file id for + * fanotify for filesystems that do not support NFS export. + */ +static int exportfs_encode_ino64_fid(struct inode *inode, struct fid *fid, + int *max_len) +{ + if (*max_len < 3) { + *max_len = 3; + return FILEID_INVALID; + } + + fid->i64.ino = inode->i_ino; + fid->i64.gen = inode->i_generation; + *max_len = 3; + + return FILEID_INO64_GEN; +} + /** * exportfs_encode_inode_fh - encode a file handle from inode * @inode: the object to encode @@ -401,10 +425,10 @@ int exportfs_encode_inode_fh(struct inode *inode, struct fid *fid, if (!exportfs_can_encode_fh(nop, flags)) return -EOPNOTSUPP; - if (nop && nop->encode_fh) - return nop->encode_fh(inode, fid->raw, max_len, parent); + if (!nop && (flags & EXPORT_FH_FID)) + return exportfs_encode_ino64_fid(inode, fid, max_len); - return -EOPNOTSUPP; + return nop->encode_fh(inode, fid->raw, max_len, parent); } EXPORT_SYMBOL_GPL(exportfs_encode_inode_fh); diff --git a/include/linux/exportfs.h b/include/linux/exportfs.h index 21eeb9f6bdbd..6688e457da64 100644 --- a/include/linux/exportfs.h +++ b/include/linux/exportfs.h @@ -134,7 +134,11 @@ struct fid { u32 parent_ino; u32 parent_gen; } i32; - struct { + struct { + u64 ino; + u32 gen; + } __packed i64; + struct { u32 block; u16 partref; u16 parent_partref; @@ -246,7 +250,7 @@ extern int exportfs_encode_fh(struct dentry *dentry, struct fid *fid, static inline bool exportfs_can_encode_fid(const struct export_operations *nop) { - return nop && nop->encode_fh; + return !nop || nop->encode_fh; } static inline bool exportfs_can_decode_fh(const struct export_operations *nop) @@ -259,7 +263,7 @@ static inline bool exportfs_can_encode_fh(const struct export_operations *nop, { /* * If a non-decodeable file handle was requested, we only need to make - * sure that filesystem can encode file handles. + * sure that filesystem did not opt-out of encoding fid. */ if (fh_flags & EXPORT_FH_FID) return exportfs_can_encode_fid(nop);