osd_initiator.h 10 KB

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