[v2,1/2] io-wq: allow grabbing existing io-wq
diff mbox series

Message ID af01e0ca2dcab907bc865a5ecdc0317c00bb059a.1580170474.git.asml.silence@gmail.com
State New
Headers show
Series
  • io-wq sharing
Related show

Commit Message

Pavel Begunkov Jan. 28, 2020, 12:15 a.m. UTC
If the id and user/creds match, return an existing io_wq if we can safely
grab a reference to it.

Reported-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 fs/io-wq.c | 8 ++++++++
 fs/io-wq.h | 1 +
 2 files changed, 9 insertions(+)

Comments

Pavel Begunkov Jan. 28, 2020, 12:18 a.m. UTC | #1
On 28/01/2020 03:15, Pavel Begunkov wrote:
> If the id and user/creds match, return an existing io_wq if we can safely
> grab a reference to it.

Missed the outdated comment. Apparently, it's too late for continue with it today.

> 
> Reported-by: Jens Axboe <axboe@kernel.dk>
> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
> ---
>  fs/io-wq.c | 8 ++++++++
>  fs/io-wq.h | 1 +
>  2 files changed, 9 insertions(+)
> 
> diff --git a/fs/io-wq.c b/fs/io-wq.c
> index b45d585cdcc8..ee49e8852d39 100644
> --- a/fs/io-wq.c
> +++ b/fs/io-wq.c
> @@ -1110,6 +1110,14 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
>  	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);
> diff --git a/fs/io-wq.h b/fs/io-wq.h
> index 167316ad447e..c42602c58c56 100644
> --- a/fs/io-wq.h
> +++ b/fs/io-wq.h
> @@ -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);
>
Jens Axboe Jan. 28, 2020, 12:20 a.m. UTC | #2
On 1/27/20 5:18 PM, Pavel Begunkov wrote:
> On 28/01/2020 03:15, Pavel Begunkov wrote:
>> If the id and user/creds match, return an existing io_wq if we can safely
>> grab a reference to it.
> 
> Missed the outdated comment. Apparently, it's too late for continue with it today.

I'll fix it up, testing it now.

Patch
diff mbox series

diff --git a/fs/io-wq.c b/fs/io-wq.c
index b45d585cdcc8..ee49e8852d39 100644
--- a/fs/io-wq.c
+++ b/fs/io-wq.c
@@ -1110,6 +1110,14 @@  struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
 	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);
diff --git a/fs/io-wq.h b/fs/io-wq.h
index 167316ad447e..c42602c58c56 100644
--- a/fs/io-wq.h
+++ b/fs/io-wq.h
@@ -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);