Revision 298800ca block/qed.h
b/block/qed.h | ||
---|---|---|
96 | 96 |
} QEDHeader; |
97 | 97 |
|
98 | 98 |
typedef struct { |
99 |
uint64_t offsets[0]; /* in bytes */ |
|
100 |
} QEDTable; |
|
101 |
|
|
102 |
/* The L2 cache is a simple write-through cache for L2 structures */ |
|
103 |
typedef struct CachedL2Table { |
|
104 |
QEDTable *table; |
|
105 |
uint64_t offset; /* offset=0 indicates an invalidate entry */ |
|
106 |
QTAILQ_ENTRY(CachedL2Table) node; |
|
107 |
int ref; |
|
108 |
} CachedL2Table; |
|
109 |
|
|
110 |
typedef struct { |
|
111 |
QTAILQ_HEAD(, CachedL2Table) entries; |
|
112 |
unsigned int n_entries; |
|
113 |
} L2TableCache; |
|
114 |
|
|
115 |
typedef struct QEDRequest { |
|
116 |
CachedL2Table *l2_table; |
|
117 |
} QEDRequest; |
|
118 |
|
|
119 |
typedef struct { |
|
99 | 120 |
BlockDriverState *bs; /* device */ |
100 | 121 |
uint64_t file_size; /* length of image file, in bytes */ |
101 | 122 |
|
102 | 123 |
QEDHeader header; /* always cpu-endian */ |
124 |
QEDTable *l1_table; |
|
125 |
L2TableCache l2_cache; /* l2 table cache */ |
|
103 | 126 |
uint32_t table_nelems; |
104 | 127 |
uint32_t l1_shift; |
105 | 128 |
uint32_t l2_shift; |
106 | 129 |
uint32_t l2_mask; |
107 | 130 |
} BDRVQEDState; |
108 | 131 |
|
132 |
enum { |
|
133 |
QED_CLUSTER_FOUND, /* cluster found */ |
|
134 |
QED_CLUSTER_L2, /* cluster missing in L2 */ |
|
135 |
QED_CLUSTER_L1, /* cluster missing in L1 */ |
|
136 |
}; |
|
137 |
|
|
138 |
/** |
|
139 |
* qed_find_cluster() completion callback |
|
140 |
* |
|
141 |
* @opaque: User data for completion callback |
|
142 |
* @ret: QED_CLUSTER_FOUND Success |
|
143 |
* QED_CLUSTER_L2 Data cluster unallocated in L2 |
|
144 |
* QED_CLUSTER_L1 L2 unallocated in L1 |
|
145 |
* -errno POSIX error occurred |
|
146 |
* @offset: Data cluster offset |
|
147 |
* @len: Contiguous bytes starting from cluster offset |
|
148 |
* |
|
149 |
* This function is invoked when qed_find_cluster() completes. |
|
150 |
* |
|
151 |
* On success ret is QED_CLUSTER_FOUND and offset/len are a contiguous range |
|
152 |
* in the image file. |
|
153 |
* |
|
154 |
* On failure ret is QED_CLUSTER_L2 or QED_CLUSTER_L1 for missing L2 or L1 |
|
155 |
* table offset, respectively. len is number of contiguous unallocated bytes. |
|
156 |
*/ |
|
157 |
typedef void QEDFindClusterFunc(void *opaque, int ret, uint64_t offset, size_t len); |
|
158 |
|
|
159 |
/** |
|
160 |
* Generic callback for chaining async callbacks |
|
161 |
*/ |
|
162 |
typedef struct { |
|
163 |
BlockDriverCompletionFunc *cb; |
|
164 |
void *opaque; |
|
165 |
} GenericCB; |
|
166 |
|
|
167 |
void *gencb_alloc(size_t len, BlockDriverCompletionFunc *cb, void *opaque); |
|
168 |
void gencb_complete(void *opaque, int ret); |
|
169 |
|
|
170 |
/** |
|
171 |
* L2 cache functions |
|
172 |
*/ |
|
173 |
void qed_init_l2_cache(L2TableCache *l2_cache); |
|
174 |
void qed_free_l2_cache(L2TableCache *l2_cache); |
|
175 |
CachedL2Table *qed_alloc_l2_cache_entry(L2TableCache *l2_cache); |
|
176 |
void qed_unref_l2_cache_entry(CachedL2Table *entry); |
|
177 |
CachedL2Table *qed_find_l2_cache_entry(L2TableCache *l2_cache, uint64_t offset); |
|
178 |
void qed_commit_l2_cache_entry(L2TableCache *l2_cache, CachedL2Table *l2_table); |
|
179 |
|
|
180 |
/** |
|
181 |
* Table I/O functions |
|
182 |
*/ |
|
183 |
int qed_read_l1_table_sync(BDRVQEDState *s); |
|
184 |
void qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n, |
|
185 |
BlockDriverCompletionFunc *cb, void *opaque); |
|
186 |
int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index, |
|
187 |
unsigned int n); |
|
188 |
int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request, |
|
189 |
uint64_t offset); |
|
190 |
void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset, |
|
191 |
BlockDriverCompletionFunc *cb, void *opaque); |
|
192 |
void qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, |
|
193 |
unsigned int index, unsigned int n, bool flush, |
|
194 |
BlockDriverCompletionFunc *cb, void *opaque); |
|
195 |
int qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request, |
|
196 |
unsigned int index, unsigned int n, bool flush); |
|
197 |
|
|
198 |
/** |
|
199 |
* Cluster functions |
|
200 |
*/ |
|
201 |
void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos, |
|
202 |
size_t len, QEDFindClusterFunc *cb, void *opaque); |
|
203 |
|
|
204 |
/** |
|
205 |
* Consistency check |
|
206 |
*/ |
|
207 |
int qed_check(BDRVQEDState *s, BdrvCheckResult *result, bool fix); |
|
208 |
|
|
209 |
QEDTable *qed_alloc_table(BDRVQEDState *s); |
|
210 |
|
|
109 | 211 |
/** |
110 | 212 |
* Round down to the start of a cluster |
111 | 213 |
*/ |
... | ... | |
114 | 216 |
return offset & ~(uint64_t)(s->header.cluster_size - 1); |
115 | 217 |
} |
116 | 218 |
|
219 |
static inline uint64_t qed_offset_into_cluster(BDRVQEDState *s, uint64_t offset) |
|
220 |
{ |
|
221 |
return offset & (s->header.cluster_size - 1); |
|
222 |
} |
|
223 |
|
|
224 |
static inline unsigned int qed_bytes_to_clusters(BDRVQEDState *s, size_t bytes) |
|
225 |
{ |
|
226 |
return qed_start_of_cluster(s, bytes + (s->header.cluster_size - 1)) / |
|
227 |
(s->header.cluster_size - 1); |
|
228 |
} |
|
229 |
|
|
230 |
static inline unsigned int qed_l1_index(BDRVQEDState *s, uint64_t pos) |
|
231 |
{ |
|
232 |
return pos >> s->l1_shift; |
|
233 |
} |
|
234 |
|
|
235 |
static inline unsigned int qed_l2_index(BDRVQEDState *s, uint64_t pos) |
|
236 |
{ |
|
237 |
return (pos >> s->l2_shift) & s->l2_mask; |
|
238 |
} |
|
239 |
|
|
117 | 240 |
/** |
118 | 241 |
* Test if a cluster offset is valid |
119 | 242 |
*/ |
Also available in: Unified diff