osd_initiator.h 11 KB

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