Skip to content

Commit 1143be1

Browse files
committed
io_uring/rw: don't mask in f_iocb_flags
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: 59a7d12 ("io_uring: introduce attributes for read/write and PI support") Signed-off-by: Jens Axboe <[email protected]>
1 parent ce94640 commit 1143be1

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

include/linux/io_uring_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ enum {
480480
REQ_F_BL_NO_RECYCLE_BIT,
481481
REQ_F_BUFFERS_COMMIT_BIT,
482482
REQ_F_BUF_NODE_BIT,
483+
REQ_F_HAS_METADATA_BIT,
483484

484485
/* not a real bit, just to check we're not overflowing the space */
485486
__REQ_F_LAST_BIT,
@@ -560,6 +561,8 @@ enum {
560561
REQ_F_BUFFERS_COMMIT = IO_REQ_FLAG(REQ_F_BUFFERS_COMMIT_BIT),
561562
/* buf node is valid */
562563
REQ_F_BUF_NODE = IO_REQ_FLAG(REQ_F_BUF_NODE_BIT),
564+
/* request has read/write metadata assigned */
565+
REQ_F_HAS_METADATA = IO_REQ_FLAG(REQ_F_HAS_METADATA_BIT),
563566
};
564567

565568
typedef void (*io_req_tw_func_t)(struct io_kiocb *req, struct io_tw_state *ts);

io_uring/rw.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ static int io_prep_rw_pi(struct io_kiocb *req, struct io_rw *rw, int ddir,
283283
pi_attr.len, &io->meta.iter);
284284
if (unlikely(ret < 0))
285285
return ret;
286-
rw->kiocb.ki_flags |= IOCB_HAS_METADATA;
286+
req->flags |= REQ_F_HAS_METADATA;
287287
io_meta_save_state(io);
288288
return ret;
289289
}
@@ -787,18 +787,17 @@ static bool io_rw_should_retry(struct io_kiocb *req)
787787
struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw);
788788
struct kiocb *kiocb = &rw->kiocb;
789789

790-
/* never retry for NOWAIT, we just complete with -EAGAIN */
791-
if (req->flags & REQ_F_NOWAIT)
790+
/*
791+
* Never retry for NOWAIT or a request with metadata, we just complete
792+
* with -EAGAIN.
793+
*/
794+
if (req->flags & (REQ_F_NOWAIT | REQ_F_HAS_METADATA))
792795
return false;
793796

794797
/* Only for buffered IO */
795798
if (kiocb->ki_flags & (IOCB_DIRECT | IOCB_HIPRI))
796799
return false;
797800

798-
/* never retry for meta io */
799-
if (kiocb->ki_flags & IOCB_HAS_METADATA)
800-
return false;
801-
802801
/*
803802
* just use poll if we can, and don't attempt if the fs doesn't
804803
* support callback based unlocks
@@ -849,7 +848,7 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type)
849848
if (!(req->flags & REQ_F_FIXED_FILE))
850849
req->flags |= io_file_get_flags(file);
851850

852-
kiocb->ki_flags |= file->f_iocb_flags;
851+
kiocb->ki_flags = file->f_iocb_flags;
853852
ret = kiocb_set_rw_flags(kiocb, rw->flags, rw_type);
854853
if (unlikely(ret))
855854
return ret;
@@ -883,7 +882,7 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type)
883882
kiocb->ki_complete = io_complete_rw;
884883
}
885884

886-
if (kiocb->ki_flags & IOCB_HAS_METADATA) {
885+
if (req->flags & REQ_F_HAS_METADATA) {
887886
struct io_async_rw *io = req->async_data;
888887

889888
/*
@@ -892,6 +891,7 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type)
892891
*/
893892
if (!(req->file->f_flags & O_DIRECT))
894893
return -EOPNOTSUPP;
894+
kiocb->ki_flags |= IOCB_HAS_METADATA;
895895
kiocb->private = &io->meta;
896896
}
897897

0 commit comments

Comments
 (0)