diff mbox series

[23/23] net-ceph: use bvec_set_page to initialize bvecs

Message ID 20230130092157.1759539-24-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [01/23] block: factor out a bvec_set_page helper | expand

Commit Message

Christoph Hellwig Jan. 30, 2023, 9:21 a.m. UTC
Use the bvec_set_page helper to initialize bvecs.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 net/ceph/messenger_v1.c |  7 ++-----
 net/ceph/messenger_v2.c | 28 +++++++++++-----------------
 2 files changed, 13 insertions(+), 22 deletions(-)

Comments

Ilya Dryomov Jan. 30, 2023, 6:20 p.m. UTC | #1
On Mon, Jan 30, 2023 at 10:23 AM Christoph Hellwig <hch@lst.de> wrote:
>
> Use the bvec_set_page helper to initialize bvecs.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  net/ceph/messenger_v1.c |  7 ++-----
>  net/ceph/messenger_v2.c | 28 +++++++++++-----------------
>  2 files changed, 13 insertions(+), 22 deletions(-)
>
> diff --git a/net/ceph/messenger_v1.c b/net/ceph/messenger_v1.c
> index d1787d7d33ef9a..d664cb1593a777 100644
> --- a/net/ceph/messenger_v1.c
> +++ b/net/ceph/messenger_v1.c
> @@ -40,15 +40,12 @@ static int ceph_tcp_recvmsg(struct socket *sock, void *buf, size_t len)
>  static int ceph_tcp_recvpage(struct socket *sock, struct page *page,
>                      int page_offset, size_t length)
>  {
> -       struct bio_vec bvec = {
> -               .bv_page = page,
> -               .bv_offset = page_offset,
> -               .bv_len = length
> -       };
> +       struct bio_vec bvec;
>         struct msghdr msg = { .msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL };
>         int r;
>
>         BUG_ON(page_offset + length > PAGE_SIZE);
> +       bvec_set_page(&bvec, page, length, page_offset);
>         iov_iter_bvec(&msg.msg_iter, ITER_DEST, &bvec, 1, length);
>         r = sock_recvmsg(sock, &msg, msg.msg_flags);
>         if (r == -EAGAIN)
> diff --git a/net/ceph/messenger_v2.c b/net/ceph/messenger_v2.c
> index 3009028c4fa28f..301a991dc6a68e 100644
> --- a/net/ceph/messenger_v2.c
> +++ b/net/ceph/messenger_v2.c
> @@ -149,10 +149,10 @@ static int do_try_sendpage(struct socket *sock, struct iov_iter *it)
>
>         while (iov_iter_count(it)) {
>                 /* iov_iter_iovec() for ITER_BVEC */
> -               bv.bv_page = it->bvec->bv_page;
> -               bv.bv_offset = it->bvec->bv_offset + it->iov_offset;
> -               bv.bv_len = min(iov_iter_count(it),
> -                               it->bvec->bv_len - it->iov_offset);
> +               bvec_set_page(&bv, it->bvec->bv_page,
> +                             min(iov_iter_count(it),
> +                                 it->bvec->bv_len - it->iov_offset),
> +                             it->bvec->bv_offset + it->iov_offset);
>
>                 /*
>                  * sendpage cannot properly handle pages with
> @@ -286,9 +286,8 @@ static void set_out_bvec_zero(struct ceph_connection *con)
>         WARN_ON(iov_iter_count(&con->v2.out_iter));
>         WARN_ON(!con->v2.out_zero);
>
> -       con->v2.out_bvec.bv_page = ceph_zero_page;
> -       con->v2.out_bvec.bv_offset = 0;
> -       con->v2.out_bvec.bv_len = min(con->v2.out_zero, (int)PAGE_SIZE);
> +       bvec_set_page(&con->v2.out_bvec, ceph_zero_page,
> +                     min(con->v2.out_zero, (int)PAGE_SIZE), 0);
>         con->v2.out_iter_sendpage = true;
>         iov_iter_bvec(&con->v2.out_iter, ITER_SOURCE, &con->v2.out_bvec, 1,
>                       con->v2.out_bvec.bv_len);
> @@ -863,10 +862,7 @@ static void get_bvec_at(struct ceph_msg_data_cursor *cursor,
>
>         /* get a piece of data, cursor isn't advanced */
>         page = ceph_msg_data_next(cursor, &off, &len);
> -
> -       bv->bv_page = page;
> -       bv->bv_offset = off;
> -       bv->bv_len = len;
> +       bvec_set_page(bv, page, len, off);
>  }
>
>  static int calc_sg_cnt(void *buf, int buf_len)
> @@ -1855,9 +1851,8 @@ static void prepare_read_enc_page(struct ceph_connection *con)
>              con->v2.in_enc_resid);
>         WARN_ON(!con->v2.in_enc_resid);
>
> -       bv.bv_page = con->v2.in_enc_pages[con->v2.in_enc_i];
> -       bv.bv_offset = 0;
> -       bv.bv_len = min(con->v2.in_enc_resid, (int)PAGE_SIZE);
> +       bvec_set_page(&bv, con->v2.in_enc_pages[con->v2.in_enc_i],
> +                     min(con->v2.in_enc_resid, (int)PAGE_SIZE), 0);
>
>         set_in_bvec(con, &bv);
>         con->v2.in_enc_i++;
> @@ -2998,9 +2993,8 @@ static void queue_enc_page(struct ceph_connection *con)
>              con->v2.out_enc_resid);
>         WARN_ON(!con->v2.out_enc_resid);
>
> -       bv.bv_page = con->v2.out_enc_pages[con->v2.out_enc_i];
> -       bv.bv_offset = 0;
> -       bv.bv_len = min(con->v2.out_enc_resid, (int)PAGE_SIZE);
> +       bvec_set_page(&bv, con->v2.out_enc_pages[con->v2.out_enc_i],
> +                     min(con->v2.out_enc_resid, (int)PAGE_SIZE), 0);
>
>         set_out_bvec(con, &bv, false);
>         con->v2.out_enc_i++;
> --
> 2.39.0
>

