From patchwork Sat Jun 9 12:29: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: 10455549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7EE94601F7 for ; Sat, 9 Jun 2018 12:32:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7126D223A4 for ; Sat, 9 Jun 2018 12:32:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6562E223A6; Sat, 9 Jun 2018 12:32:16 +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=ham 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 06E93223A4 for ; Sat, 9 Jun 2018 12:32:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 15BEC6B026F; Sat, 9 Jun 2018 08:32:15 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0E3226B0271; Sat, 9 Jun 2018 08:32:15 -0400 (EDT) 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 EC6B06B0272; Sat, 9 Jun 2018 08:32:14 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f199.google.com (mail-qt0-f199.google.com [209.85.216.199]) by kanga.kvack.org (Postfix) with ESMTP id C08036B026F for ; Sat, 9 Jun 2018 08:32:14 -0400 (EDT) Received: by mail-qt0-f199.google.com with SMTP id c4-v6so2670691qtp.16 for ; Sat, 09 Jun 2018 05:32:14 -0700 (PDT) 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=EiRjDVOsV32ZDXluOr3dnwVw7XWDSOHWlRK/DxRHtFQ=; b=XcW+OpMYMDySn0axcCmxLsJfJvlQtirkLAmT6u41OGowe/rWpaO3UyBPddEeBQA4Ng kfnEJd4fwPJijFSRGsbU3QI56Ww+++LLxgnxdiEqY+Y5zfFvrM5hechp0XSQY5+ZtFHj voZOugxDrr+S6OLeSeZBN61SkZdaxRYwC3BbGkIg34lJ0Knr7MJvfbX1iglRB0fjKEwl 9RSxT6T+8iB/xcMKoKkAfeefk3bn77QNCTi0+HE6KkFFKI1AvzS6ue6TMM/NwpnhRBdZ XmEcB35BdKPUbm4Xqcp/fCXrwbo35ML9GRZXMqINDAyFE+UejoIUgLnH2lY7gJePl5Kl uNKA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 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: APt69E2j4bAW4aYcuBSJgnEO3L6zvSEnRxzDDdPo+axg8zLMW4YDY7+z GU6bWCBAyiYdngUdLiXte0bY0QSb0JonLcOGD9/iK6D4d0Be3QyhV/9kL2Ry+k/BPa3R5xRz0Uk UP89vamJnW8o93NtBubfaReqKUTYQbHjR8od5373jW+Oes6Q6prdTU9CNVGG4Ao4i0g== X-Received: by 2002:ae9:f402:: with SMTP id y2-v6mr7732371qkl.75.1528547534593; Sat, 09 Jun 2018 05:32:14 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIVHsEo3DAh5WghXTTNjCDAvuc6C8xsp4/v3CZZKwhn8Cc5LJNvnCpLWrHqzkQLFrtQbwlF X-Received: by 2002:ae9:f402:: with SMTP id y2-v6mr7732339qkl.75.1528547534034; Sat, 09 Jun 2018 05:32:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528547534; cv=none; d=google.com; s=arc-20160816; b=Yn6GJBPHUhvfz0IuWyZVfqagMuir4t7sTimZSQ7R3J9VdByiiZ9HS+gFGzCNqO+0Ry y4+wVfPYrM/czW+7ThjuX7eqN/ajlEZu683yNDf5h7PJU0jmo334ezxLyJrNNn1GGy+t tAvpLLCOjbk+vZvZ6S21mjxafFxhUckoVUMtvlziSdvOkyGteXoHbLhObuvhmCuFAw0J /pJphjPqCTEyHHLLO4N1cjkBCO8yNhLkjfTmoow1QsCWt6XV2YeKisSFJkmnCZHJw20Y 9nqfqS26eIHdce66xaa6foRNeTLsBw97eWcGDMDtxygTmo444taKlldkgmcCGZBYTxNk xMoQ== 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 :arc-authentication-results; bh=EiRjDVOsV32ZDXluOr3dnwVw7XWDSOHWlRK/DxRHtFQ=; b=Z/vBKUtKa+ReXT/QvdJNP+QItkwaD8clDWJ3QaIYbGBSO3kJ/RcY7h1keNQZiV9kLy ZhC3gJ3MJyni5X+PjWhiD+nnNBnm6nIT7IkfycsBlIYNtEbo8PIpUd2YYeWZzeLHIyYn vIgQBVD+Q3anQ21B0w1c+p7vsVdKtn9u+CVn2zgwOaZOoorPr6SRrKI/Q/7XBlzMSfgR DpMoTuOHT/udcF+LYO4bNtNQWHvIv4mciRAP3wVZAC5lOt6Io1F17QcIVOl1n5WZd9kL McWyYJrAO2fJ94H4z70hG1VwijgjY1fuCfcPehbfPAuHvLckO82wZEPKWckWG2d/3Wit bVLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 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 (mx3-rdu2.redhat.com. [66.187.233.73]) by mx.google.com with ESMTPS id r86-v6si6237160qkr.36.2018.06.09.05.32.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Jun 2018 05:32:14 -0700 (PDT) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) client-ip=66.187.233.73; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 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-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:'' 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 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 */