2024-02-21 15:18:37

by Chen Hanxiao

[permalink] [raw]
Subject: [PATCH] nfs: fix regression in handling of namlen= option in NFSv4

Setting the maximum length of a pathname component
via the namlen= mount option is currently broken in NFSv4.

This patch will fix this issue.

Signed-off-by: Chen Hanxiao <[email protected]>
---
fs/nfs/namespace.c | 2 ++
fs/nfs/nfs4client.c | 2 ++
fs/nfs/nfs4namespace.c | 2 ++
3 files changed, 6 insertions(+)

diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c
index e7494cdd957e..8da1fc9ebbd4 100644
--- a/fs/nfs/namespace.c
+++ b/fs/nfs/namespace.c
@@ -277,6 +277,8 @@ int nfs_do_submount(struct fs_context *fc)
if (IS_ERR(server))
return PTR_ERR(server);

+ if (ctx->namlen)
+ server->namelen = ctx->namlen;
ctx->server = server;

buffer = kmalloc(4096, GFP_USER);
diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c
index 11e3a285594c..9826c2fcb0a7 100644
--- a/fs/nfs/nfs4client.c
+++ b/fs/nfs/nfs4client.c
@@ -1187,6 +1187,8 @@ static int nfs4_init_server(struct nfs_server *server, struct fs_context *fc)
server->rsize = nfs_io_size(ctx->rsize, server->nfs_client->cl_proto);
if (ctx->wsize)
server->wsize = nfs_io_size(ctx->wsize, server->nfs_client->cl_proto);
+ if (ctx->namlen)
+ server->namelen = ctx->namlen;

server->acregmin = ctx->acregmin * HZ;
server->acregmax = ctx->acregmax * HZ;
diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c
index 9a98595bb160..1a30224df7b9 100644
--- a/fs/nfs/nfs4namespace.c
+++ b/fs/nfs/nfs4namespace.c
@@ -465,6 +465,8 @@ int nfs4_submount(struct fs_context *fc, struct nfs_server *server)
return PTR_ERR(client);

ctx->selected_flavor = client->cl_auth->au_flavor;
+ if (server->namelen)
+ ctx->namlen = server->namelen;
if (ctx->clone_data.fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) {
ret = nfs_do_refmount(fc, client);
} else {
--
2.39.1



2024-02-28 21:18:56

by Trond Myklebust

[permalink] [raw]
Subject: Re: [PATCH] nfs: fix regression in handling of namlen= option in NFSv4

On Wed, 2024-02-21 at 23:16 +0800, Chen Hanxiao wrote:
> Setting the maximum length of a pathname component
> via the namlen= mount option is currently broken in NFSv4.
>
> This patch will fix this issue.

Why do we need this? In NFSv3 and NFSv4, the server will communicate
the correct value through the protocol.


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


2024-02-29 14:44:12

by Chen Hanxiao

[permalink] [raw]
Subject: Re: [PATCH] nfs: fix regression in handling of namlen= option in NFSv4



> -----邮件原件-----
> 发件人: Trond Myklebust <[email protected]>
> 发送时间: 2024年2月29日 5:03
> 收件人: [email protected];
> 抄送: [email protected]; [email protected]
> 主题: Re: [PATCH] nfs: fix regression in handling of namlen= option in NFSv4
>
> On Wed, 2024-02-21 at 23:16 +0800, Chen Hanxiao wrote:
> > Setting the maximum length of a pathname component
> > via the namlen= mount option is currently broken in NFSv4.
> >
> > This patch will fix this issue.
>
> Why do we need this? In NFSv3 and NFSv4, the server will communicate
> the correct value through the protocol.
>

In NFSv3, we could set namlen parameters:
#mount -t nfs -o vers=3,namlen=100 192.168.122.210:/nfsroot /mnt

And nfs_server.namelen is set to the values from command line.
# mount
...
192.168.122.210:/nfsroot on /mnt type nfs (rw,relatime,vers=3,rsize=262144,wsize=262144,namlen=100,hard,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=192.168.122.210,mountvers=3,mountport=20048,mountproto=udp,local_lock=none,addr=192.168.122.210)

But for NFSv4, mount cmd with namlen could success, but no effect:

# mount -t nfs4 -o vers=4.2,namlen=100 192.168.122.210:/nfsroot /mnt/

# mount
...
192.168.122.210:/nfsroot on /mnt type nfs4 (rw,relatime,vers=4.2,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.122.208,local_lock=none,addr=192.168.122.210)

I have some questions:
1) As we can set namlen in NFSv3, does NFS client use this parameter to limit something?
2) If 1) stands, do we need this for NFSv4, or reject namlen in a vers=4 mount?

Regards,
- Chen