Commit f2a48dd0 authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Jens Axboe

io_uring: refactor io_sq_offload_create()

Just a bit of code tossing in io_sq_offload_create(), so it looks a bit
better. No functional changes.
Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/939776f90de8d2cdd0414e1baa29c8ec0926b561.1618916549.git.asml.silence@gmail.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 07db298a
...@@ -7879,12 +7879,10 @@ static int io_sq_offload_create(struct io_ring_ctx *ctx, ...@@ -7879,12 +7879,10 @@ static int io_sq_offload_create(struct io_ring_ctx *ctx,
f = fdget(p->wq_fd); f = fdget(p->wq_fd);
if (!f.file) if (!f.file)
return -ENXIO; return -ENXIO;
if (f.file->f_op != &io_uring_fops) {
fdput(f); fdput(f);
if (f.file->f_op != &io_uring_fops)
return -EINVAL; return -EINVAL;
} }
fdput(f);
}
if (ctx->flags & IORING_SETUP_SQPOLL) { if (ctx->flags & IORING_SETUP_SQPOLL) {
struct task_struct *tsk; struct task_struct *tsk;
struct io_sq_data *sqd; struct io_sq_data *sqd;
...@@ -7902,13 +7900,11 @@ static int io_sq_offload_create(struct io_ring_ctx *ctx, ...@@ -7902,13 +7900,11 @@ static int io_sq_offload_create(struct io_ring_ctx *ctx,
if (!ctx->sq_thread_idle) if (!ctx->sq_thread_idle)
ctx->sq_thread_idle = HZ; ctx->sq_thread_idle = HZ;
ret = 0;
io_sq_thread_park(sqd); io_sq_thread_park(sqd);
list_add(&ctx->sqd_list, &sqd->ctx_list); list_add(&ctx->sqd_list, &sqd->ctx_list);
io_sqd_update_thread_idle(sqd); io_sqd_update_thread_idle(sqd);
/* don't attach to a dying SQPOLL thread, would be racy */ /* don't attach to a dying SQPOLL thread, would be racy */
if (attached && !sqd->thread) ret = (attached && !sqd->thread) ? -ENXIO : 0;
ret = -ENXIO;
io_sq_thread_unpark(sqd); io_sq_thread_unpark(sqd);
if (ret < 0) if (ret < 0)
...@@ -7920,11 +7916,8 @@ static int io_sq_offload_create(struct io_ring_ctx *ctx, ...@@ -7920,11 +7916,8 @@ static int io_sq_offload_create(struct io_ring_ctx *ctx,
int cpu = p->sq_thread_cpu; int cpu = p->sq_thread_cpu;
ret = -EINVAL; ret = -EINVAL;
if (cpu >= nr_cpu_ids) if (cpu >= nr_cpu_ids || !cpu_online(cpu))
goto err_sqpoll;
if (!cpu_online(cpu))
goto err_sqpoll; goto err_sqpoll;
sqd->sq_cpu = cpu; sqd->sq_cpu = cpu;
} else { } else {
sqd->sq_cpu = -1; sqd->sq_cpu = -1;
...@@ -7950,12 +7943,11 @@ static int io_sq_offload_create(struct io_ring_ctx *ctx, ...@@ -7950,12 +7943,11 @@ static int io_sq_offload_create(struct io_ring_ctx *ctx,
} }
return 0; return 0;
err_sqpoll:
complete(&ctx->sq_data->exited);
err: err:
io_sq_thread_finish(ctx); io_sq_thread_finish(ctx);
return ret; return ret;
err_sqpoll:
complete(&ctx->sq_data->exited);
goto err;
} }
static inline void __io_unaccount_mem(struct user_struct *user, static inline void __io_unaccount_mem(struct user_struct *user,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment