Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5168640pxb; Wed, 19 Jan 2022 12:32:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJwcpUcuNfS9h+IVCm28A3BUUbVmTKdfSYJpzgJfcvIgPOX7MggN0SOuaZNyighmjqrKireu X-Received: by 2002:a17:902:a9c4:b0:14a:d4ed:7a7a with SMTP id b4-20020a170902a9c400b0014ad4ed7a7amr10387399plr.138.1642624353251; Wed, 19 Jan 2022 12:32:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642624353; cv=none; d=google.com; s=arc-20160816; b=CB644VFMQ6WGS0Dq+ZV46aOV8rPBmDs2TFWSjompgW0jMN5Mvq1B02CBbpRShxGJEX SSVwmreV3iyh7gJOGztw3kea2MVC6Is8wJdFl8+ob2P43D1dKpMBBpuvte3iXPeGtiav +BtNquIZen9sRzHiFB4OFZonZ9ZiRW/Yp73a1yGh8AmFDHti9xyU9CqPrF/wMJ0aRDAr USnT+Cj3ptGpYOJoLl4ZyWppRKz/7LL59lfOmEEPYuQxwV3D2VQ1r/cvqvNkPk4XZnyO MZ6JxnUCkNJQPCkNGkCjO/rNfcoJvpDig0exw+QLhc86zXdMzFzb9ULOfDOA9FhB52FU Jy1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=f2brK3c1r//byFNtb7H+AigJJebcgGaABpKjDxFp+eg=; b=QSGE2y1JRkADcXoPrLRT6AEmYza9qFxJXgopWAOhUcFUOwRFWZIbVvvNcVWOEqn7FB Ja8m33akMkpJ20TzGvcGfkvMOIOY5XcIAzt8uzTjUbzoa+A6++qT/tHaQG5tVKVyBWoo Q94iAuxRwZhSxseGTUGb1pcB2laIB4AtFsyQFWy6K//A+jWbgEJGntccsbCl9ioYQ0xG mCvAicx9XfRC0PWJmY+I2Bnrean2ml5NnmhpTFQUbgUYQmwOsXJJLvKalnnAxzbe2uFr ciS6C80I1oQqHIt9g3Iby33XJxd28N2Vu5B544x1oSvIrnq9ClMGHUQ5bPVMqQPy5IoG QeLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=u24yUmqx; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y20si6769278pjp.70.2022.01.19.12.32.13; Wed, 19 Jan 2022 12:32:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=u24yUmqx; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244834AbiARHUc (ORCPT + 99 others); Tue, 18 Jan 2022 02:20:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244820AbiARHUa (ORCPT ); Tue, 18 Jan 2022 02:20:30 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6D3AC061574; Mon, 17 Jan 2022 23:20:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=f2brK3c1r//byFNtb7H+AigJJebcgGaABpKjDxFp+eg=; b=u24yUmqxGf8p+pGDi/NFrHE6oM tiw9ctFdhfoYibfXwKUv3fIcDXOsDIFrGfOv4Px/yVVx5O3fJemb3jHK0ChVy2Zxxdw2O6vKLCjAu vWPIJnLQVQWOcBFRlCPyeoMNOO+Q4CVRU5MshJ99sGKuBHaPT4SgFnhjNMaD7dJRzew884XXg2d9u Z3KM/jwMW5XPRrVcvPhZ9TybnvF7+PrdUAiM57Ba/ijIX/UdOixiz9iNq2ll6gZU0zcT5QK/+NTDA 13wiEXXo+DkO28tZczO8n6Z7sN3wC80auX/loORY0ucWpLjKoQNWoO0hfZJinRZxFQ+vnhVO9NB8D +pBCOQ6A==; Received: from [2001:4bb8:184:72a4:a4a9:19c0:5242:7768] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1n9in0-000ZXZ-GY; Tue, 18 Jan 2022 07:20:23 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Pavel Begunkov , Mike Snitzer , Ryusuke Konishi , Konstantin Komarov , Andrew Morton , "Md . Haris Iqbal " , Jack Wang , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Philipp Reisner , Lars Ellenberg , linux-block@vger.kernel.org, dm-devel@redhat.com, linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-nilfs@vger.kernel.org, ntfs3@lists.linux.dev, xen-devel@lists.xenproject.org, drbd-dev@lists.linbit.com Subject: [PATCH 10/19] rnbd-srv: simplify bio mapping in process_rdma Date: Tue, 18 Jan 2022 08:19:43 +0100 Message-Id: <20220118071952.1243143-11-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220118071952.1243143-1-hch@lst.de> References: <20220118071952.1243143-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org The memory mapped in process_rdma is contiguous, so there is no need to loop over bio_add_page. Remove rnbd_bio_map_kern and just open code the bio allocation and mapping in the caller. Signed-off-by: Christoph Hellwig --- drivers/block/rnbd/rnbd-srv-dev.c | 57 ------------------------------- drivers/block/rnbd/rnbd-srv-dev.h | 5 --- drivers/block/rnbd/rnbd-srv.c | 20 ++++++++--- 3 files changed, 15 insertions(+), 67 deletions(-) diff --git a/drivers/block/rnbd/rnbd-srv-dev.c b/drivers/block/rnbd/rnbd-srv-dev.c index b241a099aeae2..98d3e591a0885 100644 --- a/drivers/block/rnbd/rnbd-srv-dev.c +++ b/drivers/block/rnbd/rnbd-srv-dev.c @@ -44,60 +44,3 @@ void rnbd_dev_close(struct rnbd_dev *dev) blkdev_put(dev->bdev, dev->blk_open_flags); kfree(dev); } - -void rnbd_dev_bi_end_io(struct bio *bio) -{ - struct rnbd_dev_blk_io *io = bio->bi_private; - - rnbd_endio(io->priv, blk_status_to_errno(bio->bi_status)); - bio_put(bio); -} - -/** - * rnbd_bio_map_kern - map kernel address into bio - * @data: pointer to buffer to map - * @bs: bio_set to use. - * @len: length in bytes - * @gfp_mask: allocation flags for bio allocation - * - * Map the kernel address into a bio suitable for io to a block - * device. Returns an error pointer in case of error. - */ -struct bio *rnbd_bio_map_kern(void *data, struct bio_set *bs, - unsigned int len, gfp_t gfp_mask) -{ - unsigned long kaddr = (unsigned long)data; - unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT; - unsigned long start = kaddr >> PAGE_SHIFT; - const int nr_pages = end - start; - int offset, i; - struct bio *bio; - - bio = bio_alloc_bioset(gfp_mask, nr_pages, bs); - if (!bio) - return ERR_PTR(-ENOMEM); - - offset = offset_in_page(kaddr); - for (i = 0; i < nr_pages; i++) { - unsigned int bytes = PAGE_SIZE - offset; - - if (len <= 0) - break; - - if (bytes > len) - bytes = len; - - if (bio_add_page(bio, virt_to_page(data), bytes, - offset) < bytes) { - /* we don't support partial mappings */ - bio_put(bio); - return ERR_PTR(-EINVAL); - } - - data += bytes; - len -= bytes; - offset = 0; - } - - return bio; -} diff --git a/drivers/block/rnbd/rnbd-srv-dev.h b/drivers/block/rnbd/rnbd-srv-dev.h index 0eb23850afb95..1a14ece0be726 100644 --- a/drivers/block/rnbd/rnbd-srv-dev.h +++ b/drivers/block/rnbd/rnbd-srv-dev.h @@ -41,11 +41,6 @@ void rnbd_dev_close(struct rnbd_dev *dev); void rnbd_endio(void *priv, int error); -void rnbd_dev_bi_end_io(struct bio *bio); - -struct bio *rnbd_bio_map_kern(void *data, struct bio_set *bs, - unsigned int len, gfp_t gfp_mask); - static inline int rnbd_dev_get_max_segs(const struct rnbd_dev *dev) { return queue_max_segments(bdev_get_queue(dev->bdev)); diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c index 1ee808fc600cf..65c670e96075b 100644 --- a/drivers/block/rnbd/rnbd-srv.c +++ b/drivers/block/rnbd/rnbd-srv.c @@ -114,6 +114,14 @@ rnbd_get_sess_dev(int dev_id, struct rnbd_srv_session *srv_sess) return sess_dev; } +static void rnbd_dev_bi_end_io(struct bio *bio) +{ + struct rnbd_dev_blk_io *io = bio->bi_private; + + rnbd_endio(io->priv, blk_status_to_errno(bio->bi_status)); + bio_put(bio); +} + static int process_rdma(struct rnbd_srv_session *srv_sess, struct rtrs_srv_op *id, void *data, u32 datalen, const void *usr, size_t usrlen) @@ -144,11 +152,11 @@ static int process_rdma(struct rnbd_srv_session *srv_sess, priv->sess_dev = sess_dev; priv->id = id; - /* Generate bio with pages pointing to the rdma buffer */ - bio = rnbd_bio_map_kern(data, sess_dev->rnbd_dev->ibd_bio_set, datalen, GFP_KERNEL); - if (IS_ERR(bio)) { - err = PTR_ERR(bio); - rnbd_srv_err(sess_dev, "Failed to generate bio, err: %d\n", err); + bio = bio_alloc_bioset(GFP_KERNEL, 1, sess_dev->rnbd_dev->ibd_bio_set); + if (bio_add_page(bio, virt_to_page(data), datalen, + offset_in_page(data))) { + rnbd_srv_err(sess_dev, "Failed to map data to bio\n"); + err = -EINVAL; goto sess_dev_put; } @@ -170,6 +178,8 @@ static int process_rdma(struct rnbd_srv_session *srv_sess, return 0; +bio_put: + bio_put(bio); sess_dev_put: rnbd_put_sess_dev(sess_dev); err: -- 2.30.2