]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/ocf/inc/ocf_cache.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / ocf / inc / ocf_cache.h
1 /*
2 * Copyright(c) 2012-2018 Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause-Clear
4 */
5
6
7 #ifndef __OCF_CACHE_H__
8 #define __OCF_CACHE_H__
9
10 /**
11 * @file
12 * @brief OCF cache API
13 */
14
15 #include "ocf_types.h"
16 #include "ocf_volume.h"
17 #include "ocf_ctx.h"
18 #include "ocf_def.h"
19
20 /**
21 * @brief Cache info: configuration, status
22 */
23 struct ocf_cache_info {
24 bool attached;
25 /*!< True if caching cache is attached to cache */
26
27 uint8_t volume_type;
28 /*!< Cache volume type */
29
30 uint32_t size;
31 /*!< Actual cache size (in cache lines) */
32
33 /* Statistics of inactive cores */
34 struct {
35 uint32_t occupancy;
36 /*!< Cache occupancy (in cache lines) */
37
38 uint32_t dirty;
39 /*!< Dirty blocks within cache (in cache lines) */
40 } inactive;
41
42 uint32_t occupancy;
43 /*!< Actual cache occupancy (in cache lines) */
44
45 uint32_t dirty;
46 /*!< Dirty blocks within cache (in cache lines) */
47
48 uint32_t dirty_initial;
49 /*!< Dirty blocks within cache that where there when switching
50 * out of WB mode
51 */
52
53 uint32_t dirty_for;
54 /*!< How long there are dirty cache lines (in seconds) */
55
56 ocf_cache_mode_t cache_mode;
57 /*!< Current cache mode */
58
59 /* Statistics of fallback Pass Through */
60 struct {
61 int error_counter;
62 /*!< How many requests to cache failed because of IO error */
63
64 bool status;
65 /*!< Current cache mode is PT,
66 set as a result of reaching IO error threshold */
67 } fallback_pt;
68
69 uint8_t state;
70 /*!< Cache state (running/flushing/stopping etc...) */
71
72 ocf_eviction_t eviction_policy;
73 /*!< Eviction policy selected */
74
75 ocf_cleaning_t cleaning_policy;
76 /*!< Cleaning policy selected (alru/nop) */
77
78 ocf_cache_line_size_t cache_line_size;
79 /*!< Cache line size in KiB */
80
81 uint32_t flushed;
82 /*!< Number of block flushed in ongoing flush operation */
83
84 uint32_t core_count;
85 /*!< Number of core devices associated with this cache */
86
87 uint64_t metadata_footprint;
88 /*!< Metadata memory footprint (in bytes) */
89
90 uint32_t metadata_end_offset;
91 /*!< LBA offset where metadata ends (in 4KiB blocks) */
92 };
93
94 /**
95 * @brief Obtain volume from cache
96 *
97 * @param[in] cache Cache object
98 *
99 * @retval Volume, NULL if dettached.
100 */
101 ocf_volume_t ocf_cache_get_volume(ocf_cache_t cache);
102
103 /**
104 * @brief Get ID of given cache object
105 *
106 * @param[in] cache Cache object
107 *
108 * @retval Cache ID
109 */
110 ocf_cache_id_t ocf_cache_get_id(ocf_cache_t cache);
111
112 /**
113 * @brief Set name of given cache object
114 *
115 * @param[in] cache Cache object
116 * @param[in] src Source of Cache name
117 * @param[in] src_size Size of src
118 *
119 * @retval 0 Success
120 * @retval Non-zero Fail
121 */
122 int ocf_cache_set_name(ocf_cache_t cache, const char *src, size_t src_size);
123
124 /**
125 * @brief Get name of given cache object
126 *
127 * @param[in] cache Cache object
128 *
129 * @retval Cache name
130 */
131 const char *ocf_cache_get_name(ocf_cache_t cache);
132
133 /**
134 * @brief Check is cache in incomplete state
135 *
136 * @param[in] cache Cache object
137 *
138 * @retval 1 Cache is in incomplete state
139 * @retval 0 Cache is in complete state
140 */
141 bool ocf_cache_is_incomplete(ocf_cache_t cache);
142
143 /**
144 * @brief Check if caching device is attached
145 *
146 * @param[in] cache Cache object
147 *
148 * @retval 1 Caching device is attached
149 * @retval 0 Caching device is detached
150 */
151 bool ocf_cache_is_device_attached(ocf_cache_t cache);
152
153 /**
154 * @brief Check if cache object is running
155 *
156 * @param[in] cache Cache object
157 *
158 * @retval 1 Caching device is being stopped
159 * @retval 0 Caching device is being stopped
160 */
161 bool ocf_cache_is_running(ocf_cache_t cache);
162
163 /**
164 * @brief Wait for all IO to finish
165 *
166 * @param[in] cache Cache object
167 */
168 void ocf_cache_wait_for_io_finish(ocf_cache_t cache);
169
170 /**
171 * @brief Check if cache has any unfunished requests
172 *
173 * @param[in] cache Cache object
174 */
175 bool ocf_cache_has_pending_requests(ocf_cache_t cache);
176
177 /**
178 * @brief Check if cleaning triggered by eviction runs on the cache
179 *
180 * @param[in] cache Cache object
181 */
182 bool ocf_cache_has_pending_cleaning(ocf_cache_t cache);
183
184 /**
185 * @brief Get cache mode of given cache object
186 *
187 * @param[in] cache Cache object
188 *
189 * @retval Cache mode
190 */
191 ocf_cache_mode_t ocf_cache_get_mode(ocf_cache_t cache);
192
193 /**
194 * @brief Get cache line size of given cache object
195 *
196 * @param[in] cache Cache object
197 *
198 * @retval Cache line size
199 */
200 ocf_cache_line_size_t ocf_cache_get_line_size(ocf_cache_t cache);
201
202 /**
203 * @brief Convert bytes to cache lines
204 *
205 * @param[in] cache Cache object
206 * @param[in] bytes Number of bytes
207 *
208 * @retval Cache lines count
209 */
210 uint64_t ocf_cache_bytes_2_lines(ocf_cache_t cache, uint64_t bytes);
211
212 /**
213 * @brief Get core count of given cache object
214 *
215 * @param[in] cache Cache object
216 *
217 * @retval Core count
218 */
219 uint32_t ocf_cache_get_core_count(ocf_cache_t cache);
220
221 /**
222 * @brief Get cache mode of given cache object
223 *
224 * @param[in] cache Cache object
225 * @param[out] info Cache info structure
226 *
227 * @retval 0 Success
228 * @retval Non-zero Fail
229 */
230 int ocf_cache_get_info(ocf_cache_t cache, struct ocf_cache_info *info);
231
232 /**
233 * @brief Get UUID of volume associated with cache
234 *
235 * @param[in] cache Cache object
236 *
237 * @retval Volume UUID, NULL if detached.
238 */
239 const struct ocf_volume_uuid *ocf_cache_get_uuid(ocf_cache_t cache);
240
241 /**
242 * @brief Get OCF context of given cache object
243 *
244 * @param[in] cache Cache object
245 *
246 * @retval OCF context
247 */
248 ocf_ctx_t ocf_cache_get_ctx(ocf_cache_t cache);
249
250 /**
251 * @brief Get volume type id of given cache object
252 *
253 * @param[in] cache Cache object
254 *
255 * @retval volume type id, -1 if device detached
256 */
257 uint8_t ocf_cache_get_type_id(ocf_cache_t cache);
258
259 /**
260 * @brief Set cache private data
261 *
262 * @param[in] cache Cache object
263 * @param[in] priv Private data
264 */
265 void ocf_cache_set_priv(ocf_cache_t cache, void *priv);
266
267 /**
268 * @brief Get cache private data
269 *
270 * @param[in] cache Cache object
271 *
272 * @retval Private data
273 */
274 void *ocf_cache_get_priv(ocf_cache_t cache);
275
276 #endif /* __OCF_CACHE_H__ */