Misc cleanups
Jens Axboe
maintainercover Misc cleanups
Hi,
Nothing major in here:
1) Drop fdinfo grabbing a reference to the ring, the caller has already grabbed a reference to the ring fd so we don't need it.
2) Cleanup around file putting.
Signature · 1 line
Jens Axboe
Jens Axboe
maintainerPATCH 1/3 io_uring/fdinfo: get rid of ref tryget
The caller holds a reference to the ring itself, so by definition the ring cannot go away. There's no need to play games with tryget for the reference, as we don't need an extra reference at all.
--- io_uring/fdinfo.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
io_uring/fdinfo.c +6 -12
@@ -46,9 +46,13 @@ static __cold int io_uring_show_cred(struct seq_file *m, unsigned int id,return 0 ; } -static __cold void __io_uring_show_fdinfo (struct io_ring_ctx *ctx, -struct seq_file *m) +/* +* Caller holds a reference to the file already, we don't need to do +* anything else to get an extra reference. +*/ +__cold void io_uring_show_fdinfo (struct seq_file *m,struct file *f) { +struct io_ring_ctx *ctx = f->private_data;struct io_sq_data *sq =NULL ;struct io_overflow_cqe *ocqe;struct io_rings *r = ctx->rings;
@@ -203,14 +207,4 @@ static __cold void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, spin_unlock(&ctx->completion_lock); } - -__cold void io_uring_show_fdinfo (struct seq_file *m,struct file *f) -{ -struct io_ring_ctx *ctx = f->private_data; - -if (percpu_ref_tryget (&ctx->refs)) { -__io_uring_show_fdinfo (ctx, m); -percpu_ref_put (&ctx->refs); - } -}#endif
Signature · 1 line
2.40.1
Jens Axboe
maintainerPATCH 2/3 io_uring/splice: use fput() directly
In reply to Jens AxboeNo point in using io_file_put() here, as we need to check if it's a fixed file in the caller anyway.
--- io_uring/splice.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
io_uring/splice.c +2 -2
@@ -68,7 +68,7 @@ int io_tee(struct io_kiocb *req, unsigned int issue_flags) ret =do_tee (in, out, sp->len, flags);if (!(sp->flags &SPLICE_F_FD_IN_FIXED )) -io_put_file (in); +fput (in); done:if (ret != sp->len)req_set_fail (req);
@@ -112,7 +112,7 @@ int io_splice(struct io_kiocb *req, unsigned int issue_flags) ret =do_splice (in, poff_in, out, poff_out, sp->len, flags);if (!(sp->flags &SPLICE_F_FD_IN_FIXED )) -io_put_file (in); +fput (in); done:if (ret != sp->len)req_set_fail (req);
Signature · 1 line
2.40.1
Jens Axboe
maintainerPATCH 3/3 io_uring: have io_file_put() take an io_kiocb rather than the file
In reply to Jens AxboeNo functional changes in this patch, just a prep patch for needing the request in io_file_put().
--- io_uring/io_uring.c | 4 ++-- io_uring/io_uring.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)
io_uring/io_uring.c +2 -2
@@ -1004,7 +1004,7 @@ static void __io_req_complete_post(struct io_kiocb *req, unsigned issue_flags)if (unlikely (req->flags &IO_REQ_CLEAN_FLAGS ))io_clean_op (req);if (!(req->flags &REQ_F_FIXED_FILE )) -io_put_file (req->file); +io_put_file (req); rsrc_node = req->rsrc_node;/*
@@ -1539,7 +1539,7 @@ void io_free_batch_list(struct io_ring_ctx *ctx, struct io_wq_work_node *node)io_clean_op (req); }if (!(req->flags &REQ_F_FIXED_FILE )) -io_put_file (req->file); +io_put_file (req);io_req_put_rsrc_locked (req, ctx);
io_uring/io_uring.h +3 -3
@@ -196,10 +196,10 @@ static inline bool req_has_async_data(struct io_kiocb *req)return req->flags &REQ_F_ASYNC_DATA ; } -static inline void io_put_file (struct file *file) +static inline void io_put_file (struct io_kiocb *req) { -if (file) -fput (file); +if (req->file) +fput (req->file); } static inline void io_ring_submit_unlock(struct io_ring_ctx *ctx,
Signature · 1 line
2.40.1
Jens Axboe
maintainerRe: [PATCH 3/3] io_uring: have io_file_put() take an io_kiocb rather than the file
Quoted 2 lines · Jens Axboe
No functional changes in this patch, just a prep patch for needing the request in
io_file_put().
Gah, that was an older version. Newer version checks the REQ_F_FIXED_FILE flag in the helper instead:
commit 17bc28374cd06b7d2d3f1e88470ef89f9cd3a497
Author: Jens Axboe <[email protected]> Date: Fri Jul 7 11:14:40 2023 -0600
io_uring: have io_file_put() take an io_kiocb rather than the file
No functional changes in this patch, just a prep patch for needing the request in io_file_put().
io_uring/io_uring.c +2 -4
@@ -998,8 +998,7 @@ static void __io_req_complete_post(struct io_kiocb *req, unsigned issue_flags)io_put_kbuf_comp (req);if (unlikely (req->flags &IO_REQ_CLEAN_FLAGS ))io_clean_op (req); -if (!(req->flags &REQ_F_FIXED_FILE )) -io_put_file (req->file); +io_put_file (req); rsrc_node = req->rsrc_node;/*
@@ -1533,8 +1532,7 @@ void io_free_batch_list(struct io_ring_ctx *ctx, struct io_wq_work_node *node)if (unlikely (req->flags &IO_REQ_CLEAN_FLAGS ))io_clean_op (req); } -if (!(req->flags &REQ_F_FIXED_FILE )) -io_put_file (req->file); +io_put_file (req);io_req_put_rsrc_locked (req, ctx);
io_uring/io_uring.h +3 -3
@@ -196,10 +196,10 @@ static inline bool req_has_async_data(struct io_kiocb *req)return req->flags &REQ_F_ASYNC_DATA ; } -static inline void io_put_file (struct file *file) +static inline void io_put_file (struct io_kiocb *req) { -if (file) -fput (file); +if (!(req->flags &REQ_F_FIXED_FILE ) && req->file) +fput (req->file); } static inline void io_ring_submit_unlock(struct io_ring_ctx *ctx,
Signature · 1 line
Jens Axboe