Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp576864imu; Fri, 11 Jan 2019 05:35:57 -0800 (PST) X-Google-Smtp-Source: ALg8bN5g4syIqxeQL7WYs+KCrDyLIXf3egXy+O4PSI75akHoY7gDeC6cZLiS3NdcEPxH+4/Ed+Es X-Received: by 2002:a17:902:2bc5:: with SMTP id l63mr14936200plb.107.1547213757151; Fri, 11 Jan 2019 05:35:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547213757; cv=none; d=google.com; s=arc-20160816; b=iJbpBClqtGjry+lURDJ1F2FRrBSQ+qQpXLxW8XdDItWWYFnDZJ4DgyXpMTpr1qft0b DRVDrRV6JZSBVlO2ovl7IFvH/pD/G5IGNQrDfHPV+xxTHXQ46xqJ3OtZVS6/aqTjVJWJ 8hiNTuFMzaeDqX1Hi2ptGzU4UKZCGhQ506yUvBT38YR6/fcCP/eMX4oyD0HyePxp6tec jJW3KogEOKoT3Yhn+ib3EzeyBQ+ai2Z7s5CP9laN/4DmoPCjkrqBTNoW+77Uv/DcN/bw kEQhKSkbFXu2FTLAH/d3dlpT5eO1lhTKsePMiNi0FFPppc3Q75cx3ImUnILIqz4FG9mz qAoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=NqRnUsjWXdLCn3+BBd1E+TE68uZNAdSmdjd3DOkgrrI=; b=O6pFkQvZgWKcwfzWvgnGz3Re3juJhFI63FAk00ZAO0+l4KIagmB8sEONNyaUTXWzbI X8A39Ax2dCv+I0UoegZqQ+uWNKFTcdjxO25pUkdh2+OPU4PXgTU/09KYl45U8nA0ioqX 7lbO4tmlxmAAQWQOwZ/8loA3ewx4Cq1TPg3TbSdasTL1Us9ahk4MVPK1DYE5iMHDW1a2 c9I8Jgx+izqgZ3zJ+ul47/guAaUCR8SfqmwJwaz51szjl3BOBMDKCv7eWD+6ps+yFURM cr7WVS02I+TnYnf2X8cf+5IbFnWvB3Ct4U6v9sYBRYXw96xDDfMPgOBJJKQm8IVvm9hh QVTg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b63si77456408pfa.250.2019.01.11.05.35.41; Fri, 11 Jan 2019 05:35:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732065AbfAKLEH (ORCPT + 99 others); Fri, 11 Jan 2019 06:04:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55732 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbfAKLEF (ORCPT ); Fri, 11 Jan 2019 06:04:05 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C297F7E45A; Fri, 11 Jan 2019 11:04:04 +0000 (UTC) Received: from localhost (ovpn-8-28.pek2.redhat.com [10.72.8.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 368A71019626; Fri, 11 Jan 2019 11:03:53 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V13 09/19] block: introduce bvec_last_segment() Date: Fri, 11 Jan 2019 19:01:17 +0800 Message-Id: <20190111110127.21664-10-ming.lei@redhat.com> In-Reply-To: <20190111110127.21664-1-ming.lei@redhat.com> References: <20190111110127.21664-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 11 Jan 2019 11:04:05 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org BTRFS and guard_bio_eod() need to get the last singlepage segment from one multipage bvec, so introduce this helper to make them happy. Reviewed-by: Omar Sandoval 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 d441486db605..ca6e630f88ab 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -131,4 +131,26 @@ static inline bool bvec_iter_advance(const struct bio_vec *bv, .bi_bvec_done = 0, \ } +/* + * Get the last single-page segment from the multi-page bvec and store it + * in @seg + */ +static inline void bvec_last_segment(const struct bio_vec *bvec, + struct bio_vec *seg) +{ + unsigned total = bvec->bv_offset + bvec->bv_len; + unsigned last_page = (total - 1) / PAGE_SIZE; + + 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