]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/ocf/src/ocf_ctx_priv.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / ocf / src / ocf_ctx_priv.h
1 /*
2 * Copyright(c) 2012-2018 Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause-Clear
4 */
5
6 #ifndef __OCF_CTX_PRIV_H__
7 #define __OCF_CTX_PRIV_H__
8
9 #include "ocf_env.h"
10 #include "ocf/ocf_ctx.h"
11 #include "ocf_logger_priv.h"
12 #include "ocf_volume_priv.h"
13
14 #define OCF_VOLUME_TYPE_MAX 8
15
16 /**
17 * @brief OCF main control structure
18 */
19 struct ocf_ctx {
20 const struct ocf_ctx_ops *ops;
21 const struct ocf_ctx_config *cfg;
22 struct ocf_logger logger;
23 struct ocf_volume_type *volume_type[OCF_VOLUME_TYPE_MAX];
24 env_atomic ref_count;
25 env_rmutex lock;
26 struct list_head caches;
27 struct {
28 struct list_head core_pool_head;
29 int core_pool_count;
30 } core_pool;
31
32 struct {
33 struct ocf_req_allocator *req;
34 } resources;
35 };
36
37 #define ocf_log_prefix(ctx, lvl, prefix, fmt, ...) \
38 ocf_log_raw(&ctx->logger, lvl, prefix fmt, ##__VA_ARGS__)
39
40 #define ocf_log(ctx, lvl, fmt, ...) \
41 ocf_log_prefix(ctx, lvl, "", fmt, ##__VA_ARGS__)
42
43 #define ocf_log_rl(ctx) \
44 ocf_log_raw_rl(&ctx->logger, __func__)
45
46 #define ocf_log_stack_trace(ctx) \
47 ocf_log_stack_trace_raw(&ctx->logger)
48
49 int ocf_ctx_register_volume_type_extended(ocf_ctx_t ctx, uint8_t type_id,
50 const struct ocf_volume_properties *properties,
51 const struct ocf_volume_extended *extended);
52
53 /**
54 * @name Environment data buffer operations wrappers
55 * @{
56 */
57 static inline void *ctx_data_alloc(ocf_ctx_t ctx, uint32_t pages)
58 {
59 return ctx->ops->data.alloc(pages);
60 }
61
62 static inline void ctx_data_free(ocf_ctx_t ctx, ctx_data_t *data)
63 {
64 ctx->ops->data.free(data);
65 }
66
67 static inline int ctx_data_mlock(ocf_ctx_t ctx, ctx_data_t *data)
68 {
69 return ctx->ops->data.mlock(data);
70 }
71
72 static inline void ctx_data_munlock(ocf_ctx_t ctx, ctx_data_t *data)
73 {
74 ctx->ops->data.munlock(data);
75 }
76
77 static inline uint32_t ctx_data_rd(ocf_ctx_t ctx, void *dst,
78 ctx_data_t *src, uint32_t size)
79 {
80 return ctx->ops->data.read(dst, src, size);
81 }
82
83 static inline uint32_t ctx_data_wr(ocf_ctx_t ctx, ctx_data_t *dst,
84 const void *src, uint32_t size)
85 {
86 return ctx->ops->data.write(dst, src, size);
87 }
88
89 static inline void ctx_data_rd_check(ocf_ctx_t ctx, void *dst,
90 ctx_data_t *src, uint32_t size)
91 {
92 uint32_t read = ctx_data_rd(ctx, dst, src, size);
93
94 ENV_BUG_ON(read != size);
95 }
96
97 static inline void ctx_data_wr_check(ocf_ctx_t ctx, ctx_data_t *dst,
98 const void *src, uint32_t size)
99 {
100 uint32_t written = ctx_data_wr(ctx, dst, src, size);
101
102 ENV_BUG_ON(written != size);
103 }
104
105 static inline uint32_t ctx_data_zero(ocf_ctx_t ctx, ctx_data_t *dst,
106 uint32_t size)
107 {
108 return ctx->ops->data.zero(dst, size);
109 }
110
111 static inline void ctx_data_zero_check(ocf_ctx_t ctx, ctx_data_t *dst,
112 uint32_t size)
113 {
114 uint32_t zerored = ctx_data_zero(ctx, dst, size);
115
116 ENV_BUG_ON(zerored != size);
117 }
118
119 static inline uint32_t ctx_data_seek(ocf_ctx_t ctx, ctx_data_t *dst,
120 ctx_data_seek_t seek, uint32_t size)
121 {
122 return ctx->ops->data.seek(dst, seek, size);
123 }
124
125 static inline void ctx_data_seek_check(ocf_ctx_t ctx, ctx_data_t *dst,
126 ctx_data_seek_t seek, uint32_t size)
127 {
128 uint32_t bytes = ctx_data_seek(ctx, dst, seek, size);
129
130 ENV_BUG_ON(bytes != size);
131 }
132
133 static inline uint64_t ctx_data_cpy(ocf_ctx_t ctx, ctx_data_t *dst, ctx_data_t *src,
134 uint64_t to, uint64_t from, uint64_t bytes)
135 {
136 return ctx->ops->data.copy(dst, src, to, from, bytes);
137 }
138
139 static inline void ctx_data_secure_erase(ocf_ctx_t ctx, ctx_data_t *dst)
140 {
141 return ctx->ops->data.secure_erase(dst);
142 }
143
144 static inline int ctx_cleaner_init(ocf_ctx_t ctx, ocf_cleaner_t cleaner)
145 {
146 return ctx->ops->cleaner.init(cleaner);
147 }
148
149 static inline void ctx_cleaner_stop(ocf_ctx_t ctx, ocf_cleaner_t cleaner)
150 {
151 ctx->ops->cleaner.stop(cleaner);
152 }
153
154 static inline void ctx_cleaner_kick(ocf_ctx_t ctx, ocf_cleaner_t cleaner)
155 {
156 ctx->ops->cleaner.kick(cleaner);
157 }
158
159 static inline int ctx_metadata_updater_init(ocf_ctx_t ctx,
160 ocf_metadata_updater_t mu)
161 {
162 return ctx->ops->metadata_updater.init(mu);
163 }
164
165 static inline void ctx_metadata_updater_kick(ocf_ctx_t ctx,
166 ocf_metadata_updater_t mu)
167 {
168 ctx->ops->metadata_updater.kick(mu);
169 }
170
171 static inline void ctx_metadata_updater_stop(ocf_ctx_t ctx,
172 ocf_metadata_updater_t mu)
173 {
174 ctx->ops->metadata_updater.stop(mu);
175 }
176
177 /**
178 * @}
179 */
180
181 #endif /* __OCF_CTX_PRIV_H__ */