From: lizetao <lizetao1@huawei.com>
To: "axboe@kernel.dk" <axboe@kernel.dk>,
"asml.silence@gmail.com" <asml.silence@gmail.com>
Cc: "io-uring@vger.kernel.org" <io-uring@vger.kernel.org>
Subject: [PATCH -next] io_uring: add support for fchmod
Date: Tue, 19 Nov 2024 08:12:57 +0000 [thread overview]
Message-ID: <e291085644e14b3eb4d1c3995098bf4e@huawei.com> (raw)
Adds support for doing chmod through io_uring. IORING_OP_FCHMOD behaves like fchmod(2) and takes the same arguments.
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
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(+)
diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 5d08435b95a8..de5cce11f937 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -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,
diff --git a/io_uring/fs.c b/io_uring/fs.c index eccea851dd5a..835f66fb75ff 100644
--- a/io_uring/fs.c
+++ b/io_uring/fs.c
@@ -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;
+}
diff --git a/io_uring/fs.h b/io_uring/fs.h index 0bb5efe3d6bb..bc7d95e77b2f 100644
--- a/io_uring/fs.h
+++ b/io_uring/fs.h
@@ -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);
diff --git a/io_uring/opdef.c b/io_uring/opdef.c index 3de75eca1c92..eb5bf831513c 100644
--- a/io_uring/opdef.c
+++ b/io_uring/opdef.c
@@ -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
next reply other threads:[~2024-11-19 8:13 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-19 8:12 lizetao [this message]
2024-11-20 15:14 ` [PATCH -next] io_uring: add support for fchmod Jens Axboe
2024-11-23 12:23 ` 答复: " lizetao
2024-11-24 16:18 ` Jens Axboe
-- strict thread matches above, loose matches on Subject: below --
2024-11-26 15:07 lizetao
2024-11-27 2:10 ` Jens Axboe
2024-12-03 14:44 ` Pavel Begunkov
2024-12-04 1:54 ` lizetao
2024-12-14 16:26 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e291085644e14b3eb4d1c3995098bf4e@huawei.com \
--to=lizetao1@huawei.com \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.