History

io_uring: add support for IORING_OP_MKDIRAT

IORING_OP_MKDIRAT behaves like mkdirat(2) and takes the same flags and arguments.

Dmitry Kadashev committed 5 years ago

Commit e34a02d1 parent 45f30da2 files · +61 −0Browse files

Unified · Split

2 files
  1. fs/io_uring.c +60 −0
  2. include/uapi/linux/io_uring.h +1 −0
fs/io_uring.c+60−0
@@ -662,6 +662,13 @@ struct io_unlink { · 661 unmodified lines
662662 struct filename *filename;
663663 };
664664
665+struct io_mkdir {
666+ struct file *file;
667+ int dfd;
668+ umode_t mode;
669+ struct filename *filename;
670+};
671+
665672 struct io_completion {
666673 struct file *file;
667674 u32 cflags;
@@ -821,6 +828,7 @@ struct io_kiocb { · 153 unmodified lines
821828 struct io_shutdown shutdown;
822829 struct io_rename rename;
823830 struct io_unlink unlink;
831+ struct io_mkdir mkdir;
824832 /* use only after cleaning per-op data, see io_clean_op() */
825833 struct io_completion compl;
826834 };
@@ -1032,6 +1040,7 @@ static const struct io_op_def io_op_defs[] = { · 205 unmodified lines
10321040 },
10331041 [IORING_OP_RENAMEAT] = {},
10341042 [IORING_OP_UNLINKAT] = {},
1043+ [IORING_OP_MKDIRAT] = {},
10351044 };
10361045
10371046 /* requests with any of those set should undergo io_disarm_next() */
@@ -3603,6 +3612,49 @@ static int io_unlinkat(struct io_kiocb *req, unsigned int issue_flags) · 2565 unmodified lines
36033612 return 0;
36043613 }
36053614
3615+static int io_mkdirat_prep(struct io_kiocb *req,
3616+ const struct io_uring_sqe *sqe)
3617+{
3618+ struct io_mkdir *mkd = &req->mkdir;
3619+ const char __user *fname;
3620+
3621+ if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL))
3622+ return -EINVAL;
3623+ if (sqe->ioprio || sqe->off || sqe->rw_flags || sqe->buf_index ||
3624+ sqe->splice_fd_in)
3625+ return -EINVAL;
3626+ if (unlikely(req->flags & REQ_F_FIXED_FILE))
3627+ return -EBADF;
3628+
3629+ mkd->dfd = READ_ONCE(sqe->fd);
3630+ mkd->mode = READ_ONCE(sqe->len);
3631+
3632+ fname = u64_to_user_ptr(READ_ONCE(sqe->addr));
3633+ mkd->filename = getname(fname);
3634+ if (IS_ERR(mkd->filename))
3635+ return PTR_ERR(mkd->filename);
3636+
3637+ req->flags |= REQ_F_NEED_CLEANUP;
3638+ return 0;
3639+}
3640+
3641+static int io_mkdirat(struct io_kiocb *req, int issue_flags)
3642+{
3643+ struct io_mkdir *mkd = &req->mkdir;
3644+ int ret;
3645+
3646+ if (issue_flags & IO_URING_F_NONBLOCK)
3647+ return -EAGAIN;
3648+
3649+ ret = do_mkdirat(mkd->dfd, mkd->filename, mkd->mode);
3650+
3651+ req->flags &= ~REQ_F_NEED_CLEANUP;
3652+ if (ret < 0)
3653+ req_set_fail(req);
3654+ io_req_complete(req, ret);
3655+ return 0;
3656+}
3657+
36063658 static int io_shutdown_prep(struct io_kiocb *req,
36073659 const struct io_uring_sqe *sqe)
36083660 {
@@ -6000,6 +6052,8 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) · 2391 unmodified lines
60006052 return io_renameat_prep(req, sqe);
60016053 case IORING_OP_UNLINKAT:
60026054 return io_unlinkat_prep(req, sqe);
6055+ case IORING_OP_MKDIRAT:
6056+ return io_mkdirat_prep(req, sqe);
60036057 }
60046058
60056059 printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n",
@@ -6163,6 +6217,9 @@ static void io_clean_op(struct io_kiocb *req) · 157 unmodified lines
61636217 case IORING_OP_UNLINKAT:
61646218 putname(req->unlink.filename);
61656219 break;
6220+ case IORING_OP_MKDIRAT:
6221+ putname(req->mkdir.filename);
6222+ break;
61666223 }
61676224 }
61686225 if ((req->flags & REQ_F_POLLED) && req->apoll) {
@@ -6291,6 +6348,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) · 122 unmodified lines
62916348 case IORING_OP_UNLINKAT:
62926349 ret = io_unlinkat(req, issue_flags);
62936350 break;
6351+ case IORING_OP_MKDIRAT:
6352+ ret = io_mkdirat(req, issue_flags);
6353+ break;
62946354 default:
62956355 ret = -EINVAL;
62966356 break;
include/uapi/linux/io_uring.h+1−0
@@ -133,6 +133,7 @@ enum { · 132 unmodified lines
133133 IORING_OP_SHUTDOWN,
134134 IORING_OP_RENAMEAT,
135135 IORING_OP_UNLINKAT,
136+ IORING_OP_MKDIRAT,
136137
137138 /* this goes last, obviously */
138139 IORING_OP_LAST,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t