From patchwork Wed Nov 21 03:23:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10691659 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 88AA013BB for ; Wed, 21 Nov 2018 03:26:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74DCB2B406 for ; Wed, 21 Nov 2018 03:26:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68FB72B412; Wed, 21 Nov 2018 03:26:24 +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 0E9352B406 for ; Wed, 21 Nov 2018 03:26:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E5276B239E; Tue, 20 Nov 2018 22:26:23 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 393926B239F; Tue, 20 Nov 2018 22:26:23 -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 284386B23A0; Tue, 20 Nov 2018 22:26:23 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id EB9BB6B239E for ; Tue, 20 Nov 2018 22:26:22 -0500 (EST) Received: by mail-qk1-f198.google.com with SMTP id c84so5473794qkb.13 for ; Tue, 20 Nov 2018 19:26:22 -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=M9HjZiyQLRotInpEIRM/jIIFKCG3bEPf2w3BspfUEys=; b=WvCi/3JVFXGqaDjExMh224Xk/5VZfSof0v3gofqDqMMK/vpHwX63b8FVkcgeyhsYub Ep8HDhT3i10HqrVGgB+Se3NZJHK/fDZbrKXoD8ix5zI618D0Sy05R/IAUFQEgcC9u9L6 JXNEvG0pY7NerYsk7rAAS3zZCcT2eVkFm3bKnT+nvfhNs+Ub4yoJ2uuJvOUnfsNkAofY Tr0iIKJIKa7GKp+XEy5tXL+sSJGaniUt5bPILv4osljieOHCgZ8ohcdrNHjfiD7BYmFz V6iydZQ3ZYzq+zDGBJ3vjzLmb7WGD3Z6DEzyFdm5AudEe9ykqRnyoArRc0C5dWzFm3CS oueQ== 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: AA+aEWYzHR34xva3rmIX5TdFHAy9tkIIOQuZW3lJ4/Fg8HY2OIr4JJHY 4+UBCZq5xCI3pARPGoaiQtOc4bAcfycFFryp36qJXZnUTguL+G+o4N9e7u7MT8rEldDRCb6PMnf lxSs8HlxYVtwHO3o4u9DsRvZsL5mna6sOLkt9lYewvMFhaz6TWwsoNLSlhlQe9Gk8Sg== X-Received: by 2002:a0c:e9c4:: with SMTP id q4mr4447981qvo.18.1542770782741; Tue, 20 Nov 2018 19:26:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/WKNePAObBpgOzFzz7U6p4AIt4iZLJZkFIBYs3I+rFhpvMQfRiXVZSrPGIGcXwLxiBJLOGT X-Received: by 2002:a0c:e9c4:: with SMTP id q4mr4447958qvo.18.1542770782096; Tue, 20 Nov 2018 19:26:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770782; cv=none; d=google.com; s=arc-20160816; b=Da+RWmXizD0wJNnnPMvV2ynU0KvRJFaez+IUbaOFXLlK7Teos+oD055svp6LzZpiI1 pnvrmr93y7To6y0pedVEvn0IPrTAGZWK5/C560TgiMCJoEdi6krDWeUi8whZzrHVuW2Y w1VRRO/EngJsFAEz0iNOhgjzrdzfAwMCmWr6YuzaRmJBqBYMiJLUa5iPF1gL4TgOFQ5v jYFHhdMcq5ZA3FviooG2SbvVRUf/5cxsdypckye7rPNTYPXzLRYhk265JGjUUYUcD/Ow yY++vchaZEXMcwKst5mP8v6cuFKKJBAxWCEWm/a5DqjzTCRY+CnoX5g4mCU+qMwkx+kW uvdA== 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=M9HjZiyQLRotInpEIRM/jIIFKCG3bEPf2w3BspfUEys=; b=QGeuxu2HPA4NbvKS3XGAWCGLiVnwlRsFpfOsvw6Y9FxqfPdHICYA+jc/m/pXD9h98K 18jXBsNOmAQTcs0kh4ZXGw51DtOYsBm+hsIg61+guZapXBeFPndq6S1Qo0MSXB0elxYr doF9M6vNzVrS6qsvE8jHy8FZJ4qhsWw1IuaKVTfBjyWpJUkDKird20KovoLUTwbbKS5W +42oOWFfUtTD0PMIMBT+AsUG6vHQdLZ7P5ZheOgk1RBRcDk6ord3pajv3CcjdBB6CIL/ tLIVFcKTpnoz1kbKc8OZgI5UTgcKG072LNtjNXYclmHWndhPpFVe/uX0/ey74mp8QOlB MoRA== 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 d42si5030617qve.68.2018.11.20.19.26.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 19:26:22 -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-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E170C308FB94; Wed, 21 Nov 2018 03:26:20 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 874A7600C5; Wed, 21 Nov 2018 03:26:08 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 06/19] block: introduce bvec_last_segment() Date: Wed, 21 Nov 2018 11:23:14 +0800 Message-Id: <20181121032327.8434-7-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 21 Nov 2018 03:26:21 +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. Reviewed-by: Omar Sandoval 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 b279218c5c4d..b37d13a79a7d 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -173,4 +173,26 @@ static inline bool bvec_iter_advance(const struct bio_vec *bv, .bi_bvec_done = 0, \ } +/* + * Get the last single-page segment from the multi-page 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 - 1) / PAGE_SIZE; + + 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 */