dm-mpath-hp-sw.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * Copyright (C) 2005 Mike Christie, All rights reserved.
  3. * Copyright (C) 2007 Red Hat, Inc. All rights reserved.
  4. * Authors: Mike Christie
  5. * Dave Wysochanski
  6. *
  7. * This file is released under the GPL.
  8. *
  9. * This module implements the specific path activation code for
  10. * HP StorageWorks and FSC FibreCat Asymmetric (Active/Passive)
  11. * storage arrays.
  12. * These storage arrays have controller-based failover, not
  13. * LUN-based failover. However, LUN-based failover is the design
  14. * of dm-multipath. Thus, this module is written for LUN-based failover.
  15. */
  16. #include <linux/blkdev.h>
  17. #include <linux/list.h>
  18. #include <linux/types.h>
  19. #include <scsi/scsi.h>
  20. #include <scsi/scsi_cmnd.h>
  21. #include <scsi/scsi_dbg.h>
  22. #include "dm.h"
  23. #include "dm-hw-handler.h"
  24. #define DM_MSG_PREFIX "multipath hp-sw"
  25. #define DM_HP_HWH_NAME "hp-sw"
  26. #define DM_HP_HWH_VER "1.0.0"
  27. struct hp_sw_context {
  28. unsigned char sense[SCSI_SENSE_BUFFERSIZE];
  29. };
  30. /*
  31. * hp_sw_error_is_retryable - Is an HP-specific check condition retryable?
  32. * @req: path activation request
  33. *
  34. * Examine error codes of request and determine whether the error is retryable.
  35. * Some error codes are already retried by scsi-ml (see
  36. * scsi_decide_disposition), but some HP specific codes are not.
  37. * The intent of this routine is to supply the logic for the HP specific
  38. * check conditions.
  39. *
  40. * Returns:
  41. * 1 - command completed with retryable error
  42. * 0 - command completed with non-retryable error
  43. *
  44. * Possible optimizations
  45. * 1. More hardware-specific error codes
  46. */
  47. static int hp_sw_error_is_retryable(struct request *req)
  48. {
  49. /*
  50. * NOT_READY is known to be retryable
  51. * For now we just dump out the sense data and call it retryable
  52. */
  53. if (status_byte(req->errors) == CHECK_CONDITION)
  54. __scsi_print_sense(DM_HP_HWH_NAME, req->sense, req->sense_len);
  55. /*
  56. * At this point we don't have complete information about all the error
  57. * codes from this hardware, so we are just conservative and retry
  58. * when in doubt.
  59. */
  60. return 1;
  61. }
  62. /*
  63. * hp_sw_end_io - Completion handler for HP path activation.
  64. * @req: path activation request
  65. * @error: scsi-ml error
  66. *
  67. * Check sense data, free request structure, and notify dm that
  68. * pg initialization has completed.
  69. *
  70. * Context: scsi-ml softirq
  71. *
  72. */
  73. static void hp_sw_end_io(struct request *req, int error)
  74. {
  75. struct dm_path *path = req->end_io_data;
  76. unsigned err_flags = 0;
  77. if (!error) {
  78. DMDEBUG("%s path activation command - success",
  79. path->dev->name);
  80. goto out;
  81. }
  82. if (hp_sw_error_is_retryable(req)) {
  83. DMDEBUG("%s path activation command - retry",
  84. path->dev->name);
  85. err_flags = MP_RETRY;
  86. goto out;
  87. }
  88. DMWARN("%s path activation fail - error=0x%x",
  89. path->dev->name, error);
  90. err_flags = MP_FAIL_PATH;
  91. out:
  92. req->end_io_data = NULL;
  93. __blk_put_request(req->q, req);
  94. dm_pg_init_complete(path, err_flags);
  95. }
  96. /*
  97. * hp_sw_get_request - Allocate an HP specific path activation request
  98. * @path: path on which request will be sent (needed for request queue)
  99. *
  100. * The START command is used for path activation request.
  101. * These arrays are controller-based failover, not LUN based.
  102. * One START command issued to a single path will fail over all
  103. * LUNs for the same controller.
  104. *
  105. * Possible optimizations
  106. * 1. Make timeout configurable
  107. * 2. Preallocate request
  108. */
  109. static struct request *hp_sw_get_request(struct dm_path *path)
  110. {
  111. struct request *req;
  112. struct block_device *bdev = path->dev->bdev;
  113. struct request_queue *q = bdev_get_queue(bdev);
  114. struct hp_sw_context *h = path->hwhcontext;
  115. req = blk_get_request(q, WRITE, GFP_NOIO);
  116. if (!req)
  117. goto out;
  118. req->timeout = 60 * HZ;
  119. req->errors = 0;
  120. req->cmd_type = REQ_TYPE_BLOCK_PC;
  121. req->cmd_flags |= REQ_FAILFAST | REQ_NOMERGE;
  122. req->end_io_data = path;
  123. req->sense = h->sense;
  124. memset(req->sense, 0, SCSI_SENSE_BUFFERSIZE);
  125. memset(&req->cmd, 0, BLK_MAX_CDB);
  126. req->cmd[0] = START_STOP;
  127. req->cmd[4] = 1;
  128. req->cmd_len = COMMAND_SIZE(req->cmd[0]);
  129. out:
  130. return req;
  131. }
  132. /*
  133. * hp_sw_pg_init - HP path activation implementation.
  134. * @hwh: hardware handler specific data
  135. * @bypassed: unused; is the path group bypassed? (see dm-mpath.c)
  136. * @path: path to send initialization command
  137. *
  138. * Send an HP-specific path activation command on 'path'.
  139. * Do not try to optimize in any way, just send the activation command.
  140. * More than one path activation command may be sent to the same controller.
  141. * This seems to work fine for basic failover support.
  142. *
  143. * Possible optimizations
  144. * 1. Detect an in-progress activation request and avoid submitting another one
  145. * 2. Model the controller and only send a single activation request at a time
  146. * 3. Determine the state of a path before sending an activation request
  147. *
  148. * Context: kmpathd (see process_queued_ios() in dm-mpath.c)
  149. */
  150. static void hp_sw_pg_init(struct hw_handler *hwh, unsigned bypassed,
  151. struct dm_path *path)
  152. {
  153. struct request *req;
  154. struct hp_sw_context *h;
  155. path->hwhcontext = hwh->context;
  156. h = hwh->context;
  157. req = hp_sw_get_request(path);
  158. if (!req) {
  159. DMERR("%s path activation command - allocation fail",
  160. path->dev->name);
  161. goto retry;
  162. }
  163. DMDEBUG("%s path activation command - sent", path->dev->name);
  164. blk_execute_rq_nowait(req->q, NULL, req, 1, hp_sw_end_io);
  165. return;
  166. retry:
  167. dm_pg_init_complete(path, MP_RETRY);
  168. }
  169. static int hp_sw_create(struct hw_handler *hwh, unsigned argc, char **argv)
  170. {
  171. struct hp_sw_context *h;
  172. h = kmalloc(sizeof(*h), GFP_KERNEL);
  173. if (!h)
  174. return -ENOMEM;
  175. hwh->context = h;
  176. return 0;
  177. }
  178. static void hp_sw_destroy(struct hw_handler *hwh)
  179. {
  180. struct hp_sw_context *h = hwh->context;
  181. kfree(h);
  182. }
  183. static struct hw_handler_type hp_sw_hwh = {
  184. .name = DM_HP_HWH_NAME,
  185. .module = THIS_MODULE,
  186. .create = hp_sw_create,
  187. .destroy = hp_sw_destroy,
  188. .pg_init = hp_sw_pg_init,
  189. };
  190. static int __init hp_sw_init(void)
  191. {
  192. int r;
  193. r = dm_register_hw_handler(&hp_sw_hwh);
  194. if (r < 0)
  195. DMERR("register failed %d", r);
  196. else
  197. DMINFO("version " DM_HP_HWH_VER " loaded");
  198. return r;
  199. }
  200. static void __exit hp_sw_exit(void)
  201. {
  202. int r;
  203. r = dm_unregister_hw_handler(&hp_sw_hwh);
  204. if (r < 0)
  205. DMERR("unregister failed %d", r);
  206. }
  207. module_init(hp_sw_init);
  208. module_exit(hp_sw_exit);
  209. MODULE_DESCRIPTION("DM Multipath HP StorageWorks / FSC FibreCat (A/P) support");
  210. MODULE_AUTHOR("Mike Christie, Dave Wysochanski <dm-devel@redhat.com>");
  211. MODULE_LICENSE("GPL");
  212. MODULE_VERSION(DM_HP_HWH_VER);