io_uring: add support for fchmod
PATCH 1/1 io_uring: add support for fchmod
Adds support for doing chmod through io_uring. IORING_OP_FCHMOD behaves like fchmod(2) and takes the same arguments.
--- include/uapi/linux/io_uring.h | 1 + io_uring/fs.c | 32 ++++++++++++++++++++++++++++++++ io_uring/fs.h | 3 +++ io_uring/opdef.c | 8 ++++++++ 4 files changed, 44 insertions(+)
include/uapi/linux/io_uring.h +1 -0
@@ -262,6 +262,7 @@ enum io_uring_op {IORING_OP_FTRUNCATE ,IORING_OP_BIND ,IORING_OP_LISTEN , +IORING_OP_FCHMOD ,/* this goes last, obviously */ IORING_OP_LAST,
io_uring/fs.c +5 -0
@@ -47,6 +47,11 @@ struct io_link {int flags; }; +struct io_fchmod { +struct file *file; +umode_t mode; +}; +int io_renameat_prep (struct io_kiocb *req,const struct io_uring_sqe *sqe) { struct io_rename *ren = io_kiocb_to_cmd(req, struct io_rename); @@ -291,3 +296,30 @@ void io_link_cleanup(struct io_kiocb *req) putname(sl->oldpath);
putname(sl->newpath);
}
+
+int io_fchmod_prep(struct io_kiocb *req, const struct io_uring_sqe +*sqe) {
+ struct io_fchmod *fc = io_kiocb_to_cmd(req, struct io_fchmod);
+
+ if (unlikely(sqe->off || sqe->addr || sqe->rw_flags ||
+ sqe->buf_index || sqe->splice_fd_in))
+ return -EINVAL;
+ if (unlikely(req->flags & REQ_F_FIXED_FILE))
+ return -EBADF;
+
+ fc->mode = READ_ONCE(sqe->len);
+ req->flags |= REQ_F_FORCE_ASYNC;
+ return 0;
+}
+
+int io_fchmod(struct io_kiocb *req, unsigned int issue_flags) {
+ struct io_fchmod *fc = io_kiocb_to_cmd(req, struct io_fchmod);
+ int ret;
+
+ WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
+
+ ret = vfs_fchmod(req->file, fc->mode);
+ io_req_set_res(req, ret, 0);
+ return IOU_OK;
+}
io_uring/fs.h +3 -0
@@ -18,3 +18,6 @@ int io_symlinkat(struct io_kiocb *req, unsigned int issue_flags); int io_linkat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); int io_linkat(struct io_kiocb *req, unsigned int issue_flags); void io_link_cleanup(struct io_kiocb *req); + +int io_fchmod_prep (struct io_kiocb *req,const struct io_uring_sqe +*sqe);int io_fchmod (struct io_kiocb *req,unsigned int issue_flags);
io_uring/opdef.c +5 -0
@@ -515,6 +515,11 @@ const struct io_issue_def io_issue_defs[] = { .prep = io_eopnotsupp_prep, #endif }, + [IORING_OP_FCHMOD ] = { + .needs_file =1 , + .prep = io_fchmod_prep, + .issue = io_fchmod, + }, }; const struct io_cold_def io_cold_defs[] = { @@ -744,6 +749,9 @@ const struct io_cold_def io_cold_defs[] = {
[IORING_OP_LISTEN] = {
.name = "LISTEN",
},
+ [IORING_OP_FCHMOD] = {
+ .name = "FCHMOD",
+ },
};
const char *io_uring_get_opcode(u8 opcode)
--
2.34.1
Jens Axboe
maintainerQuoted 2 lines · lizetao
Adds support for doing chmod through
io_uring.IORING_OP_FCHMODbehaves like fchmod(2) and takes the same arguments.
Looks pretty straight forward. The only downside is the forced use of REQ_F_FORCE_ASYNC - did you look into how feasible it would be to allow non-blocking issue of this? Would imagine the majority of fchmod calls end up not blocking in the first place.
Signature · 1 line
Jens Axboe
Hi
Quoted 5 lines
Quoted 3 lines · lizetao
Adds support for doing chmod through
io_uring.IORING_OP_FCHMODbehaves like fchmod(2) and takes the same arguments.Looks pretty straight forward. The only downside is the forced use of
REQ_F_FORCE_ASYNC- did you look into how feasible it would be to allow non-blocking issue of this? Would imagine the majority of fchmod calls end up not blocking in the first place.
Yes, I considered fchmod to allow asynchronous execution and wrote a test case to test it, the results are as follows:
fchmod:
real 0m1.413s
user 0m0.253s
sys 0m1.079s
io_uring + fchmod:
real 0m1.268s
user 0m0.015s
sys 0m5.739s
There is about a 10% improvement.
Quoted 2 lines
--
Jens Axboe
--
Li Zetao
Jens Axboe
maintainerQuoted 15 lines · lizetao
Hi
Quoted 5 lines
Quoted 3 lines · lizetao
Adds support for doing chmod through
io_uring.IORING_OP_FCHMODbehaves like fchmod(2) and takes the same arguments.Looks pretty straight forward. The only downside is the forced use of
REQ_F_FORCE_ASYNC- did you look into how feasible it would be to allow non-blocking issue of this? Would imagine the majority of fchmod calls end up not blocking in the first place.Yes, I considered fchmod to allow asynchronous execution and wrote a test case to test it, the results are as follows:
fchmod:
real 0m1.413s
user 0m0.253s
sys 0m1.079s
Quoted 6 lines
io_uring+ fchmod:
real 0m1.268s
user 0m0.015s
sys 0m5.739sThere is about a 10% improvement.
And that makes sense if you're keeping some fchmod inflight, as you'd generally just have one io-wq processing them and running things in parallel with submission. But what you you keep an indepth count of 1, eg do sync fchmod? Then it'd be considerably slower than the syscall.
This isn't necessarily something to worry about, but fact is that if you can do a nonblock issue and have it succeed most of the time, that'll be more efficient (and faster for low/sync fchmod) than something that just offloads to io-wq. You can see that from your results too, comparing the sys number netween the two.
Hence why I'm asking if you looked into doing a nonblocking issue at all. This won't necessarily gate the inclusion of the patch, and it is something that can be changed down the line, I'm mostly just curious.
Signature · 1 line
Jens Axboe