From patchwork Wed Jun 27 12:45:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10491433 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 418A9602B3 for ; Wed, 27 Jun 2018 12:49:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F48928C9A for ; Wed, 27 Jun 2018 12:49:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FC4D28D8F; Wed, 27 Jun 2018 12:49:38 +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 B2D9128C9A for ; Wed, 27 Jun 2018 12:49:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C09F96B028A; Wed, 27 Jun 2018 08:49:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BDF0B6B028C; Wed, 27 Jun 2018 08:49:36 -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 AF6CB6B028D; Wed, 27 Jun 2018 08:49:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f198.google.com (mail-qk0-f198.google.com [209.85.220.198]) by kanga.kvack.org (Postfix) with ESMTP id 80B7C6B028A for ; Wed, 27 Jun 2018 08:49:36 -0400 (EDT) Received: by mail-qk0-f198.google.com with SMTP id 99-v6so1968116qkr.14 for ; Wed, 27 Jun 2018 05:49:36 -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=BHg1BobcFVgaTTo6e3IVdIeWpPgxGxLxDuZ4jV/Th6k=; b=XGa0c9Qxp3PbXysJdyHLIFdeOlVxhyYxkCp4zPUSSuhOO00LG0djHPaZ8oVIVAm73Y hO/iC6FJ9Rj+TZjJUE3q7bu8MvC7kKGsD0zm4ZwdGw8fqK//StPaZ3Ndu29p52Ao/GZK TfyHdRKAsMQk4UOZuLh18Nzu+WXcK7BWucWF8c6ukw0tcg6B5IdAuOlal8ejOoVyKuPF xTBMfxuFtRFdUlW/MR5KeOiC0cdlcpeGHvqv3nAmD6m1/wXoI35UQjKh7S5qGq4nqifX 7M9PKRTcRHWpTNRwCRjrXC1u3JXdm/0l4FYkZUS3+AvUICZjMBnbt9yZO6y6Kop/KVT/ 3rTA== 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: APt69E33bS39NQk9pFQOQLVGvlH7T2eIumYAOwXVvM5CWbG38rpAdtq7 TpymVd9Xtkcg9ymjaVMlMaL1MVYOtybLKLDFIoosAnvuHD2SKpqz1EN2LdYHsLfUDcYylJPcVMw +utaHsvJAtWbmPOeZlCweGhkbohv3vWjNSWnTd1kReulxJvVsL4/WdbYDJPaw/9C/lQ== X-Received: by 2002:a37:2966:: with SMTP id p99-v6mr4875347qkh.390.1530103776318; Wed, 27 Jun 2018 05:49:36 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcLwefr34tJod4CA7d6IyttVPuzrwQkoARFnHxBfR/QYo5xyEPvM5vzQfhjBHxGq9yhfWu3 X-Received: by 2002:a37:2966:: with SMTP id p99-v6mr4875320qkh.390.1530103775815; Wed, 27 Jun 2018 05:49:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530103775; cv=none; d=google.com; s=arc-20160816; b=KyG29xl23vdYcF8CHfl09eLDEfgB80/ZuSuGnjc67KMkudjSicOMuI8WtBO2v0ISPH awC5LVJ8rNfiAQHuK1tkxXgT5B6R/yTJJoqjoHLQ/cqYLES5BXzBFK7GY1b0TG82usTy JNyISW/DGcxa9bZn0GFr2h8ehDsHwtz3xqp4tY3plHOG5NT2MtdwDKXthEAhjGaXCkbN 0zdFlxcS7AklhVfnGwZ4cbxDksEq8F3My8Yfwy5uQd5v+ZLt7NE4ehVAKzyLHOqr+7jY WQ8qy46fB+Fw48qqSdzCwb3FlrMg7Qvz/OcXQVXKx6UCg7cEA4uIMgvJM+xToqEqy28g eTMA== 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=BHg1BobcFVgaTTo6e3IVdIeWpPgxGxLxDuZ4jV/Th6k=; b=xbxAcx9tzWMdRU+CL2uipZvZsq7cvePUgzl7W/hPfwBheTq+XHPhwYDYULf+DoFbVa cWLWpWxwBzkeKOIRWAI2fzCR0DkxUrnK7cedffvL1GA0/roOFxg7klLBnDQui7bdooP9 bNmbpugK5mj/HxzI3QwdsvXB7z+DKyTwSd1WhsjfjslERwAJ15R/jhFUrVwBVx66n5Fl 9hXRt6vGhOqSwTZhsc4KowF+7Gl/rXXLLMqSn2EW9yZiekxCzexG47122apqH7MTeJML RXEzyK9NVfxOQxDna76JnVFOLHp0al9KDE6I9JurgZdC3oveGRcDK/Bxtr2nHcIMGV6B tkUg== 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 f5-v6si3508749qve.92.2018.06.27.05.49.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jun 2018 05:49:35 -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 75008401EF04; Wed, 27 Jun 2018 12:49:35 +0000 (UTC) Received: from localhost (ovpn-12-44.pek2.redhat.com [10.72.12.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8936D2156888; Wed, 27 Jun 2018 12:49:27 +0000 (UTC) From: Ming Lei To: Jens Axboe , Christoph Hellwig , Kent Overstreet Cc: David Sterba , Huang Ying , Mike Snitzer , 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 V7 18/24] block: introduce bio_bvecs() Date: Wed, 27 Jun 2018 20:45:42 +0800 Message-Id: <20180627124548.3456-19-ming.lei@redhat.com> In-Reply-To: <20180627124548.3456-1-ming.lei@redhat.com> References: <20180627124548.3456-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.5]); Wed, 27 Jun 2018 12:49:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 27 Jun 2018 12:49:35 +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_bvecs() 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 551444bd9795..083c1ee9c6c8 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_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; + } } /*