From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Ming Lei To: Jens Axboe , Christoph Hellwig , Alexander Viro , Kent Overstreet Cc: David Sterba , 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 , Randy Dunlap , Ming Lei Subject: [PATCH V6 08/30] block: introduce chunk_last_segment() Date: Sat, 9 Jun 2018 20:29:52 +0800 Message-Id: <20180609123014.8861-9-ming.lei@redhat.com> In-Reply-To: <20180609123014.8861-1-ming.lei@redhat.com> References: <20180609123014.8861-1-ming.lei@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: BTRFS and guard_bio_eod() need to get the last singlepage segment from one multipage chunk, so introduce this helper to make them happy. Signed-off-by: Ming Lei --- include/linux/bvec.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index 9e082d023392..aac75d87d884 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -219,4 +219,29 @@ static inline bool bvec_iter_chunk_advance(const struct bio_vec *bv, .bi_bvec_done = 0, \ } +/* + * Get the last singlepage segment from the multipage bvec and store it + * in @seg + */ +static inline void chunk_last_segment(const struct bio_vec *bvec, + struct bio_vec *seg) +{ + unsigned total = bvec->bv_offset + bvec->bv_len; + unsigned last_page = total / PAGE_SIZE; + + if (last_page * PAGE_SIZE == total) + last_page--; + + seg->bv_page = nth_page(bvec->bv_page, last_page); + + /* the whole segment is inside the last page */ + if (bvec->bv_offset >= last_page * PAGE_SIZE) { + seg->bv_offset = bvec->bv_offset % PAGE_SIZE; + seg->bv_len = bvec->bv_len; + } else { + seg->bv_offset = 0; + seg->bv_len = total - last_page * PAGE_SIZE; + } +} + #endif /* __LINUX_BVEC_ITER_H */ -- 2.9.5