Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp943411imu; Fri, 9 Nov 2018 08:28:15 -0800 (PST) X-Google-Smtp-Source: AJdET5fqmM0S6M+Bzy8pDl5A0tgRI9iKv+1wWzz+fmTEJMN0Lp5auX2I6lgEwfH4vXg1V+zTIOcz X-Received: by 2002:a63:504d:: with SMTP id q13mr8126698pgl.319.1541780895253; Fri, 09 Nov 2018 08:28:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541780895; cv=none; d=google.com; s=arc-20160816; b=JAheQy1P3jt2aaepqErU/kwTW6C2MJL5mGX3CZaFcmPsKdBwrifZzYtRaiyT20lMwG A5Z2A0wbdAB93BDodCm4GO77Pg+OkhYtIfbURAq4KP1HValldPTiGi+hh5L1YV131ACa 07QS5HZmITjR4kvJgGTBKx6QXb+uNXKUMzZWv7QTil1vOqfCLJ+9WV7OmT0JkNq7Nzaq 5YNe4bmBy+mT2jQ+8Ia1u0Upcq/pJY/DLlLzmWR0/dMN//LITt9FELBvNb1RQjxOUM+C b+VyNHoaTZAiFJLdy91AZ6BvY4E7ZW194RXwGEN82Ec9fSgfHCbL9BLfSRnhCWsl3xJL XxQA== 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=rTHT1bPYYu0VEd9jZwj1BJZCkfvuieRqlmlUHDt3TD4=; b=TSsR+mDgksev3ElJ3CVLXX7SUZYE4Ga7xaqyFwzy+JGiASsGlCp+miLdRrPiKgq8cm AnBstVGAP0QLQUQRdOeRHvM+r/xuoH/j7stuimjkoxvtXp5x2BuAmfDhcBRweSu2vVd6 ybFuv+J5snePdRAbiYmWG++vJSS6bSoU9RA3FDCvJtloQMd5bQem6aIrwDwBnbKhn0mv Pm9QB4Lh8Wtay3ynmRPXS82TtVb9Jxzh/+zX457vqO5yx+8b6GBewQL6W3bauVvaBut+ Fy/CJOa640R+2ltqMsotnqAJ8K4B61FpKgQuH+V0S87R1h5kM/EWolo/x3MGxdlzvjE8 xmLg== 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 r23si7739431pgu.359.2018.11.09.08.27.55; Fri, 09 Nov 2018 08:28:15 -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 S1728619AbeKJCIQ (ORCPT + 99 others); Fri, 9 Nov 2018 21:08:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55572 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727828AbeKJCIP (ORCPT ); Fri, 9 Nov 2018 21:08:15 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 680D5811DA; Fri, 9 Nov 2018 16:26:59 +0000 (UTC) Received: from localhost (ovpn-8-16.pek2.redhat.com [10.72.8.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65588196B0; Fri, 9 Nov 2018 16:26:56 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Ming Lei , Christoph Hellwig Subject: [PATCH V8 05/18] block: introduce bvec_last_segment() Date: Sat, 10 Nov 2018 00:25:57 +0800 Message-Id: <20181109162610.18981-6-ming.lei@redhat.com> In-Reply-To: <20181109162610.18981-1-ming.lei@redhat.com> References: <20181109162610.18981-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 09 Nov 2018 16:26:59 +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: Christoph Hellwig 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