NFSD: Rebase dropped patches for block/scsi layout
cover NFSD: Rebase dropped patches for block/scsi layout
This series resubmits two patches that were dropped due to conflicts after the deviceid4 handling rework. The first patch is rebased. Only the decoding of bex.vol_id, which has the deviceid4 type, is updated. The second patch doesn't change, it just depends on the first one.
---
Sergey Bashirov (2):
NFSD: Implement large extent array support in pNFS
NFSD: Fix last write offset handling in layoutcommit
fs/nfsd/blocklayout.c | 25 ++++++------ fs/nfsd/blocklayoutxdr.c | 83 +++++++++++++++++++++++++++------------- fs/nfsd/blocklayoutxdr.h | 4 +- fs/nfsd/nfs4proc.c | 32 ++++++++-------- fs/nfsd/nfs4xdr.c | 11 +++--- fs/nfsd/pnfs.h | 1 + fs/nfsd/xdr4.h | 3 +- 7 files changed, 95 insertions(+), 64 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 NFSD: Implement large extent array support in pNFS
When pNFS client in the block or scsi layout mode sends layoutcommit to MDS, a variable length array of modified extents is supplied within the request. This patch allows the server to accept such extent arrays if they do not fit within single memory page.
The issue can be reproduced when writing to a 1GB file using FIO with O_DIRECT, 4K block and large I/O depth without preallocation of the file. In this case, the server returns NFSERR_BADXDR to the client.
--- fs/nfsd/blocklayout.c | 20 ++++++---- fs/nfsd/blocklayoutxdr.c | 83 +++++++++++++++++++++++++++------------- fs/nfsd/blocklayoutxdr.h | 4 +- fs/nfsd/nfs4proc.c | 2 +- fs/nfsd/nfs4xdr.c | 11 +++--- fs/nfsd/pnfs.h | 1 + fs/nfsd/xdr4.h | 3 +- 7 files changed, 78 insertions(+), 46 deletions(-)
fs/nfsd/blocklayout.c +12 -8
@@ -173,16 +173,18 @@ nfsd4_block_proc_getdeviceinfo(struct super_block *sb, }static __be32 -nfsd4_block_proc_layoutcommit (struct inode *inode, +nfsd4_block_proc_layoutcommit (struct inode *inode,struct svc_rqst *rqstp,struct nfsd4_layoutcommit *lcp) {struct iomap *iomaps;int nr_iomaps;__be32 nfserr; - nfserr =nfsd4_block_decode_layoutupdate (lcp->lc_up_layout, - lcp->lc_up_len, &iomaps, &nr_iomaps, -i_blocksize (inode)); + rqstp->rq_arg = lcp->lc_up_layout; +svcxdr_init_decode (rqstp); + + nfserr =nfsd4_block_decode_layoutupdate (&rqstp->rq_arg_stream, + &iomaps, &nr_iomaps,i_blocksize (inode));if (nfserr != nfs_ok)return nfserr;
@@ -313,16 +315,18 @@ nfsd4_scsi_proc_getdeviceinfo(struct super_block *sb,return nfserrno (nfsd4_block_get_device_info_scsi (sb, clp, gdp)); }static __be32 -nfsd4_scsi_proc_layoutcommit (struct inode *inode, +nfsd4_scsi_proc_layoutcommit (struct inode *inode,struct svc_rqst *rqstp,struct nfsd4_layoutcommit *lcp) {struct iomap *iomaps;int nr_iomaps;__be32 nfserr; - nfserr =nfsd4_scsi_decode_layoutupdate (lcp->lc_up_layout, - lcp->lc_up_len, &iomaps, &nr_iomaps, -i_blocksize (inode)); + rqstp->rq_arg = lcp->lc_up_layout; +svcxdr_init_decode (rqstp); + + nfserr =nfsd4_scsi_decode_layoutupdate (&rqstp->rq_arg_stream, + &iomaps, &nr_iomaps,i_blocksize (inode));if (nfserr != nfs_ok)return nfserr;
fs/nfsd/blocklayoutxdr.c +56 -27
163 lines not on this page · raw message
fs/nfsd/blocklayoutxdr.h +2 -2
@@ -54,9 +54,9 @@ __be32 nfsd4_block_encode_getdeviceinfo(struct xdr_stream *xdr, const struct nfsd4_getdeviceinfo *gdp);__be32 nfsd4_block_encode_layoutget (struct xdr_stream *xdr,const struct nfsd4_layoutget *lgp); -__be32 nfsd4_block_decode_layoutupdate (__be32 *p,u32 len, +__be32 nfsd4_block_decode_layoutupdate (struct xdr_stream *xdr,struct iomap **iomapp,int *nr_iomapsp,u32 block_size); -__be32 nfsd4_scsi_decode_layoutupdate (__be32 *p,u32 len, +__be32 nfsd4_scsi_decode_layoutupdate (struct xdr_stream *xdr,struct iomap **iomapp,int *nr_iomapsp,u32 block_size);#endif /* _NFSD_BLOCKLAYOUTXDR_H */
fs/nfsd/nfs4proc.c +1 -1
@@ -2520,7 +2520,7 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp, lcp->lc_size_chg = false; } - nfserr = ops->proc_layoutcommit (inode, lcp); + nfserr = ops->proc_layoutcommit (inode, rqstp, lcp);nfs4_put_stid (&ls->ls_stid); out:return nfserr;
fs/nfsd/nfs4xdr.c +5 -6
@@ -592,6 +592,8 @@ static __be32 nfsd4_decode_layoutupdate4(struct nfsd4_compoundargs *argp, struct nfsd4_layoutcommit *lcp) { + u32 len; +if (xdr_stream_decode_u32 (argp->xdr, &lcp->lc_layout_type) <0 )return nfserr_bad_xdr;if (lcp->lc_layout_type <LAYOUT_NFSV4_1_FILES )
@@ -599,13 +601,10 @@ nfsd4_decode_layoutupdate4(struct nfsd4_compoundargs *argp,if (lcp->lc_layout_type >=LAYOUT_TYPE_MAX )return nfserr_bad_xdr; -if (xdr_stream_decode_u32 (argp->xdr, &lcp->lc_up_len) <0 ) +if (xdr_stream_decode_u32 (argp->xdr, &len) <0 ) +return nfserr_bad_xdr; +if (!xdr_stream_subsegment (argp->xdr, &lcp->lc_up_layout, len))return nfserr_bad_xdr; -if (lcp->lc_up_len >0 ) { - lcp->lc_up_layout =xdr_inline_decode (argp->xdr, lcp->lc_up_len); -if (!lcp->lc_up_layout) -return nfserr_bad_xdr; - }return nfs_ok; }
fs/nfsd/pnfs.h +1 -0
@@ -35,6 +35,7 @@ struct nfsd4_layout_ops { const struct nfsd4_layoutget *lgp);__be32 (*proc_layoutcommit)(struct inode *inode, +struct svc_rqst *rqstp,struct nfsd4_layoutcommit *lcp); void (*fence_client)(struct nfs4_layout_stateid *ls,
fs/nfsd/xdr4.h +1 -2
@@ -664,8 +664,7 @@ struct nfsd4_layoutcommit {u64 lc_last_wr;/* request */ struct timespec64 lc_mtime;/* request */ u32 lc_layout_type;/* request */ -u32 lc_up_len;/* layout length */ -void *lc_up_layout;/* decoded by callback */ +struct xdr_buf lc_up_layout;/* decoded by callback */ bool lc_size_chg;/* response */ u64 lc_newsize;/* response */ };
Signature · 1 line
2.43.0
PATCH 2/2 NFSD: Fix last write offset handling in layoutcommit
In reply to Sergey BashirovThe data type of loca_last_write_offset is newoffset4 and is switched on a boolean value, no_newoffset, that indicates if a previous write occurred or not. If no_newoffset is FALSE, an offset is not given. This means that client does not try to update the file size. Thus, server should not try to calculate new file size and check if it fits into the segment range. See RFC 8881, section 12.5.4.2.
Sometimes the current incorrect logic may cause clients to hang when trying to sync an inode. If layoutcommit fails, the client marks the inode as dirty again.
--- fs/nfsd/blocklayout.c | 5 ++--- fs/nfsd/nfs4proc.c | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 18 deletions(-)
fs/nfsd/blocklayout.c +2 -3
@@ -118,7 +118,6 @@ nfsd4_block_commit_blocks(struct inode *inode, struct nfsd4_layoutcommit *lcp, struct iomap *iomaps, int nr_iomaps) {struct timespec64 mtime =inode_get_mtime (inode); -loff_t new_size = lcp->lc_last_wr +1 ;struct iattr iattr = { .ia_valid =0 };int error;
@@ -128,9 +127,9 @@ nfsd4_block_commit_blocks(struct inode *inode, struct nfsd4_layoutcommit *lcp, iattr.ia_valid |=ATTR_ATIME |ATTR_CTIME |ATTR_MTIME ; iattr.ia_atime = iattr.ia_ctime = iattr.ia_mtime = lcp->lc_mtime; -if (new_size >i_size_read (inode)) { +if (lcp->lc_size_chg) { iattr.ia_valid |=ATTR_SIZE ; - iattr.ia_size = new_size; + iattr.ia_size = lcp->lc_newsize; } error = inode->i_sb->s_export_op->commit_blocks(inode, iomaps,
fs/nfsd/nfs4proc.c +15 -15
@@ -2475,7 +2475,6 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp,const struct nfsd4_layout_seg *seg = &lcp->lc_seg;struct svc_fh *current_fh = &cstate->current_fh;const struct nfsd4_layout_ops *ops; -loff_t new_size = lcp->lc_last_wr +1 ;struct inode *inode;struct nfs4_layout_stateid *ls;__be32 nfserr;
@@ -2491,13 +2490,21 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp, goto out; inode =d_inode (current_fh->fh_dentry); - nfserr = nfserr_inval; -if (new_size <= seg->offset) - goto out; -if (new_size > seg->offset + seg->length) - goto out; -if (!lcp->lc_newoffset && new_size >i_size_read (inode)) - goto out; + lcp->lc_size_chg = false; +if (lcp->lc_newoffset) { +loff_t new_size = lcp->lc_last_wr +1 ; + + nfserr = nfserr_inval; +if (new_size <= seg->offset) + goto out; +if (new_size > seg->offset + seg->length) + goto out; + +if (new_size >i_size_read (inode)) { + lcp->lc_size_chg = true; + lcp->lc_newsize = new_size; + } + } nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid, false, lcp->lc_layout_type,
@@ -2513,13 +2520,6 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp,/* LAYOUTCOMMIT does not require any serialization */ mutex_unlock (&ls->ls_mutex); -if (new_size >i_size_read (inode)) { - lcp->lc_size_chg = true; - lcp->lc_newsize = new_size; - }else { - lcp->lc_size_chg = false; - } - nfserr = ops->proc_layoutcommit (inode, rqstp, lcp);nfs4_put_stid (&ls->ls_stid); out:
Signature · 1 line
2.43.0
Re: [PATCH 2/2] NFSD: Fix last write offset handling in layoutcommit
Quoted 3 lines · Sergey Bashirov
The data type of
loca_last_write_offsetis newoffset4 and is switched on a boolean value,no_newoffset, that indicates if a previous write occurred or not. Ifno_newoffsetis FALSE, an offset is not given.
Gah, what a confusing label in the spec. I went down the rabbit hole of trying to understand why "no_newoffset" being TRUE means that you do get an offset. The "no_" in this case is just a prefix for "union newoffset", and not a negation of the flag.
Quoted 88 lines
This means that client does not try to update the file size. Thus, server should not try to calculate new file size and check if it fits into the segment range. See RFC 8881, section 12.5.4.2.
Sometimes the current incorrect logic may cause clients to hang when trying to sync an inode. If layoutcommit fails, the client marks the inode as dirty again.
Fixes 9cf514ccfacb ("nfsd: implement pNFS operations")Co-developed-by Konstantin Evtushenko <[email protected]>Signed-off-by Konstantin Evtushenko <[email protected]>Signed-off-by Sergey Bashirov <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>--- fs/nfsd/blocklayout.c | 5 ++--- fs/nfsd/nfs4proc.c | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 18 deletions(-)fs/nfsd/blocklayout.c +2
-3@@ -118,7 +118,6 @@ nfsd4_block_commit_blocks(struct inode *inode, struct nfsd4_layoutcommit *lcp, struct iomap *iomaps, int nr_iomaps) {struct timespec64 mtime =inode_get_mtime (inode); -loff_t new_size = lcp->lc_last_wr +1 ;struct iattr iattr = { .ia_valid =0 };int error;@@ -128,9 +127,9 @@ nfsd4_block_commit_blocks(struct inode *inode, struct nfsd4_layoutcommit *lcp, iattr.ia_valid |=ATTR_ATIME |ATTR_CTIME |ATTR_MTIME ; iattr.ia_atime = iattr.ia_ctime = iattr.ia_mtime = lcp->lc_mtime; -if (new_size >i_size_read (inode)) { +if (lcp->lc_size_chg) { iattr.ia_valid |=ATTR_SIZE ; - iattr.ia_size = new_size; + iattr.ia_size = lcp->lc_newsize; } error = inode->i_sb->s_export_op->commit_blocks(inode, iomaps,fs/nfsd/nfs4proc.c +15
-8@@ -2475,7 +2475,6 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp,const struct nfsd4_layout_seg *seg = &lcp->lc_seg;struct svc_fh *current_fh = &cstate->current_fh;const struct nfsd4_layout_ops *ops; -loff_t new_size = lcp->lc_last_wr +1 ;struct inode *inode;struct nfs4_layout_stateid *ls;__be32 nfserr;@@ -2491,13 +2490,21 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp, goto out; inode =d_inode (current_fh->fh_dentry); - nfserr = nfserr_inval; -if (new_size <= seg->offset) - goto out; -if (new_size > seg->offset + seg->length) - goto out; -if (!lcp->lc_newoffset && new_size >i_size_read (inode)) - goto out; + lcp->lc_size_chg = false; +if (lcp->lc_newoffset) { +loff_t new_size = lcp->lc_last_wr +1 ; + + nfserr = nfserr_inval; +if (new_size <= seg->offset) + goto out; +if (new_size > seg->offset + seg->length) + goto out; + +if (new_size >i_size_read (inode)) { + lcp->lc_size_chg = true; + lcp->lc_newsize = new_size; + } + } nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid, false, lcp->lc_layout_type,@@ -2513,13 +2520,6 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp,/* LAYOUTCOMMIT does not require any serialization */ mutex_unlock (&ls->ls_mutex);
fs/nfsd/nfs4proc.c nfsd4_layoutcommit(struct svc_rqst *rqstp, · line 2525
Quoted 10 lines
fs/nfsd/nfs4proc.c +0
-7-if (new_size >i_size_read (inode)) { - lcp->lc_size_chg = true; - lcp->lc_newsize = new_size; - }else { - lcp->lc_size_chg = false; - } - nfserr = ops->proc_layoutcommit (inode, rqstp, lcp);nfs4_put_stid (&ls->ls_stid); out:
Code looks correct to me though.
Chuck Lever
maintainerFrom: Chuck Lever <[email protected]>
Quoted 6 lines · Sergey Bashirov
This series resubmits two patches that were dropped due to conflicts after the deviceid4 handling rework. The first patch is rebased. Only the decoding of bex.vol_id, which has the deviceid4 type, is updated. The second patch doesn't change, it just depends on the first one.
Applied to nfsd-testing, thanks!
[1/2] NFSD: Implement large extent array support in pNFS
commit: 0c8cc94a6dc2b200617094c0016cd46f01c12490
[2/2] NFSD: Fix last write offset handling in layoutcommit
commit: f91f48cedc8ef26d55a548e4e3879070d06906f6--
Chuck Lever