Hi Christoph,

Nit on the patch title: this subsystem should be referred to as
libceph instead of net-ceph or similar, see "git log -- net/ceph" or
MAINTAINERS.

Reviewed-by: Ilya Dryomov <idryomov@gmail.com>

Thanks,

                Ilya
diff mbox series

Patch

diff --git a/net/ceph/messenger_v1.c b/net/ceph/messenger_v1.c
index d1787d7d33ef9a..d664cb1593a777 100644
--- a/net/ceph/messenger_v1.c
+++ b/net/ceph/messenger_v1.c
@@ -40,15 +40,12 @@  static int ceph_tcp_recvmsg(struct socket *sock, void *buf, size_t len)
 static int ceph_tcp_recvpage(struct socket *sock, struct page *page,
 		     int page_offset, size_t length)
 {
-	struct bio_vec bvec = {
-		.bv_page = page,
-		.bv_offset = page_offset,
-		.bv_len = length
-	};
+	struct bio_vec bvec;
 	struct msghdr msg = { .msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL };
 	int r;
 
 	BUG_ON(page_offset + length > PAGE_SIZE);
+	bvec_set_page(&bvec, page, length, page_offset);
 	iov_iter_bvec(&msg.msg_iter, ITER_DEST, &bvec, 1, length);
 	r = sock_recvmsg(sock, &msg, msg.msg_flags);
 	if (r == -EAGAIN)
diff --git a/net/ceph/messenger_v2.c b/net/ceph/messenger_v2.c
index 3009028c4fa28f..301a991dc6a68e 100644
--- a/net/ceph/messenger_v2.c
+++ b/net/ceph/messenger_v2.c
@@ -149,10 +149,10 @@  static int do_try_sendpage(struct socket *sock, struct iov_iter *it)
 
 	while (iov_iter_count(it)) {
 		/* iov_iter_iovec() for ITER_BVEC */
-		bv.bv_page = it->bvec->bv_page;
-		bv.bv_offset = it->bvec->bv_offset + it->iov_offset;
-		bv.bv_len = min(iov_iter_count(it),
-				it->bvec->bv_len - it->iov_offset);
+		bvec_set_page(&bv, it->bvec->bv_page,
+			      min(iov_iter_count(it),
+				  it->bvec->bv_len - it->iov_offset),
+			      it->bvec->bv_offset + it->iov_offset);
 
 		/*
 		 * sendpage cannot properly handle pages with
@@ -286,9 +286,8 @@  static void set_out_bvec_zero(struct ceph_connection *con)
 	WARN_ON(iov_iter_count(&con->v2.out_iter));
 	WARN_ON(!con->v2.out_zero);
 
-	con->v2.out_bvec.bv_page = ceph_zero_page;
-	con->v2.out_bvec.bv_offset = 0;
-	con->v2.out_bvec.bv_len = min(con->v2.out_zero, (int)PAGE_SIZE);
+	bvec_set_page(&con->v2.out_bvec, ceph_zero_page,
+		      min(con->v2.out_zero, (int)PAGE_SIZE), 0);
 	con->v2.out_iter_sendpage = true;
 	iov_iter_bvec(&con->v2.out_iter, ITER_SOURCE, &con->v2.out_bvec, 1,
 		      con->v2.out_bvec.bv_len);
@@ -863,10 +862,7 @@  static void get_bvec_at(struct ceph_msg_data_cursor *cursor,
 
 	/* get a piece of data, cursor isn't advanced */
 	page = ceph_msg_data_next(cursor, &off, &len);
-
-	bv->bv_page = page;
-	bv->bv_offset = off;
-	bv->bv_len = len;
+	bvec_set_page(bv, page, len, off);
 }
 
 static int calc_sg_cnt(void *buf, int buf_len)
@@ -1855,9 +1851,8 @@  static void prepare_read_enc_page(struct ceph_connection *con)
 	     con->v2.in_enc_resid);
 	WARN_ON(!con->v2.in_enc_resid);
 
-	bv.bv_page = con->v2.in_enc_pages[con->v2.in_enc_i];
-	bv.bv_offset = 0;
-	bv.bv_len = min(con->v2.in_enc_resid, (int)PAGE_SIZE);
+	bvec_set_page(&bv, con->v2.in_enc_pages[con->v2.in_enc_i],
+		      min(con->v2.in_enc_resid, (int)PAGE_SIZE), 0);
 
 	set_in_bvec(con, &bv);
 	con->v2.in_enc_i++;
@@ -2998,9 +2993,8 @@  static void queue_enc_page(struct ceph_connection *con)
 	     con->v2.out_enc_resid);
 	WARN_ON(!con->v2.out_enc_resid);
 
-	bv.bv_page = con->v2.out_enc_pages[con->v2.out_enc_i];
-	bv.bv_offset = 0;
-	bv.bv_len = min(con->v2.out_enc_resid, (int)PAGE_SIZE);
+	bvec_set_page(&bv, con->v2.out_enc_pages[con->v2.out_enc_i],
+		      min(con->v2.out_enc_resid, (int)PAGE_SIZE), 0);
 
 	set_out_bvec(con, &bv, false);
 	con->v2.out_enc_i++;