]>
Commit | Line | Data |
---|---|---|
39c0564e VJ |
1 | /* |
2 | * Virtio 9p backend | |
3 | * | |
4 | * Copyright IBM, Corp. 2010 | |
5 | * | |
6 | * Authors: | |
7 | * Harsh Prateek Bora <[email protected]> | |
8 | * Venkateswararao Jujjuri(JV) <[email protected]> | |
9 | * | |
10 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
11 | * the COPYING file in the top-level directory. | |
12 | * | |
13 | */ | |
14 | ||
39c0564e | 15 | #include "fsdev/qemu-fsdev.h" |
1de7afc9 | 16 | #include "qemu/thread.h" |
4d91558d | 17 | #include "qemu/event_notifier.h" |
737e150e | 18 | #include "block/coroutine.h" |
39c0564e VJ |
19 | #include "virtio-9p-coth.h" |
20 | ||
21 | /* v9fs glib thread pool */ | |
22 | static V9fsThPool v9fs_pool; | |
23 | ||
24 | void co_run_in_worker_bh(void *opaque) | |
25 | { | |
26 | Coroutine *co = opaque; | |
27 | g_thread_pool_push(v9fs_pool.pool, co, NULL); | |
28 | } | |
29 | ||
4d91558d | 30 | static void v9fs_qemu_process_req_done(EventNotifier *e) |
39c0564e | 31 | { |
39c0564e VJ |
32 | Coroutine *co; |
33 | ||
4d91558d | 34 | event_notifier_test_and_clear(e); |
39c0564e VJ |
35 | |
36 | while ((co = g_async_queue_try_pop(v9fs_pool.completed)) != NULL) { | |
37 | qemu_coroutine_enter(co, NULL); | |
38 | } | |
39 | } | |
40 | ||
41 | static void v9fs_thread_routine(gpointer data, gpointer user_data) | |
42 | { | |
39c0564e VJ |
43 | Coroutine *co = data; |
44 | ||
45 | qemu_coroutine_enter(co, NULL); | |
46 | ||
47 | g_async_queue_push(v9fs_pool.completed, co); | |
4d91558d SH |
48 | |
49 | event_notifier_set(&v9fs_pool.e); | |
39c0564e VJ |
50 | } |
51 | ||
52 | int v9fs_init_worker_threads(void) | |
53 | { | |
54 | int ret = 0; | |
39c0564e VJ |
55 | V9fsThPool *p = &v9fs_pool; |
56 | sigset_t set, oldset; | |
57 | ||
58 | sigfillset(&set); | |
59 | /* Leave signal handling to the iothread. */ | |
60 | pthread_sigmask(SIG_SETMASK, &set, &oldset); | |
61 | ||
39c0564e VJ |
62 | p->pool = g_thread_pool_new(v9fs_thread_routine, p, -1, FALSE, NULL); |
63 | if (!p->pool) { | |
64 | ret = -1; | |
65 | goto err_out; | |
66 | } | |
67 | p->completed = g_async_queue_new(); | |
68 | if (!p->completed) { | |
69 | /* | |
70 | * We are going to terminate. | |
71 | * So don't worry about cleanup | |
72 | */ | |
73 | ret = -1; | |
74 | goto err_out; | |
75 | } | |
4d91558d | 76 | event_notifier_init(&p->e, 0); |
39c0564e | 77 | |
4d91558d | 78 | event_notifier_set_handler(&p->e, v9fs_qemu_process_req_done); |
39c0564e VJ |
79 | err_out: |
80 | pthread_sigmask(SIG_SETMASK, &oldset, NULL); | |
81 | return ret; | |
82 | } |