blob: 0d218ab0e083d0c58561f7d55c8f8a980ecea1f3 [file] [log] [blame]
Kevin Wolf4f999d02009-10-22 17:54:37 +02001/*
2 * QEMU System Emulator
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
Peter Maydelld38ea872016-01-29 17:50:05 +000025#include "qemu/osdep.h"
Markus Armbrusterda34e652016-03-14 09:01:28 +010026#include "qapi/error.h"
Kevin Wolf4f999d02009-10-22 17:54:37 +020027#include "qemu-common.h"
Paolo Bonzini737e1502012-12-17 18:19:44 +010028#include "block/aio.h"
Stefan Hajnoczi9b342772013-03-07 13:41:47 +010029#include "block/thread-pool.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010030#include "qemu/main-loop.h"
Paolo Bonzini0ceb8492014-07-07 15:18:04 +020031#include "qemu/atomic.h"
Paolo Bonzini0187f5c2016-07-04 18:33:20 +020032#include "block/raw-aio.h"
Kevin Wolf9a1e9482009-10-22 17:54:38 +020033
Kevin Wolf4f999d02009-10-22 17:54:37 +020034/***********************************************************/
35/* bottom halves (can be seen as timers which expire ASAP) */
36
37struct QEMUBH {
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +020038 AioContext *ctx;
Kevin Wolf4f999d02009-10-22 17:54:37 +020039 QEMUBHFunc *cb;
40 void *opaque;
Kevin Wolf4f999d02009-10-22 17:54:37 +020041 QEMUBH *next;
Stefan Weil9b47b172012-04-29 19:08:45 +020042 bool scheduled;
43 bool idle;
44 bool deleted;
Kevin Wolf4f999d02009-10-22 17:54:37 +020045};
46
Paolo Bonzini5b8bb352016-10-03 18:14:15 +020047void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
48{
49 QEMUBH *bh;
50 bh = g_new(QEMUBH, 1);
51 *bh = (QEMUBH){
52 .ctx = ctx,
53 .cb = cb,
54 .opaque = opaque,
55 };
Paolo Bonzinid7c99a12017-01-12 19:07:53 +010056 qemu_lockcnt_lock(&ctx->list_lock);
Paolo Bonzini5b8bb352016-10-03 18:14:15 +020057 bh->next = ctx->first_bh;
58 bh->scheduled = 1;
59 bh->deleted = 1;
60 /* Make sure that the members are ready before putting bh into list */
61 smp_wmb();
62 ctx->first_bh = bh;
Paolo Bonzinid7c99a12017-01-12 19:07:53 +010063 qemu_lockcnt_unlock(&ctx->list_lock);
Paolo Bonzinic9d1a562016-10-27 12:49:05 +020064 aio_notify(ctx);
Paolo Bonzini5b8bb352016-10-03 18:14:15 +020065}
66
Paolo Bonzinif627aab2012-10-29 23:45:23 +010067QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
Kevin Wolf4f999d02009-10-22 17:54:37 +020068{
69 QEMUBH *bh;
Paolo Bonziniee823102014-12-17 16:10:00 +010070 bh = g_new(QEMUBH, 1);
71 *bh = (QEMUBH){
72 .ctx = ctx,
73 .cb = cb,
74 .opaque = opaque,
75 };
Paolo Bonzinid7c99a12017-01-12 19:07:53 +010076 qemu_lockcnt_lock(&ctx->list_lock);
Paolo Bonzinif627aab2012-10-29 23:45:23 +010077 bh->next = ctx->first_bh;
Liu Ping Fandcc772e2013-07-16 12:28:58 +080078 /* Make sure that the members are ready before putting bh into list */
79 smp_wmb();
Paolo Bonzinif627aab2012-10-29 23:45:23 +010080 ctx->first_bh = bh;
Paolo Bonzinid7c99a12017-01-12 19:07:53 +010081 qemu_lockcnt_unlock(&ctx->list_lock);
Kevin Wolf4f999d02009-10-22 17:54:37 +020082 return bh;
83}
84
Pavel Dovgalyukdf281b82015-09-17 19:24:50 +030085void aio_bh_call(QEMUBH *bh)
86{
87 bh->cb(bh->opaque);
88}
89
Liu Ping Fandcc772e2013-07-16 12:28:58 +080090/* Multiple occurrences of aio_bh_poll cannot be called concurrently */
Paolo Bonzinif627aab2012-10-29 23:45:23 +010091int aio_bh_poll(AioContext *ctx)
Kevin Wolf4f999d02009-10-22 17:54:37 +020092{
Kevin Wolf7887f622011-06-07 17:51:21 +020093 QEMUBH *bh, **bhp, *next;
Kevin Wolf4f999d02009-10-22 17:54:37 +020094 int ret;
Paolo Bonzini7d506c92017-01-12 19:08:00 +010095 bool deleted = false;
Kevin Wolf648fb0e2011-09-01 16:16:10 +020096
Paolo Bonzinid7c99a12017-01-12 19:07:53 +010097 qemu_lockcnt_inc(&ctx->list_lock);
Kevin Wolf4f999d02009-10-22 17:54:37 +020098
99 ret = 0;
Paolo Bonzinid7c99a12017-01-12 19:07:53 +0100100 for (bh = atomic_rcu_read(&ctx->first_bh); bh; bh = next) {
101 next = atomic_rcu_read(&bh->next);
Paolo Bonzinie8d3b1a2015-04-07 17:16:19 +0200102 /* The atomic_xchg is paired with the one in qemu_bh_schedule. The
103 * implicit memory barrier ensures that the callback sees all writes
104 * done by the scheduling thread. It also ensures that the scheduling
105 * thread sees the zero before bh->cb has run, and thus will call
106 * aio_notify again if necessary.
107 */
Paolo Bonzini5b8bb352016-10-03 18:14:15 +0200108 if (atomic_xchg(&bh->scheduled, 0)) {
Paolo Bonzini65c1b5b2016-10-27 12:49:06 +0200109 /* Idle BHs don't count as progress */
110 if (!bh->idle) {
Kevin Wolf4f999d02009-10-22 17:54:37 +0200111 ret = 1;
Stefan Hajnoczica96ac42015-07-28 18:34:09 +0200112 }
Kevin Wolf4f999d02009-10-22 17:54:37 +0200113 bh->idle = 0;
Pavel Dovgalyukdf281b82015-09-17 19:24:50 +0300114 aio_bh_call(bh);
Kevin Wolf4f999d02009-10-22 17:54:37 +0200115 }
Paolo Bonzini7d506c92017-01-12 19:08:00 +0100116 if (bh->deleted) {
117 deleted = true;
118 }
Kevin Wolf4f999d02009-10-22 17:54:37 +0200119 }
120
121 /* remove deleted bhs */
Paolo Bonzini7d506c92017-01-12 19:08:00 +0100122 if (!deleted) {
123 qemu_lockcnt_dec(&ctx->list_lock);
124 return ret;
125 }
126
Paolo Bonzinid7c99a12017-01-12 19:07:53 +0100127 if (qemu_lockcnt_dec_and_lock(&ctx->list_lock)) {
Paolo Bonzinif627aab2012-10-29 23:45:23 +0100128 bhp = &ctx->first_bh;
Kevin Wolf648fb0e2011-09-01 16:16:10 +0200129 while (*bhp) {
130 bh = *bhp;
Paolo Bonzini5b8bb352016-10-03 18:14:15 +0200131 if (bh->deleted && !bh->scheduled) {
Kevin Wolf648fb0e2011-09-01 16:16:10 +0200132 *bhp = bh->next;
133 g_free(bh);
134 } else {
135 bhp = &bh->next;
136 }
137 }
Paolo Bonzinid7c99a12017-01-12 19:07:53 +0100138 qemu_lockcnt_unlock(&ctx->list_lock);
Kevin Wolf4f999d02009-10-22 17:54:37 +0200139 }
Kevin Wolf4f999d02009-10-22 17:54:37 +0200140 return ret;
141}
142
143void qemu_bh_schedule_idle(QEMUBH *bh)
144{
Kevin Wolf4f999d02009-10-22 17:54:37 +0200145 bh->idle = 1;
Liu Ping Fandcc772e2013-07-16 12:28:58 +0800146 /* Make sure that idle & any writes needed by the callback are done
147 * before the locations are read in the aio_bh_poll.
148 */
Paolo Bonzinie8d3b1a2015-04-07 17:16:19 +0200149 atomic_mb_set(&bh->scheduled, 1);
Kevin Wolf4f999d02009-10-22 17:54:37 +0200150}
151
152void qemu_bh_schedule(QEMUBH *bh)
153{
Stefan Hajnoczi924fe122014-06-03 11:21:01 +0200154 AioContext *ctx;
155
Stefan Hajnoczi924fe122014-06-03 11:21:01 +0200156 ctx = bh->ctx;
Kevin Wolf4f999d02009-10-22 17:54:37 +0200157 bh->idle = 0;
Paolo Bonzinie8d3b1a2015-04-07 17:16:19 +0200158 /* The memory barrier implicit in atomic_xchg makes sure that:
Stefan Hajnoczi924fe122014-06-03 11:21:01 +0200159 * 1. idle & any writes needed by the callback are done before the
160 * locations are read in the aio_bh_poll.
161 * 2. ctx is loaded before scheduled is set and the callback has a chance
162 * to execute.
Liu Ping Fandcc772e2013-07-16 12:28:58 +0800163 */
Paolo Bonzinie8d3b1a2015-04-07 17:16:19 +0200164 if (atomic_xchg(&bh->scheduled, 1) == 0) {
165 aio_notify(ctx);
166 }
Kevin Wolf4f999d02009-10-22 17:54:37 +0200167}
168
Liu Ping Fandcc772e2013-07-16 12:28:58 +0800169
170/* This func is async.
171 */
Kevin Wolf4f999d02009-10-22 17:54:37 +0200172void qemu_bh_cancel(QEMUBH *bh)
173{
174 bh->scheduled = 0;
175}
176
Liu Ping Fandcc772e2013-07-16 12:28:58 +0800177/* This func is async.The bottom half will do the delete action at the finial
178 * end.
179 */
Kevin Wolf4f999d02009-10-22 17:54:37 +0200180void qemu_bh_delete(QEMUBH *bh)
181{
182 bh->scheduled = 0;
183 bh->deleted = 1;
184}
185
Paolo Bonzini845ca102014-07-09 11:53:01 +0200186int64_t
187aio_compute_timeout(AioContext *ctx)
Kevin Wolf4f999d02009-10-22 17:54:37 +0200188{
Paolo Bonzini845ca102014-07-09 11:53:01 +0200189 int64_t deadline;
190 int timeout = -1;
Kevin Wolf4f999d02009-10-22 17:54:37 +0200191 QEMUBH *bh;
192
Paolo Bonzinid7c99a12017-01-12 19:07:53 +0100193 for (bh = atomic_rcu_read(&ctx->first_bh); bh;
194 bh = atomic_rcu_read(&bh->next)) {
Paolo Bonzini5b8bb352016-10-03 18:14:15 +0200195 if (bh->scheduled) {
Kevin Wolf4f999d02009-10-22 17:54:37 +0200196 if (bh->idle) {
197 /* idle bottom halves will be polled at least
198 * every 10ms */
Paolo Bonzini845ca102014-07-09 11:53:01 +0200199 timeout = 10000000;
Kevin Wolf4f999d02009-10-22 17:54:37 +0200200 } else {
201 /* non-idle bottom halves will be executed
202 * immediately */
Paolo Bonzini845ca102014-07-09 11:53:01 +0200203 return 0;
Kevin Wolf4f999d02009-10-22 17:54:37 +0200204 }
205 }
206 }
Kevin Wolf4f999d02009-10-22 17:54:37 +0200207
Paolo Bonzini845ca102014-07-09 11:53:01 +0200208 deadline = timerlistgroup_deadline_ns(&ctx->tlg);
Alex Bligh533a8cf2013-08-21 16:02:51 +0100209 if (deadline == 0) {
Paolo Bonzini845ca102014-07-09 11:53:01 +0200210 return 0;
Alex Bligh533a8cf2013-08-21 16:02:51 +0100211 } else {
Paolo Bonzini845ca102014-07-09 11:53:01 +0200212 return qemu_soonest_timeout(timeout, deadline);
Alex Bligh533a8cf2013-08-21 16:02:51 +0100213 }
Paolo Bonzini845ca102014-07-09 11:53:01 +0200214}
Alex Bligh533a8cf2013-08-21 16:02:51 +0100215
Paolo Bonzini845ca102014-07-09 11:53:01 +0200216static gboolean
217aio_ctx_prepare(GSource *source, gint *timeout)
218{
219 AioContext *ctx = (AioContext *) source;
220
Paolo Bonzinieabc9772015-07-21 16:07:51 +0200221 atomic_or(&ctx->notify_me, 1);
222
Paolo Bonzini845ca102014-07-09 11:53:01 +0200223 /* We assume there is no timeout already supplied */
224 *timeout = qemu_timeout_ns_to_ms(aio_compute_timeout(ctx));
Paolo Bonzinia3462c62014-07-09 11:53:08 +0200225
226 if (aio_prepare(ctx)) {
227 *timeout = 0;
228 }
229
Paolo Bonzini845ca102014-07-09 11:53:01 +0200230 return *timeout == 0;
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200231}
232
233static gboolean
234aio_ctx_check(GSource *source)
235{
236 AioContext *ctx = (AioContext *) source;
237 QEMUBH *bh;
238
Paolo Bonzinieabc9772015-07-21 16:07:51 +0200239 atomic_and(&ctx->notify_me, ~1);
Paolo Bonzini05e514b2015-07-21 16:07:53 +0200240 aio_notify_accept(ctx);
Paolo Bonzini21a03d12015-07-21 16:07:52 +0200241
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200242 for (bh = ctx->first_bh; bh; bh = bh->next) {
Paolo Bonzini5b8bb352016-10-03 18:14:15 +0200243 if (bh->scheduled) {
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200244 return true;
Cao jin6977d902016-07-14 21:10:43 +0800245 }
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200246 }
Alex Bligh533a8cf2013-08-21 16:02:51 +0100247 return aio_pending(ctx) || (timerlistgroup_deadline_ns(&ctx->tlg) == 0);
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200248}
249
250static gboolean
251aio_ctx_dispatch(GSource *source,
252 GSourceFunc callback,
253 gpointer user_data)
254{
255 AioContext *ctx = (AioContext *) source;
256
257 assert(callback == NULL);
Stefan Hajnoczi721671a2016-12-01 19:26:40 +0000258 aio_dispatch(ctx, true);
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200259 return true;
260}
261
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200262static void
263aio_ctx_finalize(GSource *source)
264{
265 AioContext *ctx = (AioContext *) source;
266
Stefan Hajnoczi9b342772013-03-07 13:41:47 +0100267 thread_pool_free(ctx->thread_pool);
Stefan Hajnoczia0769722015-07-28 18:34:08 +0200268
Paolo Bonzini0187f5c2016-07-04 18:33:20 +0200269#ifdef CONFIG_LINUX_AIO
270 if (ctx->linux_aio) {
271 laio_detach_aio_context(ctx->linux_aio, ctx);
272 laio_cleanup(ctx->linux_aio);
273 ctx->linux_aio = NULL;
274 }
275#endif
276
Paolo Bonzinid7c99a12017-01-12 19:07:53 +0100277 qemu_lockcnt_lock(&ctx->list_lock);
278 assert(!qemu_lockcnt_count(&ctx->list_lock));
Stefan Hajnoczia0769722015-07-28 18:34:08 +0200279 while (ctx->first_bh) {
280 QEMUBH *next = ctx->first_bh->next;
281
282 /* qemu_bh_delete() must have been called on BHs in this AioContext */
283 assert(ctx->first_bh->deleted);
284
285 g_free(ctx->first_bh);
286 ctx->first_bh = next;
287 }
Paolo Bonzinid7c99a12017-01-12 19:07:53 +0100288 qemu_lockcnt_unlock(&ctx->list_lock);
Stefan Hajnoczia0769722015-07-28 18:34:08 +0200289
Stefan Hajnoczif6a51c82016-12-01 19:26:41 +0000290 aio_set_event_notifier(ctx, &ctx->notifier, false, NULL, NULL);
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200291 event_notifier_cleanup(&ctx->notifier);
Paolo Bonzini3fe71222016-10-27 12:49:08 +0200292 qemu_rec_mutex_destroy(&ctx->lock);
Paolo Bonzinid7c99a12017-01-12 19:07:53 +0100293 qemu_lockcnt_destroy(&ctx->list_lock);
Alex Blighdae21b92013-08-21 16:02:49 +0100294 timerlistgroup_deinit(&ctx->tlg);
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200295}
296
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200297static GSourceFuncs aio_source_funcs = {
298 aio_ctx_prepare,
299 aio_ctx_check,
300 aio_ctx_dispatch,
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200301 aio_ctx_finalize
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200302};
303
304GSource *aio_get_g_source(AioContext *ctx)
305{
306 g_source_ref(&ctx->source);
307 return &ctx->source;
308}
Paolo Bonzinia915f4b2012-09-13 12:28:51 +0200309
Stefan Hajnoczi9b342772013-03-07 13:41:47 +0100310ThreadPool *aio_get_thread_pool(AioContext *ctx)
311{
312 if (!ctx->thread_pool) {
313 ctx->thread_pool = thread_pool_new(ctx);
314 }
315 return ctx->thread_pool;
316}
317
Paolo Bonzini0187f5c2016-07-04 18:33:20 +0200318#ifdef CONFIG_LINUX_AIO
319LinuxAioState *aio_get_linux_aio(AioContext *ctx)
320{
321 if (!ctx->linux_aio) {
322 ctx->linux_aio = laio_init();
323 laio_attach_aio_context(ctx->linux_aio, ctx);
324 }
325 return ctx->linux_aio;
326}
327#endif
328
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200329void aio_notify(AioContext *ctx)
330{
Paolo Bonzinieabc9772015-07-21 16:07:51 +0200331 /* Write e.g. bh->scheduled before reading ctx->notify_me. Pairs
332 * with atomic_or in aio_ctx_prepare or atomic_add in aio_poll.
333 */
Paolo Bonzini0ceb8492014-07-07 15:18:04 +0200334 smp_mb();
Paolo Bonzinieabc9772015-07-21 16:07:51 +0200335 if (ctx->notify_me) {
Paolo Bonzini0ceb8492014-07-07 15:18:04 +0200336 event_notifier_set(&ctx->notifier);
Paolo Bonzini05e514b2015-07-21 16:07:53 +0200337 atomic_mb_set(&ctx->notified, true);
338 }
339}
340
341void aio_notify_accept(AioContext *ctx)
342{
343 if (atomic_xchg(&ctx->notified, false)) {
344 event_notifier_test_and_clear(&ctx->notifier);
Paolo Bonzini0ceb8492014-07-07 15:18:04 +0200345 }
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200346}
347
Alex Blighd5541d82013-08-21 16:02:50 +0100348static void aio_timerlist_notify(void *opaque)
349{
350 aio_notify(opaque);
351}
352
Paolo Bonzini21a03d12015-07-21 16:07:52 +0200353static void event_notifier_dummy_cb(EventNotifier *e)
354{
355}
356
Stefan Hajnoczi4a1cba32016-12-01 19:26:42 +0000357/* Returns true if aio_notify() was called (e.g. a BH was scheduled) */
358static bool event_notifier_poll(void *opaque)
359{
360 EventNotifier *e = opaque;
361 AioContext *ctx = container_of(e, AioContext, notifier);
362
363 return atomic_read(&ctx->notified);
364}
365
Chrysostomos Nanakos2f78e492014-09-18 14:30:49 +0300366AioContext *aio_context_new(Error **errp)
Paolo Bonzinif627aab2012-10-29 23:45:23 +0100367{
Chrysostomos Nanakos2f78e492014-09-18 14:30:49 +0300368 int ret;
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200369 AioContext *ctx;
Fam Zheng37fcee52015-10-30 12:06:28 +0800370
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200371 ctx = (AioContext *) g_source_new(&aio_source_funcs, sizeof(AioContext));
Cao jin7e003462016-07-15 18:28:44 +0800372 aio_context_setup(ctx);
373
Chrysostomos Nanakos2f78e492014-09-18 14:30:49 +0300374 ret = event_notifier_init(&ctx->notifier, false);
375 if (ret < 0) {
Chrysostomos Nanakos2f78e492014-09-18 14:30:49 +0300376 error_setg_errno(errp, -ret, "Failed to initialize event notifier");
Fam Zheng37fcee52015-10-30 12:06:28 +0800377 goto fail;
Chrysostomos Nanakos2f78e492014-09-18 14:30:49 +0300378 }
Paolo Bonzinifcf5def2014-12-17 16:09:58 +0100379 g_source_set_can_recurse(&ctx->source, true);
Paolo Bonzinid7c99a12017-01-12 19:07:53 +0100380 qemu_lockcnt_init(&ctx->list_lock);
Chrysostomos Nanakos2f78e492014-09-18 14:30:49 +0300381 aio_set_event_notifier(ctx, &ctx->notifier,
Fam Zhengdca21ef2015-10-23 11:08:05 +0800382 false,
Chrysostomos Nanakos2f78e492014-09-18 14:30:49 +0300383 (EventNotifierHandler *)
Stefan Hajnoczif6a51c82016-12-01 19:26:41 +0000384 event_notifier_dummy_cb,
Stefan Hajnoczi4a1cba32016-12-01 19:26:42 +0000385 event_notifier_poll);
Paolo Bonzini0187f5c2016-07-04 18:33:20 +0200386#ifdef CONFIG_LINUX_AIO
387 ctx->linux_aio = NULL;
388#endif
Stefan Hajnoczi9b342772013-03-07 13:41:47 +0100389 ctx->thread_pool = NULL;
Paolo Bonzini3fe71222016-10-27 12:49:08 +0200390 qemu_rec_mutex_init(&ctx->lock);
Alex Blighd5541d82013-08-21 16:02:50 +0100391 timerlistgroup_init(&ctx->tlg, aio_timerlist_notify, ctx);
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200392
Stefan Hajnoczi82a41182016-12-01 19:26:51 +0000393 ctx->poll_ns = 0;
Stefan Hajnoczi4a1cba32016-12-01 19:26:42 +0000394 ctx->poll_max_ns = 0;
Stefan Hajnoczi82a41182016-12-01 19:26:51 +0000395 ctx->poll_grow = 0;
396 ctx->poll_shrink = 0;
Stefan Hajnoczi4a1cba32016-12-01 19:26:42 +0000397
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200398 return ctx;
Fam Zheng37fcee52015-10-30 12:06:28 +0800399fail:
400 g_source_destroy(&ctx->source);
401 return NULL;
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200402}
403
404void aio_context_ref(AioContext *ctx)
405{
406 g_source_ref(&ctx->source);
407}
408
409void aio_context_unref(AioContext *ctx)
410{
411 g_source_unref(&ctx->source);
Paolo Bonzinif627aab2012-10-29 23:45:23 +0100412}
Stefan Hajnoczi98563fc2014-03-03 11:30:04 +0100413
414void aio_context_acquire(AioContext *ctx)
415{
Paolo Bonzini3fe71222016-10-27 12:49:08 +0200416 qemu_rec_mutex_lock(&ctx->lock);
Stefan Hajnoczi98563fc2014-03-03 11:30:04 +0100417}
418
419void aio_context_release(AioContext *ctx)
420{
Paolo Bonzini3fe71222016-10-27 12:49:08 +0200421 qemu_rec_mutex_unlock(&ctx->lock);
Stefan Hajnoczi98563fc2014-03-03 11:30:04 +0100422}