Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp490785imu; Fri, 16 Nov 2018 05:47:50 -0800 (PST) X-Google-Smtp-Source: AJdET5fXbTTSUJlkCr2eRGI5gz9azceWI28jq63gbaF2T+tGlZ6Y2evfaLd5Crg8X9kwm0Dr4DuT X-Received: by 2002:a63:6704:: with SMTP id b4mr10039836pgc.100.1542376070446; Fri, 16 Nov 2018 05:47:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542376070; cv=none; d=google.com; s=arc-20160816; b=mfH4Pr8XHrAmc+izfp1LKYdmvSV63+MkuNN/Vs1mF+B6E9vS3KP1XgfN2111Adox9M kbJ9e+W1fbr3Fuzsc6Gt5uDNcyr/GSZ66ApLQ5NO3OdowHLXR0rR/QPyv7NcMfsbgYD4 CRcVWnHcAWHBPY6rzk4U6n1B3UuJh5LqGI8rh2Pm+9vVahcH4akbYTKW5OM2gK9DcQP8 hnUamoa9Y4ju86gtPRN0+yRxbE9jGZi6v6WStZ8cZ5UmNVL+gwdcarYBWmA258P9DgMf a7jZZWtw3rXXg8mxB1Ng9cZvJebR4AFwbS3+i+InU2NxANkHrk5NE9Hp8+GbSDYh2AS7 Zx1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=LEe/PV+tgu8zPMatiOhZkfzIwuMVOLOkuvYakvxdGSE=; b=FTXGLKnXj1kN7nL1ekqZDMD4ezsagWD0/6UWmz+DSxXqKBJXKIxRDruBDodpuPosFE c7cH5Pe0OuE+qaAGuaszW+ZvJopd1Eg6gkP7lJXKgmou5PW11aJUBfYvU/v/SuYoTW8Y f5hk4tMHv145tfUIcuHzahSJ2zNamswxEUlhsv1ZFY+QSIlvSIfFYakjNLB4QucVEE4m DXt+zebAFBFdjTBd3MVQHgqM8zEXC3SkyGXbp+AQ/rl9LS5CLjCkLeuoyxZjAFJXVoGR BxKzLEHR9EVNL8H9WaFqYOR/6h56fdqkfgqsyreTYhY2mYuiMN3ARPH79FPK9R9WWLia PxvA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 92-v6si13254427plw.117.2018.11.16.05.47.35; Fri, 16 Nov 2018 05:47:50 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389691AbeKPX6M (ORCPT + 99 others); Fri, 16 Nov 2018 18:58:12 -0500 Received: from verein.lst.de ([213.95.11.211]:49948 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727997AbeKPX6L (ORCPT ); Fri, 16 Nov 2018 18:58:11 -0500 Received: by newverein.lst.de (Postfix, from userid 2407) id ACCE668D60; Fri, 16 Nov 2018 14:45:41 +0100 (CET) Date: Fri, 16 Nov 2018 14:45:41 +0100 From: Christoph Hellwig To: Ming Lei Cc: Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, 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: Re: [PATCH V10 09/19] block: introduce bio_bvecs() Message-ID: <20181116134541.GH3165@lst.de> References: <20181115085306.9910-1-ming.lei@redhat.com> <20181115085306.9910-10-ming.lei@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181115085306.9910-10-ming.lei@redhat.com> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 15, 2018 at 04:52:56PM +0800, Ming Lei wrote: > There are still cases in which we need to use bio_bvecs() for get the > number of multi-page segment, so introduce it. The only user in your final tree seems to be the loop driver, and even that one only uses the helper for read/write bios. I think something like this would be much simpler in the end: diff --git a/drivers/block/loop.c b/drivers/block/loop.c index d509902a8046..712511815ac6 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -514,16 +514,18 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, struct request *rq = blk_mq_rq_from_pdu(cmd); struct bio *bio = rq->bio; struct file *file = lo->lo_backing_file; + struct bvec_iter bvec_iter; + struct bio_vec tmp; unsigned int offset; int nr_bvec = 0; int ret; + __rq_for_each_bio(bio, rq) + bio_for_each_bvec(tmp, bio, bvec_iter) + nr_bvec++; + if (rq->bio != rq->biotail) { - struct bvec_iter iter; - struct bio_vec tmp; - __rq_for_each_bio(bio, rq) - nr_bvec += bio_bvecs(bio); bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec), GFP_NOIO); if (!bvec) @@ -537,7 +539,7 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, * API will take care of all details for us. */ __rq_for_each_bio(bio, rq) - bio_for_each_bvec(tmp, bio, iter) { + bio_for_each_bvec(tmp, bio, bvec_iter) { *bvec = tmp; bvec++; } @@ -551,7 +553,6 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, */ offset = bio->bi_iter.bi_bvec_done; bvec = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter); - nr_bvec = bio_bvecs(bio); } atomic_set(&cmd->ref, 2); diff --git a/include/linux/bio.h b/include/linux/bio.h index dcad0b69f57a..379440d1ced0 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -200,30 +200,6 @@ static inline unsigned bio_segments(struct bio *bio) } } -static inline unsigned bio_bvecs(struct bio *bio) -{ - unsigned bvecs = 0; - struct bio_vec bv; - struct bvec_iter iter; - - /* - * 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; - } -} - /* * get a reference to a bio, so it won't disappear. the intended use is * something like: