From patchwork Sat Jun 9 12:29:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10455569 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 81C1C60467 for ; Sat, 9 Jun 2018 12:33:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74CD9223A4 for ; Sat, 9 Jun 2018 12:33:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67D99223A6; Sat, 9 Jun 2018 12:33:07 +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 07674223A4 for ; Sat, 9 Jun 2018 12:33:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 181186B0277; Sat, 9 Jun 2018 08:33:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 130D66B0279; Sat, 9 Jun 2018 08:33:06 -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 F3BEE6B027A; Sat, 9 Jun 2018 08:33:05 -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 C727D6B0277 for ; Sat, 9 Jun 2018 08:33:05 -0400 (EDT) Received: by mail-qt0-f199.google.com with SMTP id f8-v6so4522194qth.9 for ; Sat, 09 Jun 2018 05:33:05 -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=r8cPAuKQA/nh9PDEz0rzlpEhaUHJU6CuWO2tL32k1Ew=; b=WkTs2+Z3OGhICNRnIyQ+9vrS8bxPUuVRXImM7tVVyRleXKp/k6Jd7DKNmHwxV0n/Wi XJJaiaqc+vFIbFqeIxra7K4rafhTH5Zli/O6VZPJXUKs0C0HaqqkHGvNjB1KjnxoPstW GR7cbXMYT9/fy/IYGmfl/qAh4pP+rhJXfG+050x6RrVaPxcK+XDuc9ZpMaJajl30FHKL ciHxueQS2bm9KgNOwaVst3Uz3uYJRwtbkoFmbblA/0fDGZROtWwKhLNHjB6hi0a9a8Js peIpQGSWo7V7S34XbkAPkE2xU7yYJ5pD3JVstH6WeG7bT6HrS/gPZLvqcqf7UCvesGR8 Lpxg== 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: APt69E2r9EysDfd9XE30dUTOTgjwyDm+0zjA/YjytlEQaxp2/NU8aLWs ms7CFql6AJO+Fc+YM8JiH54k9tAiwYTJtJWVD1p4Ylejl2z3gfRi38J28VJF5vUVzlhP37v70ON n3En3+JUvP1xkOyErA0zy27WAU3lwDRBDduNwdB7he2OQJ7TlkTxztwbT1A+sh3ngTA== X-Received: by 2002:a37:5687:: with SMTP id k129-v6mr4908764qkb.163.1528547585604; Sat, 09 Jun 2018 05:33:05 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKsT5tQ5Z1RFcqgKf7A+5Hwl79RGNV+V70AUB/M+e9uS9bL9AlrpTUMBIVYzLNJSpIPhPoh X-Received: by 2002:a37:5687:: with SMTP id k129-v6mr4908728qkb.163.1528547584988; Sat, 09 Jun 2018 05:33:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528547584; cv=none; d=google.com; s=arc-20160816; b=sMmZC1xMsAIvq+3rcmia9YeQzzfhGn2728TeS3yGMsPPRPYCeqHKehfUqsjgu6aPM/ 27qJYNJLgyLuJtk8Lv4HoyZRuSgN9z4MLQVQYH1n2VxUy9OxvZMeYP2lRkrlEXSqCoK7 7AJC8xKopVVgY1Qqa2h3M42ZPi9h/s8WU1Fk3Q85V/MyTe7W42GL1r1OY7picQWc8f9/ bQk1XIIOX1Z4aDckUAoOAzqtMDNwpUtarPgQpK/C4cHU+CDZJqMA48mWC5ATGA6fTvVK GqxMfkp0TZ+qerVkLwUe13PuYjMGYjDkPlhGk9ylRrE/03Pa+3RCocV7qhfDaQ8e16+b vnGQ== 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=r8cPAuKQA/nh9PDEz0rzlpEhaUHJU6CuWO2tL32k1Ew=; b=F/v470aM/iJaTx71R1AoWa9p8xEcnqCrQFwRkmFIq00u3rSfteg3yQIaol9bjbJk9k ftvjMCqaiVnV+2JTWYJVf+xRqk9CpeZhGbPzeUuoynVf5+F2yO+DhNGKxyBqdzi4ZgBP L8Q4Wwp+LTWweaFB26kQkNDcYL6q27g8QM8VMTaLpmn1aIsphgrvPDEyBQ+d/XqRx/+q /tZ2tl2KD2cRlM2IScdNNMJnH2Rg6PLMF3NuIbxllIFwUDaDkXgoDjV9pVHoAH/snJhY hQUxnXS0cJ+kKpeKBTr4XzGlavUoWN9CEcMTmEKLkr30Vtt4BTDvD1pun3Gxca0VXzfE xoIA== 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 k33-v6si66755qta.311.2018.06.09.05.33.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Jun 2018 05:33:04 -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-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8C21E4022407; Sat, 9 Jun 2018 12:33:04 +0000 (UTC) Received: from localhost (ovpn-12-40.pek2.redhat.com [10.72.12.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CA332166BB2; Sat, 9 Jun 2018 12:32:56 +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 12/30] block: introduce bio_chunks() Date: Sat, 9 Jun 2018 20:29:56 +0800 Message-Id: <20180609123014.8861-13-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.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sat, 09 Jun 2018 12:33:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sat, 09 Jun 2018 12:33:04 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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_chunks() for get the number of multipage segment, so introduce it. Signed-off-by: Ming Lei --- include/linux/bio.h | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/include/linux/bio.h b/include/linux/bio.h index c17b8f80d650..13fd7bc30390 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -242,7 +242,6 @@ static inline unsigned bio_segments(struct bio *bio) * We special case discard/write same/write zeroes, because they * interpret bi_size differently: */ - switch (bio_op(bio)) { case REQ_OP_DISCARD: case REQ_OP_SECURE_ERASE: @@ -251,13 +250,34 @@ static inline unsigned bio_segments(struct bio *bio) case REQ_OP_WRITE_SAME: return 1; default: - break; + bio_for_each_segment(bv, bio, iter) + segs++; + return segs; } +} - bio_for_each_segment(bv, bio, iter) - segs++; +static inline unsigned bio_chunks(struct bio *bio) +{ + unsigned chunks = 0; + struct bio_vec bv; + struct bvec_iter iter; - return segs; + /* + * We special case discard/write same/write zeroes, because they + * interpret bi_size differently: + */ + switch (bio_op(bio)) { + case REQ_OP_DISCARD: + case REQ_OP_SECURE_ERASE: + case REQ_OP_WRITE_ZEROES: + return 0; + case REQ_OP_WRITE_SAME: + return 1; + default: + bio_for_each_chunk(bv, bio, iter) + chunks++; + return chunks; + } } /*