public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] io_uring/rw: don't mask in f_iocb_flags
@ 2024-12-17 15:05 Jens Axboe
  2024-12-18 15:08 ` Anuj gupta
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2024-12-17 15:05 UTC (permalink / raw)
  To: io-uring; +Cc: Kanchan Joshi, Anuj Gupta

A previous commit changed overwriting kiocb->ki_flags with
->f_iocb_flags with masking it in. This breaks for retry situations,
where we don't necessarily want to retain previously set flags, like
IOCB_NOWAIT.

The use case needs IOCB_HAS_METADATA to be persistent, but the change
makes all flags persistent, which is an issue. Add a request flag to
track whether the request has metadata or not, as that is persistent
across issues.

Fixes: 4dde0cc4459c ("io_uring: introduce attributes for read/write and PI support")
Signed-off-by: Jens Axboe <[email protected]>

---

The identitied commit breaks test cases which end up reporting -EAGAIN
rather than just blocking/retrying. I have not tested this with the
metadata path, so please do that...

diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h
index c141ffec81fe..493a8f7fa8e4 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -480,6 +480,7 @@ enum {
 	REQ_F_BL_NO_RECYCLE_BIT,
 	REQ_F_BUFFERS_COMMIT_BIT,
 	REQ_F_BUF_NODE_BIT,
+	REQ_F_HAS_METADATA_BIT,
 
 	/* not a real bit, just to check we're not overflowing the space */
 	__REQ_F_LAST_BIT,
@@ -560,6 +561,8 @@ enum {
 	REQ_F_BUFFERS_COMMIT	= IO_REQ_FLAG(REQ_F_BUFFERS_COMMIT_BIT),
 	/* buf node is valid */
 	REQ_F_BUF_NODE		= IO_REQ_FLAG(REQ_F_BUF_NODE_BIT),
+	/* request has read/write metadata assigned */
+	REQ_F_HAS_METADATA	= IO_REQ_FLAG(REQ_F_HAS_METADATA_BIT),
 };
 
 typedef void (*io_req_tw_func_t)(struct io_kiocb *req, struct io_tw_state *ts);
diff --git a/io_uring/rw.c b/io_uring/rw.c
index bdfc3faef85d..d0ac4a51420e 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -283,7 +283,7 @@ static int io_prep_rw_pi(struct io_kiocb *req, struct io_rw *rw, int ddir,
 			  pi_attr.len, &io->meta.iter);
 	if (unlikely(ret < 0))
 		return ret;
-	rw->kiocb.ki_flags |= IOCB_HAS_METADATA;
+	req->flags |= REQ_F_HAS_METADATA;
 	io_meta_save_state(io);
 	return ret;
 }
@@ -787,18 +787,17 @@ static bool io_rw_should_retry(struct io_kiocb *req)
 	struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw);
 	struct kiocb *kiocb = &rw->kiocb;
 
-	/* never retry for NOWAIT, we just complete with -EAGAIN */
-	if (req->flags & REQ_F_NOWAIT)
+	/*
+	 * Never retry for NOWAIT or a request with metadata, we just complete
+	 * with -EAGAIN.
+	 */
+	if (req->flags & (REQ_F_NOWAIT | REQ_F_HAS_METADATA))
 		return false;
 
 	/* Only for buffered IO */
 	if (kiocb->ki_flags & (IOCB_DIRECT | IOCB_HIPRI))
 		return false;
 
-	/* never retry for meta io */
-	if (kiocb->ki_flags & IOCB_HAS_METADATA)
-		return false;
-
 	/*
 	 * just use poll if we can, and don't attempt if the fs doesn't
 	 * support callback based unlocks
@@ -849,7 +848,7 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type)
 	if (!(req->flags & REQ_F_FIXED_FILE))
 		req->flags |= io_file_get_flags(file);
 
-	kiocb->ki_flags |= file->f_iocb_flags;
+	kiocb->ki_flags = file->f_iocb_flags;
 	ret = kiocb_set_rw_flags(kiocb, rw->flags, rw_type);
 	if (unlikely(ret))
 		return ret;
@@ -883,7 +882,7 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type)
 		kiocb->ki_complete = io_complete_rw;
 	}
 
-	if (kiocb->ki_flags & IOCB_HAS_METADATA) {
+	if (req->flags & REQ_F_HAS_METADATA) {
 		struct io_async_rw *io = req->async_data;
 
 		/*
@@ -892,6 +891,7 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type)
 		 */
 		if (!(req->file->f_flags & O_DIRECT))
 			return -EOPNOTSUPP;
+		kiocb->ki_flags |= IOCB_HAS_METADATA;
 		kiocb->private = &io->meta;
 	}
 
-- 
Jens Axboe


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

* Re: [PATCH] io_uring/rw: don't mask in f_iocb_flags
  2024-12-17 15:05 [PATCH] io_uring/rw: don't mask in f_iocb_flags Jens Axboe
@ 2024-12-18 15:08 ` Anuj gupta
  2024-12-18 15:37   ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Anuj gupta @ 2024-12-18 15:08 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring, Kanchan Joshi, Anuj Gupta

> The identitied commit breaks test cases which end up reporting -EAGAIN
> rather than just blocking/retrying. I have not tested this with the
> metadata path, so please do that...

Tested the metadata path, works fine.
Feel free to add:
Reviewed-by: Anuj Gupta <[email protected]>

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

* Re: [PATCH] io_uring/rw: don't mask in f_iocb_flags
  2024-12-18 15:08 ` Anuj gupta
@ 2024-12-18 15:37   ` Jens Axboe
  0 siblings, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2024-12-18 15:37 UTC (permalink / raw)
  To: Anuj gupta; +Cc: io-uring, Kanchan Joshi, Anuj Gupta

On 12/18/24 8:08 AM, Anuj gupta wrote:
>> The identitied commit breaks test cases which end up reporting -EAGAIN
>> rather than just blocking/retrying. I have not tested this with the
>> metadata path, so please do that...
> 
> Tested the metadata path, works fine.
> Feel free to add:
> Reviewed-by: Anuj Gupta <[email protected]>

Great, thanks for testing!

-- 
Jens Axboe


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

end of thread, other threads:[~2024-12-18 15:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-17 15:05 [PATCH] io_uring/rw: don't mask in f_iocb_flags Jens Axboe
2024-12-18 15:08 ` Anuj gupta
2024-12-18 15:37   ` Jens Axboe

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