From patchwork Tue May 2 12:48:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 13228869 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 03DEFC7EE2E for ; Tue, 2 May 2023 12:48:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234241AbjEBMsf (ORCPT ); Tue, 2 May 2023 08:48:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234146AbjEBMs2 (ORCPT ); Tue, 2 May 2023 08:48:28 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BF1359E1; Tue, 2 May 2023 05:48:26 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-3062b101ae1so1650003f8f.2; Tue, 02 May 2023 05:48:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683031705; x=1685623705; 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=vjYpK+xxCL8lt/8cmLRqktVRJYxjE9M35ggTsbeXktw=; b=PtNnZDgcd4JaXJYhROzvogPEYsP/mjQAagAXmMeTaE71zXMHmzbrpJbxU8aZxVbfGu uqRQO75241GPJSW1gi+ZrXnSxSg80SGiEJTU1xl+YgaWNa/3X+MWvBysFq/x4YzJrZaC 9RvVlvNLGdfkTWhXujejwbqkoafdEHXOpbgZoOxKTGMYspF2J07PkThFrzq+9bXPELvq J2kMg5y//H53h/SSqKxHJre1ABFgDiA76v6zWNCmdxYMlGBj7fF2jqay1kr+RbKkOo0B d/33RRtNS7nl3ZBXOTbKqbsyy3xp0T5KFok7kh51s2X5w0KXV4bz+U4XDGqdDlIp1BE2 aObA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683031705; x=1685623705; 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=vjYpK+xxCL8lt/8cmLRqktVRJYxjE9M35ggTsbeXktw=; b=Ew424nCy2noHV9n72bE2Q3GgMtN9oCy/wCk+BdoqbY39av7uV550iIazHK2u3M3cNo nHLRA05iqMuIPaQ3LBw7tZQjIbUhbUzCfvceHd9SiU+TsA9Wnxe2YxTYbAQLwlPk0463 rcxN4bV0RVqFzcycoI1+dHA66QBqN3sOEjRms0U4h1kuuMHCTH3BN1lKm0qAyPK8Lydk rNbOY1NTI2UWPHI8YbDDhIt3kVApF+J6gqaNFFCpQjE+nvf/P3A4jhe9oPYhHcdD272s J/3SAVzFH7DQ4Le/+Ar71lRh5AOPLG2n+tgnQ2tuoj8Jv3F9sJJjMlKtkgxDgaYG5qTU bEdQ== X-Gm-Message-State: AC+VfDzaKtGgqyVyD1RplXaqt0Y4wMC/qTOZ/i79MlJZqNikWy37ebOb EaxUrjABhnfTAH1afhJAPyM= X-Google-Smtp-Source: ACHHUZ46pAdh5nrXUz4ensPQsgGhFbH8llcw3yjTXdNKf7VhKZW+HE5WyNeR1pBXIPnhY9qeQOfLqg== X-Received: by 2002:adf:ff91:0:b0:2d7:4c98:78fe with SMTP id j17-20020adfff91000000b002d74c9878femr11739176wrr.34.1683031704851; Tue, 02 May 2023 05:48:24 -0700 (PDT) Received: from amir-ThinkPad-T480.lan ([5.29.249.86]) by smtp.gmail.com with ESMTPSA id d9-20020a5d6dc9000000b00304adbeeabbsm14226259wrz.99.2023.05.02.05.48.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 05:48:24 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Christian Brauner , Miklos Szeredi , Jeff Layton , Chuck Lever , linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH v2 1/4] exportfs: change connectable argument to bit flags Date: Tue, 2 May 2023 15:48:14 +0300 Message-Id: <20230502124817.3070545-2-amir73il@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230502124817.3070545-1-amir73il@gmail.com> References: <20230502124817.3070545-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Convert the bool connectable arguemnt into a bit flags argument and define the EXPORT_FS_CONNECTABLE flag as a requested property of the file handle. We are going to add a flag for requesting non-decodeable file handles. Acked-by: Jeff Layton Acked-by: Chuck Lever Signed-off-by: Amir Goldstein --- fs/exportfs/expfs.c | 13 +++++++++++-- fs/nfsd/nfsfh.c | 5 +++-- include/linux/exportfs.h | 6 ++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/fs/exportfs/expfs.c b/fs/exportfs/expfs.c index ab88d33d106c..ab7feffe2d19 100644 --- a/fs/exportfs/expfs.c +++ b/fs/exportfs/expfs.c @@ -393,14 +393,23 @@ int exportfs_encode_inode_fh(struct inode *inode, struct fid *fid, } EXPORT_SYMBOL_GPL(exportfs_encode_inode_fh); +/** + * exportfs_encode_fh - encode a file handle from dentry + * @dentry: the object to encode + * @fid: where to store the file handle fragment + * @max_len: maximum length to store there + * @flags: properties of the requested file handle + * + * Returns an enum fid_type or a negative errno. + */ int exportfs_encode_fh(struct dentry *dentry, struct fid *fid, int *max_len, - int connectable) + int flags) { int error; struct dentry *p = NULL; struct inode *inode = dentry->d_inode, *parent = NULL; - if (connectable && !S_ISDIR(inode->i_mode)) { + if ((flags & EXPORT_FH_CONNECTABLE) && !S_ISDIR(inode->i_mode)) { p = dget_parent(dentry); /* * note that while p might've ceased to be our parent already, diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c index ccd8485fee04..31e4505c0df3 100644 --- a/fs/nfsd/nfsfh.c +++ b/fs/nfsd/nfsfh.c @@ -414,10 +414,11 @@ static void _fh_update(struct svc_fh *fhp, struct svc_export *exp, struct fid *fid = (struct fid *) (fhp->fh_handle.fh_fsid + fhp->fh_handle.fh_size/4 - 1); int maxsize = (fhp->fh_maxsize - fhp->fh_handle.fh_size)/4; - int subtreecheck = !(exp->ex_flags & NFSEXP_NOSUBTREECHECK); + int fh_flags = (exp->ex_flags & NFSEXP_NOSUBTREECHECK) ? 0 : + EXPORT_FH_CONNECTABLE; fhp->fh_handle.fh_fileid_type = - exportfs_encode_fh(dentry, fid, &maxsize, subtreecheck); + exportfs_encode_fh(dentry, fid, &maxsize, fh_flags); fhp->fh_handle.fh_size += maxsize * 4; } else { fhp->fh_handle.fh_fileid_type = FILEID_ROOT; diff --git a/include/linux/exportfs.h b/include/linux/exportfs.h index 601700fedc91..66e16022cc3d 100644 --- a/include/linux/exportfs.h +++ b/include/linux/exportfs.h @@ -135,6 +135,8 @@ struct fid { }; }; +#define EXPORT_FH_CONNECTABLE 0x1 /* Encode file handle with parent */ + /** * struct export_operations - for nfsd to communicate with file systems * @encode_fh: encode a file handle fragment from a dentry @@ -150,7 +152,7 @@ struct fid { * encode_fh: * @encode_fh should store in the file handle fragment @fh (using at most * @max_len bytes) information that can be used by @decode_fh to recover the - * file referred to by the &struct dentry @de. If the @connectable flag is + * file referred to by the &struct dentry @de. If @flag has CONNECTABLE bit * set, the encode_fh() should store sufficient information so that a good * attempt can be made to find not only the file but also it's place in the * filesystem. This typically means storing a reference to de->d_parent in @@ -226,7 +228,7 @@ struct export_operations { extern int exportfs_encode_inode_fh(struct inode *inode, struct fid *fid, int *max_len, struct inode *parent); extern int exportfs_encode_fh(struct dentry *dentry, struct fid *fid, - int *max_len, int connectable); + int *max_len, int flags); extern struct dentry *exportfs_decode_fh_raw(struct vfsmount *mnt, struct fid *fid, int fh_len, int fileid_type, From patchwork Tue May 2 12:48:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 13228870 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 555CCC7EE24 for ; Tue, 2 May 2023 12:48:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234149AbjEBMsg (ORCPT ); Tue, 2 May 2023 08:48:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234150AbjEBMsa (ORCPT ); Tue, 2 May 2023 08:48:30 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 128965FD9; Tue, 2 May 2023 05:48:28 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-2f7db354092so2284658f8f.2; Tue, 02 May 2023 05:48:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683031706; x=1685623706; 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=H5eU89oHST/7fvITjEeMaKb7E2zwQgt9tUDlip0QRSg=; b=o+UEpohY74fcEJiG8P+67E+mLiuCU2d0fV84RfcfQJkM0uOfetuuTHO8b67SK2e2Xp DsUbGzgc2TDvomNaYWa7xvpqmlBorBf9s0dcWVw8nK12EWMnukS0POs9sBoJb35fS9Du Yuj9FeAmC+ZfA+nZ1cpdNtBQCCOtwXuHrD7WJ9TzYZqDh921wFNVkCZbchpTeyy9qIbC pyW93PTkMarctKPhvCafJCh2CGYNCU9ch8Ww1fVBatBhvV6dXecbF3judlWwtzO94l9C nQvbSmy8rJxX56ElHdJbDsRQDR84lcNC8Vm4Cc0osU5BRiQRVMDnB38xYMQhWoAu+Rsa QqYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683031706; x=1685623706; 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=H5eU89oHST/7fvITjEeMaKb7E2zwQgt9tUDlip0QRSg=; b=Hk/OP4/364WucQlukhxY8GUtZ3H6S4qoDnDYEwMAgg3Ur8JI3V9J9QhNF8ilb4Zdk6 G00FOyFuV5keZ3XRi3qhcnMWafL/u4SCD47UU1fcebiDqUBfjZHcRFUiE7vlL9Lf9rtt 5vW6yOHf0I7iywe033E02m9Dz3Iqbk2NSo74DlvsiX7gCqdhPB2CAECOO4Xaqn/7rXb/ Z3UZ4UDP7CjBk4FQp+hb5izjUoemys03j+YpAjs9aVtAwSgc58/c3EbGatfNwLIb/Fam hMUGGPyMXn8mnFIyChbh6xtLS07Rkrv6w52Knoe0bqShcje2t/RbJzp53z19I02kAc4H 5gRw== X-Gm-Message-State: AC+VfDzscwTToZVe1DZwX8YPpou8BpLjjE/vTrAzgNPPAJnAGGARzKYX IL0cqToH/dlCtm2d8PUYtcKUaLMgCEQ= X-Google-Smtp-Source: ACHHUZ5IJscLTLN+QUx5LvObb1s7wrOlbQnauB/Od2TkLY9KPcJA7WL/v56SFC0m3dxVitK+cNM2lw== X-Received: by 2002:adf:e647:0:b0:306:3153:d2fe with SMTP id b7-20020adfe647000000b003063153d2femr3170243wrn.27.1683031706531; Tue, 02 May 2023 05:48:26 -0700 (PDT) Received: from amir-ThinkPad-T480.lan ([5.29.249.86]) by smtp.gmail.com with ESMTPSA id d9-20020a5d6dc9000000b00304adbeeabbsm14226259wrz.99.2023.05.02.05.48.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 05:48:26 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Christian Brauner , Miklos Szeredi , Jeff Layton , Chuck Lever , linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH v2 2/4] exportfs: add explicit flag to request non-decodeable file handles Date: Tue, 2 May 2023 15:48:15 +0300 Message-Id: <20230502124817.3070545-3-amir73il@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230502124817.3070545-1-amir73il@gmail.com> References: <20230502124817.3070545-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org So far, all callers of exportfs_encode_inode_fh(), except for fsnotify's show_mark_fhandle(), check that filesystem can decode file handles, but we would like to add more callers that do not require a file handle that can be decoded. Introduce a flag to explicitly request a file handle that may not to be decoded later and a wrapper exportfs_encode_fid() that sets this flag and convert show_mark_fhandle() to use the new wrapper. This will be used to allow adding fanotify support to filesystems that do not support NFS export. Acked-by: Jeff Layton Acked-by: Chuck Lever Signed-off-by: Amir Goldstein --- Documentation/filesystems/nfs/exporting.rst | 4 ++-- fs/exportfs/expfs.c | 20 ++++++++++++++++++-- fs/notify/fanotify/fanotify.c | 4 ++-- fs/notify/fdinfo.c | 2 +- include/linux/exportfs.h | 12 +++++++++++- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Documentation/filesystems/nfs/exporting.rst b/Documentation/filesystems/nfs/exporting.rst index 0e98edd353b5..3d97b8d8f735 100644 --- a/Documentation/filesystems/nfs/exporting.rst +++ b/Documentation/filesystems/nfs/exporting.rst @@ -122,8 +122,8 @@ 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) - Takes a dentry and creates a filehandle fragment which can later be used + encode_fh (optional) + 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 diff --git a/fs/exportfs/expfs.c b/fs/exportfs/expfs.c index ab7feffe2d19..40e624cf7e92 100644 --- a/fs/exportfs/expfs.c +++ b/fs/exportfs/expfs.c @@ -381,11 +381,27 @@ static int export_encode_fh(struct inode *inode, struct fid *fid, return type; } +/** + * exportfs_encode_inode_fh - encode a file handle from inode + * @inode: the object to encode + * @fid: where to store the file handle fragment + * @max_len: maximum length to store there + * @flags: properties of the requested file handle + * + * Returns an enum fid_type or a negative errno. + */ int exportfs_encode_inode_fh(struct inode *inode, struct fid *fid, - int *max_len, struct inode *parent) + int *max_len, struct inode *parent, int flags) { 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) + return -EOPNOTSUPP; + if (nop && nop->encode_fh) return nop->encode_fh(inode, fid->raw, max_len, parent); @@ -418,7 +434,7 @@ int exportfs_encode_fh(struct dentry *dentry, struct fid *fid, int *max_len, parent = p->d_inode; } - error = exportfs_encode_inode_fh(inode, fid, max_len, parent); + error = exportfs_encode_inode_fh(inode, fid, max_len, parent, flags); dput(p); return error; diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 29bdd99b29fa..d1a49f5b6e6d 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -380,7 +380,7 @@ static int fanotify_encode_fh_len(struct inode *inode) if (!inode) return 0; - exportfs_encode_inode_fh(inode, NULL, &dwords, NULL); + exportfs_encode_inode_fh(inode, NULL, &dwords, NULL, 0); fh_len = dwords << 2; /* @@ -443,7 +443,7 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, } dwords = fh_len >> 2; - type = exportfs_encode_inode_fh(inode, buf, &dwords, NULL); + type = exportfs_encode_inode_fh(inode, buf, &dwords, NULL, 0); err = -EINVAL; if (!type || type == FILEID_INVALID || fh_len != dwords << 2) goto out_err; diff --git a/fs/notify/fdinfo.c b/fs/notify/fdinfo.c index 55081ae3a6ec..5c430736ec12 100644 --- a/fs/notify/fdinfo.c +++ b/fs/notify/fdinfo.c @@ -50,7 +50,7 @@ static void show_mark_fhandle(struct seq_file *m, struct inode *inode) f.handle.handle_bytes = sizeof(f.pad); size = f.handle.handle_bytes >> 2; - ret = exportfs_encode_inode_fh(inode, (struct fid *)f.handle.f_handle, &size, NULL); + ret = exportfs_encode_fid(inode, (struct fid *)f.handle.f_handle, &size); if ((ret == FILEID_INVALID) || (ret < 0)) { WARN_ONCE(1, "Can't encode file handler for inotify: %d\n", ret); return; diff --git a/include/linux/exportfs.h b/include/linux/exportfs.h index 66e16022cc3d..ec86ea4fa5c1 100644 --- a/include/linux/exportfs.h +++ b/include/linux/exportfs.h @@ -136,6 +136,7 @@ struct fid { }; #define EXPORT_FH_CONNECTABLE 0x1 /* Encode file handle with parent */ +#define EXPORT_FH_FID 0x2 /* File handle may be non-decodeable */ /** * struct export_operations - for nfsd to communicate with file systems @@ -226,9 +227,18 @@ struct export_operations { }; extern int exportfs_encode_inode_fh(struct inode *inode, struct fid *fid, - int *max_len, struct inode *parent); + int *max_len, struct inode *parent, + int flags); extern int exportfs_encode_fh(struct dentry *dentry, struct fid *fid, int *max_len, int flags); + +static inline int exportfs_encode_fid(struct inode *inode, struct fid *fid, + int *max_len) +{ + return exportfs_encode_inode_fh(inode, fid, max_len, NULL, + EXPORT_FH_FID); +} + extern struct dentry *exportfs_decode_fh_raw(struct vfsmount *mnt, struct fid *fid, int fh_len, int fileid_type, From patchwork Tue May 2 12:48:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 13228872 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 4C2CBC7EE26 for ; Tue, 2 May 2023 12:48:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234109AbjEBMsl (ORCPT ); Tue, 2 May 2023 08:48:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234175AbjEBMsb (ORCPT ); Tue, 2 May 2023 08:48:31 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C35759E5; Tue, 2 May 2023 05:48:29 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3f199696149so23104855e9.0; Tue, 02 May 2023 05:48:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683031708; x=1685623708; 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=h8BXJ75gYzzYprFFZm4HHrpNV5bb1uDaD8X/yAOq6xE=; b=Vej277/uvg5RtQa7PfkAJ+kQyYGnCl/VM/mlzVewXkVZX5bK/5RECW12tqaon7FHfc xxj99UwAfDgh89FtLZuvt9zFkZYN3t3dUZp9RVx6iBX0EDpEDTViMiIs5BhFUh0FNZ7C p7BvE01KWlL8GTleGJHiAfytwUyqbzIspLU0qutOyWmcNtREhCBvdXGqZgSqSj95jqz/ 6+toPvturMJBjhMzDuSdJiTjfHSMxCz+dMCDE+Z/Ywe2agm5xJmJOc7UseofNGN45b1w hvX0/SO48kkX4UhLUY7JshpNWz7qc44sL8ByZ9yW77RUszLaWPqtpjxe+0V17rWwAqdx GQJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683031708; x=1685623708; 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=h8BXJ75gYzzYprFFZm4HHrpNV5bb1uDaD8X/yAOq6xE=; b=g4jTTpMTiIh0xqGmEOkTy6d1cgZNMqiiRssv9i8a1hIz7Ii41FbwBG5fk4byPT3ekS L3tzcuYqEPyEzkBhL02Cq4/pwNqR37N6WUyK8+DyJg4QiDR+00DMVrOmtoYLhrGL6QwG 2S7ZyzHS9UEkT2/H5oRFhaoYWA8+aj+14d8LBcNzPzy2bus/K+wjW4Hs6sxZtVQ/rmjA i2WRiun6tem90TNyaGPqUJPY3a3xj3RaOdsV6Ky0/3kAm7BRIWKL7OTFyhtQ1HMQ3kYs eikMOlUCIn88TIESnnrN8Lw6KGdsOeSl0Ih9G4ke1u2UWzeZhf/UtZHIM6O7ykWKNo+O Ba+w== X-Gm-Message-State: AC+VfDyPVrbSkQydBkLbA/NwCZNvjrnbz4TkUletOp377r9DjYX1IZCC xQGItuUy8lii3Wd3/la+QrU= X-Google-Smtp-Source: ACHHUZ56mV1h2noLhrpy/lUrHlFJl3n9dlxIoFIg3BmoUKvwGkC67UZ83WZ4LmMv/hkbK5kUXT+iYw== X-Received: by 2002:a05:600c:257:b0:3f0:5887:bea3 with SMTP id 23-20020a05600c025700b003f05887bea3mr12229044wmj.27.1683031707995; Tue, 02 May 2023 05:48:27 -0700 (PDT) Received: from amir-ThinkPad-T480.lan ([5.29.249.86]) by smtp.gmail.com with ESMTPSA id d9-20020a5d6dc9000000b00304adbeeabbsm14226259wrz.99.2023.05.02.05.48.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 05:48:27 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Christian Brauner , Miklos Szeredi , Jeff Layton , Chuck Lever , linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH v2 3/4] exportfs: allow exporting non-decodeable file handles to userspace Date: Tue, 2 May 2023 15:48:16 +0300 Message-Id: <20230502124817.3070545-4-amir73il@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230502124817.3070545-1-amir73il@gmail.com> References: <20230502124817.3070545-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Some userspace programs use st_ino as a unique object identifier, even though inode numbers may be recycable. This issue has been addressed for NFS export long ago using the exportfs file handle API and the unique file handle identifiers are also exported to userspace via name_to_handle_at(2). fanotify also uses file handles to identify objects in events, but only for filesystems that support NFS export. Relax the requirement for NFS export support and allow more filesystems to export a unique object identifier via name_to_handle_at(2) with the flag AT_HANDLE_FID. A file handle requested with the AT_HANDLE_FID flag, may or may not be usable as an argument to open_by_handle_at(2). To allow filesystems to opt-in to supporting AT_HANDLE_FID, a struct export_operations is required, but even an empty struct is sufficient for encoding FIDs. Acked-by: Jeff Layton Acked-by: Chuck Lever Signed-off-by: Amir Goldstein Acked-by: Christian Brauner --- fs/fhandle.c | 22 ++++++++++++++-------- include/uapi/linux/fcntl.h | 5 +++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/fs/fhandle.c b/fs/fhandle.c index f2bc27d1975e..4a635cf787fc 100644 --- a/fs/fhandle.c +++ b/fs/fhandle.c @@ -16,7 +16,7 @@ static long do_sys_name_to_handle(const struct path *path, struct file_handle __user *ufh, - int __user *mnt_id) + int __user *mnt_id, int fh_flags) { long retval; struct file_handle f_handle; @@ -24,11 +24,14 @@ static long do_sys_name_to_handle(const struct path *path, struct file_handle *handle = NULL; /* - * We need to make sure whether the file system - * support decoding of the file handle + * 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 || - !path->dentry->d_sb->s_export_op->fh_to_dentry) + (!(fh_flags & EXPORT_FH_FID) && + !path->dentry->d_sb->s_export_op->fh_to_dentry)) return -EOPNOTSUPP; if (copy_from_user(&f_handle, ufh, sizeof(struct file_handle))) @@ -45,10 +48,10 @@ static long do_sys_name_to_handle(const struct path *path, /* convert handle size to multiple of sizeof(u32) */ handle_dwords = f_handle.handle_bytes >> 2; - /* we ask for a non connected handle */ + /* we ask for a non connectable maybe decodeable file handle */ retval = exportfs_encode_fh(path->dentry, (struct fid *)handle->f_handle, - &handle_dwords, 0); + &handle_dwords, fh_flags); handle->handle_type = retval; /* convert handle size to bytes */ handle_bytes = handle_dwords * sizeof(u32); @@ -84,6 +87,7 @@ static long do_sys_name_to_handle(const struct path *path, * @handle: resulting file handle * @mnt_id: mount id of the file system containing the file * @flag: flag value to indicate whether to follow symlink or not + * and whether a decodable file handle is required. * * @handle->handle_size indicate the space available to store the * variable part of the file handle in bytes. If there is not @@ -96,17 +100,19 @@ SYSCALL_DEFINE5(name_to_handle_at, int, dfd, const char __user *, name, { struct path path; int lookup_flags; + int fh_flags; int err; - if ((flag & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH)) != 0) + if (flag & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH | AT_HANDLE_FID)) return -EINVAL; lookup_flags = (flag & AT_SYMLINK_FOLLOW) ? LOOKUP_FOLLOW : 0; + fh_flags = (flag & AT_HANDLE_FID) ? EXPORT_FH_FID : 0; if (flag & AT_EMPTY_PATH) lookup_flags |= LOOKUP_EMPTY; err = user_path_at(dfd, name, lookup_flags, &path); if (!err) { - err = do_sys_name_to_handle(&path, handle, mnt_id); + err = do_sys_name_to_handle(&path, handle, mnt_id, fh_flags); path_put(&path); } return err; diff --git a/include/uapi/linux/fcntl.h b/include/uapi/linux/fcntl.h index e8c07da58c9f..3091080db069 100644 --- a/include/uapi/linux/fcntl.h +++ b/include/uapi/linux/fcntl.h @@ -112,4 +112,9 @@ #define AT_RECURSIVE 0x8000 /* Apply to the entire subtree */ +/* Flags for name_to_handle_at(2) */ +#define AT_HANDLE_FID 0x10000 /* file handle is needed to compare + object indentity and may not be + usable to open_by_handle_at(2) */ + #endif /* _UAPI_LINUX_FCNTL_H */ From patchwork Tue May 2 12:48:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 13228871 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 75AD6C7EE2E for ; Tue, 2 May 2023 12:48:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234249AbjEBMsk (ORCPT ); Tue, 2 May 2023 08:48:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229533AbjEBMsd (ORCPT ); Tue, 2 May 2023 08:48:33 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AF091B9; Tue, 2 May 2023 05:48:31 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3062c1e7df8so1607730f8f.1; Tue, 02 May 2023 05:48:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683031709; x=1685623709; 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=AeBn/JgpFqZE/TKMjDDbt2tMOlGTFfUTgS2LGEIVV+A=; b=BMBMxugwl4l3D1wY8kMpBLT7AjqGPGCrZ4OoFhPN+V0nKD0/gr5BHZ1M3oSf8nGfpJ gsJqEfBd8KFo8fJGe6ciCIIbIHtSMPn4SFNLDUzebSXff77CYFESFwSz49QE/R09iP/y pA+poYwh+V25PFsAqF6quA951X+pPN4E2XLvn5b8c+IS/mjSCKjwUe1ngNsBxKe103kE b71ZlFFU18LY+XyEbsg4iif7idtwC7KUWRWsi6PvPzsBTZezbacLw9kgo+6VlCe8XjVm JkvnIW1TduZUffmOjGzs5FM8QN9Bv/H6wGW+FFvy5xhGmlpQ6mSa+HBAWR6aJu4ON0CM 2xcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683031709; x=1685623709; 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=AeBn/JgpFqZE/TKMjDDbt2tMOlGTFfUTgS2LGEIVV+A=; b=RdyhUkaOIZoXzfIyS/OL8XJIrsdql2+DNrjW11QvFeR83uEOJlYkmOZQ2nFNg+5fX3 NgBoVv0mqW0FqxwURmAb9jkMKCkumjnzD6kozltwKW2aLwhTV6aMtM5rGjh03XcyYwPP zeUvigZLJAYPelw/RzBdxyDL3bvpeG0sGy9Hg/IS8IHUaWbTjpnfUpdngKi46eiAFd/G ImfK4bNQQNOyWGyHpD7RiOzBXHX3/HpmUEa/wlvsi4fzu/NSy9aqdDctCBYWba5d8V+U QKPhslnj72q7oNervgqzXS8cyZZxO6D0ngiwUFgUm749TWAWblKBEumzcOzk2OFpZAnU fUEA== X-Gm-Message-State: AC+VfDwpRjtONyIm5IAMmPGrWk/cESGbw4rRiQc/5N99ieYW3vOI1bv7 Qdt//TsRKBTbqC+apliJKlw= X-Google-Smtp-Source: ACHHUZ5PKQMo9PRvFeGHtHlUyI5p/qrVociXaKSKIGuGQpveGTSwcPjTDU/WcEMkZQ2l1L+X8NG63Q== X-Received: by 2002:a5d:6a43:0:b0:2fe:80b7:3527 with SMTP id t3-20020a5d6a43000000b002fe80b73527mr11303588wrw.17.1683031709553; Tue, 02 May 2023 05:48:29 -0700 (PDT) Received: from amir-ThinkPad-T480.lan ([5.29.249.86]) by smtp.gmail.com with ESMTPSA id d9-20020a5d6dc9000000b00304adbeeabbsm14226259wrz.99.2023.05.02.05.48.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 05:48:29 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Christian Brauner , Miklos Szeredi , Jeff Layton , Chuck Lever , linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH v2 4/4] fanotify: support reporting non-decodeable file handles Date: Tue, 2 May 2023 15:48:17 +0300 Message-Id: <20230502124817.3070545-5-amir73il@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230502124817.3070545-1-amir73il@gmail.com> References: <20230502124817.3070545-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org fanotify users do not always need to decode the file handles reported with FAN_REPORT_FID. Relax the restriction that filesystem needs to support NFS export and allow reporting file handles from filesystems that only support ecoding unique file handles. Even filesystems that do not have export_operations at all can fallback to use the default FILEID_INO32_GEN encoding, but we use the existence of export_operations as an indication that the encoded file handles will be sufficiently unique and that user will be able to compare them to filesystem objects using AT_HANDLE_FID flag to name_to_handle_at(2). For filesystems that do not support NFS export, users will have to use the AT_HANDLE_FID of name_to_handle_at(2) if they want to compare the object in path to the object fid reported in an event. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 4 ++-- fs/notify/fanotify/fanotify_user.c | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index d1a49f5b6e6d..d2bbf1445a9e 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -380,7 +380,7 @@ static int fanotify_encode_fh_len(struct inode *inode) if (!inode) return 0; - exportfs_encode_inode_fh(inode, NULL, &dwords, NULL, 0); + exportfs_encode_fid(inode, NULL, &dwords); fh_len = dwords << 2; /* @@ -443,7 +443,7 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, } dwords = fh_len >> 2; - type = exportfs_encode_inode_fh(inode, buf, &dwords, NULL, 0); + type = exportfs_encode_fid(inode, buf, &dwords); err = -EINVAL; if (!type || type == FILEID_INVALID || fh_len != dwords << 2) goto out_err; diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 8f430bfad487..e1936e968abb 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1586,11 +1586,10 @@ 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 * 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. + * objects. However, even the relaxed AT_HANDLE_FID flag requires + * at least empty export_operations for ecoding unique file ids. */ - if (!dentry->d_sb->s_export_op || - !dentry->d_sb->s_export_op->fh_to_dentry) + if (!dentry->d_sb->s_export_op) return -EOPNOTSUPP; return 0;