From patchwork Fri May 25 03:45:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10426041 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 5741A602D8 for ; Fri, 25 May 2018 03:48:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46E8A28D8F for ; Fri, 25 May 2018 03:48:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B46128DB7; Fri, 25 May 2018 03:48:28 +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=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CBAEB28D8F for ; Fri, 25 May 2018 03:48:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9AB86B029A; Thu, 24 May 2018 23:48:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C4C8D6B029C; Thu, 24 May 2018 23:48:26 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B3BA46B029D; Thu, 24 May 2018 23:48:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f200.google.com (mail-qt0-f200.google.com [209.85.216.200]) by kanga.kvack.org (Postfix) with ESMTP id 8989B6B029A for ; Thu, 24 May 2018 23:48:26 -0400 (EDT) Received: by mail-qt0-f200.google.com with SMTP id x2-v6so2830343qto.10 for ; Thu, 24 May 2018 20:48:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=kIf8e2+CSp2GoGN1UOam58rvDOPaAEMzrBC6zmq0pBg=; b=bhaUXitu016DiCdIJn+8SVPMmNCZ401vsWc10f56VOpdF4MZE6jwLBiZ4UEde/tJR4 MAeQxcpDRGO+d209E30KFGR3UHkRB+yFQmfMUFR0nKwhmr6h3RraPVNiz41JyHVTq2T9 +g5NLvlWemjm/cGXCqxhjwXmgTJY7eVa1tbZqJmF2A15DdkMJ4X1sWZZ0vqT4x9oOcmg YCzSX1PrIFaUnzlDIH8lpY823IejFNi/Iw9nDQhiPwn9CcgoWQuvatwV4QJqTBFai+1f 1vP+HoYFO5qUlQtc+NkSzbgdaUqsJEM3914/4eI60YMagjKpm0ATioPdO6kC2OdwLwDW 4Q+w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: ALKqPwf6LSZQZRvMR/jCn7Vur5LapEmIgoVWTqXVCrkmNokfyqAyPCfY O50/nc32szXyQwLXFTNuJPi5SPiGs8+ucB6sihmqCTQB9NG4QF5+5/tJOmFVxJT3tut6B93aMlD FKKtzfg+X/+vtD3MP/ITi+torvlyqaJ+xRtSO53Zu9sOEe32llzWcYH5e96j9tTW/6A== X-Received: by 2002:ac8:1bdb:: with SMTP id m27-v6mr566063qtk.161.1527220106372; Thu, 24 May 2018 20:48:26 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKREVIf4dUr0Mhod4QF9zZvX3DXllaAiisQm7aTwCRcAlHyKGDbePZtPdIjHZMbMt16CYOH X-Received: by 2002:ac8:1bdb:: with SMTP id m27-v6mr566051qtk.161.1527220105897; Thu, 24 May 2018 20:48:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527220105; cv=none; d=google.com; s=arc-20160816; b=uBluYA7qh4krze0TXpFYVhj0zSZKLp2/EGynXo2MvKyQjyffHE+pmAehj+nRakJTiB wGHshaInb1uStFmoi+DSX51TeTkDyme/54kDWKOK9ZC4MbB6de2cMdh4kssRN2GhECDy aVRKaA4wgl7KzF/6oCR0warKTNYPK0qgPIgVEieZMlUa2yizJJpgpscqK0Lq1nxW89bj TznjcTgcvNEoLgPVrvs5/MNdZsrHZeNGF5mZ0V1thuG5lxvPgYGrgqVGK+/0PAUx8hZ2 vC0jyOFOMCo+pAhQ15PHKB0kGmNGm3g7b608jshRlZNYX22k2munRgOTeYtM5kxrY0Qg QzPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=kIf8e2+CSp2GoGN1UOam58rvDOPaAEMzrBC6zmq0pBg=; b=WlNsw9SO8XdJzODEoN1oVfXTrr5XHqX+L6yHbHdS+9Rn5dfhJfTbQ3LY0KAnARroXN RZ8zJCGDlshTcXAntb7zXuUKzUxHfwTC7/2Dti0WrHQKnlsV/e0/h4RDIltaogwG5io5 IgQgbBRDqdc9SJN9nAO4Qz5mntNvkm1XstcUzZPtLDvBi6t/QVZg1qTqYuvl3YtmqdBs drR/KLDXTfHhGrPfYWGSpxAjYISCyxLh3p7k//s18+nTDat9u1IqJBjPNcfoev/XT3Dz rDIY756wXwj9HgjyxpbN8xQnHepFRYF3cAENGossXC21n9grKxVnQBpfCN1Y1RBLZpdB 2v0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx3-rdu2.redhat.com. [66.187.233.73]) by mx.google.com with ESMTPS id n12-v6si5817090qkl.306.2018.05.24.20.48.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 May 2018 20:48:25 -0700 (PDT) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) client-ip=66.187.233.73; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8F6C04022414; Fri, 25 May 2018 03:48:25 +0000 (UTC) Received: from localhost (ovpn-12-30.pek2.redhat.com [10.72.12.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id B368F111765C; Fri, 25 May 2018 03:48:15 +0000 (UTC) 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 , Ming Lei Subject: [RESEND PATCH V5 08/33] block: introduce segment_last_page() Date: Fri, 25 May 2018 11:45:56 +0800 Message-Id: <20180525034621.31147-9-ming.lei@redhat.com> In-Reply-To: <20180525034621.31147-1-ming.lei@redhat.com> References: <20180525034621.31147-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 25 May 2018 03:48:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 25 May 2018 03:48:25 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ming.lei@redhat.com' RCPT:'' X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 */