2 * Copyright(c) 2012-2018 Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause-Clear
7 #ifndef __OCF_CACHE_H__
8 #define __OCF_CACHE_H__
12 * @brief OCF cache API
15 #include "ocf_types.h"
16 #include "ocf_volume.h"
21 * @brief Cache info: configuration, status
23 struct ocf_cache_info
{
25 /*!< True if caching cache is attached to cache */
28 /*!< Cache volume type */
31 /*!< Actual cache size (in cache lines) */
33 /* Statistics of inactive cores */
36 /*!< Cache occupancy (in cache lines) */
39 /*!< Dirty blocks within cache (in cache lines) */
43 /*!< Actual cache occupancy (in cache lines) */
46 /*!< Dirty blocks within cache (in cache lines) */
48 uint32_t dirty_initial
;
49 /*!< Dirty blocks within cache that where there when switching
54 /*!< How long there are dirty cache lines (in seconds) */
56 ocf_cache_mode_t cache_mode
;
57 /*!< Current cache mode */
59 /* Statistics of fallback Pass Through */
62 /*!< How many requests to cache failed because of IO error */
65 /*!< Current cache mode is PT,
66 set as a result of reaching IO error threshold */
70 /*!< Cache state (running/flushing/stopping etc...) */
72 ocf_eviction_t eviction_policy
;
73 /*!< Eviction policy selected */
75 ocf_cleaning_t cleaning_policy
;
76 /*!< Cleaning policy selected (alru/nop) */
78 ocf_cache_line_size_t cache_line_size
;
79 /*!< Cache line size in KiB */
82 /*!< Number of block flushed in ongoing flush operation */
85 /*!< Number of core devices associated with this cache */
87 uint64_t metadata_footprint
;
88 /*!< Metadata memory footprint (in bytes) */
90 uint32_t metadata_end_offset
;
91 /*!< LBA offset where metadata ends (in 4KiB blocks) */
95 * @brief Obtain volume from cache
97 * @param[in] cache Cache object
99 * @retval Volume, NULL if dettached.
101 ocf_volume_t
ocf_cache_get_volume(ocf_cache_t cache
);
104 * @brief Get ID of given cache object
106 * @param[in] cache Cache object
110 ocf_cache_id_t
ocf_cache_get_id(ocf_cache_t cache
);
113 * @brief Set name of given cache object
115 * @param[in] cache Cache object
116 * @param[in] src Source of Cache name
117 * @param[in] src_size Size of src
120 * @retval Non-zero Fail
122 int ocf_cache_set_name(ocf_cache_t cache
, const char *src
, size_t src_size
);
125 * @brief Get name of given cache object
127 * @param[in] cache Cache object
131 const char *ocf_cache_get_name(ocf_cache_t cache
);
134 * @brief Check is cache in incomplete state
136 * @param[in] cache Cache object
138 * @retval 1 Cache is in incomplete state
139 * @retval 0 Cache is in complete state
141 bool ocf_cache_is_incomplete(ocf_cache_t cache
);
144 * @brief Check if caching device is attached
146 * @param[in] cache Cache object
148 * @retval 1 Caching device is attached
149 * @retval 0 Caching device is detached
151 bool ocf_cache_is_device_attached(ocf_cache_t cache
);
154 * @brief Check if cache object is running
156 * @param[in] cache Cache object
158 * @retval 1 Caching device is being stopped
159 * @retval 0 Caching device is being stopped
161 bool ocf_cache_is_running(ocf_cache_t cache
);
164 * @brief Wait for all IO to finish
166 * @param[in] cache Cache object
168 void ocf_cache_wait_for_io_finish(ocf_cache_t cache
);
171 * @brief Check if cache has any unfunished requests
173 * @param[in] cache Cache object
175 bool ocf_cache_has_pending_requests(ocf_cache_t cache
);
178 * @brief Check if cleaning triggered by eviction runs on the cache
180 * @param[in] cache Cache object
182 bool ocf_cache_has_pending_cleaning(ocf_cache_t cache
);
185 * @brief Get cache mode of given cache object
187 * @param[in] cache Cache object
191 ocf_cache_mode_t
ocf_cache_get_mode(ocf_cache_t cache
);
194 * @brief Get cache line size of given cache object
196 * @param[in] cache Cache object
198 * @retval Cache line size
200 ocf_cache_line_size_t
ocf_cache_get_line_size(ocf_cache_t cache
);
203 * @brief Convert bytes to cache lines
205 * @param[in] cache Cache object
206 * @param[in] bytes Number of bytes
208 * @retval Cache lines count
210 uint64_t ocf_cache_bytes_2_lines(ocf_cache_t cache
, uint64_t bytes
);
213 * @brief Get core count of given cache object
215 * @param[in] cache Cache object
219 uint32_t ocf_cache_get_core_count(ocf_cache_t cache
);
222 * @brief Get cache mode of given cache object
224 * @param[in] cache Cache object
225 * @param[out] info Cache info structure
228 * @retval Non-zero Fail
230 int ocf_cache_get_info(ocf_cache_t cache
, struct ocf_cache_info
*info
);
233 * @brief Get UUID of volume associated with cache
235 * @param[in] cache Cache object
237 * @retval Volume UUID, NULL if detached.
239 const struct ocf_volume_uuid
*ocf_cache_get_uuid(ocf_cache_t cache
);
242 * @brief Get OCF context of given cache object
244 * @param[in] cache Cache object
246 * @retval OCF context
248 ocf_ctx_t
ocf_cache_get_ctx(ocf_cache_t cache
);
251 * @brief Get volume type id of given cache object
253 * @param[in] cache Cache object
255 * @retval volume type id, -1 if device detached
257 uint8_t ocf_cache_get_type_id(ocf_cache_t cache
);
260 * @brief Set cache private data
262 * @param[in] cache Cache object
263 * @param[in] priv Private data
265 void ocf_cache_set_priv(ocf_cache_t cache
, void *priv
);
268 * @brief Get cache private data
270 * @param[in] cache Cache object
272 * @retval Private data
274 void *ocf_cache_get_priv(ocf_cache_t cache
);
276 #endif /* __OCF_CACHE_H__ */