From patchwork Mon Dec 18 12:22:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10119425 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EB7A460327 for ; Mon, 18 Dec 2017 12:39:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBD0D28FD5 for ; Mon, 18 Dec 2017 12:39:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDFBE28FD6; Mon, 18 Dec 2017 12:39:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 940FA28FD4 for ; Mon, 18 Dec 2017 12:39:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759128AbdLRM2x (ORCPT ); Mon, 18 Dec 2017 07:28:53 -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 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7E692356F4; Mon, 18 Dec 2017 12:28:51 +0000 (UTC) Received: from localhost (ovpn-12-48.pek2.redhat.com [10.72.12.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BBA47BFFC; Mon, 18 Dec 2017 12:28:41 +0000 (UTC) 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 */