Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2998548imm; Thu, 24 May 2018 20:50:49 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpqFbvxDKuZ8xrmk/kT+clIrWtdpl1wzBNLk5D3OMKlta4v366MfMTtmsLmRBArjRL93oN8 X-Received: by 2002:a63:8f43:: with SMTP id r3-v6mr646035pgn.10.1527220249142; Thu, 24 May 2018 20:50:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527220249; cv=none; d=google.com; s=arc-20160816; b=vRj7HAB7Lx9rChTK+TyCigoinBixxfiuBzHbWZjb2+ctbp93In0G1Rneo3WLki28jQ OlxQNCtFi9fE0QhoAfLXFW7RkemQrQ96ZYfWQ4+TSB9v1eb+kbM1Omlhmo7qSvzQREBY R9QzlnOnSZ+E2kZ6zTJV4VanyhdfC8DGAUVS24kIJi7tKd7rlMCAW8Eui3a/EG9CH09/ HAL/NilWVM5VyVWDOiy3Vf1oSvuHI+TOanLjU4yctYJqpK/f2jCQTsgyxXLd+oU7gtE6 kavv3Tv/Ca/iPjCksedIJDD2iCvdLCb+tIsqbQyf4mgq6meNttw7AhaL917PYV7mz2Hp FQLg== 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:arc-authentication-results; bh=nJKjWPeJU1as+ZG1xwR85I1uMqEsjhA3OEA6CaSlbMI=; b=piBFiGxVbnJjyiesrm87fhgcvMEysZJtbEXkhZ1ba82QZkY2GU1c7eYMIrFdGV7+mk AYeAlhDRe/STKRVifwcnvYMO9SH6wdBGwddYjd45f5JKj6Rr7QDO9+Vv1rKzriNGi5U/ Ejfs2k4AnS2+aBD3yoNn1lAn7BIkiWsbyS6A+02Itv2D/KqHGrXKDqJ21Z5QW4JalB/C PIdbJdLoZyd8mxUG3Bg0F1pfmQ0fbFXLaKvO1AtZrp5wrxOhucCN2JbV5Tx+0FZg+1eJ CkEokbHnRFmfUHahJu7IYrfW46GSQcoGY28xXc2weKk7wySgKMwkS7x9lEf9sEme2Mr5 89IA== 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 y18-v6si17702974pgv.202.2018.05.24.20.50.34; Thu, 24 May 2018 20:50:49 -0700 (PDT) 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 S935103AbeEYDtM (ORCPT + 99 others); Thu, 24 May 2018 23:49:12 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39678 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934623AbeEYDtK (ORCPT ); Thu, 24 May 2018 23:49:10 -0400 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:'' 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_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); } /* -- 2.9.5