Support case insensitive filesystems in NFSv4
Subsystems (2)
[email protected]
maintainercover Support case insensitive filesystems in NFSv4
From: Trond Myklebust <[email protected]>
Add support for detecting an export of a case insensitive filesystem in NFSv4. If that is the case, then we need to adjust the dentry caching and invalidation rules to ensure that we don't inadvertently end up caching other case folded aliases after an operation that results in a directory entry name change.
Trond Myklebust (5):
NFSv4: Add some support for case insensitive filesystems
NFSv4: Just don't cache negative dentries on case insensitive servers
NFS: Invalidate negative dentries on all case insensitive directory
changes
NFS: Add a helper to remove case-insensitive aliases
NFS: Fix the verifier for case sensitive filesystem in
nfs_atomic_open()
fs/nfs/dir.c | 41 +++++++++++++++++++++++++++++++++------ fs/nfs/internal.h | 1 + fs/nfs/nfs4proc.c | 13 +++++++++++-- fs/nfs/nfs4xdr.c | 40 ++++++++++++++++++++++++++++++++++++++ include/linux/nfs_fs_sb.h | 2 ++ include/linux/nfs_xdr.h | 2 ++ 6 files changed, 91 insertions(+), 8 deletions(-)
Signature · 1 line
2.33.1
[email protected]
maintainerPATCH 1/5 NFSv4: Add some support for case insensitive filesystems
From: Trond Myklebust <[email protected]>
Add capabilities to allow the NFS client to recognise when it is dealing with case insensitive and case preserving filesystems.
--- fs/nfs/nfs4proc.c | 8 +++++++- fs/nfs/nfs4xdr.c | 40 +++++++++++++++++++++++++++++++++++++++ include/linux/nfs_fs_sb.h | 2 ++ include/linux/nfs_xdr.h | 2 ++ 4 files changed, 51 insertions(+), 1 deletion(-)
fs/nfs/nfs4proc.c +7 -1
@@ -3840,7 +3840,9 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fFATTR4_WORD0_FH_EXPIRE_TYPE |FATTR4_WORD0_LINK_SUPPORT |FATTR4_WORD0_SYMLINK_SUPPORT | -FATTR4_WORD0_ACLSUPPORT ; +FATTR4_WORD0_ACLSUPPORT | +FATTR4_WORD0_CASE_INSENSITIVE | +FATTR4_WORD0_CASE_PRESERVING ;if (minorversion) bitmask[2 ] =FATTR4_WORD2_SUPPATTR_EXCLCREAT ;
@@ -3869,6 +3871,10 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *f server->caps |=NFS_CAP_HARDLINKS ;if (res.has_symlinks !=0 ) server->caps |=NFS_CAP_SYMLINKS ; +if (res.case_insensitive) + server->caps |=NFS_CAP_CASE_INSENSITIVE ; +if (res.case_preserving) + server->caps |=NFS_CAP_CASE_PRESERVING ;#ifdef CONFIG_NFS_V4_SECURITY_LABEL if (res.attr_bitmask[2 ] &FATTR4_WORD2_SECURITY_LABEL ) server->caps |=NFS_CAP_SECURITY_LABEL ;
fs/nfs/nfs4xdr.c +40 -0
@@ -3533,6 +3533,42 @@ static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uintreturn 0 ; } +static int decode_attr_case_insensitive (struct xdr_stream *xdr,uint32_t *bitmap,uint32_t *res) +{ +__be32 *p; + + *res =0 ; +if (unlikely (bitmap[0 ] & (FATTR4_WORD0_CASE_INSENSITIVE -1U ))) +return -EIO ; +if (likely (bitmap[0 ] &FATTR4_WORD0_CASE_INSENSITIVE )) { + p =xdr_inline_decode (xdr,4 ); +if (unlikely (!p)) +return -EIO ; + *res =be32_to_cpup (p); + bitmap[0 ] &= ~FATTR4_WORD0_CASE_INSENSITIVE ; + } +dprintk ("%s: case_insensitive=%s\n" , __func__, *res ==0 ?"false" :"true" ); +return 0 ; +} + +static int decode_attr_case_preserving (struct xdr_stream *xdr,uint32_t *bitmap,uint32_t *res) +{ +__be32 *p; + + *res =0 ; +if (unlikely (bitmap[0 ] & (FATTR4_WORD0_CASE_PRESERVING -1U ))) +return -EIO ; +if (likely (bitmap[0 ] &FATTR4_WORD0_CASE_PRESERVING )) { + p =xdr_inline_decode (xdr,4 ); +if (unlikely (!p)) +return -EIO ; + *res =be32_to_cpup (p); + bitmap[0 ] &= ~FATTR4_WORD0_CASE_PRESERVING ; + } +dprintk ("%s: case_preserving=%s\n" , __func__, *res ==0 ?"false" :"true" ); +return 0 ; +} +static int decode_attr_fileid (struct xdr_stream *xdr,uint32_t *bitmap,uint64_t *fileid) {__be32 *p;
@@ -4412,6 +4448,10 @@ static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_re goto xdr_error;if ((status =decode_attr_aclsupport (xdr, bitmap, &res->acl_bitmask)) !=0 ) goto xdr_error; +if ((status =decode_attr_case_insensitive (xdr, bitmap, &res->case_insensitive)) !=0 ) + goto xdr_error; +if ((status =decode_attr_case_preserving (xdr, bitmap, &res->case_preserving)) !=0 ) + goto xdr_error;if ((status =decode_attr_exclcreat_supported (xdr, bitmap, res->exclcreat_bitmask)) !=0 ) goto xdr_error;
include/linux/nfs_fs_sb.h +2 -0
@@ -271,6 +271,8 @@ struct nfs_server {#define NFS_CAP_ACLS (1U << 3)#define NFS_CAP_ATOMIC_OPEN (1U << 4)#define NFS_CAP_LGOPEN (1U << 5) +#define NFS_CAP_CASE_INSENSITIVE (1U << 6) +#define NFS_CAP_CASE_PRESERVING (1U << 7)#define NFS_CAP_POSIX_LOCK (1U << 14)#define NFS_CAP_UIDGID_NOMAP (1U << 15)#define NFS_CAP_STATEID_NFSV41 (1U << 16)
include/linux/nfs_xdr.h +2 -0
@@ -1194,6 +1194,8 @@ struct nfs4_server_caps_res {u32 has_links;u32 has_symlinks;u32 fh_expire_type; +u32 case_insensitive; +u32 case_preserving; };#define NFS4_PATHNAME_MAXCOMPONENTS 512
Signature · 1 line
2.33.1
[email protected]
maintainerPATCH 2/5 NFSv4: Just don't cache negative dentries on case insensitive servers
From: Trond Myklebust <[email protected]>
If the directory contents change, we cannot rely on the negative dentry being cacheable.
--- fs/nfs/dir.c | 3 +++ 1 file changed, 3 insertions(+)
fs/nfs/dir.c +3 -0
@@ -1436,6 +1436,9 @@ int nfs_neg_need_reval(struct inode *dir, struct dentry *dentry,return 0 ;if (NFS_SERVER (dir)->flags &NFS_MOUNT_LOOKUP_CACHE_NONEG )return 1 ; +/* Case insensitive server? Revalidate negative dentries */ +if (nfs_server_capable (dir,NFS_CAP_CASE_INSENSITIVE )) +return 1 ;return !nfs_check_verifier (dir, dentry, flags &LOOKUP_RCU ); }
Signature · 1 line
2.33.1
[email protected]
maintainerPATCH 3/5 NFS: Invalidate negative dentries on all case insensitive directory changes
From: Trond Myklebust <[email protected]>
If we create a file, rename it, or hardlink it, then we need to assume that cached negative dentries need to be revalidated.
--- fs/nfs/dir.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
fs/nfs/dir.c +15 -4
@@ -1324,6 +1324,14 @@ void nfs_clear_verifier_delegated(struct inode *inode)EXPORT_SYMBOL_GPL (nfs_clear_verifier_delegated);#endif /* IS_ENABLED(CONFIG_NFS_V4) */ +static int nfs_dentry_verify_change (struct inode *dir,struct dentry *dentry) +{ +if (nfs_server_capable (dir,NFS_CAP_CASE_INSENSITIVE ) && +d_really_is_negative (dentry)) +return dentry->d_time ==inode_peek_iversion_raw (dir); +return nfs_verify_change_attribute (dir, dentry->d_time); +} +/* * A check for whether or not the parent directory has changed. * In the case it has, we assume that the dentries are untrustworthy
@@ -1337,7 +1345,7 @@ static int nfs_check_verifier(struct inode *dir, struct dentry *dentry,return 1 ;if (NFS_SERVER (dir)->flags &NFS_MOUNT_LOOKUP_CACHE_NONE )return 0 ; -if (!nfs_verify_change_attribute (dir, dentry->d_time)) +if (!nfs_dentry_verify_change (dir, dentry))return 0 ;/* Revalidate nfsi->cache_change_attribute before we declare a match */ if (nfs_mapping_need_revalidate_inode (dir)) {
@@ -1346,7 +1354,7 @@ static int nfs_check_verifier(struct inode *dir, struct dentry *dentry,if (__nfs_revalidate_inode (NFS_SERVER (dir), dir) <0 )return 0 ; } -if (!nfs_verify_change_attribute (dir, dentry->d_time)) +if (!nfs_dentry_verify_change (dir, dentry))return 0 ;return 1 ; }
@@ -1539,7 +1547,7 @@ nfs_lookup_revalidate_dentry(struct inode *dir, struct dentry *dentry,* If the lookup failed despite the dentry change attribute being * a match, then we should revalidate the directory cache. */ -if (!ret &&nfs_verify_change_attribute (dir, dentry->d_time)) +if (!ret &&nfs_dentry_verify_change (dir, dentry))nfs_mark_dir_for_revalidate (dir);return nfs_lookup_revalidate_done (dir, dentry, inode, ret); }
@@ -1778,8 +1786,11 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in dir_verifier =nfs_save_change_attribute (dir);trace_nfs_lookup_enter (dir, dentry, flags); error =NFS_PROTO (dir)->lookup (dir, dentry, fhandle, fattr); -if (error == -ENOENT ) +if (error == -ENOENT ) { +if (nfs_server_capable (dir,NFS_CAP_CASE_INSENSITIVE )) + dir_verifier =inode_peek_iversion_raw (dir); goto no_entry; + }if (error <0 ) { res =ERR_PTR (error); goto out;
Signature · 1 line
2.33.1
[email protected]
maintainerPATCH 4/5 NFS: Add a helper to remove case-insensitive aliases
From: Trond Myklebust <[email protected]>
When dealing with case insensitive names, the client has no idea how the server performs the mapping, so cannot collapse the dentries into a single representative. So both rename and unlink need to deal with the fact that there could be several dentries representing the file, and have to somehow force them to be revalidated. Use d_prune_aliases() as a big hammer approach.
--- fs/nfs/dir.c | 12 +++++++++++- fs/nfs/internal.h | 1 + fs/nfs/nfs4proc.c | 5 ++++- 3 files changed, 16 insertions(+), 2 deletions(-)
fs/nfs/dir.c +11 -1
@@ -1819,6 +1819,14 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in }EXPORT_SYMBOL_GPL (nfs_lookup); +void nfs_d_prune_case_insensitive_aliases (struct inode *inode) +{ +/* Case insensitive server? Revalidate dentries */ +if (inode &&nfs_server_capable (inode,NFS_CAP_CASE_INSENSITIVE )) +d_prune_aliases (inode); +} +EXPORT_SYMBOL_GPL (nfs_d_prune_case_insensitive_aliases); +#if IS_ENABLED (CONFIG_NFS_V4 )static int nfs4_lookup_revalidate (struct dentry *,unsigned int );
@@ -2199,8 +2207,10 @@ static void nfs_dentry_remove_handle_error(struct inode *dir,switch (error) {case -ENOENT :d_delete (dentry); - fallthrough; +nfs_set_verifier (dentry,nfs_save_change_attribute (dir)); +break ;case 0 : +nfs_d_prune_case_insensitive_aliases (d_inode (dentry));nfs_set_verifier (dentry,nfs_save_change_attribute (dir)); } }
fs/nfs/internal.h +1 -0
@@ -373,6 +373,7 @@ extern unsigned long nfs_access_cache_count(struct shrinker *shrink,extern unsigned long nfs_access_cache_scan (struct shrinker *shrink,struct shrink_control *sc);struct dentry *nfs_lookup (struct inode *,struct dentry *,unsigned int ); +void nfs_d_prune_case_insensitive_aliases (struct inode *inode);int nfs_create (struct user_namespace *,struct inode *,struct dentry *,umode_t ,bool ); int nfs_mkdir(struct user_namespace *, struct inode *, struct dentry *,
fs/nfs/nfs4proc.c +4 -1
@@ -4668,8 +4668,10 @@ static void nfs4_proc_unlink_setup(struct rpc_message *msg,nfs_fattr_init (res->dir_attr); -if (inode) +if (inode) {nfs4_inode_return_delegation (inode); +nfs_d_prune_case_insensitive_aliases (inode); + } }static void nfs4_proc_unlink_rpc_prepare (struct rpc_task *task,struct nfs_unlinkdata *data)
@@ -4735,6 +4737,7 @@ static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir,return 0 ;if (task->tk_status ==0 ) { +nfs_d_prune_case_insensitive_aliases (d_inode (data->old_dentry));if (new_dir != old_dir) {/* Note: If we moved a directory, nlink will change */ nfs4_update_changeattr(old_dir, &res->old_cinfo,
Signature · 1 line
2.33.1
[email protected]
maintainerPATCH 5/5 NFS: Fix the verifier for case sensitive filesystem in nfs_atomic_open()
From: Trond Myklebust <[email protected]>
--- fs/nfs/dir.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/nfs/dir.c +6 -1
@@ -1888,6 +1888,7 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,struct iattr attr = { .ia_valid =ATTR_OPEN };struct inode *inode;unsigned int lookup_flags =0 ; +unsigned long dir_verifier;bool switched = false;int created =0 ;int err;
@@ -1961,7 +1962,11 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,switch (err) {case -ENOENT :d_splice_alias (NULL , dentry); -nfs_set_verifier (dentry,nfs_save_change_attribute (dir)); +if (nfs_server_capable (dir,NFS_CAP_CASE_INSENSITIVE )) + dir_verifier =inode_peek_iversion_raw (dir); +else + dir_verifier =nfs_save_change_attribute (dir); +nfs_set_verifier (dentry, dir_verifier);break ;case -EISDIR :case -ENOTDIR :
Signature · 1 line
2.33.1
Quoted 7 lines · On Fri, Dec 17, 2021 at 03:36:53PM -0500, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Add support for detecting an export of a case insensitive filesystem in NFSv4. If that is the case, then we need to adjust the dentry caching and invalidation rules to ensure that we don't inadvertently end up caching other case folded aliases after an operation that results in a directory entry name change.
What server and configuration are you testing this against?
--b.
Quoted 20 lines
Trond Myklebust (5):
NFSv4: Add some support for case insensitive filesystems
NFSv4: Just don't cache negative dentries on case insensitive servers
NFS: Invalidate negative dentries on all case insensitive directory
changes
NFS: Add a helper to remove case-insensitive aliases
NFS: Fix the verifier for case sensitive filesystem in
nfs_atomic_open()fs/nfs/dir.c | 41 +++++++++++++++++++++++++++++++++------ fs/nfs/internal.h | 1 + fs/nfs/nfs4proc.c | 13 +++++++++++-- fs/nfs/nfs4xdr.c | 40 ++++++++++++++++++++++++++++++++++++++ include/linux/nfs_fs_sb.h | 2 ++ include/linux/nfs_xdr.h | 2 ++ 6 files changed, 91 insertions(+), 8 deletions(-)Signature · 1 line
2.33.1
Quoted 12 lines · J. Bruce Fields
Quoted 10 lines · On Fri, Dec 17, 2021 at 03:36:53PM -0500, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Add support for detecting an export of a case insensitive filesystem in
NFSv4. If that is the case, then we need to adjust the dentry caching
and invalidation rules to ensure that we don't inadvertently end up caching other case folded aliases after an operation that results in a
directory entry name change.
Quoted 3 lines
What server and configuration are you testing this against?
Ours. Why?
Quoted 26 lines
--b.
Quoted 24 lines
Trond Myklebust (5):
NFSv4: Add some support for case insensitive filesystems
NFSv4: Just don't cache negative dentries on case insensitive servers
NFS: Invalidate negative dentries on all case insensitive directory
changes
NFS: Add a helper to remove case-insensitive aliases
NFS: Fix the verifier for case sensitive filesystem innfs_atomic_open()fs/nfs/dir.c | 41 +++++++++++++++++++++++++++++++++--
----
fs/nfs/internal.h | 1 +
fs/nfs/nfs4proc.c | 13 +++++++++++-- fs/nfs/nfs4xdr.c | 40
++++++++++++++++++++++++++++++++++++++
include/linux/nfs_fs_sb.h | 2 ++ include/linux/nfs_xdr.h | 2 ++6 files changed, 91 insertions(+), 8 deletions(-)Signature · 1 line
2.33.1
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Quoted 13 lines · Trond Myklebust
Quoted 12 lines · J. Bruce Fields
Quoted 10 lines · On Fri, Dec 17, 2021 at 03:36:53PM -0500, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Add support for detecting an export of a case insensitive filesystem in
NFSv4. If that is the case, then we need to adjust the dentry caching
and invalidation rules to ensure that we don't inadvertently end up caching other case folded aliases after an operation that results in a
directory entry name change.
Quoted 3 lines
Quoted 1 line
What server and configuration are you testing this against?
Ours.
You mean, hammerspace?
Quoted 1 line
Why?
Partly just curiousity. Partly I thought we'd previously been trying to add features on server and client side together when it makes sense, if only to make it possible to test without access to proprietary software.
I don't actually have a strong opinion on the policy, but if this *is* a change in policy then it's worth mentioning.
There should be other exportable filesystems supporting those attributes so the work to export them on the server side wouldn't be a whole lot. (But I can't volunteer.)
--b.
Quoted 31 lines
Quoted 24 lines
Quoted 24 lines
Trond Myklebust (5):
NFSv4: Add some support for case insensitive filesystems
NFSv4: Just don't cache negative dentries on case insensitive servers
NFS: Invalidate negative dentries on all case insensitive directory
changes
NFS: Add a helper to remove case-insensitive aliases
NFS: Fix the verifier for case sensitive filesystem innfs_atomic_open()fs/nfs/dir.c | 41 +++++++++++++++++++++++++++++++++--
----
fs/nfs/internal.h | 1 +
fs/nfs/nfs4proc.c | 13 +++++++++++-- fs/nfs/nfs4xdr.c | 40
++++++++++++++++++++++++++++++++++++++
include/linux/nfs_fs_sb.h | 2 ++ include/linux/nfs_xdr.h | 2 ++6 files changed, 91 insertions(+), 8 deletions(-)Signature · 1 line
2.33.1Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Quoted 36 lines · On Mon, 2022-01-03 at 16:46 -0500, [email protected] wrote:
Quoted 16 lines · Trond Myklebust
Quoted 15 lines · J. Bruce Fields
Quoted 12 lines · On Fri, Dec 17, 2021 at 03:36:53PM -0500, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Add support for detecting an export of a case insensitive filesystem in
NFSv4. If that is the case, then we need to adjust the dentry caching
and invalidation rules to ensure that we don't inadvertently end up
caching other case folded aliases after an operation that results
in a
directory entry name change.Quoted 3 lines
Quoted 1 line
What server and configuration are you testing this against?
Ours.
You mean, hammerspace?
Quoted 1 line
Why?
Partly just curiousity. Partly I thought we'd previously been trying to
add features on server and client side together when it makes sense, if
only to make it possible to test without access to proprietary software.I don't actually have a strong opinion on the policy, but if this *is* a
change in policy then it's worth mentioning.
Quoted 9 lines
There should be other exportable filesystems supporting those attributes
so the work to export them on the server side wouldn't be a whole lot.
(But I can't volunteer.)--b.
Quoted 1 line
Quoted 1 line
Quoted 1 line
I don't see how it can be considered a change in policy or why it matters if it was. We already have plenty of features in the client which are not supported by knfsd, including several pNFS features, pNFS drivers, NFS ACL modes, filesystem migration support, to name but a few... knfsd lags behind in all these areas for a variety of reasons.
As for these particular features, they are of interest for Linux, not just for interoperability reasons. With recent changes, Linux has several filesystems that either are case insensitive, or can be configured that way, so there should be an interest in having knfsd support it. However I'm not going to volunteer either, because it's not something I can commit my employer's resources towards doing at this time.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]