Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5486445imu; Tue, 13 Nov 2018 07:18:52 -0800 (PST) X-Google-Smtp-Source: AJdET5cSEV2/NQ4mBupe7+BM+QS5jpH7D1UYL+h6shu2/mbPZ8Unj5t9Op+Lq4eskRHL5tGnXsly X-Received: by 2002:a17:902:3084:: with SMTP id v4-v6mr5380383plb.326.1542122332206; Tue, 13 Nov 2018 07:18:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542122332; cv=none; d=google.com; s=arc-20160816; b=W4EtuYDJWcGhXGOt4rokbygyVyjpD3IflkCH6iotn4ecFEYESVsfWYV9Vgk71gEgbc Zo4zF/uar1LKgH0/1aRSa5N/QIReuNKYm9xD7P0L1oP0dr3vR6obFRm49H3rxCRsirwO qsOt9gQ3K1Y+7853hdt7UfXtwRLiQmFasrUyjwJp+MF0P/O1LB77gmwggSruv4bdUWw1 iqLfew1AhypKkQ8EiUK7ihkglNVzXnfP7EMJcN4JsdBfyhohVJBjIB3UJYvJGz78O8VK UitZt0gBRQye/Zsjw/3NAkHINfMyqig8/Ghd8Ae/azv0RFLaN5vg38uxfZq7Ak6iVB6K Fugw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=eBv3DHtbJdW2+eGV2OlrNF4hw2d8RzaUgcnEtDSiZ/Y=; b=oK8ojjfPxPhzCWeSEDgMTnPp1BpUfaINp+P9VJOx9IjSiSAH8VOjEmx+ZrbG1xk6t0 anWIZGhBlEW3FuDQSFGZEuqH7G2E8Z6KF90QwkWCiT8miqJssH/BwuzWcfHCejBwc/Uk M/lZca7yEPDa9L8JzpYyhjPgWC+Y5TWoT3FHbaAJs4WP8/tQnIa3+Wq1tlkxl8+NuK/k FB6n6116AOb3RnCI+L28bmFmgsopWO5S7tvE8iESuXicWrtL16Dxp32jYnrci9xS41Oh Bv1F9ZPiGsta3yJAfsbpRDRQos83XV5r2fy8d4Wo1BxQS0HkfaOg7PmGt5egrUV5ZsxW PGpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z10si2888594pfm.37.2018.11.13.07.18.36; Tue, 13 Nov 2018 07:18:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388059AbeKNBOs (ORCPT + 99 others); Tue, 13 Nov 2018 20:14:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50872 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731105AbeKNBOr (ORCPT ); Tue, 13 Nov 2018 20:14:47 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 336B6C04BD2F; Tue, 13 Nov 2018 15:16:13 +0000 (UTC) Received: from localhost (ovpn-8-23.pek2.redhat.com [10.72.8.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91C365D757; Tue, 13 Nov 2018 15:16:09 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Ming Lei , Christoph Hellwig Subject: [PATCH V9 09/19] block: introduce bio_bvecs() Date: Tue, 13 Nov 2018 23:14:55 +0800 Message-Id: <20181113151505.15498-10-ming.lei@redhat.com> In-Reply-To: <20181113151505.15498-1-ming.lei@redhat.com> References: <20181113151505.15498-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 13 Nov 2018 15:16:13 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are still cases in which we need to use bio_bvecs() for get the number of multi-page segment, so introduce it. Cc: Christoph Hellwig 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 1f0dcf109841..3496c816946e 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -196,7 +196,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: @@ -205,13 +204,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_bvecs(struct bio *bio) +{ + unsigned bvecs = 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_bvec(bv, bio, iter) + bvecs++; + return bvecs; + } } /* -- 2.9.5