]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | /* |
2 | * Copyright(c) 2012-2018 Intel Corporation | |
3 | * SPDX-License-Identifier: BSD-3-Clause-Clear | |
4 | */ | |
5 | ||
6 | #ifndef __METADATA_IO_H__ | |
7 | #define __METADATA_IO_H__ | |
8 | ||
9 | /** | |
10 | * @file metadata_io.h | |
11 | * @brief Metadata IO utilities | |
12 | */ | |
13 | ||
14 | /** | |
15 | * @brief Metadata IO event | |
16 | * | |
17 | * The client of metadata IO service if informed trough this event: | |
18 | * - on completion of read from cache device | |
19 | * - on fill data which will be written into cache device | |
20 | * | |
21 | * @param data[in,out] Environment data for read ot write IO | |
22 | * @param page[in] Page which is issued | |
23 | * @param context[in] context caller | |
24 | * | |
25 | * @retval 0 Success | |
26 | * @retval Non-zero Error which will bee finally returned to the caller | |
27 | */ | |
28 | typedef int (*ocf_metadata_io_event_t)(ocf_cache_t cache, | |
29 | ctx_data_t *data, uint32_t page, void *context); | |
30 | ||
31 | /** | |
32 | * @brief Metadata write end callback | |
33 | * | |
34 | * @param cache - Cache instance | |
35 | * @param context - Read context | |
36 | * @param error - error | |
37 | * @param page - page that was written | |
38 | */ | |
39 | typedef void (*ocf_metadata_io_end_t)(ocf_cache_t cache, | |
40 | void *context, int error); | |
41 | ||
42 | struct metadata_io_request_asynch; | |
43 | ||
44 | /* | |
45 | * IO request context | |
46 | */ | |
47 | struct metadata_io_request { | |
48 | ocf_cache_t cache; | |
49 | void *context; | |
50 | uint32_t page; | |
51 | uint32_t count; | |
52 | ocf_metadata_io_event_t on_meta_fill; | |
53 | ocf_metadata_io_event_t on_meta_drain; | |
9f95a23c TL |
54 | ctx_data_t *data; |
55 | int error; | |
56 | struct metadata_io_request_asynch *asynch; | |
57 | env_atomic finished; | |
58 | ||
f67539c2 | 59 | struct ocf_request req; |
9f95a23c TL |
60 | struct list_head list; |
61 | }; | |
62 | ||
f67539c2 | 63 | #define METADATA_IO_REQS_LIMIT 128 |
9f95a23c TL |
64 | |
65 | /* | |
66 | * Asynchronous IO request context | |
67 | */ | |
68 | struct metadata_io_request_asynch { | |
f67539c2 | 69 | struct metadata_io_request reqs[METADATA_IO_REQS_LIMIT]; |
9f95a23c TL |
70 | void *context; |
71 | int error; | |
9f95a23c TL |
72 | env_atomic req_remaining; |
73 | env_atomic req_active; | |
f67539c2 | 74 | env_atomic req_current; |
9f95a23c | 75 | uint32_t page; |
f67539c2 | 76 | uint32_t count; |
9f95a23c TL |
77 | ocf_metadata_io_end_t on_complete; |
78 | }; | |
79 | ||
f67539c2 TL |
80 | void metadata_io_req_complete(struct metadata_io_request *m_req); |
81 | ||
9f95a23c TL |
82 | /** |
83 | * @brief Metadata read end callback | |
84 | * | |
85 | * @param cache Cache instance | |
86 | * @param sector_addr Begin sector of metadata | |
87 | * @param sector_no Number of sectors | |
88 | * @param data Data environment buffer with atomic metadata | |
89 | * | |
90 | * @retval 0 Success | |
91 | * @retval Non-zero Error which will bee finally returned to the caller | |
92 | */ | |
93 | typedef int (*ocf_metadata_atomic_io_event_t)(void *priv, uint64_t sector_addr, | |
94 | uint32_t sector_no, ctx_data_t *data); | |
95 | ||
96 | /** | |
97 | * @brief Iterative asynchronous read atomic metadata | |
98 | * | |
99 | * @param cache - Cache instance | |
100 | * @param queue - Queue to be used for IO | |
101 | * @param context - Read context | |
102 | * @param drain_hndl - Drain callback | |
103 | * @param compl_hndl - All IOs completed callback | |
104 | * | |
105 | * @return 0 - No errors, otherwise error occurred | |
106 | */ | |
107 | int metadata_io_read_i_atomic(ocf_cache_t cache, ocf_queue_t queue, | |
108 | void *context, ocf_metadata_atomic_io_event_t drain_hndl, | |
109 | ocf_metadata_io_end_t compl_hndl); | |
110 | ||
111 | /** | |
112 | * @brief Iterative asynchronous pages write | |
113 | * | |
114 | * @param cache - Cache instance | |
115 | * @param queue - Queue to be used for IO | |
116 | * @param context - Read context | |
117 | * @param page - Start page of SSD (cache device) where data will be written | |
118 | * @param count - Counts of page to be processed | |
119 | * @param fill_hndl - Fill callback | |
120 | * @param compl_hndl - All IOs completed callback | |
121 | * | |
122 | * @return 0 - No errors, otherwise error occurred | |
123 | */ | |
124 | int metadata_io_write_i_asynch(ocf_cache_t cache, ocf_queue_t queue, | |
125 | void *context, uint32_t page, uint32_t count, | |
126 | ocf_metadata_io_event_t fill_hndl, | |
127 | ocf_metadata_io_end_t compl_hndl); | |
128 | ||
129 | /** | |
130 | * @brief Iterative asynchronous pages read | |
131 | * | |
132 | * @param cache - Cache instance | |
133 | * @param queue - Queue to be used for IO | |
134 | * @param context - Read context | |
135 | * @param page - Start page of SSD (cache device) where data will be read | |
136 | * @param count - Counts of page to be processed | |
137 | * @param drain_hndl - Drain callback | |
138 | * @param compl_hndl - All IOs completed callback | |
139 | * | |
140 | * @return 0 - No errors, otherwise error occurred | |
141 | */ | |
142 | int metadata_io_read_i_asynch(ocf_cache_t cache, ocf_queue_t queue, | |
143 | void *context, uint32_t page, uint32_t count, | |
144 | ocf_metadata_io_event_t drain_hndl, | |
145 | ocf_metadata_io_end_t compl_hndl); | |
146 | ||
147 | /** | |
148 | * Function for initializing metadata io. | |
149 | */ | |
150 | int ocf_metadata_io_init(ocf_cache_t cache); | |
151 | ||
152 | /** | |
153 | * Function for deinitializing metadata io. | |
154 | */ | |
155 | void ocf_metadata_io_deinit(ocf_cache_t cache); | |
156 | ||
157 | #endif /* METADATA_IO_UTILS_H_ */ |