2021-12-17 20:43:12

by Trond Myklebust

[permalink] [raw]
Subject: [PATCH 0/5] 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(-)

--
2.33.1



2021-12-17 20:43:13

by Trond Myklebust

[permalink] [raw]
Subject: [PATCH 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.

Signed-off-by: Trond Myklebust <[email protected]>
---
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(-)

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 535436dbdc9a..422375149c7c 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -3840,7 +3840,9 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *f
FATTR4_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;
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 69862bf6db00..c7250645e8b4 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -3533,6 +3533,42 @@ static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint
return 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;
diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h
index 2a9acbfe00f0..f24fc67af42d 100644
--- a/include/linux/nfs_fs_sb.h
+++ b/include/linux/nfs_fs_sb.h
@@ -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)
diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
index 967a0098f0a9..1d1f77809d5e 100644
--- a/include/linux/nfs_xdr.h
+++ b/include/linux/nfs_xdr.h
@@ -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
--
2.33.1


2021-12-17 20:43:16

by Trond Myklebust

[permalink] [raw]
Subject: [PATCH 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.

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/dir.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 731d31015b6a..2822681192b0 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -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);
}

--
2.33.1


2022-01-03 20:08:49

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH 0/5] Support case insensitive filesystems in NFSv4

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.

>
> 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(-)
>
> --
> 2.33.1

2022-01-03 20:12:04

by Trond Myklebust

[permalink] [raw]
Subject: Re: [PATCH 0/5] Support case insensitive filesystems in NFSv4

On Mon, 2022-01-03 at 15:08 -0500, J. Bruce Fields wrote:
> 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?
>
>

Ours. Why?

> --b.
>
> >
> > 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(-)
> >
> > --
> > 2.33.1

--
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]


2022-01-03 21:46:29

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH 0/5] Support case insensitive filesystems in NFSv4

On Mon, Jan 03, 2022 at 08:11:57PM +0000, Trond Myklebust wrote:
> On Mon, 2022-01-03 at 15:08 -0500, J. Bruce Fields wrote:
> > 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?
>
> Ours.

You mean, hammerspace?

> 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.

> > >
> > > 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(-)
> > >
> > > --
> > > 2.33.1
>
> --
> Trond Myklebust
> Linux NFS client maintainer, Hammerspace
> [email protected]
>
>

2022-01-03 22:13:49

by Trond Myklebust

[permalink] [raw]
Subject: Re: [PATCH 0/5] Support case insensitive filesystems in NFSv4

On Mon, 2022-01-03 at 16:46 -0500, [email protected] wrote:
> On Mon, Jan 03, 2022 at 08:11:57PM +0000, Trond Myklebust wrote:
> > On Mon, 2022-01-03 at 15:08 -0500, J. Bruce Fields wrote:
> > > 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?
> >
> > Ours.
>
> You mean, hammerspace?
>
> > 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.
>
> > > >

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.

--
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]