io-wq: allow grabbing existing io-wq
authorPavel Begunkov <asml.silence@gmail.com>
Tue, 28 Jan 2020 00:15:47 +0000 (03:15 +0300)
committerJens Axboe <axboe@kernel.dk>
Wed, 29 Jan 2020 00:44:40 +0000 (17:44 -0700)
Export a helper to attach to an existing io-wq, rather than setting up
a new one. This is doable now that we have reference counted io_wq's.

Reported-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/io-wq.c
fs/io-wq.h

index 7ccedc8..f7eb577 100644 (file)
@@ -1114,6 +1114,14 @@ err:
        return ERR_PTR(ret);
 }
 
+bool io_wq_get(struct io_wq *wq, struct io_wq_data *data)
+{
+       if (data->get_work != wq->get_work || data->put_work != wq->put_work)
+               return false;
+
+       return refcount_inc_not_zero(&wq->use_refs);
+}
+
 static bool io_wq_worker_wake(struct io_worker *worker, void *data)
 {
        wake_up_process(worker->task);
index 167316a..c42602c 100644 (file)
@@ -99,6 +99,7 @@ struct io_wq_data {
 };
 
 struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data);
+bool io_wq_get(struct io_wq *wq, struct io_wq_data *data);
 void io_wq_destroy(struct io_wq *wq);
 
 void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work);