summaryrefslogtreecommitdiffstats
path: root/src/spdk/ocf/inc/ocf_cache.h
blob: 80860dc81009dec0ec28151d4fc7dbb09d8ba6c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
 * Copyright(c) 2012-2018 Intel Corporation
 * SPDX-License-Identifier: BSD-3-Clause-Clear
 */


#ifndef __OCF_CACHE_H__
#define __OCF_CACHE_H__

/**
 * @file
 * @brief OCF cache API
 */

#include "ocf_volume.h"
#include "ocf_ctx.h"
#include "ocf_def.h"
#include "ocf_stats.h"

/**
 * @brief Cache info: configuration, status
 */
struct ocf_cache_info {
	bool attached;
		/*!< True if caching cache is attached to cache */

	uint8_t volume_type;
		/*!< Cache volume type */

	uint32_t size;
		/*!< Actual cache size (in cache lines) */

	/* Statistics of inactive cores */
	struct {
		struct ocf_stat occupancy;
			/*!< Cache occupancy (in cache lines) */

		struct ocf_stat clean;
			/*!< Clean blocks within cache (in cache lines) */

		struct ocf_stat dirty;
			/*!< Dirty blocks within cache (in cache lines) */
	} inactive;

	uint32_t occupancy;
		/*!< Actual cache occupancy (in cache lines) */

	uint32_t dirty;
		/*!< Dirty blocks within cache (in cache lines) */

	uint32_t dirty_initial;
		/*!< Dirty blocks within cache that where there when switching
		 * out of WB mode
		 */

	uint32_t dirty_for;
		/*!< How long there are dirty cache lines (in seconds) */

	ocf_cache_mode_t cache_mode;
		/*!< Current cache mode */

	/* Statistics of fallback Pass Through */
	struct {
		int error_counter;
			/*!< How many requests to cache failed because of IO error */

		bool status;
			/*!< Current cache mode is PT,
			  set as a result of reaching IO error threshold */
	} fallback_pt;

	uint8_t state;
		/*!< Cache state (running/flushing/stopping etc...) */

	ocf_eviction_t eviction_policy;
		/*!< Eviction policy selected */

	ocf_cleaning_t cleaning_policy;
		/*!< Cleaning policy selected */

	ocf_promotion_t promotion_policy;
		/*!< Promotion policy selected */

	ocf_cache_line_size_t cache_line_size;
		/*!< Cache line size in KiB */

	uint32_t flushed;
		/*!< Number of block flushed in ongoing flush operation */

	uint32_t core_count;
		/*!< Number of core devices associated with this cache */

	uint64_t metadata_footprint;
		/*!< Metadata memory footprint (in bytes) */

	uint32_t metadata_end_offset;
		/*!< LBA offset where metadata ends (in 4KiB blocks) */
};

/**
 * @brief Obtain volume from cache
 *
 * @param[in] cache Cache object
 *
 * @retval Volume, NULL if dettached.
 */
ocf_volume_t ocf_cache_get_volume(ocf_cache_t cache);

/**
 * @brief Get name of given cache object
 *
 * @param[in] cache Cache object
 *
 * @retval Cache name
 */
const char *ocf_cache_get_name(ocf_cache_t cache);

/**
 * @brief Check is cache in incomplete state
 *
 * @param[in] cache Cache object
 *
 * @retval 1 Cache is in incomplete state
 * @retval 0 Cache is in complete state
 */
bool ocf_cache_is_incomplete(ocf_cache_t cache);

/**
 * @brief Check if caching device is attached
 *
 * @param[in] cache Cache object
 *
 * @retval 1 Caching device is attached
 * @retval 0 Caching device is detached
 */
bool ocf_cache_is_device_attached(ocf_cache_t cache);

/**
 * @brief Check if cache object is running
 *
 * @param[in] cache Cache object
 *
 * @retval 1 Caching device is being stopped
 * @retval 0 Caching device is being stopped
 */
bool ocf_cache_is_running(ocf_cache_t cache);

/**
 * @brief Get cache mode of given cache object
 *
 * @param[in] cache Cache object
 *
 * @retval Cache mode
 */
ocf_cache_mode_t ocf_cache_get_mode(ocf_cache_t cache);

/**
 * @brief Get cache line size of given cache object
 *
 * @param[in] cache Cache object
 *
 * @retval Cache line size
 */
ocf_cache_line_size_t ocf_cache_get_line_size(ocf_cache_t cache);

/**
 * @brief Convert bytes to cache lines
 *
 * @param[in] cache Cache object
 * @param[in] bytes Number of bytes
 *
 * @retval Cache lines count
 */
uint64_t ocf_cache_bytes_2_lines(ocf_cache_t cache, uint64_t bytes);

/**
 * @brief Get core count of given cache object
 *
 * @param[in] cache Cache object
 *
 * @retval Core count
 */
uint32_t ocf_cache_get_core_count(ocf_cache_t cache);

/**
 * @brief Get cache mode of given cache object
 *
 * @param[in] cache Cache object
 * @param[out] info Cache info structure
 *
 * @retval 0 Success
 * @retval Non-zero Fail
 */
int ocf_cache_get_info(ocf_cache_t cache, struct ocf_cache_info *info);

/**
 * @brief Get UUID of volume associated with cache
 *
 * @param[in] cache Cache object
 *
 * @retval Volume UUID, NULL if detached.
 */
const struct ocf_volume_uuid *ocf_cache_get_uuid(ocf_cache_t cache);

/**
 * @brief Get OCF context of given cache object
 *
 * @param[in] cache Cache object
 *
 * @retval OCF context
 */
ocf_ctx_t ocf_cache_get_ctx(ocf_cache_t cache);

/**
 * @brief Get volume type id of given cache object
 *
 * @param[in] cache Cache object
 *
 * @retval volume type id, -1 if device detached
 */
uint8_t ocf_cache_get_type_id(ocf_cache_t cache);

/**
 * @brief Set cache private data
 *
 * @param[in] cache Cache object
 * @param[in] priv Private data
 */
void ocf_cache_set_priv(ocf_cache_t cache, void *priv);

/**
 * @brief Get cache private data
 *
 * @param[in] cache Cache object
 *
 * @retval Private data
 */
void *ocf_cache_get_priv(ocf_cache_t cache);

#endif /* __OCF_CACHE_H__ */