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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
/*
* Copyright(c) 2012-2018 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef __OCF_VOLUME_H__
#define __OCF_VOLUME_H__
/**
* @file
* @brief OCF volume API
*/
#include "ocf_types.h"
#include "ocf_env.h"
#include "ocf/ocf_err.h"
struct ocf_io;
/**
* @brief OCF volume UUID maximum allowed size
*/
#define OCF_VOLUME_UUID_MAX_SIZE (4096UL - sizeof(uint32_t))
/**
* @brief OCF volume UUID
*/
struct ocf_volume_uuid {
size_t size;
/*!< UUID data size */
void *data;
/*!< UUID data content */
};
/**
* @brief This structure describes volume capabilities
*/
struct ocf_volume_caps {
uint32_t atomic_writes : 1;
/*!< Volume supports atomic writes */
};
/**
* @brief OCF volume interface declaration
*/
struct ocf_volume_ops {
/**
* @brief Submit IO on this volume
*
* @param[in] io IO to be submitted
*/
void (*submit_io)(struct ocf_io *io);
/**
* @brief Submit IO with flush command
*
* @param[in] io IO to be submitted
*/
void (*submit_flush)(struct ocf_io *io);
/**
* @brief Submit IO with metadata
*
* @param[in] io IO to be submitted
*/
void (*submit_metadata)(struct ocf_io *io);
/**
* @brief Submit IO with discard command
*
* @param[in] io IO to be submitted
*/
void (*submit_discard)(struct ocf_io *io);
/**
* @brief Submit operation to write zeroes to target address (including
* metadata extended LBAs in atomic mode)
*
* @param[in] io IO description (addr, size)
*/
void (*submit_write_zeroes)(struct ocf_io *io);
/**
* @brief Open volume
*
* @note This function performs volume initialization and should
* be called before any other operation on volume
*
* @param[in] volume Volume
* @param[in] volume_params optional volume parameters, opaque to OCF
*
* @return Zero on success, otherwise error code
*/
int (*open)(ocf_volume_t volume, void *volume_params);
/**
* @brief Close volume
*
* @param[in] volume Volume
*/
void (*close)(ocf_volume_t volume);
/**
* @brief Get maximum io size
*
* @param[in] volume Volume
*
* @return Maximum io size in bytes
*/
unsigned int (*get_max_io_size)(ocf_volume_t volume);
/**
* @brief Get volume length
*
* @param[in] volume Volume
*
* @return Volume lenght in bytes
*/
uint64_t (*get_length)(ocf_volume_t volume);
};
/**
* @brief This structure describes volume properties
*/
struct ocf_volume_properties {
const char *name;
/*!< The name of volume operations */
uint32_t io_priv_size;
/*!< Size of io private context structure */
uint32_t volume_priv_size;
/*!< Size of volume private context structure */
struct ocf_volume_caps caps;
/*!< Volume capabilities */
struct ocf_volume_ops ops;
/*!< Volume operations */
struct ocf_io_ops io_ops;
/*!< IO operations */
void (*deinit)(void);
/*!< Deinitialize volume type */
};
/**
* @brief Initialize UUID from string
*
* @param[in] uuid UUID to be initialized
* @param[in] str NULL-terminated string
*
* @return Zero when success, othewise error
*/
static inline int ocf_uuid_set_str(ocf_uuid_t uuid, char *str)
{
size_t len = env_strnlen(str, OCF_VOLUME_UUID_MAX_SIZE);
if (len >= OCF_VOLUME_UUID_MAX_SIZE)
return -OCF_ERR_INVAL;
uuid->data = str;
uuid->size = len + 1;
return 0;
}
/**
* @brief Obtain string from UUID
* @param[in] uuid pointer to UUID
* @return String contained within UUID
*/
static inline const char *ocf_uuid_to_str(const struct ocf_volume_uuid *uuid)
{
return (const char *)uuid->data;
}
/**
* @brief Initialize volume
*
* @param[in] volume volume handle
* @param[in] type cache/core volume type
* @param[in] uuid OCF volume UUID
* @param[in] uuid_copy crate copy of uuid data
*
* @return Zero when success, othewise error
*/
int ocf_volume_init(ocf_volume_t volume, ocf_volume_type_t type,
struct ocf_volume_uuid *uuid, bool uuid_copy);
/**
* @brief Deinitialize volume
*
* @param[in] volume volume handle
*/
void ocf_volume_deinit(ocf_volume_t volume);
/**
* @brief Allocate and initialize volume
*
* @param[out] volume pointer to volume handle
* @param[in] type cache/core volume type
* @param[in] uuid OCF volume UUID
*
* @return Zero when success, othewise en error
*/
int ocf_volume_create(ocf_volume_t *volume, ocf_volume_type_t type,
struct ocf_volume_uuid *uuid);
/**
* @brief Deinitialize and free volume
*
* @param[in] volume volume handle
*/
void ocf_volume_destroy(ocf_volume_t volume);
/**
* @brief Get volume type
*
* @param[in] volume Volume
*
* @return Volume type
*/
ocf_volume_type_t ocf_volume_get_type(ocf_volume_t volume);
/**
* @brief Get volume UUID
*
* @param[in] volume Volume
*
* @return UUID of volume
*/
const struct ocf_volume_uuid *ocf_volume_get_uuid(ocf_volume_t volume);
/**
* @brief Get private context of volume
*
* @param[in] volume Volume
*
* @return Volume private context
*/
void *ocf_volume_get_priv(ocf_volume_t volume);
/**
* @brief Get cache handle for given volume
*
* @param volume volume handle
*
* @return Handle to cache for which volume belongs to
*/
ocf_cache_t ocf_volume_get_cache(ocf_volume_t volume);
/**
* @brief Check if volume supports atomic mode
*
* @param[in] volume Volume
*
* @return Non-zero value if volume is atomic, otherwise zero
*/
int ocf_volume_is_atomic(ocf_volume_t volume);
/**
* @brief Allocate new io
*
* @param[in] volume Volume
* @param[in] queue IO queue handle
* @param[in] addr OCF IO destination address
* @param[in] bytes OCF IO size in bytes
* @param[in] dir OCF IO direction
* @param[in] io_class OCF IO destination class
* @param[in] flags OCF IO flags
*
* @return ocf_io on success atomic, otherwise NULL
*/
struct ocf_io *ocf_volume_new_io(ocf_volume_t volume, ocf_queue_t queue,
uint64_t addr, uint32_t bytes, uint32_t dir,
uint32_t io_class, uint64_t flags);
/**
* @brief Submit io to volume
*
* @param[in] io IO
*/
void ocf_volume_submit_io(struct ocf_io *io);
/**
* @brief Submit flush to volume
*
* @param[in] io IO
*/
void ocf_volume_submit_flush(struct ocf_io *io);
/**
* @brief Submit discard to volume
*
* @param[in] io IO
*/
void ocf_volume_submit_discard(struct ocf_io *io);
/**
* @brief Open volume
*
* @param[in] volume Volume
* @param[in] volume_params Opaque volume params
*
* @return Zero when success, othewise en error
*/
int ocf_volume_open(ocf_volume_t volume, void *volume_params);
/**
* @brief Get volume max io size
*
* @param[in] volume Volume
*/
void ocf_volume_close(ocf_volume_t volume);
/**
* @brief Get volume max io size
*
* @param[in] volume Volume
*
* @return Volume max io size in bytes
*/
unsigned int ocf_volume_get_max_io_size(ocf_volume_t volume);
/**
* @brief Get volume length
*
* @param[in] volume Volume
*
* @return Length of volume in bytes
*/
uint64_t ocf_volume_get_length(ocf_volume_t volume);
#endif /* __OCF_VOLUME_H__ */
|