From f57030811f20b7c3e1432134ff97c9929ff4e0c8 Mon Sep 17 00:00:00 2001 From: Mikhail Pershin Date: Fri, 14 Feb 2020 12:59:05 +0300 Subject: [PATCH] LU-13004 target: take offset into account in tgt_send_buffer While calculating amount of pages needed, take buffer offset into account because it can be non-aligned after allocations in out_read(). Signed-off-by: Mikhail Pershin Change-Id: Ib7c9b35d328d366a27cc553ffe2f2c5930949cf4 Reviewed-on: https://review.whamcloud.com/37571 Tested-by: jenkins Reviewed-by: Neil Brown Reviewed-by: James Simmons Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/ptlrpc/client.c | 4 ++-- lustre/target/tgt_handler.c | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lustre/ptlrpc/client.c b/lustre/ptlrpc/client.c index cc93dd4..98486eb 100644 --- a/lustre/ptlrpc/client.c +++ b/lustre/ptlrpc/client.c @@ -72,13 +72,13 @@ static void ptlrpc_release_bulk_page_pin(struct ptlrpc_bulk_desc *desc) static int ptlrpc_prep_bulk_frag_pages(struct ptlrpc_bulk_desc *desc, void *frag, int len) { - unsigned int offset = (uintptr_t)frag & ~PAGE_MASK; + unsigned int offset = (unsigned long)frag & ~PAGE_MASK; ENTRY; while (len > 0) { int page_len = min_t(unsigned int, PAGE_SIZE - offset, len); - uintptr_t vaddr = (uintptr_t) frag; + unsigned long vaddr = (unsigned long)frag; ptlrpc_prep_bulk_page_nopin(desc, lnet_kvaddr_to_page(vaddr), diff --git a/lustre/target/tgt_handler.c b/lustre/target/tgt_handler.c index dd2ec2e..df2b1c6 100644 --- a/lustre/target/tgt_handler.c +++ b/lustre/target/tgt_handler.c @@ -1073,12 +1073,14 @@ int tgt_send_buffer(struct tgt_session_info *tsi, struct lu_rdbuf *rdbuf) ENTRY; - for (i = 0; i < rdbuf->rb_nbufs; i++) - /* There is only one caller (out_read) and we *know* that - * bufs are at most 4K, and 4K aligned, so a simple DIV_ROUND_UP - * is always sufficient. - */ - pages += DIV_ROUND_UP(rdbuf->rb_bufs[i].lb_len, PAGE_SIZE); + for (i = 0; i < rdbuf->rb_nbufs; i++) { + unsigned int offset; + + offset = (unsigned long)rdbuf->rb_bufs[i].lb_buf & ~PAGE_MASK; + pages += DIV_ROUND_UP(rdbuf->rb_bufs[i].lb_len + offset, + PAGE_SIZE); + } + desc = ptlrpc_prep_bulk_exp(req, pages, 1, PTLRPC_BULK_PUT_SOURCE | PTLRPC_BULK_BUF_KIOV, MDS_BULK_PORTAL, -- 1.8.3.1