-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathtd-blkif.h
More file actions
330 lines (276 loc) · 8.5 KB
/
Copy pathtd-blkif.h
File metadata and controls
330 lines (276 loc) · 8.5 KB
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
/*
* Copyright (c) 2016, Citrix Systems, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __TD_BLKIF_H__
#define __TD_BLKIF_H__
#include "blktap-xenif.h"
#include <inttypes.h> /* required by xen/event_channel.h */
#include <xen/xen.h>
#include <xen/io/xenbus.h>
#include <xen/event_channel.h>
#include <xen/grant_table.h>
#include <stdbool.h>
#include "xen_blkif.h"
#include "td-req.h"
#include "td-stats.h"
#include "tapdisk-vbd.h"
#include "tapdisk-utils.h"
#include "tapdisk-metrics.h"
struct td_xenio_ctx;
struct td_vbd_handle;
struct td_xenblkif_stats;
struct td_xenblkif {
/**
* The domain ID where the front-end is running.
*/
int domid;
/**
* The device ID of the VBD.
*/
int devid;
/**
* Pointer to the context this block interface belongs to.
*/
struct td_xenio_ctx *ctx;
/**
* allows struct td_blkif's to be linked into lists, for whomever needs to
* maintain multiple struct td_blkif's
*/
struct list_head entry_ctx;
struct list_head entry;
/**
* The local port corresponding to the remote port of the domain where the
* front-end is running. We use this to tell for which VBD a pending event
* is, and for notifying the front-end for responses we have produced and
* placed in the shared ring.
*/
/*
* FIXME shoud be evtchn_port_or_error_t, which is declared in
* xenctrl.h. Including xenctrl.h conflicts with xen_blkif.h.
*/
int port;
/**
* protocol (native, x86, or x64)
* Need to keep around? Replace with function pointer?
*/
int proto;
blkif_back_rings_t rings;
/**
* TODO Why 8 specifically?
* TODO Do we really need to keep it around?
*/
grant_ref_t ring_ref[8];
/**
* Number of pages in the ring that holds the request descriptors.
*/
unsigned int ring_n_pages;
/*
* Size of the ring, expressed in requests.
* TODO Do we really need to keep this around?
*/
int ring_size;
/**
* Intermediate requests. The array is managed as a stack, with n_reqs_free
* pointing to the top of the stack, at the next available intermediate
* request.
*/
struct td_xenblkif_req *reqs;
/**
* Stack pointer to the aforementioned stack.
*/
int n_reqs_free;
blkif_request_t **reqs_free;
/**
* Pointer to the actual VBD.
*/
struct td_vbd_handle *vbd;
/**
* stats
*/
struct td_xenblkif_stats stats;
stats_t vbd_stats;
struct {
/**
* Root directory of the stats.
*/
char *root;
/**
* Xenbus ring
*/
struct shm io_ring;
/**
* blkback-style stats. We keep all seven of them in a single file
* because keeping each one in a separate file requires an entire
* page because of mmap(2). The order is: ds_req, f_req, oo_req,
* rd_req, rd_sect, wr_req, and wr_sect.
*/
struct shm stats;
time_t last;
} xenvbd_stats;
/**
* Request buffer cache.
*/
void **reqs_bufcache;
unsigned n_reqs_bufcache_free;
event_id_t reqs_bufcache_evtid;
bool dead;
struct {
/**
* Pointer to he pending barrier request.
*/
blkif_request_t *msg;
/**
* Tells whether the write I/O part of a barrier request (if any) has
* completed.
*/
bool io_done;
/**
* I/O error code for the write I/O part of a barrier request (if any).
*/
int io_err;
} barrier;
event_id_t chkrng_event;
event_id_t stoppolling_event;
bool in_polling;
int poll_duration; /* microseconds; 0 means no polling. */
int poll_idle_threshold;
};
#define RING_DEBUG(blkif, fmt, args...) \
DPRINTF("%d/%d, ring=%p: "fmt, (blkif)->domid, (blkif)->devid, (blkif), \
##args);
#define RING_ERR(blkif, fmt, args...) \
EPRINTF("%d/%d, ring=%p: "fmt, (blkif)->domid, (blkif)->devid, (blkif), \
##args);
/* TODO rename from xenio */
#define tapdisk_xenio_for_each_ctx(_ctx) \
list_for_each_entry(_ctx, &_td_xenio_ctxs, entry)
/**
* Connects the tapdisk to the shared ring.
*
* @param domid the ID of the guest domain
* @param devid the device ID
* @param grefs the grant references
* @param order number of grant references
* @param port event channel port of the guest domain to use for ring
* notifications
* @param proto protocol (native, x86, or x64)
* @param poll_duration polling duration (microseconds; 0 means no polling)
* @param poll_idle_threshold CPU threshold above which we permit polling
* @param pool name of the context
* @param vbd the VBD
* @returns 0 on success
*/
int
tapdisk_xenblkif_connect(domid_t domid, int devid, const grant_ref_t * grefs,
int order, evtchn_port_t port, int proto, int poll_duration,
int poll_idle_threshold, const char *pool, td_vbd_t * vbd);
/**
* Disconnects the tapdisk from the shared ring.
*
* @param domid the domain ID of the guest domain
* @param devid the device ID of the VBD
*
* @returns 0 on success, or one of the following error codes:
* -ENODEV: no such domain and/or device
* -EBUSY: there are pending requests in the ring
* -ESHUTDOWN: there are pending requests and the VBD is paused
*/
int
tapdisk_xenblkif_disconnect(const domid_t domid, const int devid);
/**
* Destroys a XEN block interface.
*
* @param blkif the block interface to destroy
*/
int
tapdisk_xenblkif_destroy(struct td_xenblkif * blkif);
/**
* Searches all block interfaces in all contexts for a block interface
* having the specified domain and device ID. Dead block interfaces are
* ignored.
*
* @param domid the domain ID
* @param devid the device ID
* @returns a pointer to the block interface if found, else NULL
*/
struct td_xenblkif *
tapdisk_xenblkif_find(const domid_t domid, const int devid);
/**
* Updates ring stats.
*/
int
tapdisk_xenblkif_ring_stats_update(struct td_xenblkif *blkif);
/**
* Suspends the operation of the ring. NB the operation of the ring might
* have been already suspended.
*/
void
tapdisk_xenblkif_suspend(struct td_xenblkif * const blkif);
/**
* Resumes the operation of the ring.
*/
void
tapdisk_xenblkif_resume(struct td_xenblkif * const blkif);
/**
* Tells how many requests are pending.
*/
int
tapdisk_xenblkif_reqs_pending(const struct td_xenblkif * const blkif);
/**
* Schedules the cessation of polling.
*/
void
tapdisk_xenblkif_sched_stoppolling(const struct td_xenblkif *blkif);
/**
* Unschedules the cessation of polling.
*/
void
tapdisk_xenblkif_unsched_stoppolling(const struct td_xenblkif *blkif);
/**
* Start polling now.
*/
void
tapdisk_start_polling(struct td_xenblkif *blkif);
/**
* Schedules a ring check.
*/
void
tapdisk_xenblkif_sched_chkrng(const struct td_xenblkif *blkif);
/**
* Unschedules the ring check.
*/
void
tapdisk_xenblkif_unsched_chkrng(const struct td_xenblkif *blkif);
/**
* Tells whether a barrier request can be completed.
*/
bool
tapdisk_xenblkif_barrier_should_complete(
const struct td_xenblkif * const blkif);
#endif /* __TD_BLKIF_H__ */