Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp873091imj; Fri, 15 Feb 2019 08:11:38 -0800 (PST) X-Google-Smtp-Source: AHgI3Ibs7J31eCb07UfmU4AmPZgtPSIN89Cgox94Z4oU09BpxkEaT+bqiMT7NDZeVN1wpm9bjNWu X-Received: by 2002:a17:902:6b87:: with SMTP id p7mr11132329plk.282.1550247098288; Fri, 15 Feb 2019 08:11:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550247098; cv=none; d=google.com; s=arc-20160816; b=lHPlSfnv5gmPYcmXeS5sWgmGy0GvqmYLrqhwuijrRaPka6IjsTRbqTMpdFGMtkVtsy PKprP0t8BvB5lw1KGCMzxozYsNcVuQnfblPdMkmhSPqUIUsi9kqIOrn6rNSsJQ7HJSgQ AZ5r2Uu8XXzJkispFi/XGCEwo7Z9YaQJBESEEqZW0hTDbFtlgW2IYQSqp6L/Kkl5e2H0 kWzpj2S7hKQeIMMGXMZqrad75lRum4JOdSTWSVelBK5LkHTpbXeT3IoooQEtlRPvY3/x /6Sb/S2/KqsrPSD2yL1o3iEnXB7bFVNbk4k9Y/nOVUIuAAfPsO/ubdBZUSrRya95Xo4i RdTw== 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=UPqY5b1JqVkM1npPaeOz/GFx2XqKiaYkjhq3oYeVa/0=; b=sFbKuAhVDtS98DuMQj5IYx8wNccTKEpg3M0aGAmyWaKCC8kxrsZx5fg2OKGBnkTgAc lKuYZToVe8y/oRE+35M/7e+aYPZuHsKJTch9+nERIdSpHDhIZmKK4WzJB/4S4RyXcLM6 peOXnAAQUAtbU7LvG+cEQYB5k8cK2pa3tIGn+0EToYECYYaqTTU3qoO+XkR+aczntcwI I0iVRee1JmSrdQy83gthY88j7WdgFf8AtyDk5uLlU4dekCwIGUt0BBm8EdXfZt1SElpV uSlPbCpuTGDjQteJ+6kBeFq1ff4OUbi4uwLtcIBy1tLW5La/XE3WWKDIfTX5/OV373g0 MNig== 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 w31si6051634pla.308.2019.02.15.08.11.22; Fri, 15 Feb 2019 08:11:38 -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 S2394275AbfBOLP4 (ORCPT + 99 others); Fri, 15 Feb 2019 06:15:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48706 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394232AbfBOLPv (ORCPT ); Fri, 15 Feb 2019 06:15:51 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F39521244C3; Fri, 15 Feb 2019 11:15:50 +0000 (UTC) Received: from localhost (ovpn-8-22.pek2.redhat.com [10.72.8.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 312215DD6B; Fri, 15 Feb 2019 11:15:49 +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 V15 08/18] block: introduce mp_bvec_last_segment() Date: Fri, 15 Feb 2019 19:13:14 +0800 Message-Id: <20190215111324.30129-9-ming.lei@redhat.com> In-Reply-To: <20190215111324.30129-1-ming.lei@redhat.com> References: <20190215111324.30129-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 15 Feb 2019 11:15:51 +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 0ae729b1c9fe..21f76bad7be2 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 mp_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