Skip to content

Commit e62753e

Browse files
Bijan Mottahedehaxboe
authored andcommitted
io_uring: call statx directly
Calling statx directly both simplifies the interface and avoids potential incompatibilities between sync and async invokations. Signed-off-by: Bijan Mottahedeh <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 0018784 commit e62753e

File tree

1 file changed

+4
-46
lines changed

1 file changed

+4
-46
lines changed

fs/io_uring.c

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ struct io_statx {
482482
int dfd;
483483
unsigned int mask;
484484
unsigned int flags;
485-
struct filename *filename;
485+
const char __user *filename;
486486
struct statx __user *buffer;
487487
};
488488

@@ -3376,43 +3376,23 @@ static int io_fadvise(struct io_kiocb *req, bool force_nonblock)
33763376

33773377
static int io_statx_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
33783378
{
3379-
const char __user *fname;
3380-
unsigned lookup_flags;
3381-
int ret;
3382-
33833379
if (sqe->ioprio || sqe->buf_index)
33843380
return -EINVAL;
33853381
if (req->flags & REQ_F_FIXED_FILE)
33863382
return -EBADF;
3387-
if (req->flags & REQ_F_NEED_CLEANUP)
3388-
return 0;
33893383

33903384
req->statx.dfd = READ_ONCE(sqe->fd);
33913385
req->statx.mask = READ_ONCE(sqe->len);
3392-
fname = u64_to_user_ptr(READ_ONCE(sqe->addr));
3386+
req->statx.filename = u64_to_user_ptr(READ_ONCE(sqe->addr));
33933387
req->statx.buffer = u64_to_user_ptr(READ_ONCE(sqe->addr2));
33943388
req->statx.flags = READ_ONCE(sqe->statx_flags);
33953389

3396-
if (vfs_stat_set_lookup_flags(&lookup_flags, req->statx.flags))
3397-
return -EINVAL;
3398-
3399-
req->statx.filename = getname_flags(fname, lookup_flags, NULL);
3400-
if (IS_ERR(req->statx.filename)) {
3401-
ret = PTR_ERR(req->statx.filename);
3402-
req->statx.filename = NULL;
3403-
return ret;
3404-
}
3405-
3406-
req->flags |= REQ_F_NEED_CLEANUP;
34073390
return 0;
34083391
}
34093392

34103393
static int io_statx(struct io_kiocb *req, bool force_nonblock)
34113394
{
34123395
struct io_statx *ctx = &req->statx;
3413-
unsigned lookup_flags;
3414-
struct path path;
3415-
struct kstat stat;
34163396
int ret;
34173397

34183398
if (force_nonblock) {
@@ -3422,29 +3402,9 @@ static int io_statx(struct io_kiocb *req, bool force_nonblock)
34223402
return -EAGAIN;
34233403
}
34243404

3425-
if (vfs_stat_set_lookup_flags(&lookup_flags, ctx->flags))
3426-
return -EINVAL;
3427-
3428-
retry:
3429-
/* filename_lookup() drops it, keep a reference */
3430-
ctx->filename->refcnt++;
3431-
3432-
ret = filename_lookup(ctx->dfd, ctx->filename, lookup_flags, &path,
3433-
NULL);
3434-
if (ret)
3435-
goto err;
3405+
ret = do_statx(ctx->dfd, ctx->filename, ctx->flags, ctx->mask,
3406+
ctx->buffer);
34363407

3437-
ret = vfs_getattr(&path, &stat, ctx->mask, ctx->flags);
3438-
path_put(&path);
3439-
if (retry_estale(ret, lookup_flags)) {
3440-
lookup_flags |= LOOKUP_REVAL;
3441-
goto retry;
3442-
}
3443-
if (!ret)
3444-
ret = cp_statx(&stat, ctx->buffer);
3445-
err:
3446-
putname(ctx->filename);
3447-
req->flags &= ~REQ_F_NEED_CLEANUP;
34483408
if (ret < 0)
34493409
req_set_fail_links(req);
34503410
io_cqring_add_event(req, ret);
@@ -5196,8 +5156,6 @@ static void io_cleanup_req(struct io_kiocb *req)
51965156
break;
51975157
case IORING_OP_OPENAT:
51985158
case IORING_OP_OPENAT2:
5199-
case IORING_OP_STATX:
5200-
putname(req->open.filename);
52015159
break;
52025160
case IORING_OP_SPLICE:
52035161
case IORING_OP_TEE:

0 commit comments

Comments
 (0)