xref: /openbmc/qemu/include/block/aio_task.h (revision 72cb4806fdb0c5d7efca181dedfd46bed2acc9e7)
1*6e9b225fSVladimir Sementsov-Ogievskiy /*
2*6e9b225fSVladimir Sementsov-Ogievskiy  * Aio tasks loops
3*6e9b225fSVladimir Sementsov-Ogievskiy  *
4*6e9b225fSVladimir Sementsov-Ogievskiy  * Copyright (c) 2019 Virtuozzo International GmbH.
5*6e9b225fSVladimir Sementsov-Ogievskiy  *
6*6e9b225fSVladimir Sementsov-Ogievskiy  * Permission is hereby granted, free of charge, to any person obtaining a copy
7*6e9b225fSVladimir Sementsov-Ogievskiy  * of this software and associated documentation files (the "Software"), to deal
8*6e9b225fSVladimir Sementsov-Ogievskiy  * in the Software without restriction, including without limitation the rights
9*6e9b225fSVladimir Sementsov-Ogievskiy  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10*6e9b225fSVladimir Sementsov-Ogievskiy  * copies of the Software, and to permit persons to whom the Software is
11*6e9b225fSVladimir Sementsov-Ogievskiy  * furnished to do so, subject to the following conditions:
12*6e9b225fSVladimir Sementsov-Ogievskiy  *
13*6e9b225fSVladimir Sementsov-Ogievskiy  * The above copyright notice and this permission notice shall be included in
14*6e9b225fSVladimir Sementsov-Ogievskiy  * all copies or substantial portions of the Software.
15*6e9b225fSVladimir Sementsov-Ogievskiy  *
16*6e9b225fSVladimir Sementsov-Ogievskiy  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*6e9b225fSVladimir Sementsov-Ogievskiy  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*6e9b225fSVladimir Sementsov-Ogievskiy  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19*6e9b225fSVladimir Sementsov-Ogievskiy  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20*6e9b225fSVladimir Sementsov-Ogievskiy  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21*6e9b225fSVladimir Sementsov-Ogievskiy  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22*6e9b225fSVladimir Sementsov-Ogievskiy  * THE SOFTWARE.
23*6e9b225fSVladimir Sementsov-Ogievskiy  */
24*6e9b225fSVladimir Sementsov-Ogievskiy 
25*6e9b225fSVladimir Sementsov-Ogievskiy #ifndef BLOCK_AIO_TASK_H
26*6e9b225fSVladimir Sementsov-Ogievskiy #define BLOCK_AIO_TASK_H
27*6e9b225fSVladimir Sementsov-Ogievskiy 
28*6e9b225fSVladimir Sementsov-Ogievskiy typedef struct AioTaskPool AioTaskPool;
29*6e9b225fSVladimir Sementsov-Ogievskiy typedef struct AioTask AioTask;
30*6e9b225fSVladimir Sementsov-Ogievskiy typedef int coroutine_fn (*AioTaskFunc)(AioTask *task);
31*6e9b225fSVladimir Sementsov-Ogievskiy struct AioTask {
32*6e9b225fSVladimir Sementsov-Ogievskiy     AioTaskPool *pool;
33*6e9b225fSVladimir Sementsov-Ogievskiy     AioTaskFunc func;
34*6e9b225fSVladimir Sementsov-Ogievskiy     int ret;
35*6e9b225fSVladimir Sementsov-Ogievskiy };
36*6e9b225fSVladimir Sementsov-Ogievskiy 
37*6e9b225fSVladimir Sementsov-Ogievskiy AioTaskPool *coroutine_fn aio_task_pool_new(int max_busy_tasks);
38*6e9b225fSVladimir Sementsov-Ogievskiy void aio_task_pool_free(AioTaskPool *);
39*6e9b225fSVladimir Sementsov-Ogievskiy 
40*6e9b225fSVladimir Sementsov-Ogievskiy /* error code of failed task or 0 if all is OK */
41*6e9b225fSVladimir Sementsov-Ogievskiy int aio_task_pool_status(AioTaskPool *pool);
42*6e9b225fSVladimir Sementsov-Ogievskiy 
43*6e9b225fSVladimir Sementsov-Ogievskiy /* User provides filled @task, however task->pool will be set automatically */
44*6e9b225fSVladimir Sementsov-Ogievskiy void coroutine_fn aio_task_pool_start_task(AioTaskPool *pool, AioTask *task);
45*6e9b225fSVladimir Sementsov-Ogievskiy 
46*6e9b225fSVladimir Sementsov-Ogievskiy void coroutine_fn aio_task_pool_wait_slot(AioTaskPool *pool);
47*6e9b225fSVladimir Sementsov-Ogievskiy void coroutine_fn aio_task_pool_wait_one(AioTaskPool *pool);
48*6e9b225fSVladimir Sementsov-Ogievskiy void coroutine_fn aio_task_pool_wait_all(AioTaskPool *pool);
49*6e9b225fSVladimir Sementsov-Ogievskiy 
50*6e9b225fSVladimir Sementsov-Ogievskiy #endif /* BLOCK_AIO_TASK_H */
51