]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/ocf/inc/ocf_volume.h
2 * Copyright(c) 2012-2018 Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause-Clear
6 #ifndef __OCF_VOLUME_H__
7 #define __OCF_VOLUME_H__
11 * @brief OCF volume API
14 #include "ocf_types.h"
21 * @brief OCF volume UUID maximum allowed size
23 #define OCF_VOLUME_UUID_MAX_SIZE (4096UL - sizeof(uint32_t))
26 * @brief OCF volume UUID
28 struct ocf_volume_uuid
{
30 /*!< UUID data size */
33 /*!< UUID data content */
37 * @brief This structure describes volume capabilities
39 struct ocf_volume_caps
{
40 uint32_t atomic_writes
: 1;
41 /*!< Volume supports atomic writes */
45 * @brief OCF volume interface declaration
47 struct ocf_volume_ops
{
49 * @brief Submit IO on this volume
51 * @param[in] io IO to be submitted
53 void (*submit_io
)(struct ocf_io
*io
);
56 * @brief Submit IO with flush command
58 * @param[in] io IO to be submitted
60 void (*submit_flush
)(struct ocf_io
*io
);
63 * @brief Submit IO with metadata
65 * @param[in] io IO to be submitted
67 void (*submit_metadata
)(struct ocf_io
*io
);
70 * @brief Submit IO with discard command
72 * @param[in] io IO to be submitted
74 void (*submit_discard
)(struct ocf_io
*io
);
77 * @brief Submit operation to write zeroes to target address (including
78 * metadata extended LBAs in atomic mode)
80 * @param[in] io IO description (addr, size)
82 void (*submit_write_zeroes
)(struct ocf_io
*io
);
87 * @note This function performs volume initialization and should
88 * be called before any other operation on volume
90 * @param[in] volume Volume
91 * @param[in] volume_params optional volume parameters, opaque to OCF
93 int (*open
)(ocf_volume_t volume
, void *volume_params
);
98 * @param[in] volume Volume
100 void (*close
)(ocf_volume_t volume
);
103 * @brief Close volume
105 * @param[in] volume Volume
107 unsigned int (*get_max_io_size
)(ocf_volume_t volume
);
110 * @brief Close volume
112 * @param[in] volume Volume
114 uint64_t (*get_length
)(ocf_volume_t volume
);
118 * @brief This structure describes volume properties
120 struct ocf_volume_properties
{
122 /*!< The name of volume operations */
124 uint32_t io_priv_size
;
125 /*!< Size of io private context structure */
127 uint32_t volume_priv_size
;
128 /*!< Size of volume private context structure */
130 struct ocf_volume_caps caps
;
131 /*!< Volume capabilities */
133 struct ocf_volume_ops ops
;
134 /*!< Volume operations */
136 struct ocf_io_ops io_ops
;
137 /*!< IO operations */
141 * @brief Initialize UUID from string
143 * @param[in] uuid UUID to be initialized
144 * @param[in] str NULL-terminated string
146 * @return Zero when success, othewise error
148 static inline int ocf_uuid_set_str(ocf_uuid_t uuid
, char *str
)
150 size_t len
= env_strnlen(str
, OCF_VOLUME_UUID_MAX_SIZE
);
152 if (len
>= OCF_VOLUME_UUID_MAX_SIZE
)
153 return -OCF_ERR_INVAL
;
156 uuid
->size
= len
+ 1;
162 * @brief Obtain string from UUID
163 * @param[in] uuid pointer to UUID
164 * @return String contained within UUID
166 static inline const char *ocf_uuid_to_str(const struct ocf_volume_uuid
*uuid
)
172 * @brief Initialize volume
174 * @param[in] volume volume handle
175 * @param[in] type cache/core volume type
176 * @param[in] uuid OCF volume UUID
177 * @param[in] uuid_copy crate copy of uuid data
179 * @return Zero when success, othewise error
181 int ocf_volume_init(ocf_volume_t volume
, ocf_volume_type_t type
,
182 struct ocf_volume_uuid
*uuid
, bool uuid_copy
);
185 * @brief Deinitialize volume
187 * @param[in] volume volume handle
189 void ocf_volume_deinit(ocf_volume_t volume
);
192 * @brief Allocate and initialize volume
194 * @param[out] volume pointer to volume handle
195 * @param[in] type cache/core volume type
196 * @param[in] uuid OCF volume UUID
198 * @return Zero when success, othewise en error
200 int ocf_volume_create(ocf_volume_t
*volume
, ocf_volume_type_t type
,
201 struct ocf_volume_uuid
*uuid
);
204 * @brief Deinitialize and free volume
206 * @param[in] volume volume handle
208 void ocf_volume_destroy(ocf_volume_t volume
);
211 * @brief Get volume type
213 * @param[in] volume Volume
215 * @return Volume type
217 ocf_volume_type_t
ocf_volume_get_type(ocf_volume_t volume
);
220 * @brief Get volume UUID
222 * @param[in] volume Volume
224 * @return UUID of volume
226 const struct ocf_volume_uuid
*ocf_volume_get_uuid(ocf_volume_t volume
);
229 * @brief Get private context of volume
231 * @param[in] volume Volume
233 * @return Volume private context
235 void *ocf_volume_get_priv(ocf_volume_t volume
);
238 * @brief Get cache handle for given volume
240 * @param volume volume handle
242 * @return Handle to cache for which volume belongs to
244 ocf_cache_t
ocf_volume_get_cache(ocf_volume_t volume
);
247 * @brief Check if volume supports atomic mode
249 * @param[in] volume Volume
251 * @return Non-zero value if volume is atomic, otherwise zero
253 int ocf_volume_is_atomic(ocf_volume_t volume
);
256 * @brief Allocate new io
258 * @param[in] volume Volume
260 * @return ocf_io on success atomic, otherwise NULL
262 struct ocf_io
*ocf_volume_new_io(ocf_volume_t volume
);
265 * @brief Submit io to volume
269 void ocf_volume_submit_io(struct ocf_io
*io
);
272 * @brief Submit flush to volume
276 void ocf_volume_submit_flush(struct ocf_io
*io
);
279 * @brief Submit discard to volume
283 void ocf_volume_submit_discard(struct ocf_io
*io
);
288 * @param[in] volume Volume
289 * @param[in] volume_params Opaque volume params
291 * @return Zero when success, othewise en error
293 int ocf_volume_open(ocf_volume_t volume
, void *volume_params
);
296 * @brief Get volume max io size
298 * @param[in] volume Volume
300 void ocf_volume_close(ocf_volume_t volume
);
303 * @brief Get volume max io size
305 * @param[in] volume Volume
307 * @return Volume max io size in bytes
309 unsigned int ocf_volume_get_max_io_size(ocf_volume_t volume
);
312 * @brief Get volume length
314 * @param[in] volume Volume
316 * @return Length of volume in bytes
318 uint64_t ocf_volume_get_length(ocf_volume_t volume
);
320 #endif /* __OCF_VOLUME_H__ */