2 * osd_initiator.h - OSD initiator API definition
4 * Copyright (C) 2008 Panasas Inc. All rights reserved.
7 * Boaz Harrosh <bharrosh@panasas.com>
8 * Benny Halevy <bhalevy@panasas.com>
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
14 #ifndef __OSD_INITIATOR_H__
15 #define __OSD_INITIATOR_H__
17 #include "osd_protocol.h"
18 #include "osd_types.h"
20 #include <linux/blkdev.h>
22 /* Note: "NI" in comments below means "Not Implemented yet" */
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.
32 struct scsi_device *scsi_device;
36 /* Add/remove test ioctls from external modules */
37 typedef int (do_test_fn)(struct osd_dev *od, unsigned cmd, unsigned long arg);
38 int osduld_register_test(unsigned ioctl, do_test_fn *do_test);
39 void osduld_unregister_test(unsigned ioctl);
41 /* These are called by uld at probe time */
42 void osd_dev_init(struct osd_dev *od, struct scsi_device *scsi_device);
43 void osd_dev_fini(struct osd_dev *od);
46 typedef void (osd_req_done_fn)(struct osd_request *or, void *private);
50 struct osd_data_out_integrity_info out_data_integ;
51 struct osd_data_in_integrity_info in_data_integ;
53 struct osd_dev *osd_dev;
54 struct request *request;
56 struct _osd_req_data_segment {
58 unsigned alloc_size; /* 0 here means: don't call kfree */
60 } set_attr, enc_get_attr, get_attr;
66 struct _osd_req_data_segment *last_seg;
73 u8 sense[OSD_MAX_SENSE_LEN];
74 enum osd_attributes_mode attributes_mode;
76 osd_req_done_fn *async_done;
82 * How to use the osd library:
85 * Allocates a request.
88 * Call one of, to encode the desired operation.
90 * osd_add_{get,set}_attr
91 * Optionally add attributes to the CDB, list or page mode.
93 * osd_finalize_request
94 * Computes final data out/in offsets and signs the request,
95 * making it ready for execution.
98 * May be called to execute it through the block layer. Other wise submit
99 * the associated block request in some other way.
102 * osd_req_decode_sense
103 * Decodes sense information to verify execution results.
105 * osd_req_decode_get_attr
106 * Retrieve osd_add_get_attr_list() values if used.
109 * Must be called to deallocate the request.
113 * osd_start_request - Allocate and initialize an osd_request
115 * @osd_dev: OSD device that holds the scsi-device and default values
116 * that the request is associated with.
117 * @gfp: The allocation flags to use for request allocation, and all
118 * subsequent allocations. This will be stored at
119 * osd_request->alloc_flags, can be changed by user later
121 * Allocate osd_request and initialize all members to the
122 * default/initial state.
124 struct osd_request *osd_start_request(struct osd_dev *od, gfp_t gfp);
126 enum osd_req_options {
127 OSD_REQ_FUA = 0x08, /* Force Unit Access */
128 OSD_REQ_DPO = 0x10, /* Disable Page Out */
130 OSD_REQ_BYPASS_TIMESTAMPS = 0x80,
134 * osd_finalize_request - Sign request and prepare request for execution
136 * @or: osd_request to prepare
137 * @options: combination of osd_req_options bit flags or 0.
138 * @cap: A Pointer to an OSD_CAP_LEN bytes buffer that is received from
139 * The security manager as capabilities for this cdb.
140 * @cap_key: The cryptographic key used to sign the cdb/data. Can be null
143 * The actual request and bios are only allocated here, so are the get_attr
144 * buffers that will receive the returned attributes. Copy's @cap to cdb.
145 * Sign the cdb/data with @cap_key.
147 int osd_finalize_request(struct osd_request *or,
148 u8 options, const void *cap, const u8 *cap_key);
151 * osd_execute_request - Execute the request synchronously through block-layer
153 * @or: osd_request to Executed
155 * Calls blk_execute_rq to q the command and waits for completion.
157 int osd_execute_request(struct osd_request *or);
160 * osd_execute_request_async - Execute the request without waitting.
162 * @or: - osd_request to Executed
163 * @done: (Optional) - Called at end of execution
164 * @private: - Will be passed to @done function
166 * Calls blk_execute_rq_nowait to queue the command. When execution is done
167 * optionally calls @done with @private as parameter. @or->async_error will
168 * have the return code
170 int osd_execute_request_async(struct osd_request *or,
171 osd_req_done_fn *done, void *private);
174 * osd_end_request - return osd_request to free store
176 * @or: osd_request to free
178 * Deallocate all osd_request resources (struct req's, BIOs, buffers, etc.)
180 void osd_end_request(struct osd_request *or);
185 * Note: call only one of the following methods.
191 void osd_req_set_master_seed_xchg(struct osd_request *or, ...);/* NI */
192 void osd_req_set_master_key(struct osd_request *or, ...);/* NI */
194 void osd_req_format(struct osd_request *or, u64 tot_capacity);
196 /* list all partitions
197 * @list header must be initialized to zero on first run.
199 * Call osd_is_obj_list_done() to find if we got the complete list.
201 int osd_req_list_dev_partitions(struct osd_request *or,
202 osd_id initial_id, struct osd_obj_id_list *list, unsigned nelem);
204 void osd_req_flush_obsd(struct osd_request *or,
205 enum osd_options_flush_scope_values);
207 void osd_req_perform_scsi_command(struct osd_request *or,
208 const u8 *cdb, ...);/* NI */
209 void osd_req_task_management(struct osd_request *or, ...);/* NI */
214 void osd_req_create_partition(struct osd_request *or, osd_id partition);
215 void osd_req_remove_partition(struct osd_request *or, osd_id partition);
217 void osd_req_set_partition_key(struct osd_request *or,
218 osd_id partition, u8 new_key_id[OSD_CRYPTO_KEYID_SIZE],
219 u8 seed[OSD_CRYPTO_SEED_SIZE]);/* NI */
221 /* list all collections in the partition
222 * @list header must be init to zero on first run.
224 * Call osd_is_obj_list_done() to find if we got the complete list.
226 int osd_req_list_partition_collections(struct osd_request *or,
227 osd_id partition, osd_id initial_id, struct osd_obj_id_list *list,
230 /* list all objects in the partition
231 * @list header must be init to zero on first run.
233 * Call osd_is_obj_list_done() to find if we got the complete list.
235 int osd_req_list_partition_objects(struct osd_request *or,
236 osd_id partition, osd_id initial_id, struct osd_obj_id_list *list,
239 void osd_req_flush_partition(struct osd_request *or,
240 osd_id partition, enum osd_options_flush_scope_values);
243 * Collection commands
245 void osd_req_create_collection(struct osd_request *or,
246 const struct osd_obj_id *);/* NI */
247 void osd_req_remove_collection(struct osd_request *or,
248 const struct osd_obj_id *);/* NI */
250 /* list all objects in the collection */
251 int osd_req_list_collection_objects(struct osd_request *or,
252 const struct osd_obj_id *, osd_id initial_id,
253 struct osd_obj_id_list *list, unsigned nelem);
255 /* V2 only filtered list of objects in the collection */
256 void osd_req_query(struct osd_request *or, ...);/* NI */
258 void osd_req_flush_collection(struct osd_request *or,
259 const struct osd_obj_id *, enum osd_options_flush_scope_values);
261 void osd_req_get_member_attrs(struct osd_request *or, ...);/* V2-only NI */
262 void osd_req_set_member_attrs(struct osd_request *or, ...);/* V2-only NI */
267 void osd_req_create_object(struct osd_request *or, struct osd_obj_id *);
268 void osd_req_remove_object(struct osd_request *or, struct osd_obj_id *);
270 void osd_req_write(struct osd_request *or,
271 const struct osd_obj_id *, struct bio *data_out, u64 offset);
272 void osd_req_append(struct osd_request *or,
273 const struct osd_obj_id *, struct bio *data_out);/* NI */
274 void osd_req_create_write(struct osd_request *or,
275 const struct osd_obj_id *, struct bio *data_out, u64 offset);/* NI */
276 void osd_req_clear(struct osd_request *or,
277 const struct osd_obj_id *, u64 offset, u64 len);/* NI */
278 void osd_req_punch(struct osd_request *or,
279 const struct osd_obj_id *, u64 offset, u64 len);/* V2-only NI */
281 void osd_req_flush_object(struct osd_request *or,
282 const struct osd_obj_id *, enum osd_options_flush_scope_values,
283 /*V2*/ u64 offset, /*V2*/ u64 len);
285 void osd_req_read(struct osd_request *or,
286 const struct osd_obj_id *, struct bio *data_in, u64 offset);
289 * Root/Partition/Collection/Object Attributes commands
293 void osd_req_get_attributes(struct osd_request *or, const struct osd_obj_id *);
296 void osd_req_set_attributes(struct osd_request *or, const struct osd_obj_id *);
299 * Attributes appended to most commands
302 /* Attributes List mode (or V2 CDB) */
304 * TODO: In ver2 if at finalize time only one attr was set and no gets,
305 * then the Attributes CDB mode is used automatically to save IO.
308 /* set a list of attributes. */
309 int osd_req_add_set_attr_list(struct osd_request *or,
310 const struct osd_attr *, unsigned nelem);
312 /* get a list of attributes */
313 int osd_req_add_get_attr_list(struct osd_request *or,
314 const struct osd_attr *, unsigned nelem);
317 * Attributes list decoding
318 * Must be called after osd_request.request was executed
319 * It is called in a loop to decode the returned get_attr
320 * (see osd_add_get_attr)
322 int osd_req_decode_get_attr_list(struct osd_request *or,
323 struct osd_attr *, int *nelem, void **iterator);
325 /* Attributes Page mode */
328 * Read an attribute page and optionally set one attribute
330 * Retrieves the attribute page directly to a user buffer.
331 * @attr_page_data shall stay valid until end of execution.
332 * See osd_attributes.h for common page structures
334 int osd_req_add_get_attr_page(struct osd_request *or,
335 u32 page_id, void *attr_page_data, unsigned max_page_len,
336 const struct osd_attr *set_one);
338 #endif /* __OSD_LIB_H__ */