All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: "Pavel Begunkov" <asml.silence@gmail.com>,
	"Mike Snitzer" <snitzer@redhat.com>,
	"Ryusuke Konishi" <konishi.ryusuke@gmail.com>,
	"Konstantin Komarov" <almaz.alexandrovich@paragon-software.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Md . Haris Iqbal " <haris.iqbal@ionos.com>,
	"Jack Wang" <jinpu.wang@ionos.com>,
	"Roger Pau Monné" <roger.pau@citrix.co>,
	"Philipp Reisner" <philipp.reisner@linbit.com>,
	"Lars Ellenberg" <lars.ellenberg@linbit.com>,
	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	[thread overview]
Message-ID: <20220118071952.1243143-11-hch@lst.de> (raw)
In-Reply-To: <20220118071952.1243143-1-hch@lst.de>

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 <hch@lst.de>
---
 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


WARNING: multiple messages have this Message-ID
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-nfs@vger.kernel.org,
	linux-nilfs@vger.kernel.org, "Mike Snitzer" <snitzer@redhat.com>,
	"Philipp Reisner" <philipp.reisner@linbit.com>,
	"Ryusuke Konishi" <konishi.ryusuke@gmail.com>,
	"Konstantin Komarov" <almaz.alexandrovich@paragon-software.com>,
	"Roger Pau Monné" <roger.pau@citrix.co>,
	dm-devel@redhat.com, "Md . Haris Iqbal " <haris.iqbal@ionos.com>,
	"Lars Ellenberg" <lars.ellenberg@linbit.com>,
	linux-fsdevel@vger.kernel.org, xen-devel@lists.xenproject.org,
	"Andrew Morton" <akpm@linux-foundation.org>,
	ntfs3@lists.linux.dev, "Jack Wang" <jinpu.wang@ionos.com>,
	"Pavel Begunkov" <asml.silence@gmail.com>,
	drbd-dev@lists.linbit.com
