public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH 5.11 0/3] rw import_iovec cleanups
@ 2020-11-07 13:16 Pavel Begunkov
  2020-11-07 13:16 ` [PATCH 1/3] fs/io_uring Don't use the return value from import_iovec() Pavel Begunkov
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Pavel Begunkov @ 2020-11-07 13:16 UTC (permalink / raw)
  To: Jens Axboe, io-uring, David Laight

There are a couple of things duplicated, it's how we get
len after import, vars in which we keep it, etc. Clean
this up.

David Laight (1):
  fs/io_uring Don't use the return value from import_iovec().

Pavel Begunkov (2):
  io_uring: remove duplicated io_size from rw
  io_uring: inline io_import_iovec()

 fs/io_uring.c | 58 ++++++++++++++++++++-------------------------------
 1 file changed, 23 insertions(+), 35 deletions(-)

-- 
2.24.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] fs/io_uring Don't use the return value from import_iovec().
  2020-11-07 13:16 [PATCH 5.11 0/3] rw import_iovec cleanups Pavel Begunkov
@ 2020-11-07 13:16 ` Pavel Begunkov
  2020-11-07 13:16 ` [PATCH 2/3] io_uring: remove duplicated io_size from rw Pavel Begunkov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2020-11-07 13:16 UTC (permalink / raw)
  To: Jens Axboe, io-uring, David Laight; +Cc: David Laight

From: David Laight <[email protected]>

This is the only code that relies on import_iovec() returning
iter.count on success.
This allows a better interface to import_iovec().

Reviewed-by: Pavel Begunkov <[email protected]>
Signed-off-by: David Laight <[email protected]>
Signed-off-by: Pavel Begunkov <[email protected]>
---
 fs/io_uring.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index a4146b1f50ef..e72f9a3fd8b5 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -3164,7 +3164,7 @@ static ssize_t __io_import_iovec(int rw, struct io_kiocb *req,
 
 		ret = import_single_range(rw, buf, sqe_len, *iovec, iter);
 		*iovec = NULL;
-		return ret < 0 ? ret : sqe_len;
+		return ret;
 	}
 
 	if (req->flags & REQ_F_BUFFER_SELECT) {
@@ -3190,7 +3190,7 @@ static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
 	if (!iorw)
 		return __io_import_iovec(rw, req, iovec, iter, needs_lock);
 	*iovec = NULL;
-	return iov_iter_count(&iorw->iter);
+	return 0;
 }
 
 static inline loff_t *io_kiocb_ppos(struct kiocb *kiocb)
@@ -3459,7 +3459,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock,
 	if (ret < 0)
 		return ret;
 	iov_count = iov_iter_count(iter);
-	io_size = ret;
+	io_size = iov_count;
 	req->result = io_size;
 	ret = 0;
 
@@ -3587,7 +3587,7 @@ static int io_write(struct io_kiocb *req, bool force_nonblock,
 	if (ret < 0)
 		return ret;
 	iov_count = iov_iter_count(iter);
-	io_size = ret;
+	io_size = iov_count;
 	req->result = io_size;
 
 	/* Ensure we clear previously set non-block flag */
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] io_uring: remove duplicated io_size from rw
  2020-11-07 13:16 [PATCH 5.11 0/3] rw import_iovec cleanups Pavel Begunkov
  2020-11-07 13:16 ` [PATCH 1/3] fs/io_uring Don't use the return value from import_iovec() Pavel Begunkov
