pNFS: Fix the pnfs block driver's calculation of layoutget size

Instead of relying on the value of the 'bytes_left' field, we should
calculate the layout size based on the offset of the request that is
being written out.

Reported-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Fixes: 954998b60c ("NFS: Fix error handling for O_DIRECT write scheduling")
Reviewed-by: Benjamin Coddington <bcodding@redhat.com>
Tested-by: Benjamin Coddington <bcodding@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
Trond Myklebust 2023-11-17 06:25:13 -05:00 committed by Anna Schumaker
parent f6e70c59ed
commit 8a6291bf3b
4 changed files with 8 additions and 7 deletions

View File

@ -895,10 +895,9 @@ bl_pg_init_write(struct nfs_pageio_descriptor *pgio, struct nfs_page *req)
} }
if (pgio->pg_dreq == NULL) if (pgio->pg_dreq == NULL)
wb_size = pnfs_num_cont_bytes(pgio->pg_inode, wb_size = pnfs_num_cont_bytes(pgio->pg_inode, req->wb_index);
req->wb_index);
else else
wb_size = nfs_dreq_bytes_left(pgio->pg_dreq); wb_size = nfs_dreq_bytes_left(pgio->pg_dreq, req_offset(req));
pnfs_generic_pg_init_write(pgio, req, wb_size); pnfs_generic_pg_init_write(pgio, req, wb_size);

View File

@ -205,9 +205,10 @@ static void nfs_direct_req_release(struct nfs_direct_req *dreq)
kref_put(&dreq->kref, nfs_direct_req_free); kref_put(&dreq->kref, nfs_direct_req_free);
} }
ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq) ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq, loff_t offset)
{ {
return dreq->bytes_left; loff_t start = offset - dreq->io_start;
return dreq->max_count - start;
} }
EXPORT_SYMBOL_GPL(nfs_dreq_bytes_left); EXPORT_SYMBOL_GPL(nfs_dreq_bytes_left);

View File

@ -655,7 +655,7 @@ extern int nfs_sillyrename(struct inode *dir, struct dentry *dentry);
/* direct.c */ /* direct.c */
void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo, void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo,
struct nfs_direct_req *dreq); struct nfs_direct_req *dreq);
extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq); extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq, loff_t offset);
/* nfs4proc.c */ /* nfs4proc.c */
extern struct nfs_client *nfs4_init_client(struct nfs_client *clp, extern struct nfs_client *nfs4_init_client(struct nfs_client *clp,

View File

@ -2733,7 +2733,8 @@ pnfs_generic_pg_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *r
if (pgio->pg_dreq == NULL) if (pgio->pg_dreq == NULL)
rd_size = i_size_read(pgio->pg_inode) - req_offset(req); rd_size = i_size_read(pgio->pg_inode) - req_offset(req);
else else
rd_size = nfs_dreq_bytes_left(pgio->pg_dreq); rd_size = nfs_dreq_bytes_left(pgio->pg_dreq,
req_offset(req));
pgio->pg_lseg = pgio->pg_lseg =
pnfs_update_layout(pgio->pg_inode, nfs_req_openctx(req), pnfs_update_layout(pgio->pg_inode, nfs_req_openctx(req),