Message ID | 20240221151613.555-1-chenhx.fnst@fujitsu.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | nfs: fix regression in handling of namlen= option in NFSv4 | expand |
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 <trondmy@hammerspace.com> > 发送时间: 2024年2月29日 5:03 > 收件人: anna@kernel.org; > 抄送: linux-nfs@vger.kernel.org; jlayton@kernel.org > 主题: 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
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 {
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 <chenhx.fnst@fujitsu.com> --- fs/nfs/namespace.c | 2 ++ fs/nfs/nfs4client.c | 2 ++ fs/nfs/nfs4namespace.c | 2 ++ 3 files changed, 6 insertions(+)