Line data Source code
1 : /* 2 : * Copyright(c) 2012-2022 Intel Corporation 3 : * SPDX-License-Identifier: BSD-3-Clause 4 : */ 5 : 6 : /** 7 : * @file 8 : * @brief OCF core API 9 : */ 10 : 11 : #ifndef __OCF_CORE_H__ 12 : #define __OCF_CORE_H__ 13 : 14 : #include "ocf_volume.h" 15 : #include "ocf_io.h" 16 : #include "ocf_mngt.h" 17 : 18 : struct ocf_core_info { 19 : /** Core size in cache line size unit */ 20 : uint64_t core_size; 21 : 22 : /** Core size in bytes unit */ 23 : uint64_t core_size_bytes; 24 : 25 : /** Number of blocks flushed in ongoing flush operation */ 26 : uint32_t flushed; 27 : 28 : /** Number of blocks left to flush in ongoing flush operation */ 29 : uint32_t dirty; 30 : 31 : /** How long core is dirty in seconds unit */ 32 : uint64_t dirty_for; 33 : 34 : /** Sequential cutoff threshold (in bytes) */ 35 : uint32_t seq_cutoff_threshold; 36 : 37 : /** Sequential cutoff policy */ 38 : ocf_seq_cutoff_policy seq_cutoff_policy; 39 : }; 40 : 41 : /** 42 : * @brief Get OCF core by name 43 : * 44 : * @param[in] cache OCF cache 45 : * @param[in] name Core name 46 : * @param[in] name_len Core name length 47 : * @param[out] core OCF core handle 48 : * 49 : * @retval 0 Get cache successfully 50 : * @retval -OCF_ERR_CORE_NOT_EXIST Core with given name doesn't exist 51 : */ 52 : int ocf_core_get_by_name(ocf_cache_t cache, const char *name, size_t name_len, 53 : ocf_core_t *core); 54 : 55 : /** 56 : * @brief Obtain cache object from core 57 : * 58 : * @param[in] core Core object 59 : * 60 : * @retval Cache object 61 : */ 62 : ocf_cache_t ocf_core_get_cache(ocf_core_t core); 63 : 64 : /** 65 : * @brief Obtain volume associated with core 66 : * 67 : * @param[in] core Core object 68 : * 69 : * @retval Volume 70 : */ 71 : ocf_volume_t ocf_core_get_volume(ocf_core_t core); 72 : 73 : /** 74 : * @brief Obtain volume of the core 75 : * 76 : * @param[in] core Core object 77 : * 78 : * @retval Front volume 79 : */ 80 : ocf_volume_t ocf_core_get_front_volume(ocf_core_t core); 81 : 82 : /** 83 : * @brief Get UUID of volume associated with core 84 : * 85 : * @param[in] core Core object 86 : * 87 : * @retval Volume UUID 88 : */ 89 : static inline const struct ocf_volume_uuid *ocf_core_get_uuid(ocf_core_t core) 90 : { 91 : return ocf_volume_get_uuid(ocf_core_get_volume(core)); 92 : } 93 : 94 : /** 95 : * @brief Get sequential cutoff threshold of given core object 96 : * 97 : * @param[in] core Core object 98 : * 99 : * @retval Sequential cutoff threshold [B] 100 : */ 101 : uint32_t ocf_core_get_seq_cutoff_threshold(ocf_core_t core); 102 : 103 : /** 104 : * @brief Get sequential cutoff policy of given core object 105 : * 106 : * @param[in] core Core object 107 : * 108 : * @retval Sequential cutoff policy 109 : */ 110 : ocf_seq_cutoff_policy ocf_core_get_seq_cutoff_policy(ocf_core_t core); 111 : 112 : /** 113 : * @brief Get sequential cutoff stream promotion req count of given core object 114 : * 115 : * @param[in] core Core object 116 : * 117 : * @retval Sequential cutoff stream promotion request count 118 : */ 119 : uint32_t ocf_core_get_seq_cutoff_promotion_count(ocf_core_t core); 120 : 121 : /** 122 : * @brief Whether to promote sequential cutoff stream 123 : * to global structures when threshold is reached 124 : * 125 : * @param[in] core Core object 126 : * 127 : * @retval Sequential cutoff stream promote_on_threshold switch value 128 : */ 129 : bool ocf_core_get_seq_cutoff_promote_on_threshold(ocf_core_t core); 130 : 131 : /** 132 : * @brief Get name of given core object 133 : * 134 : * @param[in] core Core object 135 : * 136 : * @retval Core name 137 : */ 138 : const char *ocf_core_get_name(ocf_core_t core); 139 : 140 : /** 141 : * @brief Get core state 142 : * 143 : * @param[in] core Core object 144 : * 145 : * @retval Core state 146 : */ 147 : ocf_core_state_t ocf_core_get_state(ocf_core_t core); 148 : 149 : /** 150 : * @brief Submit ocf_io 151 : * 152 : * @param[in] io IO to be submitted 153 : */ 154 0 : static inline void ocf_core_submit_io(struct ocf_io *io) 155 : { 156 0 : ocf_volume_submit_io(io); 157 0 : } 158 : 159 : /** 160 : * @brief Submit ocf_io with flush command 161 : * 162 : * @param[in] io IO to be submitted 163 : */ 164 0 : static inline void ocf_core_submit_flush(struct ocf_io *io) 165 : { 166 0 : ocf_volume_submit_flush(io); 167 0 : } 168 : 169 : /** 170 : * @brief Submit ocf_io with discard command 171 : * 172 : * @param[in] io IO to be submitted 173 : */ 174 0 : static inline void ocf_core_submit_discard(struct ocf_io *io) 175 : { 176 0 : ocf_volume_submit_discard(io); 177 0 : } 178 : 179 : /** 180 : * @brief Core visitor function type which is called back when iterating over 181 : * cores. 182 : * 183 : * @param[in] core Core which is currently iterated (visited) 184 : * @param[in] cntx Visitor context 185 : * 186 : * @retval 0 continue visiting cores 187 : * @retval Non-zero stop iterating and return result 188 : */ 189 : typedef int (*ocf_core_visitor_t)(ocf_core_t core, void *cntx); 190 : 191 : /** 192 : * @brief Run visitor function for each core of given cache 193 : * 194 : * @param[in] cache OCF cache instance 195 : * @param[in] visitor Visitor function 196 : * @param[in] cntx Visitor context 197 : * @param[in] only_opened Visit only opened cores 198 : * 199 : * @retval 0 Success 200 : * @retval Non-zero Fail 201 : */ 202 : int ocf_core_visit(ocf_cache_t cache, ocf_core_visitor_t visitor, void *cntx, 203 : bool only_opened); 204 : 205 : /** 206 : * @brief Get info of given core object 207 : * 208 : * @param[in] core Core object 209 : * @param[out] info Core info structure 210 : * 211 : * @retval 0 Success 212 : * @retval Non-zero Fail 213 : */ 214 : int ocf_core_get_info(ocf_core_t core, struct ocf_core_info *info); 215 : 216 : /** 217 : * @brief Set core private data 218 : * 219 : * @param[in] core Core object 220 : * @param[in] priv Private data 221 : */ 222 : void ocf_core_set_priv(ocf_core_t core, void *priv); 223 : 224 : /** 225 : * @brief Get core private data 226 : * 227 : * @param[in] core Core object 228 : * 229 : * @retval Private data 230 : */ 231 : void *ocf_core_get_priv(ocf_core_t core); 232 : 233 : #endif /* __OCF_CORE_H__ */