mpath_persist.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /* version - 1.0 */
  2. #ifndef MPATH_PERSIST_LIB_H
  3. #define MPATH_PERSIST_LIB_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #include <inttypes.h>
  8. #define MPATH_MAX_PARAM_LEN 8192
  9. #define MPATH_MX_TIDS 32 /* Max number of transport ids"*/
  10. #define MPATH_MX_TID_LEN 256 /* Max length of transport id */
  11. /* PRIN Service Actions */
  12. #define MPATH_PRIN_RKEY_SA 0x00 /* READ KEYS SA*/
  13. #define MPATH_PRIN_RRES_SA 0x01 /* READ RESERVATION SA*/
  14. #define MPATH_PRIN_RCAP_SA 0x02 /* REPORT CAPABILITIES SA*/
  15. #define MPATH_PRIN_RFSTAT_SA 0x03 /* READ FULL STATUS SA*/
  16. /* PROUT Service Actions */
  17. #define MPATH_PROUT_REG_SA 0x00 /* REGISTER SA */
  18. #define MPATH_PROUT_RES_SA 0x01 /* RESERVE SA*/
  19. #define MPATH_PROUT_REL_SA 0x02 /* RELEASE SA*/
  20. #define MPATH_PROUT_CLEAR_SA 0x03 /* CLEAR SA*/
  21. #define MPATH_PROUT_PREE_SA 0x04 /* PREEMPT SA*/
  22. #define MPATH_PROUT_PREE_AB_SA 0x05 /* PREEMPT AND ABORT SA*/
  23. #define MPATH_PROUT_REG_IGN_SA 0x06 /* REGISTER AND IGNORE EXISTING KEY SA*/
  24. #define MPATH_PROUT_REG_MOV_SA 0x07 /* REGISTER AND MOVE SA*/
  25. #define MPATH_LU_SCOPE 0x00 /* LU_SCOPE */
  26. /* Persistent reservations type */
  27. #define MPATH_PRTPE_WE 0x01 /* Write Exclusive */
  28. #define MPATH_PRTPE_EA 0x03 /* Exclusive Access*/
  29. #define MPATH_PRTPE_WE_RO 0x05 /* WriteExclusive Registrants Only */
  30. #define MPATH_PRTPE_EA_RO 0x06 /* Exclusive Access. Registrants Only*/
  31. #define MPATH_PRTPE_WE_AR 0x07 /* Write Exclusive. All Registrants*/
  32. #define MPATH_PRTPE_EA_AR 0x08 /* Exclusive Access. All Registrants */
  33. /* PR RETURN_STATUS */
  34. #define MPATH_PR_SKIP -1 /* skipping this path */
  35. #define MPATH_PR_SUCCESS 0
  36. #define MPATH_PR_SYNTAX_ERROR 1 /* syntax error or invalid parameter */
  37. /* status for check condition */
  38. #define MPATH_PR_SENSE_NOT_READY 2 /* [sk,asc,ascq: 0x2,*,*] */
  39. #define MPATH_PR_SENSE_MEDIUM_ERROR 3 /* [sk,asc,ascq: 0x3,*,*] */
  40. #define MPATH_PR_SENSE_HARDWARE_ERROR 4 /* [sk,asc,ascq: 0x4,*,*] */
  41. #define MPATH_PR_ILLEGAL_REQ 5 /* [sk,asc,ascq: 0x5,*,*]*/
  42. #define MPATH_PR_SENSE_UNIT_ATTENTION 6 /* [sk,asc,ascq: 0x6,*,*] */
  43. #define MPATH_PR_SENSE_INVALID_OP 7 /* [sk,asc,ascq: 0x5,0x20,0x0]*/
  44. #define MPATH_PR_SENSE_ABORTED_COMMAND 8 /* [sk,asc,ascq: 0xb,*,*] */
  45. #define MPATH_PR_NO_SENSE 9 /* [sk,asc,ascq: 0x0,*,*] */
  46. #define MPATH_PR_SENSE_MALFORMED 10 /* Response to SCSI command malformed */
  47. #define MPATH_PR_RESERV_CONFLICT 11 /* Reservation conflict on the device */
  48. #define MPATH_PR_FILE_ERROR 12 /* file (device node) problems(e.g. not found)*/
  49. #define MPATH_PR_DMMP_ERROR 13 /* DMMP related error.(e.g Error in getting dm info */
  50. #define MPATH_PR_THREAD_ERROR 14 /* pthreads error (e.g. unable to create new thread) */
  51. #define MPATH_PR_OTHER 15 /*other error/warning has occurred(transport
  52. or driver error) */
  53. /* PR MASK */
  54. #define MPATH_F_APTPL_MASK 0x01 /* APTPL MASK*/
  55. #define MPATH_F_ALL_TG_PT_MASK 0x04 /* ALL_TG_PT MASK*/
  56. #define MPATH_F_SPEC_I_PT_MASK 0x08 /* SPEC_I_PT MASK*/
  57. #define MPATH_PR_TYPE_MASK 0x0f /* TYPE MASK*/
  58. #define MPATH_PR_SCOPE_MASK 0xf0 /* SCOPE MASK*/
  59. /*Transport ID PROTOCOL IDENTIFIER values */
  60. #define MPATH_PROTOCOL_ID_FC 0x00
  61. #define MPATH_PROTOCOL_ID_ISCSI 0x05
  62. #define MPATH_PROTOCOL_ID_SAS 0x06
  63. /*Transport ID FORMATE CODE */
  64. #define MPATH_WWUI_DEVICE_NAME 0x00 /* World wide unique initiator device name */
  65. #define MPATH_WWUI_PORT_IDENTIFIER 0x40 /* World wide unique initiator port identifier */
  66. extern unsigned int mpath_mx_alloc_len;
  67. struct prin_readdescr
  68. {
  69. uint32_t prgeneration;
  70. uint32_t additional_length; /* The value should be either 0 or divisible by 8.
  71. 0 indicates no registered reservation key. */
  72. uint8_t key_list[MPATH_MAX_PARAM_LEN];
  73. };
  74. struct prin_resvdescr
  75. {
  76. uint32_t prgeneration;
  77. uint32_t additional_length; /* The value should be either 0 or 10h. 0 indicates
  78. there is no reservation held. 10h indicates the
  79. key[8] and scope_type have valid values */
  80. uint8_t key[8];
  81. uint32_t _obsolete;
  82. uint8_t _reserved;
  83. uint8_t scope_type; /* Use PR SCOPE AND TYPE MASK specified above */
  84. uint16_t _obsolete1;
  85. };
  86. struct prin_capdescr
  87. {
  88. uint16_t length;
  89. uint8_t flags[2];
  90. uint16_t pr_type_mask;
  91. uint16_t _reserved;
  92. };
  93. struct transportid
  94. {
  95. uint8_t format_code;
  96. uint8_t protocol_id;
  97. union {
  98. uint8_t n_port_name[8]; /* FC transport*/
  99. uint8_t sas_address[8]; /* SAS transport */
  100. uint8_t iscsi_name[256]; /* ISCSI transport */
  101. };
  102. };
  103. struct prin_fulldescr
  104. {
  105. uint8_t key[8];
  106. uint8_t flag; /* All_tg_pt and reservation holder */
  107. uint8_t scope_type; /* Use PR SCOPE AND TYPE MASK specified above.
  108. Meaningful only for reservation holder */
  109. uint16_t rtpi;
  110. struct transportid trnptid;
  111. };
  112. struct print_fulldescr_list
  113. {
  114. uint32_t prgeneration;
  115. uint32_t number_of_descriptor;
  116. uint8_t private_buffer[MPATH_MAX_PARAM_LEN]; /*Private buffer for list storage*/
  117. struct prin_fulldescr *descriptors[];
  118. };
  119. struct prin_resp
  120. {
  121. union
  122. {
  123. struct prin_readdescr prin_readkeys; /* for PRIN read keys SA*/
  124. struct prin_resvdescr prin_readresv; /* for PRIN read reservation SA*/
  125. struct prin_capdescr prin_readcap; /* for PRIN Report Capabilities SA*/
  126. struct print_fulldescr_list prin_readfd; /* for PRIN read full status SA*/
  127. }prin_descriptor;
  128. };
  129. struct prout_param_descriptor { /* PROUT parameter descriptor */
  130. uint8_t key[8];
  131. uint8_t sa_key[8];
  132. uint32_t _obsolete;
  133. uint8_t sa_flags;
  134. uint8_t _reserved;
  135. uint16_t _obsolete1;
  136. uint8_t private_buffer[MPATH_MAX_PARAM_LEN]; /*private buffer for list storage*/
  137. uint32_t num_transportid; /* Number of Transport ID listed in trnptid_list[]*/
  138. struct transportid *trnptid_list[];
  139. };
  140. /* Function declarations */
  141. /*
  142. * DESCRIPTION :
  143. * Initialize device mapper multipath configuration. This function must be invoked first
  144. * before performing reservation management functions.
  145. * RESTRICTIONS:
  146. *
  147. * RETURNS: struct config ->Success, NULL->Failed.
  148. */
  149. extern struct config * mpath_lib_init (void);
  150. /*
  151. * DESCRIPTION :
  152. * Release device mapper multipath configuration. This function must be invoked after
  153. * performing reservation management functions.
  154. * RESTRICTIONS:
  155. *
  156. * RETURNS: 0->Success, 1->Failed.
  157. */
  158. extern int mpath_lib_exit (struct config *conf);
  159. /*
  160. * DESCRIPTION :
  161. * This function sends PRIN command to the DM device and get the response.
  162. *
  163. * @fd: The file descriptor of a multipath device. Input argument.
  164. * @rq_servact: PRIN command service action. Input argument
  165. * @resp: The response from PRIN service action. The resp is a struct specified above. The caller should
  166. * manage the memory allocation of this struct
  167. * @noisy: Turn on debugging trace: Input argument. 0->Disable, 1->Enable
  168. * @verbose: Set verbosity level. Input argument. value:[0-3]. 0->disabled, 3->Max verbose
  169. *
  170. * RESTRICTIONS:
  171. *
  172. * RETURNS: MPATH_PR_SUCCESS if PR command successful else returns any of the status specified
  173. * above in RETURN_STATUS.
  174. *
  175. */
  176. extern int mpath_persistent_reserve_in (int fd, int rq_servact, struct prin_resp *resp,
  177. int noisy, int verbose);
  178. /*
  179. * DESCRIPTION :
  180. * This function is like mpath_persistent_reserve_in(), except that it doesn't call
  181. * mpath_persistent_reserve_init_vecs() and mpath_persistent_reserve_free_vecs()
  182. * before and after the actual PR call.
  183. */
  184. extern int __mpath_persistent_reserve_in(int fd, int rq_servact,
  185. struct prin_resp *resp, int noisy);
  186. /*
  187. * DESCRIPTION :
  188. * This function sends PROUT command to the DM device and get the response.
  189. *
  190. * @fd: The file descriptor of a multipath device. Input argument.
  191. * @rq_servact: PROUT command service action. Input argument
  192. * @rq_scope: Persistent reservation scope. The value should be always LU_SCOPE (0h).
  193. * @rq_type: Persistent reservation type. The valid values of persistent reservation types are
  194. * 5h (Write exclusive - registrants only)
  195. * 6h (Exclusive access - registrants only)
  196. * 7h (Write exclusive - All registrants)
  197. * 8h (Exclusive access - All registrants).
  198. * @paramp: PROUT command parameter data. The paramp is a struct which describes PROUT
  199. * parameter list. The caller should manage the memory allocation of this struct.
  200. * @noisy: Turn on debugging trace: Input argument.0->Disable, 1->Enable.
  201. * @verbose: Set verbosity level. Input argument. value:0 to 3. 0->disabled, 3->Max verbose
  202. *
  203. * RESTRICTIONS:
  204. *
  205. * RETURNS: MPATH_PR_SUCCESS if PR command successful else returns any of the status specified
  206. * above in RETURN_STATUS.
  207. */
  208. extern int mpath_persistent_reserve_out ( int fd, int rq_servact, int rq_scope,
  209. unsigned int rq_type, struct prout_param_descriptor *paramp, int noisy,
  210. int verbose);
  211. /*
  212. * DESCRIPTION :
  213. * This function is like mpath_persistent_reserve_out(), except that it doesn't call
  214. * mpath_persistent_reserve_init_vecs() and mpath_persistent_reserve_free_vecs()
  215. * before and after the actual PR call.
  216. */
  217. extern int __mpath_persistent_reserve_out( int fd, int rq_servact, int rq_scope,
  218. unsigned int rq_type, struct prout_param_descriptor *paramp,
  219. int noisy);
  220. /*
  221. * DESCRIPTION :
  222. * This function allocates data structures and performs basic initialization and
  223. * device discovery for later calls of __mpath_persistent_reserve_in() or
  224. * __mpath_persistent_reserve_out().
  225. * @verbose: Set verbosity level. Input argument. value:0 to 3. 0->disabled, 3->Max verbose
  226. *
  227. * RESTRICTIONS:
  228. *
  229. * RETURNS: MPATH_PR_SUCCESS if successful else returns any of the status specified
  230. * above in RETURN_STATUS.
  231. */
  232. int mpath_persistent_reserve_init_vecs(int verbose);
  233. /*
  234. * DESCRIPTION :
  235. * This function frees data structures allocated by
  236. * mpath_persistent_reserve_init_vecs().
  237. */
  238. void mpath_persistent_reserve_free_vecs(void);
  239. #ifdef __cplusplus
  240. }
  241. #endif
  242. #endif /*MPATH_PERSIST_LIB_H*/