Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp6392886imm; Wed, 27 Jun 2018 07:04:07 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI5HXlP9lZ9L6tjpmxqhTF0eAIBxNKH9RgUnjW7qe3C/VEFlEplAKNuEulEf7F1zfI5OByD X-Received: by 2002:a17:902:24e:: with SMTP id 72-v6mr6230566plc.87.1530108247439; Wed, 27 Jun 2018 07:04:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530108247; cv=none; d=google.com; s=arc-20160816; b=ZvrbWS3V7rKdrKGpeHccmokb6dOxGyDCAGpPDXfEkC/cTxg975tcLWz97YZQ+7XVlw KChDbtL1faw4wmXhlJ0826vL8EhehMwD7yUDsv9AwDxMamSoNCUPocI4CQMIwpE863i/ MR1ZvSLcM6Lixdr39NOvfvn7Ht9j7eXOeF172j9qgzEUQVPqsCI3000vrCuZAQ1PTwmu ScwLzRQlqq7jw/NEporafQnwAjyuYTgo2j8C6baHVAbpt6SrLPCiDw6GVkRSKynlRwNi QQCYny+GUDiWLnU+QOFCeQj/DnayGmxnHSncgmexLqrYXuhDGDpopuOIVkudHL8vGS4Q /+Vg== 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:arc-authentication-results; bh=rStqc6ZYuBxwnhHNibknb5sxMcxqSod0DzPk49ANLc8=; b=k+yEEIxqR/BZi/+lPj137wEWM+gdq9AWGMr9vqEgdfOyXa6hPFRkvAJCKq3gnvOy27 8FkTfRz+tsjM3cGoMvuuwv2zKS0PzC3Xb8CFas+9IuYfF+1cgtjrL8fjQDRrI8sLEsfx rg1te86ST7aKwmivW4fyc1sKDPfW63EKANzqmQLgYhJIxoK0/jqWEPrs30fI0Gyfkmn0 Eo2v114NWLyFL7HVb/P+BOUn3lNc50Lbchd+UAN34ZA61unAi9+UZFspLg6ZQ5E93XrB CHrYfHjPI++gsQ5Xtxk/cZc7P/McafGthj04d48oPJZxHG2EmH8iijVc4ZMueBB1ijfw pV3Q== 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 p91-v6si3946203plb.457.2018.06.27.07.03.50; Wed, 27 Jun 2018 07:04:07 -0700 (PDT) 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 S934552AbeF0Mst (ORCPT + 99 others); Wed, 27 Jun 2018 08:48:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60880 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934000AbeF0Msq (ORCPT ); Wed, 27 Jun 2018 08:48:46 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 92AB181A4EBC; Wed, 27 Jun 2018 12:48:45 +0000 (UTC) Received: from localhost (ovpn-12-44.pek2.redhat.com [10.72.12.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76A372026D5B; Wed, 27 Jun 2018 12:48:37 +0000 (UTC) From: Ming Lei To: Jens Axboe , Christoph Hellwig , Kent Overstreet Cc: David Sterba , Huang Ying , Mike Snitzer , 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 , Randy Dunlap , Ming Lei Subject: [PATCH V7 14/24] block: introduce bvec_last_segment() Date: Wed, 27 Jun 2018 20:45:38 +0800 Message-Id: <20180627124548.3456-15-ming.lei@redhat.com> In-Reply-To: <20180627124548.3456-1-ming.lei@redhat.com> References: <20180627124548.3456-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 27 Jun 2018 12:48:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 27 Jun 2018 12:48:45 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ming.lei@redhat.com' RCPT:'' 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. 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 417d44cf1e82..2269c7608a3e 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -219,4 +219,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