Namjae Jeon | 0626e66 | 2021-03-16 13:07:11 +0900 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * Copyright (C) 2019 Samsung Electronics Co., Ltd. |
| 4 | */ |
| 5 | |
| 6 | #include <linux/list.h> |
| 7 | #include <linux/mm.h> |
| 8 | #include <linux/slab.h> |
| 9 | #include <linux/workqueue.h> |
| 10 | |
| 11 | #include "server.h" |
| 12 | #include "connection.h" |
| 13 | #include "ksmbd_work.h" |
Namjae Jeon | 0626e66 | 2021-03-16 13:07:11 +0900 | [diff] [blame] | 14 | #include "mgmt/ksmbd_ida.h" |
Namjae Jeon | 0626e66 | 2021-03-16 13:07:11 +0900 | [diff] [blame] | 15 | |
| 16 | static struct kmem_cache *work_cache; |
| 17 | static struct workqueue_struct *ksmbd_wq; |
| 18 | |
| 19 | struct ksmbd_work *ksmbd_alloc_work_struct(void) |
| 20 | { |
| 21 | struct ksmbd_work *work = kmem_cache_zalloc(work_cache, GFP_KERNEL); |
| 22 | |
| 23 | if (work) { |
| 24 | work->compound_fid = KSMBD_NO_FID; |
| 25 | work->compound_pfid = KSMBD_NO_FID; |
| 26 | INIT_LIST_HEAD(&work->request_entry); |
| 27 | INIT_LIST_HEAD(&work->async_request_entry); |
| 28 | INIT_LIST_HEAD(&work->fp_entry); |
| 29 | INIT_LIST_HEAD(&work->interim_entry); |
| 30 | } |
| 31 | return work; |
| 32 | } |
| 33 | |
| 34 | void ksmbd_free_work_struct(struct ksmbd_work *work) |
| 35 | { |
| 36 | WARN_ON(work->saved_cred != NULL); |
Namjae Jeon | 0626e66 | 2021-03-16 13:07:11 +0900 | [diff] [blame] | 37 | |
Namjae Jeon | c30f4eb | 2021-06-18 10:17:37 +0900 | [diff] [blame] | 38 | kvfree(work->response_buf); |
| 39 | kvfree(work->aux_payload_buf); |
Namjae Jeon | 79f6b11 | 2021-04-02 12:47:14 +0900 | [diff] [blame] | 40 | kfree(work->tr_buf); |
| 41 | kvfree(work->request_buf); |
Namjae Jeon | 0626e66 | 2021-03-16 13:07:11 +0900 | [diff] [blame] | 42 | if (work->async_id) |
Namjae Jeon | d40012a | 2021-04-13 13:06:30 +0900 | [diff] [blame] | 43 | ksmbd_release_id(&work->conn->async_ida, work->async_id); |
Namjae Jeon | 0626e66 | 2021-03-16 13:07:11 +0900 | [diff] [blame] | 44 | kmem_cache_free(work_cache, work); |
| 45 | } |
| 46 | |
| 47 | void ksmbd_work_pool_destroy(void) |
| 48 | { |
| 49 | kmem_cache_destroy(work_cache); |
| 50 | } |
| 51 | |
| 52 | int ksmbd_work_pool_init(void) |
| 53 | { |
| 54 | work_cache = kmem_cache_create("ksmbd_work_cache", |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 55 | sizeof(struct ksmbd_work), 0, |
| 56 | SLAB_HWCACHE_ALIGN, NULL); |
Namjae Jeon | 0626e66 | 2021-03-16 13:07:11 +0900 | [diff] [blame] | 57 | if (!work_cache) |
| 58 | return -ENOMEM; |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | int ksmbd_workqueue_init(void) |
| 63 | { |
| 64 | ksmbd_wq = alloc_workqueue("ksmbd-io", 0, 0); |
| 65 | if (!ksmbd_wq) |
| 66 | return -ENOMEM; |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | void ksmbd_workqueue_destroy(void) |
| 71 | { |
Namjae Jeon | 0626e66 | 2021-03-16 13:07:11 +0900 | [diff] [blame] | 72 | destroy_workqueue(ksmbd_wq); |
| 73 | ksmbd_wq = NULL; |
| 74 | } |
| 75 | |
| 76 | bool ksmbd_queue_work(struct ksmbd_work *work) |
| 77 | { |
| 78 | return queue_work(ksmbd_wq, &work->work); |
| 79 | } |