Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp943911imu; Fri, 9 Nov 2018 08:28:42 -0800 (PST) X-Google-Smtp-Source: AJdET5d0nsBqjUv+QsMydBZqZfO451c6TosMxqi1HllTlxdHsdeiTHP+dNtGrJctgc3mRk3QfSYQ X-Received: by 2002:a17:902:598f:: with SMTP id p15-v6mr9488094pli.260.1541780922270; Fri, 09 Nov 2018 08:28:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541780922; cv=none; d=google.com; s=arc-20160816; b=euIgcghHAn15O9JD80pyuRbxNZmOsm5IeBR0waGW0gA8XKFGVyaA7L46kHlcA//Pu5 MjgwwOe2HEY3RZGBbXkPPkXd1lDDdN182C/h+b73hfHd/8OK6uZUvbXIpfSHwyqtuaD+ Tw9iQLxl+DZuJXbTeDwp8//N5Z55Z9fPs9RHs/yUkRHfIjFPo4Hi2PI3pJZux6gUE7FX q7HKJxmTWSX9QtOENd5/Hv4liw2NniTn8lchihhya9C7gA5365ekaQD1i0HcK5KBZ4yF PfaUMNyy5/uaE9cv+U/NEJE6eYXw9VZmPS/PPf8S6f6KLE0Yzh/h7rgCAIq1Oj8f/9i6 8mKg== 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=GG4+KiK80jEeiecxMuiFg9YVpkmo/zi5NgU3l6jxUXmK5Jgscdd9Qkfd1MAMjvKjd4 neEPYAy7nu+dK0ZiEZlxPVHqiiESxxgGha//0K55CyxTuaSwyGma5x3xnQvnCqGly5ed 6qYm+UQFfSCM1oIgevfxaGlzPvM/d4aVQO5zY6imaJSU2DOCKM5mj0oAJpYve2PjW4jb UiwsUN+VRsnrM2WM3uMI7XTTodastEcSfRRvId+XwdmFCveN5voMdXv6z3dISo14F6S2 5Zpu+kifaSA1O4gbjYggnfrG0GCkU/uTqyjROpV61dwx6Jy0PpcM8YlbjhpsY0hBbOT+ l/AA== 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 z4-v6si1633465pfz.270.2018.11.09.08.28.19; Fri, 09 Nov 2018 08:28:42 -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 S1728713AbeKJCIe (ORCPT + 99 others); Fri, 9 Nov 2018 21:08:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:10148 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728311AbeKJCIe (ORCPT ); Fri, 9 Nov 2018 21:08:34 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6B3257F6C7; Fri, 9 Nov 2018 16:27:17 +0000 (UTC) Received: from localhost (ovpn-8-16.pek2.redhat.com [10.72.8.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 769A160CD6; Fri, 9 Nov 2018 16:27:14 +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 V8 09/18] block: introduce bio_bvecs() Date: Sat, 10 Nov 2018 00:26:01 +0800 Message-Id: <20181109162610.18981-10-ming.lei@redhat.com> In-Reply-To: <20181109162610.18981-1-ming.lei@redhat.com> References: <20181109162610.18981-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 09 Nov 2018 16:27:17 +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