]>
Commit | Line | Data |
---|---|---|
de258bf5 BH |
1 | /* |
2 | * osd_initiator.h - OSD initiator API definition | |
3 | * | |
4 | * Copyright (C) 2008 Panasas Inc. All rights reserved. | |
5 | * | |
6 | * Authors: | |
7 | * Boaz Harrosh <bharrosh@panasas.com> | |
8 | * Benny Halevy <bhalevy@panasas.com> | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License version 2 | |
12 | * | |
13 | */ | |
14 | #ifndef __OSD_INITIATOR_H__ | |
15 | #define __OSD_INITIATOR_H__ | |
16 | ||
17 | #include "osd_protocol.h" | |
18 | #include "osd_types.h" | |
19 | ||
20 | #include <linux/blkdev.h> | |
21 | ||
22 | /* Note: "NI" in comments below means "Not Implemented yet" */ | |
23 | ||
24 | /* | |
25 | * Object-based Storage Device. | |
26 | * This object represents an OSD device. | |
27 | * It is not a full linux device in any way. It is only | |
28 | * a place to hang resources associated with a Linux | |
29 | * request Q and some default properties. | |
30 | */ | |
31 | struct osd_dev { | |
32 | struct scsi_device *scsi_device; | |
33 | unsigned def_timeout; | |
34 | }; | |
35 | ||
36 | void osd_dev_init(struct osd_dev *od, struct scsi_device *scsi_device); | |
37 | void osd_dev_fini(struct osd_dev *od); | |
38 | ||
39 | struct osd_request; | |
40 | typedef void (osd_req_done_fn)(struct osd_request *or, void *private); | |
41 | ||
42 | struct osd_request { | |
43 | struct osd_cdb cdb; | |
44 | struct osd_data_out_integrity_info out_data_integ; | |
45 | struct osd_data_in_integrity_info in_data_integ; | |
46 | ||
47 | struct osd_dev *osd_dev; | |
48 | struct request *request; | |
49 | ||
50 | struct _osd_req_data_segment { | |
51 | void *buff; | |
52 | unsigned alloc_size; /* 0 here means: don't call kfree */ | |
53 | unsigned total_bytes; | |
54 | } set_attr, enc_get_attr, get_attr; | |
55 | ||
56 | struct _osd_io_info { | |
57 | struct bio *bio; | |
58 | u64 total_bytes; | |
59 | struct request *req; | |
60 | struct _osd_req_data_segment *last_seg; | |
61 | u8 *pad_buff; | |
62 | } out, in; | |
63 | ||
64 | gfp_t alloc_flags; | |
65 | unsigned timeout; | |
66 | unsigned retries; | |
67 | u8 sense[OSD_MAX_SENSE_LEN]; | |
68 | enum osd_attributes_mode attributes_mode; | |
69 | ||
70 | osd_req_done_fn *async_done; | |
71 | void *async_private; | |
72 | int async_error; | |
73 | }; | |
74 | ||
75 | /* | |
76 | * How to use the osd library: | |
77 | * | |
78 | * osd_start_request | |
79 | * Allocates a request. | |
80 | * | |
81 | * osd_req_* | |
82 | * Call one of, to encode the desired operation. | |
83 | * | |
84 | * osd_add_{get,set}_attr | |
85 | * Optionally add attributes to the CDB, list or page mode. | |
86 | * | |
87 | * osd_finalize_request | |
88 | * Computes final data out/in offsets and signs the request, | |
89 | * making it ready for execution. | |
90 | * | |
91 | * osd_execute_request | |
92 | * May be called to execute it through the block layer. Other wise submit | |
93 | * the associated block request in some other way. | |
94 | * | |
95 | * After execution: | |
96 | * osd_req_decode_sense | |
97 | * Decodes sense information to verify execution results. | |
98 | * | |
99 | * osd_req_decode_get_attr | |
100 | * Retrieve osd_add_get_attr_list() values if used. | |
101 | * | |
102 | * osd_end_request | |
103 | * Must be called to deallocate the request. | |
104 | */ | |
105 | ||
106 | /** | |
107 | * osd_start_request - Allocate and initialize an osd_request | |
108 | * | |
109 | * @osd_dev: OSD device that holds the scsi-device and default values | |
110 | * that the request is associated with. | |
111 | * @gfp: The allocation flags to use for request allocation, and all | |
112 | * subsequent allocations. This will be stored at | |
113 | * osd_request->alloc_flags, can be changed by user later | |
114 | * | |
115 | * Allocate osd_request and initialize all members to the | |
116 | * default/initial state. | |
117 | */ | |
118 | struct osd_request *osd_start_request(struct osd_dev *od, gfp_t gfp); | |
119 | ||
120 | enum osd_req_options { | |
121 | OSD_REQ_FUA = 0x08, /* Force Unit Access */ | |
122 | OSD_REQ_DPO = 0x10, /* Disable Page Out */ | |
123 | ||
124 | OSD_REQ_BYPASS_TIMESTAMPS = 0x80, | |
125 | }; | |
126 | ||
127 | /** | |
128 | * osd_finalize_request - Sign request and prepare request for execution | |
129 | * | |
130 | * @or: osd_request to prepare | |
131 | * @options: combination of osd_req_options bit flags or 0. | |
132 | * @cap: A Pointer to an OSD_CAP_LEN bytes buffer that is received from | |
133 | * The security manager as capabilities for this cdb. | |
134 | * @cap_key: The cryptographic key used to sign the cdb/data. Can be null | |
135 | * if NOSEC is used. | |
136 | * | |
137 | * The actual request and bios are only allocated here, so are the get_attr | |
138 | * buffers that will receive the returned attributes. Copy's @cap to cdb. | |
139 | * Sign the cdb/data with @cap_key. | |
140 | */ | |
141 | int osd_finalize_request(struct osd_request *or, | |
142 | u8 options, const void *cap, const u8 *cap_key); | |
143 | ||
144 | /** | |
145 | * osd_execute_request - Execute the request synchronously through block-layer | |
146 | * | |
147 | * @or: osd_request to Executed | |
148 | * | |
149 | * Calls blk_execute_rq to q the command and waits for completion. | |
150 | */ | |
151 | int osd_execute_request(struct osd_request *or); | |
152 | ||
153 | /** | |
154 | * osd_execute_request_async - Execute the request without waitting. | |
155 | * | |
156 | * @or: - osd_request to Executed | |
157 | * @done: (Optional) - Called at end of execution | |
158 | * @private: - Will be passed to @done function | |
159 | * | |
160 | * Calls blk_execute_rq_nowait to queue the command. When execution is done | |
161 | * optionally calls @done with @private as parameter. @or->async_error will | |
162 | * have the return code | |
163 | */ | |
164 | int osd_execute_request_async(struct osd_request *or, | |
165 | osd_req_done_fn *done, void *private); | |
166 | ||
167 | /** | |
168 | * osd_end_request - return osd_request to free store | |
169 | * | |
170 | * @or: osd_request to free | |
171 | * | |
172 | * Deallocate all osd_request resources (struct req's, BIOs, buffers, etc.) | |
173 | */ | |
174 | void osd_end_request(struct osd_request *or); | |
175 | ||
176 | /* | |
177 | * CDB Encoding | |
178 | * | |
179 | * Note: call only one of the following methods. | |
180 | */ | |
181 | ||
182 | /* | |
183 | * Device commands | |
184 | */ | |
185 | void osd_req_set_master_seed_xchg(struct osd_request *or, ...);/* NI */ | |
186 | void osd_req_set_master_key(struct osd_request *or, ...);/* NI */ | |
187 | ||
188 | void osd_req_format(struct osd_request *or, u64 tot_capacity); | |
189 | ||
190 | /* list all partitions | |
191 | * @list header must be initialized to zero on first run. | |
192 | * | |
193 | * Call osd_is_obj_list_done() to find if we got the complete list. | |
194 | */ | |
195 | int osd_req_list_dev_partitions(struct osd_request *or, | |
196 | osd_id initial_id, struct osd_obj_id_list *list, unsigned nelem); | |
197 | ||
198 | void osd_req_flush_obsd(struct osd_request *or, | |
199 | enum osd_options_flush_scope_values); | |
200 | ||
201 | void osd_req_perform_scsi_command(struct osd_request *or, | |
202 | const u8 *cdb, ...);/* NI */ | |
203 | void osd_req_task_management(struct osd_request *or, ...);/* NI */ | |
204 | ||
205 | /* | |
206 | * Partition commands | |
207 | */ | |
208 | void osd_req_create_partition(struct osd_request *or, osd_id partition); | |
209 | void osd_req_remove_partition(struct osd_request *or, osd_id partition); | |
210 | ||
211 | void osd_req_set_partition_key(struct osd_request *or, | |
212 | osd_id partition, u8 new_key_id[OSD_CRYPTO_KEYID_SIZE], | |
213 | u8 seed[OSD_CRYPTO_SEED_SIZE]);/* NI */ | |
214 | ||
215 | /* list all collections in the partition | |
216 | * @list header must be init to zero on first run. | |
217 | * | |
218 | * Call osd_is_obj_list_done() to find if we got the complete list. | |
219 | */ | |
220 | int osd_req_list_partition_collections(struct osd_request *or, | |
221 | osd_id partition, osd_id initial_id, struct osd_obj_id_list *list, | |
222 | unsigned nelem); | |
223 | ||
224 | /* list all objects in the partition | |
225 | * @list header must be init to zero on first run. | |
226 | * | |
227 | * Call osd_is_obj_list_done() to find if we got the complete list. | |
228 | */ | |
229 | int osd_req_list_partition_objects(struct osd_request *or, | |
230 | osd_id partition, osd_id initial_id, struct osd_obj_id_list *list, | |
231 | unsigned nelem); | |
232 | ||
233 | void osd_req_flush_partition(struct osd_request *or, | |
234 | osd_id partition, enum osd_options_flush_scope_values); | |
235 | ||
236 | /* | |
237 | * Collection commands | |
238 | */ | |
239 | void osd_req_create_collection(struct osd_request *or, | |
240 | const struct osd_obj_id *);/* NI */ | |
241 | void osd_req_remove_collection(struct osd_request *or, | |
242 | const struct osd_obj_id *);/* NI */ | |
243 | ||
244 | /* list all objects in the collection */ | |
245 | int osd_req_list_collection_objects(struct osd_request *or, | |
246 | const struct osd_obj_id *, osd_id initial_id, | |
247 | struct osd_obj_id_list *list, unsigned nelem); | |
248 | ||
249 | /* V2 only filtered list of objects in the collection */ | |
250 | void osd_req_query(struct osd_request *or, ...);/* NI */ | |
251 | ||
252 | void osd_req_flush_collection(struct osd_request *or, | |
253 | const struct osd_obj_id *, enum osd_options_flush_scope_values); | |
254 | ||
255 | void osd_req_get_member_attrs(struct osd_request *or, ...);/* V2-only NI */ | |
256 | void osd_req_set_member_attrs(struct osd_request *or, ...);/* V2-only NI */ | |
257 | ||
258 | /* | |
259 | * Object commands | |
260 | */ | |
261 | void osd_req_create_object(struct osd_request *or, struct osd_obj_id *); | |
262 | void osd_req_remove_object(struct osd_request *or, struct osd_obj_id *); | |
263 | ||
264 | void osd_req_write(struct osd_request *or, | |
265 | const struct osd_obj_id *, struct bio *data_out, u64 offset); | |
266 | void osd_req_append(struct osd_request *or, | |
267 | const struct osd_obj_id *, struct bio *data_out);/* NI */ | |
268 | void osd_req_create_write(struct osd_request *or, | |
269 | const struct osd_obj_id *, struct bio *data_out, u64 offset);/* NI */ | |
270 | void osd_req_clear(struct osd_request *or, | |
271 | const struct osd_obj_id *, u64 offset, u64 len);/* NI */ | |
272 | void osd_req_punch(struct osd_request *or, | |
273 | const struct osd_obj_id *, u64 offset, u64 len);/* V2-only NI */ | |
274 | ||
275 | void osd_req_flush_object(struct osd_request *or, | |
276 | const struct osd_obj_id *, enum osd_options_flush_scope_values, | |
277 | /*V2*/ u64 offset, /*V2*/ u64 len); | |
278 | ||
279 | void osd_req_read(struct osd_request *or, | |
280 | const struct osd_obj_id *, struct bio *data_in, u64 offset); | |
281 | ||
282 | /* | |
283 | * Root/Partition/Collection/Object Attributes commands | |
284 | */ | |
285 | ||
286 | /* get before set */ | |
287 | void osd_req_get_attributes(struct osd_request *or, const struct osd_obj_id *); | |
288 | ||
289 | /* set before get */ | |
290 | void osd_req_set_attributes(struct osd_request *or, const struct osd_obj_id *); | |
291 | ||
292 | /* | |
293 | * Attributes appended to most commands | |
294 | */ | |
295 | ||
296 | /* Attributes List mode (or V2 CDB) */ | |
297 | /* | |
298 | * TODO: In ver2 if at finalize time only one attr was set and no gets, | |
299 | * then the Attributes CDB mode is used automatically to save IO. | |
300 | */ | |
301 | ||
302 | /* set a list of attributes. */ | |
303 | int osd_req_add_set_attr_list(struct osd_request *or, | |
304 | const struct osd_attr *, unsigned nelem); | |
305 | ||
306 | /* get a list of attributes */ | |
307 | int osd_req_add_get_attr_list(struct osd_request *or, | |
308 | const struct osd_attr *, unsigned nelem); | |
309 | ||
310 | /* | |
311 | * Attributes list decoding | |
312 | * Must be called after osd_request.request was executed | |
313 | * It is called in a loop to decode the returned get_attr | |
314 | * (see osd_add_get_attr) | |
315 | */ | |
316 | int osd_req_decode_get_attr_list(struct osd_request *or, | |
317 | struct osd_attr *, int *nelem, void **iterator); | |
318 | ||
319 | /* Attributes Page mode */ | |
320 | ||
321 | /* | |
322 | * Read an attribute page and optionally set one attribute | |
323 | * | |
324 | * Retrieves the attribute page directly to a user buffer. | |
325 | * @attr_page_data shall stay valid until end of execution. | |
326 | * See osd_attributes.h for common page structures | |
327 | */ | |
328 | int osd_req_add_get_attr_page(struct osd_request *or, | |
329 | u32 page_id, void *attr_page_data, unsigned max_page_len, | |
330 | const struct osd_attr *set_one); | |
331 | ||
332 | #endif /* __OSD_LIB_H__ */ |