Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1976246imm; Sat, 9 Jun 2018 05:34:19 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLMxXW82OOcFfmWYUlhVU3JJNqdnNC4C67PtNr8gSK+GRoiNulBlL6UnqqYO7DryXWnQIIU X-Received: by 2002:a63:4c8:: with SMTP id 191-v6mr8600820pge.129.1528547659432; Sat, 09 Jun 2018 05:34:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528547659; cv=none; d=google.com; s=arc-20160816; b=AK/9gnDKS/G0BGtecnSVN6eowlFs8/zOELTcjsKM+ICDiIhZAh0qjowDaXql2tN+Jq 1cGbXx3kg+8X6WXzkKJGMwYi7F6tOuxF1+ymtIOqE74TBf1VvJAnPz8xKwvrf78HyMkA nIGWevQZfdcXIF7/CxYaOcqRveEEdtGmoqJM621gATO9wQNY9U0szB/MoX+zfFnyFwE7 dv42TpukSONc4Ed+sExTx5Lym7Lf11LEjIEgcdRayxpfSKYbVDJF5ZELfTyuqmCJgKer hKWxbZuLquHxLF3DK1e1+7hiKapKKOo/memlLCTDtQkv89AySDkNaVpshgMfkLmrV9+z L5Jw== 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=EiRjDVOsV32ZDXluOr3dnwVw7XWDSOHWlRK/DxRHtFQ=; b=r90Yku2Wpkvi5yZe/b9+/dZe7bdQtkEkY+AVCX0IFOMrtfgJ2woDWE1PeWWMRwTgjH 4BtZQm/kGknuCu6Yc3TQYW/c2UgUQk2Zj+yQXBewgGFyQ0aFWlMewefP9Fe7Cev7wfQh 3/y8dJjj6FygfBJ11YB3uFXDGX2nHkFrWnJrAC4oL8nRBfIPENFvvfF0irBEQc1OZpTb GGQbAKgcH5/rIokgalODpg9nwSCGQX/ZTR7F9zaCxJmK2/GNUZKb6I6DbaEynERhFsuW kae4OrtUhSeQU/zGvaNfnXZWdNQZmVsGFVmItksoeQWxsHiCSyg31zRfIVHTuZeFwJbc Q9yg== 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 k22-v6si18491392pli.331.2018.06.09.05.34.05; Sat, 09 Jun 2018 05:34:19 -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 S1753409AbeFIMcS (ORCPT + 99 others); Sat, 9 Jun 2018 08:32:18 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44496 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753227AbeFIMcO (ORCPT ); Sat, 9 Jun 2018 08:32:14 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A39D0401EF22; Sat, 9 Jun 2018 12:32:13 +0000 (UTC) Received: from localhost (ovpn-12-40.pek2.redhat.com [10.72.12.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8B39111765B; Sat, 9 Jun 2018 12:32:03 +0000 (UTC) From: Ming Lei To: Jens Axboe , Christoph Hellwig , Alexander Viro , Kent Overstreet Cc: David Sterba , Huang Ying , 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 V6 08/30] block: introduce chunk_last_segment() Date: Sat, 9 Jun 2018 20:29:52 +0800 Message-Id: <20180609123014.8861-9-ming.lei@redhat.com> In-Reply-To: <20180609123014.8861-1-ming.lei@redhat.com> References: <20180609123014.8861-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sat, 09 Jun 2018 12:32:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sat, 09 Jun 2018 12:32:13 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 chunk, 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 9e082d023392..aac75d87d884 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -219,4 +219,29 @@ static inline bool bvec_iter_chunk_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 chunk_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