Skip to content

Commit

Permalink
io_uring: convert file system request types to use io_cmd_type
Browse files Browse the repository at this point in the history
This converts statx, rename, unlink, mkdir, symlink, and hardlink to
use io_cmd_type.

Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed Jul 25, 2022
1 parent 37d4842 commit bb040a2
Showing 1 changed file with 57 additions and 45 deletions.
102 changes: 57 additions & 45 deletions io_uring/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -983,12 +983,6 @@ struct io_kiocb {
struct io_epoll epoll;
struct io_splice splice;
struct io_provide_buf pbuf;
struct io_statx statx;
struct io_rename rename;
struct io_unlink unlink;
struct io_mkdir mkdir;
struct io_symlink symlink;
struct io_hardlink hardlink;
struct io_msg msg;
struct io_xattr xattr;
struct io_uring_cmd uring_cmd;
Expand Down Expand Up @@ -4367,7 +4361,7 @@ static int io_write(struct io_kiocb *req, unsigned int issue_flags)
static int io_renameat_prep(struct io_kiocb *req,
const struct io_uring_sqe *sqe)
{
struct io_rename *ren = &req->rename;
struct io_rename *ren = io_kiocb_to_cmd(req);
const char __user *oldf, *newf;

if (sqe->buf_index || sqe->splice_fd_in)
Expand Down Expand Up @@ -4397,7 +4391,7 @@ static int io_renameat_prep(struct io_kiocb *req,

static int io_renameat(struct io_kiocb *req, unsigned int issue_flags)
{
struct io_rename *ren = &req->rename;
struct io_rename *ren = io_kiocb_to_cmd(req);
int ret;

if (issue_flags & IO_URING_F_NONBLOCK)
Expand Down Expand Up @@ -4654,7 +4648,7 @@ static int io_setxattr(struct io_kiocb *req, unsigned int issue_flags)
static int io_unlinkat_prep(struct io_kiocb *req,
const struct io_uring_sqe *sqe)
{
struct io_unlink *un = &req->unlink;
struct io_unlink *un = io_kiocb_to_cmd(req);
const char __user *fname;

if (sqe->off || sqe->len || sqe->buf_index || sqe->splice_fd_in)
Expand All @@ -4679,7 +4673,7 @@ static int io_unlinkat_prep(struct io_kiocb *req,

static int io_unlinkat(struct io_kiocb *req, unsigned int issue_flags)
{
struct io_unlink *un = &req->unlink;
struct io_unlink *un = io_kiocb_to_cmd(req);
int ret;

if (issue_flags & IO_URING_F_NONBLOCK)
Expand All @@ -4698,7 +4692,7 @@ static int io_unlinkat(struct io_kiocb *req, unsigned int issue_flags)
static int io_mkdirat_prep(struct io_kiocb *req,
const struct io_uring_sqe *sqe)
{
struct io_mkdir *mkd = &req->mkdir;
struct io_mkdir *mkd = io_kiocb_to_cmd(req);
const char __user *fname;

if (sqe->off || sqe->rw_flags || sqe->buf_index || sqe->splice_fd_in)
Expand All @@ -4720,7 +4714,7 @@ static int io_mkdirat_prep(struct io_kiocb *req,

static int io_mkdirat(struct io_kiocb *req, unsigned int issue_flags)
{
struct io_mkdir *mkd = &req->mkdir;
struct io_mkdir *mkd = io_kiocb_to_cmd(req);
int ret;

if (issue_flags & IO_URING_F_NONBLOCK)
Expand All @@ -4736,7 +4730,7 @@ static int io_mkdirat(struct io_kiocb *req, unsigned int issue_flags)
static int io_symlinkat_prep(struct io_kiocb *req,
const struct io_uring_sqe *sqe)
{
struct io_symlink *sl = &req->symlink;
struct io_symlink *sl = io_kiocb_to_cmd(req);
const char __user *oldpath, *newpath;

if (sqe->len || sqe->rw_flags || sqe->buf_index || sqe->splice_fd_in)
Expand Down Expand Up @@ -4764,7 +4758,7 @@ static int io_symlinkat_prep(struct io_kiocb *req,

static int io_symlinkat(struct io_kiocb *req, unsigned int issue_flags)
{
struct io_symlink *sl = &req->symlink;
struct io_symlink *sl = io_kiocb_to_cmd(req);
int ret;

if (issue_flags & IO_URING_F_NONBLOCK)
Expand All @@ -4780,7 +4774,7 @@ static int io_symlinkat(struct io_kiocb *req, unsigned int issue_flags)
static int io_linkat_prep(struct io_kiocb *req,
const struct io_uring_sqe *sqe)
{
struct io_hardlink *lnk = &req->hardlink;
struct io_hardlink *lnk = io_kiocb_to_cmd(req);
const char __user *oldf, *newf;

if (sqe->rw_flags || sqe->buf_index || sqe->splice_fd_in)
Expand Down Expand Up @@ -4810,7 +4804,7 @@ static int io_linkat_prep(struct io_kiocb *req,

static int io_linkat(struct io_kiocb *req, unsigned int issue_flags)
{
struct io_hardlink *lnk = &req->hardlink;
struct io_hardlink *lnk = io_kiocb_to_cmd(req);
int ret;

if (issue_flags & IO_URING_F_NONBLOCK)
Expand Down Expand Up @@ -5696,27 +5690,28 @@ static int io_fadvise(struct io_kiocb *req, unsigned int issue_flags)

static int io_statx_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{
struct io_statx *sx = io_kiocb_to_cmd(req);
const char __user *path;

if (sqe->buf_index || sqe->splice_fd_in)
return -EINVAL;
if (req->flags & REQ_F_FIXED_FILE)
return -EBADF;

req->statx.dfd = READ_ONCE(sqe->fd);
req->statx.mask = READ_ONCE(sqe->len);
sx->dfd = READ_ONCE(sqe->fd);
sx->mask = READ_ONCE(sqe->len);
path = u64_to_user_ptr(READ_ONCE(sqe->addr));
req->statx.buffer = u64_to_user_ptr(READ_ONCE(sqe->addr2));
req->statx.flags = READ_ONCE(sqe->statx_flags);
sx->buffer = u64_to_user_ptr(READ_ONCE(sqe->addr2));
sx->flags = READ_ONCE(sqe->statx_flags);

req->statx.filename = getname_flags(path,
getname_statx_lookup_flags(req->statx.flags),
NULL);
sx->filename = getname_flags(path,
getname_statx_lookup_flags(sx->flags),
NULL);

if (IS_ERR(req->statx.filename)) {
int ret = PTR_ERR(req->statx.filename);
if (IS_ERR(sx->filename)) {
int ret = PTR_ERR(sx->filename);

req->statx.filename = NULL;
sx->filename = NULL;
return ret;
}

Expand All @@ -5726,14 +5721,13 @@ static int io_statx_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)

static int io_statx(struct io_kiocb *req, unsigned int issue_flags)
{
struct io_statx *ctx = &req->statx;
struct io_statx *sx = io_kiocb_to_cmd(req);
int ret;

if (issue_flags & IO_URING_F_NONBLOCK)
return -EAGAIN;

ret = do_statx(ctx->dfd, ctx->filename, ctx->flags, ctx->mask,
ctx->buffer);
ret = do_statx(sx->dfd, sx->filename, sx->flags, sx->mask, sx->buffer);
io_req_complete(req, ret);
return 0;
}
Expand Down Expand Up @@ -7994,28 +7988,46 @@ static void io_clean_op(struct io_kiocb *req)
putname(open->filename);
break;
}
case IORING_OP_RENAMEAT:
putname(req->rename.oldpath);
putname(req->rename.newpath);
case IORING_OP_RENAMEAT: {
struct io_rename *ren = io_kiocb_to_cmd(req);

putname(ren->oldpath);
putname(ren->newpath);
break;
case IORING_OP_UNLINKAT:
putname(req->unlink.filename);
}
case IORING_OP_UNLINKAT: {
struct io_unlink *ul = io_kiocb_to_cmd(req);

putname(ul->filename);
break;
case IORING_OP_MKDIRAT:
putname(req->mkdir.filename);
}
case IORING_OP_MKDIRAT: {
struct io_mkdir *md = io_kiocb_to_cmd(req);

putname(md->filename);
break;
case IORING_OP_SYMLINKAT:
putname(req->symlink.oldpath);
putname(req->symlink.newpath);
}
case IORING_OP_SYMLINKAT: {
struct io_symlink *sl = io_kiocb_to_cmd(req);

putname(sl->oldpath);
putname(sl->newpath);
break;
case IORING_OP_LINKAT:
putname(req->hardlink.oldpath);
putname(req->hardlink.newpath);
}
case IORING_OP_LINKAT: {
struct io_hardlink *hl = io_kiocb_to_cmd(req);

putname(hl->oldpath);
putname(hl->newpath);
break;
case IORING_OP_STATX:
if (req->statx.filename)
putname(req->statx.filename);
}
case IORING_OP_STATX: {
struct io_statx *sx = io_kiocb_to_cmd(req);

if (sx->filename)
putname(sx->filename);
break;
}
case IORING_OP_SETXATTR:
case IORING_OP_FSETXATTR:
case IORING_OP_GETXATTR:
Expand Down

0 comments on commit bb040a2

Please sign in to comment.