Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759142AbdLRM2y (ORCPT ); Mon, 18 Dec 2017 07:28:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41842 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759124AbdLRM2v (ORCPT ); Mon, 18 Dec 2017 07:28:51 -0500 From: Ming Lei To: Jens Axboe , Christoph Hellwig , Alexander Viro , Kent Overstreet Cc: Huang Ying , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, "Theodore Ts'o" , "Darrick J . Wong" , Coly Li , Filipe Manana , Ming Lei Subject: [PATCH V4 22/45] block: introduce segment_last_page() Date: Mon, 18 Dec 2017 20:22:24 +0800 Message-Id: <20171218122247.3488-23-ming.lei@redhat.com> In-Reply-To: <20171218122247.3488-1-ming.lei@redhat.com> References: <20171218122247.3488-1-ming.lei@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 18 Dec 2017 12:28:51 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1193 Lines: 41 BTRFS and guard_bio_eod() need to get the last page from one segment, so introduce this helper to make them happy. Signed-off-by: Ming Lei --- include/linux/bvec.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index 84c395feed49..217afcd83a15 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -219,4 +219,26 @@ static inline bool bvec_iter_seg_advance(const struct bio_vec *bv, .bi_bvec_done = 0, \ } +/* get the last page from the multipage bvec and store it in @pg */ +static inline void segment_last_page(const struct bio_vec *seg, + struct bio_vec *pg) +{ + unsigned total = seg->bv_offset + seg->bv_len; + unsigned last_page = total / PAGE_SIZE; + + if (last_page * PAGE_SIZE == total) + last_page--; + + pg->bv_page = nth_page(seg->bv_page, last_page); + + /* the whole segment is inside the last page */ + if (seg->bv_offset >= last_page * PAGE_SIZE) { + pg->bv_offset = seg->bv_offset % PAGE_SIZE; + pg->bv_len = seg->bv_len; + } else { + pg->bv_offset = 0; + pg->bv_len = total - last_page * PAGE_SIZE; + } +} + #endif /* __LINUX_BVEC_ITER_H */ -- 2.9.5