Open CAS Framework
Open source framework of Cache Acceleration Software
ocf_mngt.h
Go to the documentation of this file.
1 /*
2  * Copyright(c) 2012-2020 Intel Corporation
3  * SPDX-License-Identifier: BSD-3-Clause-Clear
4  */
5 
6 #ifndef __OCF_MNGT_H__
7 #define __OCF_MNGT_H__
8 
9 #include "ocf_cache.h"
10 #include "ocf_core.h"
11 
25 
30 
34  uint8_t volume_type;
35 
40  bool try_add;
41 
45  struct {
46  void *data;
47  size_t size;
48  } user_metadata;
49 };
50 
59 static inline void ocf_mngt_core_config_set_default(
60  struct ocf_mngt_core_config *cfg)
61 {
62  cfg->try_add = false;
63  cfg->seq_cutoff_threshold = 1024;
64  cfg->user_metadata.data = NULL;
65  cfg->user_metadata.size = 0;
66 }
67 
76 
77 /* Cache instances getters */
78 
93 int ocf_mngt_cache_get_by_name(ocf_ctx_t ctx, const char* name, size_t name_len,
94  ocf_cache_t *cache);
95 
105 
113 void ocf_mngt_cache_put(ocf_cache_t cache);
114 
126  void *priv, int error);
127 
136  ocf_mngt_cache_lock_end_t cmpl, void *priv);
137 
148  ocf_mngt_cache_lock_end_t cmpl, void *priv);
149 
161 
175 
182 
189 
199 typedef int (*ocf_mngt_cache_visitor_t)(ocf_cache_t cache, void *cntx);
200 
214  void *cntx);
215 
229  void *cntx);
230 
239 
244 
249 
254 
259 
264 
265  bool metadata_volatile;
266 
270  struct {
271  uint32_t max_queue_size;
272  uint32_t queue_unblock_size;
273  } backfill;
274 
281  bool locked;
282 
287 
292 };
293 
302 static inline void ocf_mngt_cache_config_set_default(
303  struct ocf_mngt_cache_config *cfg)
304 {
309  cfg->metadata_layout = ocf_metadata_layout_default;
310  cfg->metadata_volatile = false;
311  cfg->backfill.max_queue_size = 65536;
312  cfg->backfill.queue_unblock_size = 60000;
313  cfg->locked = false;
314  cfg->pt_unaligned_io = false;
315  cfg->use_submit_io_fast = false;
316 }
317 
329  struct ocf_mngt_cache_config *cfg);
330 
341 
350  void *priv, int error);
351 
360  ocf_mngt_cache_stop_end_t cmpl, void *priv);
361 
370 
374  uint8_t volume_type;
375 
380 
393 
402  bool force;
403 
409 
414 
420 };
421 
430 static inline void ocf_mngt_cache_device_config_set_default(
431  struct ocf_mngt_cache_device_config *cfg)
432 {
434  cfg->open_cores = true;
435  cfg->force = false;
436  cfg->perform_test = true;
437  cfg->discard_on_start = true;
438  cfg->volume_params = NULL;
439 }
440 
452  struct ocf_mngt_cache_device_config *cfg, uint64_t *ram_needed);
453 
462  void *priv, int error);
463 
473  struct ocf_mngt_cache_device_config *cfg,
474  ocf_mngt_cache_attach_end_t cmpl, void *priv);
475 
484  void *priv, int error);
485 
494  ocf_mngt_cache_detach_end_t cmpl, void *priv);
495 
504  void *priv, int error);
505 
515  struct ocf_mngt_cache_device_config *cfg,
516  ocf_mngt_cache_load_end_t cmpl, void *priv);
517 
518 /* Adding and removing cores */
519 
529  ocf_core_t core, void *priv, int error);
530 
540  struct ocf_mngt_core_config *cfg,
541  ocf_mngt_cache_add_core_end_t cmpl, void *priv);
542 
549 typedef void (*ocf_mngt_cache_remove_core_end_t)(void *priv, int error);
550 
559  ocf_mngt_cache_remove_core_end_t cmpl, void *priv);
560 
567 typedef void (*ocf_mngt_cache_detach_core_end_t)(void *priv, int error);
568 
577  ocf_mngt_cache_detach_core_end_t cmpl, void *priv);
578 
579 /* Flush operations */
580 
589  void *priv, int error);
590 
599  ocf_mngt_cache_flush_end_t cmpl, void *priv);
600 
609 
618 
627  void *priv, int error);
628 
637  ocf_mngt_core_flush_end_t cmpl, void *priv);
638 
647  void *priv, int error);
648 
657  ocf_mngt_cache_purge_end_t cmpl, void *priv);
658 
667  void *priv, int error);
668 
677  ocf_mngt_core_purge_end_t cmpl, void *priv);
678 
685 
694  void *priv, int error);
695 
707  ocf_mngt_cache_save_end_t cmpl, void *priv);
708 
715 static inline bool ocf_mngt_cache_mode_has_lazy_write(ocf_cache_mode_t mode)
716 {
717  return mode == ocf_cache_mode_wb || mode == ocf_cache_mode_wo;
718 }
719 
733 
747 
758 
774  uint32_t param_id, uint32_t param_value);
775 
788  uint32_t param_id, uint32_t *param_value);
789 
803 
812 
825  uint8_t param_id, uint32_t param_value);
826 
839  uint8_t param_id, uint32_t *param_value);
840 
848  uint32_t class_id;
849 
853  const char *name;
854 
858  int16_t prio;
859 
864 
868  uint32_t min_size;
869 
873  uint32_t max_size;
874 };
875 
877  struct ocf_mngt_io_class_config config[OCF_IO_CLASS_MAX];
878 };
879 
893  const struct ocf_mngt_io_classes_config *cfg);
894 
907 int ocf_mngt_core_set_uuid(ocf_core_t core, const struct ocf_volume_uuid *uuid);
908 
922 int ocf_mngt_core_set_user_metadata(ocf_core_t core, void *data, size_t size);
923 
934 int ocf_mngt_core_get_user_metadata(ocf_core_t core, void *data, size_t size);
935 
948 int ocf_mngt_core_set_seq_cutoff_threshold(ocf_core_t core, uint32_t thresh);
949 
963  uint32_t thresh);
964 
974 int ocf_mngt_core_get_seq_cutoff_threshold(ocf_core_t core, uint32_t *thresh);
975 
989  ocf_seq_cutoff_policy policy);
990 
1004  ocf_seq_cutoff_policy policy);
1005 
1016  ocf_seq_cutoff_policy *policy);
1017 
1028  uint32_t threshold);
1029 
1040  uint32_t *threshold);
1041 
1050 
1059 
1070 int ocf_mngt_core_pool_add(ocf_ctx_t ctx, ocf_uuid_t uuid, uint8_t type);
1071 
1083  ocf_volume_type_t type);
1095  int (*visitor)(ocf_uuid_t, void *), void *visitor_ctx);
1096 
1107 
1108 #endif /* __OCF_CACHE_H__ */
struct ocf_cache * ocf_cache_t
handle to object designating ocf cache device
Definition: ocf_types.h:44
int ocf_mngt_cache_promotion_set_param(ocf_cache_t cache, ocf_promotion_t type, uint8_t param_id, uint32_t param_value)
Set promotion policy parameter for given cache.
ocf_promotion_t
Definition: ocf_def.h:214
Definition: ocf_mngt.h:876
int ocf_mngt_cache_cleaning_set_param(ocf_cache_t cache, ocf_cleaning_t type, uint32_t param_id, uint32_t param_value)
Set cleaning parameter in given cache.
ocf_metadata_layout_t
Definition: ocf_def.h:293
void(* ocf_mngt_cache_purge_end_t)(ocf_cache_t cache, void *priv, int error)
Completion callback of cache purge operation.
Definition: ocf_mngt.h:646
struct ocf_mngt_cache_config::@6 backfill
Backfill configuration.
uint8_t volume_type
Cache volume type.
Definition: ocf_mngt.h:374
int ocf_mngt_cache_reset_fallback_pt_error_counter(ocf_cache_t cache)
Reset cache fallback Pass Through error counter.
void ocf_mngt_cache_flush_interrupt(ocf_cache_t cache)
Interrupt existing flushing of cache or core.
Cache attach configuration.
Definition: ocf_mngt.h:365
int ocf_mngt_core_set_seq_cutoff_threshold_all(ocf_cache_t cache, uint32_t thresh)
Set sequential cutoff threshold for all cores in cache.
bool pt_unaligned_io
Use pass-through mode for I/O requests unaligned to 4KiB.
Definition: ocf_mngt.h:286
void ocf_mngt_cache_put(ocf_cache_t cache)
Decrease reference counter in cache.
uint32_t ocf_mngt_cache_get_count(ocf_ctx_t ctx)
Get number of OCF caches.
ocf_seq_cutoff_policy
Definition: ocf_def.h:180
const char * name
IO class name.
Definition: ocf_mngt.h:853
void * volume_params
Optional opaque volume parameters, passed down to cache volume open callback.
Definition: ocf_mngt.h:419
ocf_eviction_t eviction_policy
Eviction policy type.
Definition: ocf_mngt.h:248
void ocf_mngt_cache_purge(ocf_cache_t cache, ocf_mngt_cache_purge_end_t cmpl, void *priv)
Purge data from given cache.
void(* ocf_mngt_core_flush_end_t)(ocf_core_t core, void *priv, int error)
Completion callback of core flush operation.
Definition: ocf_mngt.h:626
#define OCF_CACHE_NAME_SIZE
Definition: ocf_def.h:38
void(* ocf_mngt_cache_attach_end_t)(ocf_cache_t cache, void *priv, int error)
Completion callback of cache attach operation.
Definition: ocf_mngt.h:461
void ocf_mngt_cache_add_core(ocf_cache_t cache, struct ocf_mngt_core_config *cfg, ocf_mngt_cache_add_core_end_t cmpl, void *priv)
Add core to cache instance.
int ocf_mngt_cache_cleaning_get_param(ocf_cache_t cache, ocf_cleaning_t type, uint32_t param_id, uint32_t *param_value)
Get cleaning parameter from given cache.
int ocf_mngt_cache_promotion_get_param(ocf_cache_t cache, ocf_promotion_t type, uint8_t param_id, uint32_t *param_value)
Get promotion policy parameter for given cache.
int ocf_mngt_cache_set_mngt_queue(ocf_cache_t cache, ocf_queue_t queue)
Set queue to be used during management operations.
bool ocf_mngt_core_is_dirty(ocf_core_t core)
Check if core is dirty.
bool discard_on_start
If set, cache device will be discarded on cache start.
Definition: ocf_mngt.h:413
ocf_eviction_t
Definition: ocf_def.h:200
struct ocf_volume_type * ocf_volume_type_t
handle to volume type
Definition: ocf_types.h:63
int ocf_mngt_core_set_seq_cutoff_policy(ocf_core_t core, ocf_seq_cutoff_policy policy)
Set core sequential cutoff policy.
struct ocf_ctx * ocf_ctx_t
handle to object designating ocf context
Definition: ocf_types.h:38
int ocf_mngt_core_set_user_metadata(ocf_core_t core, void *data, size_t size)
Set persistent user metadata for given core.
void ocf_mngt_cache_unlock(ocf_cache_t cache)
Write-unlock cache.
int ocf_mngt_core_get_user_metadata(ocf_core_t core, void *data, size_t size)
Get persistent user metadata from given core.
int ocf_mngt_core_set_seq_cutoff_threshold(ocf_core_t core, uint32_t thresh)
Set core sequential cutoff threshold.
int ocf_mngt_cache_visit(ocf_ctx_t ctx, ocf_mngt_cache_visitor_t visitor, void *cntx)
Loop for each cache.
Definition: ocf_def.h:259
void ocf_mngt_core_flush(ocf_core_t core, ocf_mngt_core_flush_end_t cmpl, void *priv)
Flush data to given core.
int ocf_mngt_cache_read_trylock(ocf_cache_t cache)
Lock cache for read - assures cache config does not change while lock is being held, while allowing other users to acquire read lock in parallel.
void(* ocf_mngt_cache_save_end_t)(ocf_cache_t cache, void *priv, int error)
Completion callback of save operation.
Definition: ocf_mngt.h:693
uint32_t min_size
IO class minimum size.
Definition: ocf_mngt.h:868
bool open_cores
Automatically open core volumes when loading cache.
Definition: ocf_mngt.h:392
void ocf_mngt_core_pool_remove(ocf_ctx_t ctx, ocf_volume_t volume)
Remove volume from pool.
Core start configuration.
Definition: ocf_mngt.h:20
int ocf_mngt_cache_cleaning_set_policy(ocf_cache_t cache, ocf_cleaning_t type)
Set cleaning policy in given cache.
bool locked
Start cache and keep it locked.
Definition: ocf_mngt.h:281
int ocf_mngt_core_set_uuid(ocf_core_t core, const struct ocf_volume_uuid *uuid)
Asociate new UUID value with given core.
int ocf_mngt_core_pool_add(ocf_ctx_t ctx, ocf_uuid_t uuid, uint8_t type)
Add core to pool.
char name[OCF_CORE_NAME_SIZE]
OCF core name.
Definition: ocf_mngt.h:24
int ocf_mngt_get_ram_needed(ocf_cache_t cache, struct ocf_mngt_cache_device_config *cfg, uint64_t *ram_needed)
Get amount of free RAM needed to attach cache volume.
int ocf_mngt_cache_set_fallback_pt_error_threshold(ocf_cache_t cache, uint32_t threshold)
Set cache fallback Pass Through error threshold.
ocf_cache_mode_t
Definition: ocf_def.h:149
int ocf_mngt_cache_trylock(ocf_cache_t cache)
Lock cache for management oparations (write lock, exclusive)
OCF volume UUID.
Definition: ocf_volume.h:28
void ocf_mngt_cache_read_unlock(ocf_cache_t cache)
Read-unlock cache.
void ocf_mngt_cache_load(ocf_cache_t cache, struct ocf_mngt_cache_device_config *cfg, ocf_mngt_cache_load_end_t cmpl, void *priv)
Load cache instance.
ocf_promotion_t promotion_policy
Promotion policy type.
Definition: ocf_mngt.h:253
ocf_cache_line_size_t
Definition: ocf_def.h:258
void ocf_mngt_cache_detach(ocf_cache_t cache, ocf_mngt_cache_detach_end_t cmpl, void *priv)
Detach caching cache.
int ocf_mngt_cache_io_classes_configure(ocf_cache_t cache, const struct ocf_mngt_io_classes_config *cfg)
Configure IO classes in given cache.
void ocf_mngt_cache_lock(ocf_cache_t cache, ocf_mngt_cache_lock_end_t cmpl, void *priv)
Lock cache for management oparations (write lock, exclusive)
ocf_volume_t ocf_mngt_core_pool_lookup(ocf_ctx_t ctx, ocf_uuid_t uuid, ocf_volume_type_t type)
Add core to pool.
void ocf_mngt_cache_detach_core(ocf_core_t core, ocf_mngt_cache_detach_core_end_t cmpl, void *priv)
Detach core from cache instance.
OCF cache API.
int16_t prio
IO class eviction priority.
Definition: ocf_mngt.h:858
uint32_t seq_cutoff_threshold
Definition: ocf_mngt.h:42
void ocf_mngt_cache_save(ocf_cache_t cache, ocf_mngt_cache_save_end_t cmpl, void *priv)
Save cache configuration data on cache volume.
int ocf_mngt_cache_get_by_name(ocf_ctx_t ctx, const char *name, size_t name_len, ocf_cache_t *cache)
Get OCF cache by name.
ocf_cache_line_size_t cache_line_size
Cache line size.
Definition: ocf_mngt.h:258
int ocf_mngt_core_set_seq_cutoff_policy_all(ocf_cache_t cache, ocf_seq_cutoff_policy policy)
Set sequential cutoff policy for all cores in cache.
int ocf_mngt_cache_cleaning_get_policy(ocf_cache_t cache, ocf_cleaning_t *type)
Get current cleaning policy from given cache.
Definition: ocf_def.h:153
int ocf_mngt_core_get_seq_cutoff_threshold(ocf_core_t core, uint32_t *thresh)
Get core sequential cutoff threshold.
int ocf_mngt_core_pool_visit(ocf_ctx_t ctx, int(*visitor)(ocf_uuid_t, void *), void *visitor_ctx)
Iterate over all object in pool and call visitor callback.
void(* ocf_mngt_cache_detach_end_t)(ocf_cache_t cache, void *priv, int error)
Completion callback of cache detach operation.
Definition: ocf_mngt.h:483
void ocf_mngt_cache_flush(ocf_cache_t cache, ocf_mngt_cache_flush_end_t cmpl, void *priv)
Flush data from given cache.
int ocf_mngt_core_get_seq_cutoff_policy(ocf_core_t core, ocf_seq_cutoff_policy *policy)
Get core sequential cutoff policy.
ocf_cache_mode_t cache_mode
Cache mode.
Definition: ocf_mngt.h:243
uint32_t max_size
IO class maximum size.
Definition: ocf_mngt.h:873
int ocf_mngt_cache_get_fallback_pt_error_threshold(ocf_cache_t cache, uint32_t *threshold)
Get cache fallback Pass Through error threshold.
ocf_cache_line_size_t cache_line_size
Cache line size.
Definition: ocf_mngt.h:379
void ocf_mngt_cache_attach(ocf_cache_t cache, struct ocf_mngt_cache_device_config *cfg, ocf_mngt_cache_attach_end_t cmpl, void *priv)
Attach caching device to cache instance.
int ocf_mngt_core_pool_get_count(ocf_ctx_t ctx)
Get core pool count.
int ocf_mngt_cache_get(ocf_cache_t cache)
Increment reference counter of cache.
struct ocf_volume * ocf_volume_t
handle to object designating ocf volume
Definition: ocf_types.h:56
struct ocf_queue * ocf_queue_t
handle to I/O queue
Definition: ocf_types.h:78
void(* ocf_mngt_core_purge_end_t)(ocf_core_t core, void *priv, int error)
Completion callback of core purge operation.
Definition: ocf_mngt.h:666
int(* ocf_mngt_cache_visitor_t)(ocf_cache_t cache, void *cntx)
Cache visitor function.
Definition: ocf_mngt.h:199
void ocf_mngt_cache_read_lock(ocf_cache_t cache, ocf_mngt_cache_lock_end_t cmpl, void *priv)
Lock cache for read - assures cache config does not change while lock is being held, while allowing other users to acquire read lock in parallel.
Cache start configuration.
Definition: ocf_mngt.h:234
void ocf_mngt_core_purge(ocf_core_t core, ocf_mngt_core_purge_end_t cmpl, void *priv)
Purge data to given core.
Definition: ocf_def.h:224
uint32_t class_id
IO class ID.
Definition: ocf_mngt.h:848
void(* ocf_mngt_cache_add_core_end_t)(ocf_cache_t cache, ocf_core_t core, void *priv, int error)
Completion callback of add core operation.
Definition: ocf_mngt.h:528
struct ocf_volume_uuid uuid
OCF core volume UUID.
Definition: ocf_mngt.h:29
void(* ocf_mngt_cache_load_end_t)(ocf_cache_t cache, void *priv, int error)
Completion callback of cache load operation.
Definition: ocf_mngt.h:503
int ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache, struct ocf_mngt_cache_config *cfg)
Start cache instance.
Definition: ocf_def.h:262
Definition: ocf_def.h:165
ocf_cleaning_t
Definition: ocf_def.h:231
ocf_cache_mode_t cache_mode
IO class cache mode.
Definition: ocf_mngt.h:863
ocf_metadata_layout_t metadata_layout
Metadata layout (stripping/sequential)
Definition: ocf_mngt.h:263
Definition: ocf_def.h:171
IO class configuration.
Definition: ocf_mngt.h:844
OCF core API.
int ocf_mngt_cache_set_mode(ocf_cache_t cache, ocf_cache_mode_t mode)
Set cache mode in given cache.
void(* ocf_mngt_cache_flush_end_t)(ocf_cache_t cache, void *priv, int error)
Completion callback of cache flush operation.
Definition: ocf_mngt.h:588
bool use_submit_io_fast
If set, try to submit all I/O in fast path.
Definition: ocf_mngt.h:291
void(* ocf_mngt_cache_stop_end_t)(ocf_cache_t cache, void *priv, int error)
Completion callback of cache stop operation.
Definition: ocf_mngt.h:349
int ocf_mngt_cache_visit_reverse(ocf_ctx_t ctx, ocf_mngt_cache_visitor_t visitor, void *cntx)
Loop for each cache reverse.
ocf_promotion_t ocf_mngt_cache_promotion_get_policy(ocf_cache_t cache)
Get promotion policy in given cache.
#define OCF_CORE_NAME_SIZE
Definition: ocf_def.h:78
struct ocf_core * ocf_core_t
handle to object designating ocf core object
Definition: ocf_types.h:50
uint8_t volume_type
OCF core volume type.
Definition: ocf_mngt.h:34
Definition: ocf_def.h:207
void(* ocf_mngt_cache_remove_core_end_t)(void *priv, int error)
Completion callback of remove core operation.
Definition: ocf_mngt.h:549
bool force
Ignore warnings and initialize new cache instance.
Definition: ocf_mngt.h:402
void(* ocf_mngt_cache_detach_core_end_t)(void *priv, int error)
Completion callback of detach core operation.
Definition: ocf_mngt.h:567
int ocf_mngt_cache_promotion_set_policy(ocf_cache_t cache, ocf_promotion_t type)
Set promotion policy in given cache.
void ocf_mngt_cache_stop(ocf_cache_t cache, ocf_mngt_cache_stop_end_t cmpl, void *priv)
Stop cache instance.
bool ocf_mngt_cache_is_dirty(ocf_cache_t cache)
Check if cache is dirty.
bool perform_test
If set, cache features (like discard) are tested before starting cache.
Definition: ocf_mngt.h:408
bool try_add
Add core to pool if cache isn't present or add core to earlier loaded cache.
Definition: ocf_mngt.h:40
void ocf_mngt_cache_remove_core(ocf_core_t core, ocf_mngt_cache_remove_core_end_t cmpl, void *priv)
Remove core from cache instance.
void(* ocf_mngt_cache_lock_end_t)(ocf_cache_t cache, void *priv, int error)
Lock cache for management oparations (write lock, exclusive)
Definition: ocf_mngt.h:125