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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
|
/*
* Copyright(c) 2012-2018 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef __OCF_MNGT_H__
#define __OCF_MNGT_H__
#include "ocf_cache.h"
#include "ocf_core.h"
/**
* @file
* @brief OCF management operations definitions
*/
/**
* @brief Core start configuration
*/
struct ocf_mngt_core_config {
/**
* @brief OCF core name
*/
char name[OCF_CORE_NAME_SIZE];
/**
* @brief OCF core volume UUID
*/
struct ocf_volume_uuid uuid;
/**
* @brief OCF core volume type
*/
uint8_t volume_type;
/**
* @brief Add core to pool if cache isn't present or add core to
* earlier loaded cache
*/
bool try_add;
uint32_t seq_cutoff_threshold;
/*!< Sequential cutoff threshold (in bytes) */
struct {
void *data;
size_t size;
} user_metadata;
};
/**
* @brief Initialize core config to default values
*
* @note This function doesn't initialize name, uuid and volume_type fields
* which have no default values and are required to be set by user.
*
* @param[in] cfg Core config stucture
*/
static inline void ocf_mngt_core_config_set_default(
struct ocf_mngt_core_config *cfg)
{
cfg->try_add = false;
cfg->seq_cutoff_threshold = 1024;
cfg->user_metadata.data = NULL;
cfg->user_metadata.size = 0;
}
/**
* @brief Get number of OCF caches
*
* @param[in] ctx OCF context
*
* @retval Number of caches in given OCF instance
*/
uint32_t ocf_mngt_cache_get_count(ocf_ctx_t ctx);
/* Cache instances getters */
/**
* @brief Get OCF cache by name
*
* @note This function on success also increases reference counter
* in given cache
*
* @param[in] ctx OCF context
* @param[in] name OCF cache name
* @param[in] name_len Cache name length
* @param[out] cache OCF cache handle
*
* @retval 0 Get cache successfully
* @retval -OCF_ERR_CACHE_NOT_EXIST Cache with given name doesn't exist
*/
int ocf_mngt_cache_get_by_name(ocf_ctx_t ctx, const char* name, size_t name_len,
ocf_cache_t *cache);
/**
* @brief Increment reference counter of cache
*
* @param[in] cache OCF cache handle
*
* @retval 0 Reference counter incremented
* @retval -OCF_ERR_CACHE_NOT_AVAIL cache isn't initialised yet
*/
int ocf_mngt_cache_get(ocf_cache_t cache);
/**
* @brief Decrease reference counter in cache
*
* @note If cache don't have any reference - deallocate it
*
* @param[in] cache Handle to cache
*/
void ocf_mngt_cache_put(ocf_cache_t cache);
/**
* @brief Lock cache for management oparations (write lock, exclusive)
* @param[in] cache Handle to cache
* @param[in] error Status error code. Can be one of the following:
* 0 Cache successfully locked
* -OCF_ERR_CACHE_NOT_EXIST Can not lock cache - cache is already stopping
* -OCF_ERR_NO_MEM Cannot allocate needed memory
* -OCF_ERR_INTR Wait operation interrupted
*/
typedef void (*ocf_mngt_cache_lock_end_t)(ocf_cache_t cache,
void *priv, int error);
/**
* @brief Lock cache for management oparations (write lock, exclusive)
*
* @param[in] cache Handle to cache
* @param[in] cmpl Completion callback
* @param[in] priv Private context of completion callback
*/
void ocf_mngt_cache_lock(ocf_cache_t cache,
ocf_mngt_cache_lock_end_t cmpl, void *priv);
/**
* @brief 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.
*
* @param[in] cache Handle to cache
* @param[in] cmpl Completion callback
* @param[in] priv Private context of completion callback
*/
void ocf_mngt_cache_read_lock(ocf_cache_t cache,
ocf_mngt_cache_lock_end_t cmpl, void *priv);
/**
* @brief Lock cache for management oparations (write lock, exclusive)
*
* @param[in] cache Handle to cache
*
* @retval 0 Cache successfully locked
* @retval -OCF_ERR_CACHE_NOT_EXIST Can not lock cache - cache is already
* stopping
* @retval -OCF_ERR_NO_LOCK Lock not acquired
*/
int ocf_mngt_cache_trylock(ocf_cache_t cache);
/**
* @brief 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.
*
* @param[in] cache Handle to cache
*
* @retval 0 Cache successfully locked
* @retval -OCF_ERR_CACHE_NOT_EXIST Can not lock cache - cache is already
* stopping
* @retval -OCF_ERR_NO_LOCK Lock not acquired
*/
int ocf_mngt_cache_read_trylock(ocf_cache_t cache);
/**
* @brief Write-unlock cache
*
* @param[in] cache Handle to cache
*/
void ocf_mngt_cache_unlock(ocf_cache_t cache);
/**
* @brief Read-unlock cache
*
* @param[in] cache Handle to cache
*/
void ocf_mngt_cache_read_unlock(ocf_cache_t cache);
/**
* @brief Cache visitor function
*
* @param[in] cache Handle to cache
* @param[in] cntx Visitor function context
*
* @retval 0 Success
* @retval Non-zero Error
*/
typedef int (*ocf_mngt_cache_visitor_t)(ocf_cache_t cache, void *cntx);
/**
* @brief Loop for each cache
*
* @note Visitor function is called for each cache
*
* @param[in] ctx OCF context
* @param[in] visitor OCF cache visitor function
* @param[in] cntx Context for cache visitor function
*
* @retval 0 Success
* @retval Non-zero Error
*/
int ocf_mngt_cache_visit(ocf_ctx_t ctx, ocf_mngt_cache_visitor_t visitor,
void *cntx);
/**
* @brief Loop for each cache reverse
*
* @note Visitor function is called for each cache
*
* @param[in] ctx OCF context
* @param[in] visitor OCF cache visitor function
* @param[in] cntx Context for cache visitor function
*
* @retval 0 Success
* @retval Non-zero Error
*/
int ocf_mngt_cache_visit_reverse(ocf_ctx_t ctx, ocf_mngt_cache_visitor_t visitor,
void *cntx);
/**
* @brief Cache start configuration
*/
struct ocf_mngt_cache_config {
/**
* @brief Cache name
*/
char name[OCF_CACHE_NAME_SIZE];
/**
* @brief Cache mode
*/
ocf_cache_mode_t cache_mode;
/**
* @brief Eviction policy type
*/
ocf_eviction_t eviction_policy;
/**
* @brief Promotion policy type
*/
ocf_promotion_t promotion_policy;
/**
* @brief Cache line size
*/
ocf_cache_line_size_t cache_line_size;
/**
* @brief Metadata layout (stripping/sequential)
*/
ocf_metadata_layout_t metadata_layout;
bool metadata_volatile;
/**
* @brief Backfill configuration
*/
struct {
uint32_t max_queue_size;
uint32_t queue_unblock_size;
} backfill;
/**
* @brief Start cache and keep it locked
*
* @note In this case caller is able to perform additional activities
* and then shall unlock cache
*/
bool locked;
/**
* @brief Use pass-through mode for I/O requests unaligned to 4KiB
*/
bool pt_unaligned_io;
/**
* @brief If set, try to submit all I/O in fast path.
*/
bool use_submit_io_fast;
};
/**
* @brief Initialize core config to default values
*
* @note This function doesn't initialize name field which has no default
* value and is required to be set by user.
*
* @param[in] cfg Cache config stucture
*/
static inline void ocf_mngt_cache_config_set_default(
struct ocf_mngt_cache_config *cfg)
{
cfg->cache_mode = ocf_cache_mode_default;
cfg->eviction_policy = ocf_eviction_default;
cfg->promotion_policy = ocf_promotion_default;
cfg->cache_line_size = ocf_cache_line_size_4;
cfg->metadata_layout = ocf_metadata_layout_default;
cfg->metadata_volatile = false;
cfg->backfill.max_queue_size = 65536;
cfg->backfill.queue_unblock_size = 60000;
cfg->locked = false;
cfg->pt_unaligned_io = false;
cfg->use_submit_io_fast = false;
}
/**
* @brief Start cache instance
*
* @param[in] ctx OCF context
* @param[out] cache Cache handle
* @param[in] cfg Starting cache configuration
*
* @retval 0 Cache started successfully
* @retval Non-zero Error occurred and starting cache failed
*/
int ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
struct ocf_mngt_cache_config *cfg);
/**
* @brief Set queue to be used during management operations
*
* @param[in] cache Cache object
* @param[in] queue Queue object
*
* @retval 0 Success
* @retval Non-zero Error occurred
*/
int ocf_mngt_cache_set_mngt_queue(ocf_cache_t cache, ocf_queue_t queue);
/**
* @brief Completion callback of cache stop operation
*
* @param[in] cache Cache handle
* @param[in] priv Callback context
* @param[in] error Error code (zero on success)
*/
typedef void (*ocf_mngt_cache_stop_end_t)(ocf_cache_t cache,
void *priv, int error);
/**
* @brief Stop cache instance
*
* @param[in] cache Cache handle
* @param[in] cmpl Completion callback
* @param[in] priv Completion callback context
*/
void ocf_mngt_cache_stop(ocf_cache_t cache,
ocf_mngt_cache_stop_end_t cmpl, void *priv);
/**
* @brief Cache attach configuration
*/
struct ocf_mngt_cache_device_config {
/**
* @brief Cache volume UUID
*/
struct ocf_volume_uuid uuid;
/**
* @brief Cache volume type
*/
uint8_t volume_type;
/**
* @brief Cache line size
*/
ocf_cache_line_size_t cache_line_size;
/**
* @brief Automatically open core volumes when loading cache
*
* If set to false, cache load will not attempt to open core volumes,
* and so cores will be marked "inactive" unless their volumes were
* earlier added to the core pool. In such case user will be expected
* to add cores later using function ocf_mngt_cache_add_core().
*
* @note This option is meaningful only with ocf_mngt_cache_load().
* When used with ocf_mngt_cache_attach() it's ignored.
*/
bool open_cores;
/**
* @brief Ignore warnings and start cache
*
* @note It will force starting cache despite the:
* - overwrite dirty shutdown of previous cache
* - ignore cache with dirty shutdown and reinitialize cache
*/
bool force;
/**
* @brief If set, cache features (like discard) are tested
* before starting cache
*/
bool perform_test;
/**
* @brief If set, cache device will be discarded on cache start
*/
bool discard_on_start;
/**
* @brief Optional opaque volume parameters, passed down to cache volume
* open callback
*/
void *volume_params;
};
/**
* @brief Initialize core config to default values
*
* @note This function doesn't initiialize uuid and volume_type fields
* which have no default values and are required to be set by user.
*
* @param[in] cfg Cache device config stucture
*/
static inline void ocf_mngt_cache_device_config_set_default(
struct ocf_mngt_cache_device_config *cfg)
{
cfg->cache_line_size = ocf_cache_line_size_none;
cfg->open_cores = true;
cfg->force = false;
cfg->perform_test = true;
cfg->discard_on_start = true;
cfg->volume_params = NULL;
}
/**
* @brief Get amount of free RAM needed to attach cache volume
*
* @param[in] cache Cache handle
* @param[in] cfg Caching device configuration
* @param[out] ram_needed Amount of RAM needed in bytes
*
* @retval 0 Success
* @retval Non-zero Error occurred
*/
int ocf_mngt_get_ram_needed(ocf_cache_t cache,
struct ocf_mngt_cache_device_config *cfg, uint64_t *ram_needed);
/**
* @brief Completion callback of cache attach operation
*
* @param[in] cache Cache handle
* @param[in] priv Callback context
* @param[in] error Error code (zero on success)
*/
typedef void (*ocf_mngt_cache_attach_end_t)(ocf_cache_t cache,
void *priv, int error);
/**
* @brief Attach caching device to cache instance
*
* @param[in] cache Cache handle
* @param[in] cfg Caching device configuration
* @param[in] cmpl Completion callback
* @param[in] priv Completion callback context
*/
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);
/**
* @brief Completion callback of cache detach operation
*
* @param[in] cache Cache handle
* @param[in] priv Callback context
* @param[in] error Error code (zero on success)
*/
typedef void (*ocf_mngt_cache_detach_end_t)(ocf_cache_t cache,
void *priv, int error);
/**
* @brief Detach caching cache
*
* @param[in] cache Cache handle
* @param[in] cmpl Completion callback
* @param[in] priv Completion callback context
*/
void ocf_mngt_cache_detach(ocf_cache_t cache,
ocf_mngt_cache_detach_end_t cmpl, void *priv);
/**
* @brief Completion callback of cache load operation
*
* @param[in] cache Cache handle
* @param[in] priv Callback context
* @param[in] error Error code (zero on success)
*/
typedef void (*ocf_mngt_cache_load_end_t)(ocf_cache_t cache,
void *priv, int error);
/**
* @brief Load cache instance
*
* @param[in] cache Cache handle
* @param[in] cfg Caching device configuration
* @param[in] cmpl Completion callback
* @param[in] priv Completion callback context
*/
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);
/* Adding and removing cores */
/**
* @brief Completion callback of add core operation
*
* @param[in] cache Cache handle
* @param[in] core Core handle on success or NULL on failure
* @param[in] priv Callback context
* @param[in] error Error code (zero on success)
*/
typedef void (*ocf_mngt_cache_add_core_end_t)(ocf_cache_t cache,
ocf_core_t core, void *priv, int error);
/**
* @brief Add core to cache instance
*
* @param[in] cache Cache handle
* @param[in] cfg Core configuration
* @param[in] cmpl Completion callback
* @param[in] priv Completion callback context
*/
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);
/**
* @brief Completion callback of remove core operation
*
* @param[in] priv Callback context
* @param[in] error Error code (zero on success)
*/
typedef void (*ocf_mngt_cache_remove_core_end_t)(void *priv, int error);
/**
* @brief Remove core from cache instance
*
* @param[in] core Core handle
* @param[in] cmpl Completion callback
* @param[in] priv Completion callback context
*/
void ocf_mngt_cache_remove_core(ocf_core_t core,
ocf_mngt_cache_remove_core_end_t cmpl, void *priv);
/**
* @brief Completion callback of detach core operation
*
* @param[in] priv Callback context
* @param[in] error Error code (zero on success)
*/
typedef void (*ocf_mngt_cache_detach_core_end_t)(void *priv, int error);
/**
* @brief Detach core from cache instance
*
* @param[in] core Core handle
* @param[in] cmpl Completion callback
* @param[in] priv Completion callback context
*/
void ocf_mngt_cache_detach_core(ocf_core_t core,
ocf_mngt_cache_detach_core_end_t cmpl, void *priv);
/* Flush operations */
/**
* @brief Completion callback of cache flush operation
*
* @param[in] cache Cache handle
* @param[in] priv Callback context
* @param[in] error Error code (zero on success)
*/
typedef void (*ocf_mngt_cache_flush_end_t)(ocf_cache_t cache,
void *priv, int error);
/**
* @brief Flush data from given cache
*
* @param[in] cache Cache handle
* @param[in] cmpl Completion callback
* @param[in] priv Completion callback context
*/
void ocf_mngt_cache_flush(ocf_cache_t cache,
ocf_mngt_cache_flush_end_t cmpl, void *priv);
/**
* @brief Check if core is dirty
*
* @param[in] core Core handle
*
* @retval true if core is dirty, false otherwise
*/
bool ocf_mngt_core_is_dirty(ocf_core_t core);
/**
* @brief Check if cache is dirty
*
* @param[in] cache Cache handle
*
* @retval true if cache is dirty, false otherwise
*/
bool ocf_mngt_cache_is_dirty(ocf_cache_t cache);
/**
* @brief Completion callback of core flush operation
*
* @param[in] core Core handle
* @param[in] priv Callback context
* @param[in] error Error code (zero on success)
*/
typedef void (*ocf_mngt_core_flush_end_t)(ocf_core_t core,
void *priv, int error);
/**
* @brief Flush data to given core
*
* @param[in] core Core handle
* @param[in] cmpl Completion callback
* @param[in] priv Completion callback context
*/
void ocf_mngt_core_flush(ocf_core_t core,
ocf_mngt_core_flush_end_t cmpl, void *priv);
/**
* @brief Completion callback of cache purge operation
*
* @param[in] cache Cache handle
* @param[in] priv Callback context
* @param[in] error Error code (zero on success)
*/
typedef void (*ocf_mngt_cache_purge_end_t)(ocf_cache_t cache,
void *priv, int error);
/**
* @brief Purge data from given cache
*
* @param[in] cache Cache handle
* @param[in] cmpl Completion callback
* @param[in] priv Completion callback context
*/
void ocf_mngt_cache_purge(ocf_cache_t cache,
ocf_mngt_cache_purge_end_t cmpl, void *priv);
/**
* @brief Completion callback of core purge operation
*
* @param[in] core Core handle
* @param[in] priv Callback context
* @param[in] error Error code (zero on success)
*/
typedef void (*ocf_mngt_core_purge_end_t)(ocf_core_t core,
void *priv, int error);
/**
* @brief Purge data to given core
*
* @param[in] core Core handle
* @param[in] cmpl Completion callback
* @param[in] priv Completion callback context
*/
void ocf_mngt_core_purge(ocf_core_t core,
ocf_mngt_core_purge_end_t cmpl, void *priv);
/**
* @brief Interrupt existing flushing of cache or core
*
* @param[in] cache Cache instance
*/
void ocf_mngt_cache_flush_interrupt(ocf_cache_t cache);
/**
* @brief Completion callback of save operation
*
* @param[in] cache Cache handle
* @param[in] priv Callback context
* @param[in] error Error code (zero on success)
*/
typedef void (*ocf_mngt_cache_save_end_t)(ocf_cache_t cache,
void *priv, int error);
/**
* @brief Save cache configuration data on cache volume
*
* This function should be called after changing cache or core parameters
* in order to make changes persistent.
*
* @param[in] cache Cache handle
* @param[in] cmpl Completion callback
* @param[in] priv Completion callback context
*/
void ocf_mngt_cache_save(ocf_cache_t cache,
ocf_mngt_cache_save_end_t cmpl, void *priv);
/**
* @brief Determines whether given cache mode has write-back semantics, i.e. it
* allows for writes to be serviced in cache and lazily propagated to core.
*
* @param[in] mode input cache mode
*/
static inline bool ocf_mngt_cache_mode_has_lazy_write(ocf_cache_mode_t mode)
{
return mode == ocf_cache_mode_wb || mode == ocf_cache_mode_wo;
}
/**
* @brief Set cache mode in given cache
*
* @attention This changes only runtime state. To make changes persistent
* use function ocf_mngt_cache_save().
*
* @param[in] cache Cache handle
* @param[in] mode Cache mode to set
*
* @retval 0 Cache mode have been set successfully
* @retval Non-zero Error occurred and cache mode not been set
*/
int ocf_mngt_cache_set_mode(ocf_cache_t cache, ocf_cache_mode_t mode);
/**
* @brief Set cleaning policy in given cache
*
* @attention This changes only runtime state. To make changes persistent
* use function ocf_mngt_cache_save().
*
* @param[in] cache Cache handle
* @param[in] type Cleaning policy type
*
* @retval 0 Policy has been set successfully
* @retval Non-zero Error occurred and policy has not been set
*/
int ocf_mngt_cache_cleaning_set_policy(ocf_cache_t cache, ocf_cleaning_t type);
/**
* @brief Get current cleaning policy from given cache
*
* @param[in] cache Cache handle
* @param[out] type Variable to store current cleaning policy type
*
* @retval 0 Policy has been get successfully
* @retval Non-zero Error occurred and policy has not been get
*/
int ocf_mngt_cache_cleaning_get_policy(ocf_cache_t cache, ocf_cleaning_t *type);
/**
* @brief Set cleaning parameter in given cache
*
* @attention This changes only runtime state. To make changes persistent
* use function ocf_mngt_cache_save().
*
* @param[in] cache Cache handle
* @param[in] type Cleaning policy type
* @param[in] param_id Cleaning policy parameter id
* @param[in] param_value Cleaning policy parameter value
*
* @retval 0 Parameter has been set successfully
* @retval Non-zero Error occurred and parameter has not been set
*/
int ocf_mngt_cache_cleaning_set_param(ocf_cache_t cache, ocf_cleaning_t type,
uint32_t param_id, uint32_t param_value);
/**
* @brief Get cleaning parameter from given cache
*
* @param[in] cache Cache handle
* @param[in] type Cleaning policy type
* @param[in] param_id Cleaning policy parameter id
* @param[out] param_value Variable to store parameter value
*
* @retval 0 Parameter has been get successfully
* @retval Non-zero Error occurred and parameter has not been get
*/
int ocf_mngt_cache_cleaning_get_param(ocf_cache_t cache,ocf_cleaning_t type,
uint32_t param_id, uint32_t *param_value);
/**
* @brief Set promotion policy in given cache
*
* @attention This changes only runtime state. To make changes persistent
* use function ocf_mngt_cache_save().
*
* @param[in] cache Cache handle
* @param[in] type Promotion policy type
*
* @retval 0 Policy has been set successfully
* @retval Non-zero Error occurred and policy has not been set
*/
int ocf_mngt_cache_promotion_set_policy(ocf_cache_t cache, ocf_promotion_t type);
/**
* @brief Get promotion policy in given cache
*
* @param[in] cache Cache handle
*
* @retval Currently set promotion policy type
*/
ocf_promotion_t ocf_mngt_cache_promotion_get_policy(ocf_cache_t cache);
/**
* @brief Set promotion policy parameter for given cache
*
* @param[in] cache Cache handle
* @param[in] type Promotion policy type
* @param[in] param_id Promotion policy parameter id
* @param[in] param_value Promotion policy parameter value
*
* @retval 0 Parameter has been set successfully
* @retval Non-zero Error occurred and parameter has not been set
*/
int ocf_mngt_cache_promotion_set_param(ocf_cache_t cache, ocf_promotion_t type,
uint8_t param_id, uint32_t param_value);
/**
* @brief Get promotion policy parameter for given cache
*
* @param[in] cache Cache handle
* @param[in] type Promotion policy type
* @param[in] param_id Promotion policy parameter id
* @param[out] param_value Variable to store parameter value
*
* @retval 0 Parameter has been retrieved successfully
* @retval Non-zero Error occurred and parameter has not been retrieved
*/
int ocf_mngt_cache_promotion_get_param(ocf_cache_t cache, ocf_promotion_t type,
uint8_t param_id, uint32_t *param_value);
/**
* @brief IO class configuration
*/
struct ocf_mngt_io_class_config {
/**
* @brief IO class ID
*/
uint32_t class_id;
/**
* @brief IO class name
*/
const char *name;
/**
* @brief IO class eviction priority
*/
int16_t prio;
/**
* @brief IO class cache mode
*/
ocf_cache_mode_t cache_mode;
/**
* @brief IO class minimum size
*/
uint32_t min_size;
/**
* @brief IO class maximum size
*/
uint32_t max_size;
};
struct ocf_mngt_io_classes_config {
struct ocf_mngt_io_class_config config[OCF_IO_CLASS_MAX];
};
/**
* @brief Configure IO classes in given cache
*
* @attention This changes only runtime state. To make changes persistent
* use function ocf_mngt_cache_save().
*
* @param[in] cache Cache handle
* @param[in] cfg IO class configuration
*
* @retval 0 Configuration have been set successfully
* @retval Non-zero Error occurred and configuration not been set
*/
int ocf_mngt_cache_io_classes_configure(ocf_cache_t cache,
const struct ocf_mngt_io_classes_config *cfg);
/**
* @brief Asociate new UUID value with given core
*
* @attention This changes only runtime state. To make changes persistent
* use function ocf_mngt_cache_save().
*
* @param[in] core Core object
* @param[in] uuid new core uuid
*
* @retval 0 Success
* @retval Non-zero Fail
*/
int ocf_mngt_core_set_uuid(ocf_core_t core, const struct ocf_volume_uuid *uuid);
/**
* @brief Set persistent user metadata for given core
*
* @attention This changes only runtime state. To make changes persistent
* use function ocf_mngt_cache_save().
*
* @param[in] core Core object
* @param[in] data User data buffer
* @param[in] size Size of user data buffer
*
* @retval 0 Success
* @retval Non-zero Core getting failed
*/
int ocf_mngt_core_set_user_metadata(ocf_core_t core, void *data, size_t size);
/**
* @brief Get persistent user metadata from given core
*
* @param[in] core Core object
* @param[out] data User data buffer
* @param[in] size Size of user data buffer
*
* @retval 0 Success
* @retval Non-zero Core getting failed
*/
int ocf_mngt_core_get_user_metadata(ocf_core_t core, void *data, size_t size);
/**
* @brief Set core sequential cutoff threshold
*
* @attention This changes only runtime state. To make changes persistent
* use function ocf_mngt_cache_save().
*
* @param[in] core Core handle
* @param[in] thresh threshold in bytes for sequential cutoff
*
* @retval 0 Sequential cutoff threshold has been set successfully
* @retval Non-zero Error occured and threshold hasn't been updated
*/
int ocf_mngt_core_set_seq_cutoff_threshold(ocf_core_t core, uint32_t thresh);
/**
* @brief Set sequential cutoff threshold for all cores in cache
*
* @attention This changes only runtime state. To make changes persistent
* use function ocf_mngt_cache_save().
*
* @param[in] cache Cache handle
* @param[in] thresh threshold in bytes for sequential cutoff
*
* @retval 0 Sequential cutoff threshold has been set successfully
* @retval Non-zero Error occured and threshold hasn't been updated
*/
int ocf_mngt_core_set_seq_cutoff_threshold_all(ocf_cache_t cache,
uint32_t thresh);
/**
* @brief Get core sequential cutoff threshold
*
* @param[in] core Core handle
* @param[in] thresh threshold in bytes for sequential cutoff
*
* @retval 0 Sequential cutoff threshold has been get successfully
* @retval Non-zero Error occured
*/
int ocf_mngt_core_get_seq_cutoff_threshold(ocf_core_t core, uint32_t *thresh);
/**
* @brief Set core sequential cutoff policy
*
* @attention This changes only runtime state. To make changes persistent
* use function ocf_mngt_cache_save().
*
* @param[in] core Core handle
* @param[in] policy sequential cutoff policy
*
* @retval 0 Sequential cutoff policy has been set successfully
* @retval Non-zero Error occured and policy hasn't been updated
*/
int ocf_mngt_core_set_seq_cutoff_policy(ocf_core_t core,
ocf_seq_cutoff_policy policy);
/**
* @brief Set sequential cutoff policy for all cores in cache
*
* @attention This changes only runtime state. To make changes persistent
* use function ocf_mngt_cache_save().
*
* @param[in] cache Cache handle
* @param[in] policy sequential cutoff policy
*
* @retval 0 Sequential cutoff policy has been set successfully
* @retval Non-zero Error occured and policy hasn't been updated
*/
int ocf_mngt_core_set_seq_cutoff_policy_all(ocf_cache_t cache,
ocf_seq_cutoff_policy policy);
/**
* @brief Get core sequential cutoff policy
*
* @param[in] core Core handle
* @param[in] policy sequential cutoff policy
*
* @retval 0 Sequential cutoff policy has been get successfully
* @retval Non-zero Error occured
*/
int ocf_mngt_core_get_seq_cutoff_policy(ocf_core_t core,
ocf_seq_cutoff_policy *policy);
/**
* @brief Set cache fallback Pass Through error threshold
*
* @param[in] cache Cache handle
* @param[in] threshold Value to be set as threshold
*
* @retval 0 Fallback-PT threshold have been set successfully
* @retval Non-zero Error occurred
*/
int ocf_mngt_cache_set_fallback_pt_error_threshold(ocf_cache_t cache,
uint32_t threshold);
/**
* @brief Get cache fallback Pass Through error threshold
*
* @param[in] cache Cache handle
* @param[out] threshold Fallback-PT threshold
*
* @retval 0 Fallback-PT threshold have been get successfully
* @retval Non-zero Error occurred
*/
int ocf_mngt_cache_get_fallback_pt_error_threshold(ocf_cache_t cache,
uint32_t *threshold);
/**
* @brief Reset cache fallback Pass Through error counter
*
* @param[in] cache Cache handle
*
* @retval 0 Threshold have been reset successfully
*/
int ocf_mngt_cache_reset_fallback_pt_error_counter(ocf_cache_t cache);
/**
* @brief Get core pool count
*
* @param[in] ctx OCF context
*
* @retval Number of cores in core pool
*/
int ocf_mngt_core_pool_get_count(ocf_ctx_t ctx);
/**
* @brief Add core to pool
*
* @param[in] ctx OCF context
* @param[in] uuid Cache volume UUID
* @param[in] type OCF core volume type
*
* @retval 0 Core added to pool successfully
* @retval Non-zero Error occurred and adding core to poll failed
*/
int ocf_mngt_core_pool_add(ocf_ctx_t ctx, ocf_uuid_t uuid, uint8_t type);
/**
* @brief Add core to pool
*
* @param[in] ctx OCF context
* @param[in] uuid Cache volume UUID
* @param[in] type OCF core volume type
*
* @retval Handler to object with same UUID
* @retval NULL Not found object with that id
*/
ocf_volume_t ocf_mngt_core_pool_lookup(ocf_ctx_t ctx, ocf_uuid_t uuid,
ocf_volume_type_t type);
/**
* @brief Iterate over all object in pool and call visitor callback
*
* @param[in] ctx OCF context
* @param[in] visitor Visitor callback
* @param[in] visior_ctx CContext for visitor callback
*
* @retval Handler to object with same UUID
* @retval NULL Not found object with that id
*/
int ocf_mngt_core_pool_visit(ocf_ctx_t ctx,
int (*visitor)(ocf_uuid_t, void *), void *visitor_ctx);
/**
* @brief Remove volume from pool
*
* Important: This function destroys volume instance but doesn't close it,
* so it should be either moved or closed before calling this function.
*
* @param[in] ctx OCF context
* @param[in] volume Core volume
*/
void ocf_mngt_core_pool_remove(ocf_ctx_t ctx, ocf_volume_t volume);
#endif /* __OCF_CACHE_H__ */
|