Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7768164imu; Thu, 15 Nov 2018 00:57:27 -0800 (PST) X-Google-Smtp-Source: AJdET5eiLVpLvxZKeVJdcdt5axMlJzWgT0d6YsKEWHzPWqi6rQE7WxPK7pBBf5CZiufHggmfPCmA X-Received: by 2002:a62:54c4:: with SMTP id i187-v6mr5584606pfb.155.1542272247200; Thu, 15 Nov 2018 00:57:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542272247; cv=none; d=google.com; s=arc-20160816; b=Rixn4gC3MGoLe7m6LVQ3b6q2as8+npH9d1YKjX1vQ5nHgfzAPEba6tLQxhmKjkZj2f EzVQhxSOzIsOEZ8s76lhyO1tyu0hd1ybrzkacCLa0c8hHcK0ThPC2Sytms4We8AhYNDC 4XmTfis7vc7/MrypUt2asJw4qdQoMHyjMpERMJJLGI9Y4d24cev9IDvGBC7leaa/ajgF tiOp8jdFLR2XBRpdQoLQNxCVTdyMedTXuQb3y3oZPSVsAfofz26accr43C2Z1dmZ+INh 3BhVwdPdTYOQ9n2vuXEjOoiNTygMzaMVtuB4NXQCDZ9ifw3N1lAVlNxECced9fUZjBFU tF9Q== 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=CjGkhGQ3mjObcZSlpfeHqGI+rxG1OBhrlzbMY/mtO8E=; b=tks0+7ORLdi307GTD0OO7IAet5Pnm5/z9zrSQM6/13VAUzag3zzkK6yjMB5UKb2ucw SlK6s+HKWudhYElbCzdycIDJBxy3OI/b8ziKewTQ0eoY+MrwcBkrTYhYUEhHM8wSbtZf LroZHoJtBUS61sXFmfjkp66ofAKKqNN/s7kf9v/7/OjDoQRh50iT1+hyOyr2V2OpxYDa b7DkePp/ylhWrKWuHk5zRpwWdXXZRf0RnPm6o4/eu9QqP+EKhBZvxqZD07mNEu99gzu2 EhWxjbRJghGAvuT8BuNhAURji2T1vmQTDZTCeYcX/wWMUZ5TQhFy28QWEk1XOhHWJojZ fOsw== 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 61-v6si28486120plr.72.2018.11.15.00.57.13; Thu, 15 Nov 2018 00:57:27 -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 S2387839AbeKOTBg (ORCPT + 99 others); Thu, 15 Nov 2018 14:01:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41482 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728564AbeKOTBf (ORCPT ); Thu, 15 Nov 2018 14:01:35 -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 3C14ABDE1; Thu, 15 Nov 2018 08:54:41 +0000 (UTC) Received: from localhost (ovpn-8-23.pek2.redhat.com [10.72.8.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id C235C1019638; Thu, 15 Nov 2018 08:54:26 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Ming Lei , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, linux-erofs@lists.ozlabs.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , Theodore Ts'o , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com Subject: [PATCH V10 05/19] block: introduce bvec_last_segment() Date: Thu, 15 Nov 2018 16:52:52 +0800 Message-Id: <20181115085306.9910-6-ming.lei@redhat.com> In-Reply-To: <20181115085306.9910-1-ming.lei@redhat.com> References: <20181115085306.9910-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.29]); Thu, 15 Nov 2018 08:54:41 +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. Cc: Dave Chinner Cc: Kent Overstreet Cc: Mike Snitzer Cc: dm-devel@redhat.com Cc: Alexander Viro Cc: linux-fsdevel@vger.kernel.org Cc: Shaohua Li Cc: linux-raid@vger.kernel.org Cc: linux-erofs@lists.ozlabs.org Cc: David Sterba Cc: linux-btrfs@vger.kernel.org Cc: Darrick J. Wong Cc: linux-xfs@vger.kernel.org Cc: Gao Xiang Cc: Christoph Hellwig Cc: Theodore Ts'o Cc: linux-ext4@vger.kernel.org Cc: Coly Li Cc: linux-bcache@vger.kernel.org Cc: Boaz Harrosh Cc: Bob Peterson Cc: cluster-devel@redhat.com 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 3d61352cd8cf..01616a0b6220 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -216,4 +216,29 @@ static inline bool mp_bvec_iter_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 bvec_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