Skip to contentSkip to conversation

nfsd: Use correct error code when decoding extents

PATCH Superseded Sergey Bashirov 3 participants 5 messages Jun 11, 2025 – Jun 12, 2025

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nfsd: Use correct error code when decoding extents

Update error codes in decoding functions of block and scsi layout drivers to match the core nfsd code. NFS4ERR_EINVAL means that the server was able to decode the request, but the decoded values are invalid. Use NFS4ERR_BADXDR instead to indicate a decoding error. And ENOMEM is changed to nfs code NFS4ERR_DELAY.

---
Changes in v2:
- Add kdoc comments
- Add return code handling to blocklayout.c

 fs/nfsd/blocklayout.c    |  4 +--
 fs/nfsd/blocklayoutxdr.c | 55 +++++++++++++++++++++++++++++++++-------
 2 files changed, 48 insertions(+), 11 deletions(-)
fs/nfsd/blocklayout.c +2 -2
index 08a20e5bcf7f..c3491edb0302 100644
@@ -182,7 +182,7 @@ nfsd4_block_proc_layoutcommit(struct inode *inode,
 	nr_iomaps = nfsd4_block_decode_layoutupdate(lcp->lc_up_layout,
 			lcp->lc_up_len, &iomaps, i_blocksize(inode));
 	if (nr_iomaps < 0)
-		return nfserrno(nr_iomaps);
+		return cpu_to_be32(-nr_iomaps);
 
 	return nfsd4_block_commit_blocks(inode, lcp, iomaps, nr_iomaps);
 }
@@ -320,7 +320,7 @@ nfsd4_scsi_proc_layoutcommit(struct inode *inode,
 	nr_iomaps = nfsd4_scsi_decode_layoutupdate(lcp->lc_up_layout,
 			lcp->lc_up_len, &iomaps, i_blocksize(inode));
 	if (nr_iomaps < 0)
-		return nfserrno(nr_iomaps);
+		return cpu_to_be32(-nr_iomaps);
 
 	return nfsd4_block_commit_blocks(inode, lcp, iomaps, nr_iomaps);
 }
fs/nfsd/blocklayoutxdr.c +46 -9

111 lines not on this page · raw message

Signature · 1 line
2.43.0
#1 lore raw

fs/nfsd/blocklayout.c nfsd4_block_proc_layoutcommit(struct inode *inode, · line 185

Quoted 3 lines · Sergey Bashirov
fs/nfsd/blocklayout.c +1 -1
 	if (nr_iomaps < 0)
-		return nfserrno(nr_iomaps);
+		return cpu_to_be32(-nr_iomaps);

This still feels like an odd calling convention. Maybe we should just change the calling convention to return the __be32 encoded nfs errno and have a separate output argument for the number of iomaps?

Chuck, any preference?

#2 lore raw
Quoted 11 lines · Christoph Hellwig

fs/nfsd/blocklayout.c nfsd4_block_proc_layoutcommit(struct inode *inode, · line 185

Quoted 3 lines · Sergey Bashirov
fs/nfsd/blocklayout.c +1 -1
 	if (nr_iomaps < 0)
-		return nfserrno(nr_iomaps);
+		return cpu_to_be32(-nr_iomaps);

This still feels like an odd calling convention. Maybe we should just change the calling convention to return the __be32 encoded nfs errno and have a separate output argument for the number of iomaps?

Chuck, any preference?

I thought of using an output argument. This calling convention is not uncommon in NFS code, and I recall that Linus might prefer avoiding output arguments?

If I were writing fresh code, I think I would use an output argument instead of folding results of two different types into a function's return value.

Signature · 1 line
Chuck Lever
#3 lore raw
Quoted 13 lines · Chuck Lever
Quoted 11 lines · Christoph Hellwig

fs/nfsd/blocklayout.c nfsd4_block_proc_layoutcommit(struct inode *inode, · line 185

Quoted 3 lines · Sergey Bashirov
fs/nfsd/blocklayout.c +1 -1
 	if (nr_iomaps < 0)
-		return nfserrno(nr_iomaps);
+		return cpu_to_be32(-nr_iomaps);

This still feels like an odd calling convention. Maybe we should just change the calling convention to return the __be32 encoded nfs errno and have a separate output argument for the number of iomaps?

Chuck, any preference?

Quoted 7 lines

I thought of using an output argument. This calling convention is not uncommon in NFS code, and I recall that Linus might prefer avoiding output arguments?

If I were writing fresh code, I think I would use an output argument instead of folding results of two different types into a function's return value.

In general, I am ok with either of these two approaches. But I agree with Christoph that the solution with a separate output argument seems more natural to me. Should I submit the v3 patch with a separate output argument?

--
Sergey Bashirov

#4 lore raw
Quoted 18 lines · Sergey Bashirov
Quoted 17 lines · Chuck Lever
Quoted 11 lines · Christoph Hellwig

fs/nfsd/blocklayout.c nfsd4_block_proc_layoutcommit(struct inode *inode, · line 185

Quoted 3 lines · Sergey Bashirov
fs/nfsd/blocklayout.c +1 -1
 	if (nr_iomaps < 0)
-		return nfserrno(nr_iomaps);
+		return cpu_to_be32(-nr_iomaps);

This still feels like an odd calling convention. Maybe we should just change the calling convention to return the __be32 encoded nfs errno and have a separate output argument for the number of iomaps?

Chuck, any preference?

I thought of using an output argument. This calling convention is not uncommon in NFS code, and I recall that Linus might prefer avoiding output arguments?

Quoted 8 lines
Quoted 3 lines

If I were writing fresh code, I think I would use an output argument instead of folding results of two different types into a function's return value.

In general, I am ok with either of these two approaches. But I agree with Christoph that the solution with a separate output argument seems more natural to me. Should I submit the v3 patch with a separate output argument?

Yes, thank you!

Signature · 1 line
Chuck Lever