From patchwork Thu Nov 15 08:52: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: 10683791 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6593714D6 for ; Thu, 15 Nov 2018 08:55:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54F65299C2 for ; Thu, 15 Nov 2018 08:55:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48C422B334; Thu, 15 Nov 2018 08:55:50 +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=unavailable 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 CE191299C2 for ; Thu, 15 Nov 2018 08:55:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED1546B027D; Thu, 15 Nov 2018 03:55:48 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EA7576B027E; Thu, 15 Nov 2018 03:55:48 -0500 (EST) 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 DBD8B6B027F; Thu, 15 Nov 2018 03:55:48 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by kanga.kvack.org (Postfix) with ESMTP id AF6296B027D for ; Thu, 15 Nov 2018 03:55:48 -0500 (EST) Received: by mail-qk1-f197.google.com with SMTP id 67so43054392qkj.18 for ; Thu, 15 Nov 2018 00:55:48 -0800 (PST) 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=aBBM3nmRuvsMADjOAX8n/4Cbd0z9pc1PG2XIqdD3L3o=; b=uE65hQk0O7UkM9CCQmiLlPFDC7NN9h36ljUaV+6/SoysZkL/Bwlz2e/ZSQNYf6puUn jnWzZLcmWX5wFP07oe/gR1fKeDtDTfcoCXSyl3q0cx+5v3kxGp9yacqdOpn/xxv0v6tl lbyYwEO58q0k+tgRmZskNWH5NzJM/jbNbA8AfSmScKxPI01TuI5baDPAprm5fwJFvjtG wVArHyd7MzcnViTkDrIJLPVrMu3ig3Mr4Yf35VA12oW7ItvYWUcKVkPRydxkkKyB4g3Z MVTpapgmag+1nqKdnYasJUoSXCaLey5b7lBjaT0qhj0bmhfCFSgPgvN8p9suRt+nbAKz uPQA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 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: AGRZ1gIY3LKHNsD8u4EHgU6i2auh1ia5pPQtuFc5/vJ2hsQdz32/VPGk gozX2JALB9wkQS2GZ3iQI5SCG7DuaDi6Bai3+ima/mZNepaeFifeLFZZyYicdk79HFgjyOy6V5C i66vMKo71RL0vEbM2Pdg1WXuw4XZ8s8ypufG7iaR2srTRwZtJPncbZYzA8FusnADcVQ== X-Received: by 2002:a0c:8b64:: with SMTP id d36mr5207836qvc.233.1542272148498; Thu, 15 Nov 2018 00:55:48 -0800 (PST) X-Google-Smtp-Source: AJdET5fIvr1sbFs9qYmRlHmutdPRfVece4z3gXVLUFu0MkHBwhSbCRyZm7TQnoTR01b5hR0oMbWj X-Received: by 2002:a0c:8b64:: with SMTP id d36mr5207818qvc.233.1542272147955; Thu, 15 Nov 2018 00:55:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542272147; cv=none; d=google.com; s=arc-20160816; b=WrVLk7K7J+Y+Gv2hHo3S/ykpXr+lGoJTWNqlg6dIuO2Q360xu6YHwIcD+13NvB3sJk b+F6+6J2SXTmb5jHeNCQqYdX36OiCUmqgKCyrBywSFsxKxJo1mN2U526blUHJ1wyVBsZ mvmC89G0vnBmFUXVPtwTP1MpLx4vy9pFb1w3Z4cC921MGjIDAlJvnWD0QKMRbvvlXGz0 Nztee9bGscdwyJQIesCvNncetjZ88t/56/9bwIDrFaU8AThLD+pZ4seVH5AK8mX0UZBC RppNUyQUXkO3TVhtJ0Olx69H5h0w0Rrk543zswbLyvkLcponmC1LHaxZ9dXZqQL+nrZN Jp9w== 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; bh=aBBM3nmRuvsMADjOAX8n/4Cbd0z9pc1PG2XIqdD3L3o=; b=opG9leARW0EMQCuXIrSISN5fGJpU+HcIbRU4Mvtaz16pwPkDA+NzaUupgBCYs75Ipq Gb1kz24UbATaE8GOFDy+ZvD2FcqYrsH5cqs5zHaZi74GmCoaTDKwSzy/obYwCJPDm4fu 4/RX9YX4vT9qUphDb0YTUIdzO1t+F/OucyszINiFiKekals0oKbtbBRpcnyRKYj0eCyv sv10qlg+tAvsFnCBgblmMSVqWbA8uvAOg7ijpdylIu0qTY4p+2YQZFjKYhABPr1FXEXQ H6ueX0rrqqcm1Ie6Jr2m6OSHclr92qWIydjhoGfF2WsBOOSZmfe2qmKtguIZadvhPvHS X0OA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 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 (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id s29si6771953qth.384.2018.11.15.00.55.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Nov 2018 00:55:47 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 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-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BDABE88307; Thu, 15 Nov 2018 08:55:46 +0000 (UTC) Received: from localhost (ovpn-8-23.pek2.redhat.com [10.72.8.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC1D4608E1; Thu, 15 Nov 2018 08:55:36 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Ming Lei , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, linux-erofs@lists.ozlabs.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , Theodore Ts'o , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com Subject: [PATCH V10 09/19] block: introduce bio_bvecs() Date: Thu, 15 Nov 2018 16:52:56 +0800 Message-Id: <20181115085306.9910-10-ming.lei@redhat.com> In-Reply-To: <20181115085306.9910-1-ming.lei@redhat.com> References: <20181115085306.9910-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 15 Nov 2018 08:55:47 +0000 (UTC) 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_bvecs() for get the number of multi-page segment, so introduce it. Cc: Dave Chinner Cc: Kent Overstreet Cc: Mike Snitzer Cc: dm-devel@redhat.com Cc: Alexander Viro Cc: linux-fsdevel@vger.kernel.org Cc: Shaohua Li Cc: linux-raid@vger.kernel.org Cc: linux-erofs@lists.ozlabs.org Cc: David Sterba Cc: linux-btrfs@vger.kernel.org Cc: Darrick J. Wong Cc: linux-xfs@vger.kernel.org Cc: Gao Xiang Cc: Christoph Hellwig Cc: Theodore Ts'o Cc: linux-ext4@vger.kernel.org Cc: Coly Li Cc: linux-bcache@vger.kernel.org Cc: Boaz Harrosh Cc: Bob Peterson Cc: cluster-devel@redhat.com Signed-off-by: Ming Lei Reviewed-by: Omar Sandoval --- 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; + } } /*