@ 2020-11-07 13:16 ` Pavel Begunkov
  2020-11-07 13:16 ` [PATCH 3/3] io_uring: inline io_import_iovec() Pavel Begunkov
  2020-11-09 14:42 ` [PATCH 5.11 0/3] rw import_iovec cleanups Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2020-11-07 13:16 UTC (permalink / raw)
  To: Jens Axboe, io-uring, David Laight

io_size and iov_count in io_read() and io_write() hold the same value,
kill the last one.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 fs/io_uring.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index e72f9a3fd8b5..f3033e3929c1 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -3449,7 +3449,6 @@ static int io_read(struct io_kiocb *req, bool force_nonblock,
 	struct iov_iter __iter, *iter = &__iter;
 	struct io_async_rw *rw = req->async_data;
 	ssize_t io_size, ret, ret2;
-	size_t iov_count;
 	bool no_async;
 
 	if (rw)
@@ -3458,8 +3457,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock,
 	ret = io_import_iovec(READ, req, &iovec, iter, !force_nonblock);
 	if (ret < 0)
 		return ret;
-	iov_count = iov_iter_count(iter);
-	io_size = iov_count;
+	io_size = iov_iter_count(iter);
 	req->result = io_size;
 	ret = 0;
 
@@ -3475,7 +3473,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock,
 	if (no_async)
 		goto copy_iov;
 
-	ret = rw_verify_area(READ, req->file, io_kiocb_ppos(kiocb), iov_count);
+	ret = rw_verify_area(READ, req->file, io_kiocb_ppos(kiocb), io_size);
 	if (unlikely(ret))
 		goto out_free;
 
@@ -3494,7 +3492,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock,
 		if (req->file->f_flags & O_NONBLOCK)
 			goto done;
 		/* some cases will consume bytes even on error returns */
-		iov_iter_revert(iter, iov_count - iov_iter_count(iter));
+		iov_iter_revert(iter, io_size - iov_iter_count(iter));
 		ret = 0;
 		goto copy_iov;
 	} else if (ret < 0) {
@@ -3577,7 +3575,6 @@ static int io_write(struct io_kiocb *req, bool force_nonblock,
 	struct kiocb *kiocb = &req->rw.kiocb;
 	struct iov_iter __iter, *iter = &__iter;
 	struct io_async_rw *rw = req->async_data;
-	size_t iov_count;
 	ssize_t ret, ret2, io_size;
 
 	if (rw)
@@ -3586,8 +3583,7 @@ static int io_write(struct io_kiocb *req, bool force_nonblock,
 	ret = io_import_iovec(WRITE, req, &iovec, iter, !force_nonblock);
 	if (ret < 0)
 		return ret;
-	iov_count = iov_iter_count(iter);
-	io_size = iov_count;
+	io_size = iov_iter_count(iter);
 	req->result = io_size;
 
 	/* Ensure we clear previously set non-block flag */
@@ -3605,7 +3601,7 @@ static int io_write(struct io_kiocb *req, bool force_nonblock,
 	    (req->flags & REQ_F_ISREG))
 		goto copy_iov;
 
-	ret = rw_verify_area(WRITE, req->file, io_kiocb_ppos(kiocb), iov_count);
+	ret = rw_verify_area(WRITE, req->file, io_kiocb_ppos(kiocb), io_size);
 	if (unlikely(ret))
 		goto out_free;
 
@@ -3649,7 +3645,7 @@ static int io_write(struct io_kiocb *req, bool force_nonblock,
 	} else {
 copy_iov:
 		/* some cases will consume bytes even on error returns */
-		iov_iter_revert(iter, iov_count - iov_iter_count(iter));
+		iov_iter_revert(iter, io_size - iov_iter_count(iter));
 		ret = io_setup_async_rw(req, iovec, inline_vecs, iter, false);
 		if (!ret)
 			return -EAGAIN;
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] io_uring: inline io_import_iovec()
  2020-11-07 13:16 [PATCH 5.11 0/3] rw import_iovec cleanups Pavel Begunkov
  2020-11-07 13:16 ` [PATCH 1/3] fs/io_uring Don't use the return value from import_iovec() Pavel Begunkov
  2020-11-07 13:16 ` [PATCH 2/3] io_uring: remove duplicated io_size from rw Pavel Begunkov
@ 2020-11-07 13:16 ` Pavel Begunkov
  2020-11-09 14:42 ` [PATCH 5.11 0/3] rw import_iovec cleanups Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2020-11-07 13:16 UTC (permalink / raw)
  To: Jens Axboe, io-uring, David Laight

Inline io_import_iovec() and leave only its former __io_import_iovec()
renamed to the original name. That makes it more obious what is reused in
io_read/write().

Signed-off-by: Pavel Begunkov <[email protected]>
---
 fs/io_uring.c | 40 ++++++++++++++++------------------------
 1 file changed, 16 insertions(+), 24 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index f3033e3929c1..2e435b336927 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -3135,7 +3135,7 @@ static ssize_t io_iov_buffer_select(struct io_kiocb *req, struct iovec *iov,
 	return __io_iov_buffer_select(req, iov, needs_lock);
 }
 
-static ssize_t __io_import_iovec(int rw, struct io_kiocb *req,
+static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
 				 struct iovec **iovec, struct iov_iter *iter,
 				 bool needs_lock)
 {
@@ -3181,18 +3181,6 @@ static ssize_t __io_import_iovec(int rw, struct io_kiocb *req,
 			      req->ctx->compat);
 }
 
-static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
-			       struct iovec **iovec, struct iov_iter *iter,
-			       bool needs_lock)
-{
-	struct io_async_rw *iorw = req->async_data;
-
-	if (!iorw)
-		return __io_import_iovec(rw, req, iovec, iter, needs_lock);
-	*iovec = NULL;
-	return 0;
-}
-
 static inline loff_t *io_kiocb_ppos(struct kiocb *kiocb)
 {
 	return (kiocb->ki_filp->f_mode & FMODE_STREAM) ? NULL : &kiocb->ki_pos;
@@ -3316,7 +3304,7 @@ static inline int io_rw_prep_async(struct io_kiocb *req, int rw)
 	struct iovec *iov = iorw->fast_iov;
 	ssize_t ret;
 
-	ret = __io_import_iovec(rw, req, &iov, &iorw->iter, false);
+	ret = io_import_iovec(rw, req, &iov, &iorw->iter, false);
 	if (unlikely(ret < 0))
 		return ret;
 
@@ -3451,12 +3439,14 @@ static int io_read(struct io_kiocb *req, bool force_nonblock,
 	ssize_t io_size, ret, ret2;
 	bool no_async;
 
-	if (rw)
+	if (rw) {
 		iter = &rw->iter;
-
-	ret = io_import_iovec(READ, req, &iovec, iter, !force_nonblock);
-	if (ret < 0)
-		return ret;
+		iovec = NULL;
+	} else {
+		ret = io_import_iovec(READ, req, &iovec, iter, !force_nonblock);
+		if (ret < 0)
+			return ret;
+	}
 	io_size = iov_iter_count(iter);
 	req->result = io_size;
 	ret = 0;
@@ -3577,12 +3567,14 @@ static int io_write(struct io_kiocb *req, bool force_nonblock,
 	struct io_async_rw *rw = req->async_data;
 	ssize_t ret, ret2, io_size;
 
-	if (rw)
+	if (rw) {
 		iter = &rw->iter;
-
-	ret = io_import_iovec(WRITE, req, &iovec, iter, !force_nonblock);
-	if (ret < 0)
-		return ret;
+		iovec = NULL;
+	} else {
+		ret = io_import_iovec(WRITE, req, &iovec, iter, !force_nonblock);
+		if (ret < 0)
+			return ret;
+	}
 	io_size = iov_iter_count(iter);
 	req->result = io_size;
 
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 5.11 0/3] rw import_iovec cleanups
  2020-11-07 13:16 [PATCH 5.11 0/3] rw import_iovec cleanups Pavel Begunkov
                   ` (2 preceding siblings ...)
  2020-11-07 13:16 ` [PATCH 3/3] io_uring: inline io_import_iovec() Pavel Begunkov
@ 2020-11-09 14:42 ` Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2020-11-09 14:42 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring, David Laight

On 11/7/20 6:16 AM, Pavel Begunkov wrote:
> There are a couple of things duplicated, it's how we get
> len after import, vars in which we keep it, etc. Clean
> this up.

Applied, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-11-09 14:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-07 13:16 [PATCH 5.11 0/3] rw import_iovec cleanups Pavel Begunkov
2020-11-07 13:16 ` [PATCH 1/3] fs/io_uring Don't use the return value from import_iovec() Pavel Begunkov
2020-11-07 13:16 ` [PATCH 2/3] io_uring: remove duplicated io_size from rw Pavel Begunkov
2020-11-07 13:16 ` [PATCH 3/3] io_uring: inline io_import_iovec() Pavel Begunkov
2020-11-09 14:42 ` [PATCH 5.11 0/3] rw import_iovec cleanups Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox