From patchwork Thu Nov 15 08:52:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10683751 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9571114D6 for ; Thu, 15 Nov 2018 08:54:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 860C5299C2 for ; Thu, 15 Nov 2018 08:54:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79E7D2ACBC; Thu, 15 Nov 2018 08:54:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DDB129B7E for ; Thu, 15 Nov 2018 08:54:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 582556B0275; Thu, 15 Nov 2018 03:54:43 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 532AD6B0276; Thu, 15 Nov 2018 03:54:43 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 449066B0277; Thu, 15 Nov 2018 03:54:43 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by kanga.kvack.org (Postfix) with ESMTP id 1B6716B0275 for ; Thu, 15 Nov 2018 03:54:43 -0500 (EST) Received: by mail-qk1-f197.google.com with SMTP id a199so43307672qkb.23 for ; Thu, 15 Nov 2018 00:54:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=CjGkhGQ3mjObcZSlpfeHqGI+rxG1OBhrlzbMY/mtO8E=; b=TwoRnc/Uv0c5YtTq3/1yjEns+2HOA6KfvfTmZHnoevC2hwbWX1Bmc1yr+idjz9tPt+ DrZqy/gQo2Dm9MBobu4XHv+BP3KjfdsfTJxbCHkCAvVGEto2UE6mNzI5fUGDqazQQwRj dG6IFJyXXZPJT91bId9xp45vxA1MjUAy8auJCb7jAaHeMrg1rkzdYMl4mCRcrQ77qG30 xDwvgkO9ek+eysyeSZee5R+MHmAw8CW0yT5yH1eOaJajPrIWYp6Ra9j6vqpnVcYY8v57 kBxZRn116Wn+jqQzjrcZps7PhSWjW92DD89B6YymKnq5ocRU+I1kWW5CYxPNL0+gYvkn eW9Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AGRZ1gJj9EkAr+HhObzGYQTtseDg15f45JJmK7L9D8gHFaMvVZH2Vm83 CZv+kBBctFfSR8JRSh3aaG1q91fb4m1Dcz+7Y0YNjRPCdt9kNsWkU6Eqs225duPlnvekEgeThZO o/LY48RiXLKClrm66Ry2Pi8aBmHOJxSW1jFedkQxZxPqspkFHIydLcvEL3q1tynxQQg== X-Received: by 2002:ac8:593:: with SMTP id a19mr4995382qth.111.1542272082894; Thu, 15 Nov 2018 00:54:42 -0800 (PST) X-Google-Smtp-Source: AJdET5doPPx7OejBe04FGnQ/vdkOGH5aFxNtlwD0z8TzHjmgya7ZJqDkdpdt0DugmqG6ykegdDeB X-Received: by 2002:ac8:593:: with SMTP id a19mr4995360qth.111.1542272082376; Thu, 15 Nov 2018 00:54:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542272082; cv=none; d=google.com; s=arc-20160816; b=wqKWOQcg387VcHBtrbwILMdtkkGX59p5gv98IzuzXEmBWSE2q/1wqaGDuv8ZMmW7+6 gcgugigWHes0Ei72Dn1Efu1+IiR3sEQPuuFHZcpT7NjaUeSXoyid6X3K3X3TU7+ZbERV tSJaaSUGGjHk5I8LqmD0h55pSNdiR43cmL+WeyKMY4/uNH0WVoBZyI0aGaTVD1ljUJWg Ic0bAoIuxnLr5uyzt6q0l7SAoqv8rJORUAzPVsyo/dxXgvYicEZCt2aVzRp72TYBqH1m eLZ9Od7wTwFxy3m2coR/M3Kx63x7dQUArywDfeeF7EfhFUUYTWS1N9335pWeplUccron Yu6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=CjGkhGQ3mjObcZSlpfeHqGI+rxG1OBhrlzbMY/mtO8E=; b=oL5twdlFkGakDgkJHIP129AOORGC4Xq58LNS5Tntv04GqVlAugGO35SZR+SBCZb75n nNsJDmyj86zTAM18nwueNQiaQcwK5awoBzn5n1s+KH3Ljvw2QHEPifmiOc/ac7AGjR7h nWCym0Fuj+LqpWTAK3fZ3GON4uE9xRtgiUubePXvB9BoAVEN1UAnZxIgwpaGKAimwknz 983Os2AeLoo3H5zbbKkb4T/dcs4/GxKpB9gsucGCn1hSCCFOKNOfp9I/e8r8MjOGHN7e KX+1hqhl72kCDOP6oVVrEYE8SKyC8C1BVYj9HceEdxZD6tkj+HOAZGmKJgbHR+5ucCKG TYCQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id v8si263689qkb.11.2018.11.15.00.54.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Nov 2018 00:54:42 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3C14ABDE1; Thu, 15 Nov 2018 08:54:41 +0000 (UTC) Received: from localhost (ovpn-8-23.pek2.redhat.com [10.72.8.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id C235C1019638; Thu, 15 Nov 2018 08:54:26 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Ming Lei , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, linux-erofs@lists.ozlabs.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , Theodore Ts'o , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com Subject: [PATCH V10 05/19] block: introduce bvec_last_segment() Date: Thu, 15 Nov 2018 16:52:52 +0800 Message-Id: <20181115085306.9910-6-ming.lei@redhat.com> In-Reply-To: <20181115085306.9910-1-ming.lei@redhat.com> References: <20181115085306.9910-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 15 Nov 2018 08:54:41 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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: Dave Chinner Cc: Kent Overstreet Cc: Mike Snitzer Cc: dm-devel@redhat.com Cc: Alexander Viro Cc: linux-fsdevel@vger.kernel.org Cc: Shaohua Li Cc: linux-raid@vger.kernel.org Cc: linux-erofs@lists.ozlabs.org Cc: David Sterba Cc: linux-btrfs@vger.kernel.org Cc: Darrick J. Wong Cc: linux-xfs@vger.kernel.org Cc: Gao Xiang Cc: Christoph Hellwig Cc: Theodore Ts'o Cc: linux-ext4@vger.kernel.org Cc: Coly Li Cc: linux-bcache@vger.kernel.org Cc: Boaz Harrosh Cc: Bob Peterson Cc: cluster-devel@redhat.com Signed-off-by: Ming Lei Reviewed-by: Omar Sandoval --- 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 */