osd_initiator.h 9.9 KB

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