]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/ocf/src/utils/utils_pipeline.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / ocf / src / utils / utils_pipeline.h
1 /*
2 * Copyright(c) 2019 Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause-Clear
4 */
5
6 #ifndef __UTILS_PIPELINE_H__
7 #define __UTILS_PIPELINE_H__
8
9 #include "../ocf_cache_priv.h"
10
11 enum ocf_pipeline_step_type {
12 ocf_pipeline_step_single,
13 ocf_pipeline_step_foreach,
14 ocf_pipeline_step_terminator,
15 };
16
17 enum ocf_pipeline_arg_type {
18 ocf_pipeline_arg_none,
19 ocf_pipeline_arg_int,
20 ocf_pipeline_arg_ptr,
21 ocf_pipeline_arg_terminator,
22 };
23
24 struct ocf_pipeline_arg {
25 enum ocf_pipeline_arg_type type;
26 union {
27 int i;
28 void *p;
29 } val;
30 };
31
32 typedef struct ocf_pipeline_arg *ocf_pipeline_arg_t;
33
34 #define OCF_PL_ARG_NONE() \
35 { .type = ocf_pipeline_arg_none, }
36
37 #define OCF_PL_ARG_INT(_int) \
38 { .type = ocf_pipeline_arg_int, .val.i = _int }
39
40 #define OCF_PL_ARG_PTR(_ptr) \
41 { .type = ocf_pipeline_arg_ptr, .val.p = _ptr }
42
43 #define OCF_PL_ARG_TERMINATOR() \
44 { .type = ocf_pipeline_arg_terminator, }
45
46 static inline int ocf_pipeline_arg_get_int(ocf_pipeline_arg_t arg)
47 {
48 ENV_BUG_ON(arg->type != ocf_pipeline_arg_int);
49
50 return arg->val.i;
51 }
52
53 static inline void *ocf_pipeline_arg_get_ptr(ocf_pipeline_arg_t arg)
54 {
55 ENV_BUG_ON(arg->type != ocf_pipeline_arg_ptr);
56
57 return arg->val.p;
58 }
59
60 typedef struct ocf_pipeline *ocf_pipeline_t;
61
62 typedef void (*ocf_pipeline_step_hndl_t)(ocf_pipeline_t pipeline,
63 void *priv, ocf_pipeline_arg_t arg);
64
65 typedef void (*ocf_pipeline_finish_t)(ocf_pipeline_t pipeline,
66 void *priv, int error);
67
68 struct ocf_pipeline_step {
69 enum ocf_pipeline_step_type type;
70 ocf_pipeline_step_hndl_t hndl;
71 union {
72 struct ocf_pipeline_arg arg;
73 struct ocf_pipeline_arg *args;
74 };
75 };
76
77 #define OCF_PL_STEP(_hndl) \
78 { \
79 .type = ocf_pipeline_step_single, \
80 .hndl = _hndl, \
81 }
82
83 #define OCF_PL_STEP_ARG_INT(_hndl, _int) \
84 { \
85 .type = ocf_pipeline_step_single, \
86 .hndl = _hndl, \
87 .arg = { \
88 .type = ocf_pipeline_arg_int, \
89 .val.i = _int, \
90 } \
91 }
92
93 #define OCF_PL_STEP_ARG_PTR(_hndl, _ptr) \
94 { \
95 .type = ocf_pipeline_step_single, \
96 .hndl = _hndl, \
97 .arg = { \
98 .type = ocf_pipeline_arg_ptr, \
99 .val.p = _ptr, \
100 } \
101 }
102
103 #define OCF_PL_STEP_FOREACH(_hndl, _args) \
104 { \
105 .type = ocf_pipeline_step_foreach, \
106 .hndl = _hndl, \
107 .args = _args, \
108 }
109
110 #define OCF_PL_STEP_TERMINATOR() \
111 { \
112 .type = ocf_pipeline_step_terminator, \
113 }
114
115 struct ocf_pipeline_properties {
116 uint32_t priv_size;
117 ocf_pipeline_finish_t finish;
118 struct ocf_pipeline_step steps[];
119 };
120
121 int ocf_pipeline_create(ocf_pipeline_t *pipeline, ocf_cache_t cache,
122 struct ocf_pipeline_properties *properties);
123
124 void ocf_pipeline_set_priv(ocf_pipeline_t pipeline, void *priv);
125
126 void *ocf_pipeline_get_priv(ocf_pipeline_t pipeline);
127
128 void ocf_pipeline_destroy(ocf_pipeline_t pipeline);
129
130 void ocf_pipeline_next(ocf_pipeline_t pipeline);
131
132 void ocf_pipeline_finish(ocf_pipeline_t pipeline, int error);
133
134 #endif /* __UTILS_PIPELINE_H__ */