{
struct io_wq_data data;
unsigned concurrency;
- int ret;
+ int ret, id;
init_waitqueue_head(&ctx->sqo_wait);
mmgrab(current->mm);
/* Do QD, or 4 * CPUS, whatever is smallest */
concurrency = min(ctx->sq_entries, 4 * num_online_cpus());
- ctx->io_wq = io_wq_create(concurrency, &data);
+
+ id = 0;
+ if (ctx->flags & IORING_SETUP_ATTACH_WQ) {
+ id = p->id;
+ if (!id) {
+ ret = -EINVAL;
+ goto err;
+ }
+ }
+ ctx->io_wq = io_wq_create_id(concurrency, &data, id);
if (IS_ERR(ctx->io_wq)) {
ret = PTR_ERR(ctx->io_wq);
ctx->io_wq = NULL;
goto err;
}
+ p->id = io_wq_id(ctx->io_wq);
return 0;
err:
io_finish_async(ctx);
if (p.flags & ~(IORING_SETUP_IOPOLL | IORING_SETUP_SQPOLL |
IORING_SETUP_SQ_AFF | IORING_SETUP_CQSIZE |
- IORING_SETUP_CLAMP))
+ IORING_SETUP_CLAMP | IORING_SETUP_ATTACH_WQ))
+ return -EINVAL;
+
+ /* id isn't valid without ATTACH_WQ being set */
+ if (!(p.flags & IORING_SETUP_ATTACH_WQ) && p.id)
return -EINVAL;
ret = io_uring_create(entries, &p);
#define IORING_SETUP_SQ_AFF (1U << 2) /* sq_thread_cpu is valid */
#define IORING_SETUP_CQSIZE (1U << 3) /* app defines CQ size */
#define IORING_SETUP_CLAMP (1U << 4) /* clamp SQ/CQ ring sizes */
+#define IORING_SETUP_ATTACH_WQ (1U << 5) /* attach to existing wq */
enum {
IORING_OP_NOP,
__u32 sq_thread_cpu;
__u32 sq_thread_idle;
__u32 features;
- __u32 resv[4];
+ __u32 id;
+ __u32 resv[3];
struct io_sqring_offsets sq_off;
struct io_cqring_offsets cq_off;
};