From patchwork Fri May 25 03:46:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10426067 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 9FE4B6053B for ; Fri, 25 May 2018 03:49:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F66A2959E for ; Fri, 25 May 2018 03:49:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83979295A4; Fri, 25 May 2018 03:49:12 +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 176F4295A1 for ; Fri, 25 May 2018 03:49:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DFA936B02A2; Thu, 24 May 2018 23:49:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DA9DC6B02A4; Thu, 24 May 2018 23:49:10 -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 CC1126B02A5; Thu, 24 May 2018 23:49:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f199.google.com (mail-qk0-f199.google.com [209.85.220.199]) by kanga.kvack.org (Postfix) with ESMTP id 9F67C6B02A2 for ; Thu, 24 May 2018 23:49:10 -0400 (EDT) Received: by mail-qk0-f199.google.com with SMTP id z140-v6so2893571qka.12 for ; Thu, 24 May 2018 20:49:10 -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=nJKjWPeJU1as+ZG1xwR85I1uMqEsjhA3OEA6CaSlbMI=; b=EyUb4Z+Kqu9krIbdU1uxsqD3rEsC/RkvJjMfNfeFYZJcm1588PbDc8UnAFPGmmJEF0 zurgregmMA9fY2nggB3lgAiBmEaWEJXjdBNYun9AT5kKFOW2YNaeIYK4sgzjR4GwePPf zicu5Aov6Hvq8MtaYpV2MlzjYLodAu5EYdSY/NTgZCIx8G3GJF/X0/eG/S7KKBXYB+Bb KwRDX1TwwJtRU9cFz7aXmI8oHNWEK5jGRpLEbr+D6d0yE+vapthvlz0YTr9OcSzEveFG lQqjPq+I4BzbJhrOD4OiO+EvFmoNLAUuO+PIjwmYxavdxtJRt1+pXCZ4rHp3uUKqpsTj hjoQ== 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: ALKqPwcZtuUxKwMqIx2JgTGzowqb9F+SV8L9FLWn3SG+92tUfgzG+zkB 9+nqx9RCkEMOuD7VQo7BGNYTt15aeY6hXFqh2c6ocpzEXKnpPYTMfhGjopuE4nOoGrb0V+TLjEN bM+AyuO23iFOVSiaUcT0Ac7U9bUJU9Oco2DX6SZ6TfBbc3aAAhhea1kJLpKGbp7zrIg== X-Received: by 2002:ac8:1d01:: with SMTP id d1-v6mr616344qtl.281.1527220150450; Thu, 24 May 2018 20:49:10 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLIRzm2lsE6yjvqc9gcdOn4FuWqZbn9cI6jfeNPeCFAziVeuneqgCEXp9GitfdtcSZ3mrqE X-Received: by 2002:ac8:1d01:: with SMTP id d1-v6mr616320qtl.281.1527220149887; Thu, 24 May 2018 20:49:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527220149; cv=none; d=google.com; s=arc-20160816; b=H9OjzljbpaSxar3OxTmEP18s/kw/Ayb57Ec11Ypc5iI/NhJPmlY7+9zwHz//tXugVE WYM32vV1/V+mu3+S/IJGUmnvMLqyWO6km3FXP1m8SxIoyXWE4101JhT0srIF0b6rQLeg iXmQE1IjtjJgnzDnkmKyVb2z3BmeD5fAoLsexPJRf3PV3d1+VbpjX+Km3o/PF0qQeJdJ upeeKkK6aYFNdPJhzdGf4FlafiG5cISPVabv6h/sp8UAsJisjP4bvOEzktxSSpbEfxGk Xw768mO8zPbT3me8nl/Dy4ZfUM0TqPE7LENWu4tOdGi0jCAlEXDMm2R+gx0gg+u3z7TH 7vYA== 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=nJKjWPeJU1as+ZG1xwR85I1uMqEsjhA3OEA6CaSlbMI=; b=omAKGvEzSNk45krzX6BXp4E6pcMqJo6IIOc40exRMt11+Nu6FGjGJnjwvXj30dqHA9 XnK9glewIzL3lbARsicHZ1Sb2eYCTXq/mEOuAv065eBs8hliOU5gy4IMz1JfXLJJPtx+ X5+oQz1w9logh+hqWI5jVK24JLVtAKxObCfjdkQ7PvrRfLr7O+1vJJfzffXBVB0Ww+rO Z0LJNZO8PtpVs2Ke1d0wsyC4u2j+fOO1U0ltGMKJnx4s+xn/rC8jN8YtOTWVXQT2uUTu 1/ko14vKZVK1JYAiXh7DoGCagQUVR0VYs5sWV6gTrBUfL4H/y61PicSS1Uwtw3fN222N QguQ== 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 s13-v6si1883248qve.15.2018.05.24.20.49.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 May 2018 20:49:09 -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-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C2C27C6B3; Fri, 25 May 2018 03:49:09 +0000 (UTC) Received: from localhost (ovpn-12-30.pek2.redhat.com [10.72.12.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 543BA83B82; Fri, 25 May 2018 03:48:58 +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 12/33] block: introduce bio_segments() Date: Fri, 25 May 2018 11:46:00 +0800 Message-Id: <20180525034621.31147-13-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.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 25 May 2018 03:49:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 25 May 2018 03:49:09 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 There are still cases in which we need to use bio_segments() for get the number of segment, so introduce it. Signed-off-by: Ming Lei --- include/linux/bio.h | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/include/linux/bio.h b/include/linux/bio.h index 08af9272687f..b24c00f99c9c 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -227,9 +227,9 @@ static inline bool bio_rewind_iter(struct bio *bio, struct bvec_iter *iter, #define bio_iter_last(bvec, iter) ((iter).bi_size == (bvec).bv_len) -static inline unsigned bio_pages(struct bio *bio) +static inline unsigned __bio_elements(struct bio *bio, bool seg) { - unsigned segs = 0; + unsigned elems = 0; struct bio_vec bv; struct bvec_iter iter; @@ -249,10 +249,25 @@ static inline unsigned bio_pages(struct bio *bio) break; } - bio_for_each_page(bv, bio, iter) - segs++; + if (!seg) { + bio_for_each_page(bv, bio, iter) + elems++; + } else { + bio_for_each_segment(bv, bio, iter) + elems++; + } + + return elems; +} + +static inline unsigned bio_pages(struct bio *bio) +{ + return __bio_elements(bio, false); +} - return segs; +static inline unsigned bio_segments(struct bio *bio) +{ + return __bio_elements(bio, true); } /*