Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2997591imm; Thu, 24 May 2018 20:49:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrXIpev/wUfVmsQklh1WHiqLRsGKShEgMsbkhrZcwgUUppSzS45+Ue5rQCz8AZz43mGC/2X X-Received: by 2002:aa7:850f:: with SMTP id v15-v6mr800961pfn.144.1527220160627; Thu, 24 May 2018 20:49:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527220160; cv=none; d=google.com; s=arc-20160816; b=PW8yYrbkuRnSPlPkp+74L2zIc3/b5W1V59dO2GDG3fyXfZQCOnIsPvYk0BdTDLHvgd lahvuzzDg3k05mz4glMTLPCGGcrQxMHGKHCgfytzQJXBTEwTgbpG5cVEeSHujDvrbMof h+wY4UMq2qUrBqHGvhwZrxPn8aaV6I8AzixHBCCp08oA/yODuv6/CgErx97hbBXSpYHQ v8c53WK/n1w74am3AJUX6B8zuOVLEB7kVBo3t/0oSy3yTjx/hvQ5oHF8UkbbxADCniUg +pn4c6pU4oGL9ZDeIke6Nw6sZAS+rF2TCo+2x7goW6Vp5XjqIQVRsnXJUcz9j2AGcrT0 4fCg== 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=kIf8e2+CSp2GoGN1UOam58rvDOPaAEMzrBC6zmq0pBg=; b=uIMgemK+sbjNapYDNwnbyk6pmC3MJXhbqZ9E9UGcIETGeIBUrmh4+sb6YCemObOWoB yEKmhhHLR/kjDRZwePYpm6uTAkqU5/t2sJffYad+QdaqNtkfvnVkEbEiXxUAkiYWSpRh L9IX/vMpMHGWV5H2ObINS8YI2eH3Bs9Icnor+QqOPEQhVCgCc+ZYgj+wHbNvU10XKqNP RYhTGBBmekod+K3IGt8E+qMMbSsYb5QuyJmaNKkBMIIwGO8VW1DyE4XEk2/y7lYkvUUy TUezugaeagJgz6jvSIiAbN1GN1l+7y7rzDF5kHcyQtlACVLzG91PMtTuRges8OeaTprF +NgQ== 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 b1-v6si22364972plc.403.2018.05.24.20.49.06; Thu, 24 May 2018 20:49:20 -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 S1755398AbeEYDs2 (ORCPT + 99 others); Thu, 24 May 2018 23:48:28 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37922 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755015AbeEYDs0 (ORCPT ); Thu, 24 May 2018 23:48:26 -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 8F6C04022414; Fri, 25 May 2018 03:48:25 +0000 (UTC) Received: from localhost (ovpn-12-30.pek2.redhat.com [10.72.12.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id B368F111765C; Fri, 25 May 2018 03:48:15 +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 , Ming Lei Subject: [RESEND PATCH V5 08/33] block: introduce segment_last_page() Date: Fri, 25 May 2018 11:45:56 +0800 Message-Id: <20180525034621.31147-9-ming.lei@redhat.com> In-Reply-To: <20180525034621.31147-1-ming.lei@redhat.com> References: <20180525034621.31147-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.6]); Fri, 25 May 2018 03:48:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 25 May 2018 03:48:25 +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 page from one segment, so introduce this helper to make them happy. 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 84c395feed49..217afcd83a15 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -219,4 +219,26 @@ static inline bool bvec_iter_seg_advance(const struct bio_vec *bv, .bi_bvec_done = 0, \ } +/* get the last page from the multipage bvec and store it in @pg */ +static inline void segment_last_page(const struct bio_vec *seg, + struct bio_vec *pg) +{ + unsigned total = seg->bv_offset + seg->bv_len; + unsigned last_page = total / PAGE_SIZE; + + if (last_page * PAGE_SIZE == total) + last_page--; + + pg->bv_page = nth_page(seg->bv_page, last_page); + + /* the whole segment is inside the last page */ + if (seg->bv_offset >= last_page * PAGE_SIZE) { + pg->bv_offset = seg->bv_offset % PAGE_SIZE; + pg->bv_len = seg->bv_len; + } else { + pg->bv_offset = 0; + pg->bv_len = total - last_page * PAGE_SIZE; + } +} + #endif /* __LINUX_BVEC_ITER_H */ -- 2.9.5