Subject: [dm-devel] [PATCH 10/19] rnbd-srv: simplify bio mapping in process_rdma
Date: Tue, 18 Jan 2022 08:19:43 +0100	[thread overview]
Message-ID: <20220118071952.1243143-11-hch@lst.de> (raw)
In-Reply-To: <20220118071952.1243143-1-hch@lst.de>

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 <hch@lst.de>
---
 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

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


  parent reply	other threads:[~2022-01-18  7:20 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-18  7:19 improve the bio allocation interface Christoph Hellwig
2022-01-18  7:19 ` [dm-devel] " Christoph Hellwig
2022-01-18  7:19 ` [PATCH 01/19] fs: remove mpage_alloc Christoph Hellwig
2022-01-18  7:19   ` [dm-devel] " Christoph Hellwig
2022-01-18  7:19 ` [PATCH 02/19] nilfs2: remove nilfs_alloc_seg_bio Christoph Hellwig
2022-01-18  7:19   ` [dm-devel] " Christoph Hellwig
2022-01-18  7:19 ` [PATCH 03/19] nfs/blocklayout: remove bl_alloc_init_bio Christoph Hellwig
2022-01-18  7:19   ` [dm-devel] " Christoph Hellwig
2022-01-18  7:19 ` [PATCH 04/19] ntfs3: remove ntfs_alloc_bio Christoph Hellwig
2022-01-18  7:19   ` [dm-devel] " Christoph Hellwig
2022-01-18  7:19 ` [PATCH 05/19] dm: bio_alloc can't fail if it is allowed to sleep Christoph Hellwig
2022-01-18  7:19   ` [dm-devel] " Christoph Hellwig
2022-01-18  7:19 ` [PATCH 06/19] dm-crypt: remove clone_init Christoph Hellwig
2022-01-18  7:19   ` [dm-devel] " Christoph Hellwig
2022-01-18  7:19 ` [PATCH 07/19] dm-snap: use blkdev_issue_flush instead of open coding it Christoph Hellwig
2022-01-18  7:19   ` [dm-devel] " Christoph Hellwig
2022-01-18  7:19 ` [PATCH 08/19] dm-thin: " Christoph Hellwig
2022-01-18  7:19   ` [dm-devel] " Christoph Hellwig
2022-01-18  7:19 ` [PATCH 09/19] drbd: bio_alloc can't fail if it is allow to sleep Christoph Hellwig
2022-01-18  7:19   ` [dm-devel] " Christoph Hellwig
2022-01-18  7:19 ` Christoph Hellwig [this message]
2022-01-18  7:19   ` [dm-devel] [PATCH 10/19] rnbd-srv: simplify bio mapping in process_rdma Christoph Hellwig
2022-01-19  0:20   ` Jinpu Wang
2022-01-19  0:20     ` [dm-devel] " Jinpu Wang
2022-01-19  0:48     ` Jinpu Wang
2022-01-19  0:48       ` [dm-devel] " Jinpu Wang
2022-01-20  8:37     ` Christoph Hellwig
2022-01-20  8:37       ` [dm-devel] " Christoph Hellwig
2022-01-20  8:46       ` Jinpu Wang
2022-01-20  8:46         ` [dm-devel] " Jinpu Wang
2022-01-18  7:19 ` [PATCH 11/19] rnbd-src: remove struct rnbd_dev_blk_io Christoph Hellwig
2022-01-18  7:19   ` [dm-devel] " Christoph Hellwig
2022-01-19 15:32   ` Jinpu Wang
2022-01-19 15:32     ` [dm-devel] " Jinpu Wang
2022-01-18  7:19 ` [PATCH 12/19] xen-blkback: bio_alloc can't fail if it is allow to sleep Christoph Hellwig
2022-01-18  7:19   ` [dm-devel] " Christoph Hellwig
2022-01-18  7:19 ` [dm-devel] [PATCH 13/19] block: move blk_next_bio to bio.c Christoph Hellwig
2022-01-18  7:19   ` Christoph Hellwig
2022-01-18 22:10   ` Chaitanya Kulkarni
2022-01-18 22:10     ` [dm-devel] " Chaitanya Kulkarni
2022-01-18  7:19 ` [PATCH 14/19] block: pass a block_device and opf to blk_next_bio Christoph Hellwig
2022-01-18  7:19   ` [dm-devel] " Christoph Hellwig
2022-01-18 22:11   ` Chaitanya Kulkarni
2022-01-18 22:11     ` [dm-devel] " Chaitanya Kulkarni
2022-01-20  8:34     ` Christoph Hellwig
2022-01-20  8:34       ` [dm-devel] " Christoph Hellwig
2022-01-18  7:19 ` [dm-devel] [PATCH 15/19] block: pass a block_device and opf to bio_alloc_bioset Christoph Hellwig
2022-01-18  7:19   ` Christoph Hellwig
2022-01-18 22:12   ` Chaitanya Kulkarni
2022-01-18 22:12     ` [dm-devel] " Chaitanya Kulkarni
2022-01-18  7:19 ` [PATCH 16/19] block: pass a block_device and opf to bio_alloc_kiocb Christoph Hellwig
2022-01-18  7:19   ` [dm-devel] " Christoph Hellwig
2022-01-18 22:12   ` Chaitanya Kulkarni
2022-01-18 22:12     ` [dm-devel] " Chaitanya Kulkarni
2022-01-18  7:19 ` [PATCH 17/19] block: pass a block_device and opf to bio_alloc Christoph Hellwig
2022-01-18  7:19   ` [dm-devel] " Christoph Hellwig
2022-01-18 22:14   ` Chaitanya Kulkarni
2022-01-18 22:14     ` [dm-devel] " Chaitanya Kulkarni
2022-01-18  7:19 ` [PATCH 18/19] block: pass a block_device and opf to bio_init Christoph Hellwig
2022-01-18  7:19   ` [dm-devel] " Christoph Hellwig
2022-01-18 22:15   ` Chaitanya Kulkarni
2022-01-18 22:15     ` [dm-devel] " Chaitanya Kulkarni
2022-01-18  7:19 ` [PATCH 19/19] block: pass a block_device and opf to bio_reset Christoph Hellwig
2022-01-18  7:19   ` [dm-devel] " Christoph Hellwig
2022-01-18 22:16   ` Chaitanya Kulkarni
2022-01-18 22:16     ` [dm-devel] " Chaitanya Kulkarni
2022-01-19 13:27 ` improve the bio allocation interface Jens Axboe
2022-01-19 13:27   ` [dm-devel] " Jens Axboe
2022-01-24  9:10 improve the bio allocation interface v2 Christoph Hellwig
2022-01-24  9:10 ` [PATCH 10/19] rnbd-srv: simplify bio mapping in process_rdma Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220118071952.1243143-11-hch@lst.de \
    --to=hch@lst.de \
    --cc=akpm@linux-foundation.org \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=dm-devel@redhat.com \
    --cc=drbd-dev@lists.linbit.com \
    --cc=haris.iqbal@ionos.com \
    --cc=jinpu.wang@ionos.com \
    --cc=konishi.ryusuke@gmail.com \
    --cc=lars.ellenberg@linbit.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-nilfs@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    --cc=philipp.reisner@linbit.com \
    --cc=roger.pau@citrix.co \
    --cc=snitzer@redhat.com \
    --cc=xen-devel@lists.xenproject.org \
    --subject='Re: [PATCH 10/19] rnbd-srv: simplify bio mapping in process_rdma' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.