scsi_dh_alua.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  1. /*
  2. * Generic SCSI-3 ALUA SCSI Device Handler
  3. *
  4. * Copyright (C) 2007-2010 Hannes Reinecke, SUSE Linux Products GmbH.
  5. * All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. *
  21. */
  22. #include <linux/slab.h>
  23. #include <linux/delay.h>
  24. #include <linux/module.h>
  25. #include <asm/unaligned.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_proto.h>
  28. #include <scsi/scsi_dbg.h>
  29. #include <scsi/scsi_eh.h>
  30. #include <scsi/scsi_dh.h>
  31. #define ALUA_DH_NAME "alua"
  32. #define ALUA_DH_VER "2.0"
  33. #define TPGS_SUPPORT_NONE 0x00
  34. #define TPGS_SUPPORT_OPTIMIZED 0x01
  35. #define TPGS_SUPPORT_NONOPTIMIZED 0x02
  36. #define TPGS_SUPPORT_STANDBY 0x04
  37. #define TPGS_SUPPORT_UNAVAILABLE 0x08
  38. #define TPGS_SUPPORT_LBA_DEPENDENT 0x10
  39. #define TPGS_SUPPORT_OFFLINE 0x40
  40. #define TPGS_SUPPORT_TRANSITION 0x80
  41. #define RTPG_FMT_MASK 0x70
  42. #define RTPG_FMT_EXT_HDR 0x10
  43. #define TPGS_MODE_UNINITIALIZED -1
  44. #define TPGS_MODE_NONE 0x0
  45. #define TPGS_MODE_IMPLICIT 0x1
  46. #define TPGS_MODE_EXPLICIT 0x2
  47. #define ALUA_RTPG_SIZE 128
  48. #define ALUA_FAILOVER_TIMEOUT 60
  49. #define ALUA_FAILOVER_RETRIES 5
  50. #define ALUA_RTPG_DELAY_MSECS 5
  51. /* device handler flags */
  52. #define ALUA_OPTIMIZE_STPG 0x01
  53. #define ALUA_RTPG_EXT_HDR_UNSUPP 0x02
  54. #define ALUA_SYNC_STPG 0x04
  55. /* State machine flags */
  56. #define ALUA_PG_RUN_RTPG 0x10
  57. #define ALUA_PG_RUN_STPG 0x20
  58. #define ALUA_PG_RUNNING 0x40
  59. static uint optimize_stpg;
  60. module_param(optimize_stpg, uint, S_IRUGO|S_IWUSR);
  61. MODULE_PARM_DESC(optimize_stpg, "Allow use of a non-optimized path, rather than sending a STPG, when implicit TPGS is supported (0=No,1=Yes). Default is 0.");
  62. static LIST_HEAD(port_group_list);
  63. static DEFINE_SPINLOCK(port_group_lock);
  64. static struct workqueue_struct *kaluad_wq;
  65. static struct workqueue_struct *kaluad_sync_wq;
  66. struct alua_port_group {
  67. struct kref kref;
  68. struct rcu_head rcu;
  69. struct list_head node;
  70. struct list_head dh_list;
  71. unsigned char device_id_str[256];
  72. int device_id_len;
  73. int group_id;
  74. int tpgs;
  75. int state;
  76. int pref;
  77. unsigned flags; /* used for optimizing STPG */
  78. unsigned char transition_tmo;
  79. unsigned long expiry;
  80. unsigned long interval;
  81. struct delayed_work rtpg_work;
  82. spinlock_t lock;
  83. struct list_head rtpg_list;
  84. struct scsi_device *rtpg_sdev;
  85. };
  86. struct alua_dh_data {
  87. struct list_head node;
  88. struct alua_port_group *pg;
  89. int group_id;
  90. spinlock_t pg_lock;
  91. struct scsi_device *sdev;
  92. int init_error;
  93. struct mutex init_mutex;
  94. };
  95. struct alua_queue_data {
  96. struct list_head entry;
  97. activate_complete callback_fn;
  98. void *callback_data;
  99. };
  100. #define ALUA_POLICY_SWITCH_CURRENT 0
  101. #define ALUA_POLICY_SWITCH_ALL 1
  102. static void alua_rtpg_work(struct work_struct *work);
  103. static bool alua_rtpg_queue(struct alua_port_group *pg,
  104. struct scsi_device *sdev,
  105. struct alua_queue_data *qdata, bool force);
  106. static void alua_check(struct scsi_device *sdev, bool force);
  107. static void release_port_group(struct kref *kref)
  108. {
  109. struct alua_port_group *pg;
  110. pg = container_of(kref, struct alua_port_group, kref);
  111. if (pg->rtpg_sdev)
  112. flush_delayed_work(&pg->rtpg_work);
  113. spin_lock(&port_group_lock);
  114. list_del(&pg->node);
  115. spin_unlock(&port_group_lock);
  116. kfree_rcu(pg, rcu);
  117. }
  118. /*
  119. * submit_rtpg - Issue a REPORT TARGET GROUP STATES command
  120. * @sdev: sdev the command should be sent to
  121. */
  122. static int submit_rtpg(struct scsi_device *sdev, unsigned char *buff,
  123. int bufflen, struct scsi_sense_hdr *sshdr, int flags)
  124. {
  125. u8 cdb[COMMAND_SIZE(MAINTENANCE_IN)];
  126. int req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
  127. REQ_FAILFAST_DRIVER;
  128. /* Prepare the command. */
  129. memset(cdb, 0x0, COMMAND_SIZE(MAINTENANCE_IN));
  130. cdb[0] = MAINTENANCE_IN;
  131. if (!(flags & ALUA_RTPG_EXT_HDR_UNSUPP))
  132. cdb[1] = MI_REPORT_TARGET_PGS | MI_EXT_HDR_PARAM_FMT;
  133. else
  134. cdb[1] = MI_REPORT_TARGET_PGS;
  135. put_unaligned_be32(bufflen, &cdb[6]);
  136. return scsi_execute_req_flags(sdev, cdb, DMA_FROM_DEVICE,
  137. buff, bufflen, sshdr,
  138. ALUA_FAILOVER_TIMEOUT * HZ,
  139. ALUA_FAILOVER_RETRIES, NULL, req_flags);
  140. }
  141. /*
  142. * submit_stpg - Issue a SET TARGET PORT GROUP command
  143. *
  144. * Currently we're only setting the current target port group state
  145. * to 'active/optimized' and let the array firmware figure out
  146. * the states of the remaining groups.
  147. */
  148. static int submit_stpg(struct scsi_device *sdev, int group_id,
  149. struct scsi_sense_hdr *sshdr)
  150. {
  151. u8 cdb[COMMAND_SIZE(MAINTENANCE_OUT)];
  152. unsigned char stpg_data[8];
  153. int stpg_len = 8;
  154. int req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
  155. REQ_FAILFAST_DRIVER;
  156. /* Prepare the data buffer */
  157. memset(stpg_data, 0, stpg_len);
  158. stpg_data[4] = SCSI_ACCESS_STATE_OPTIMAL;
  159. put_unaligned_be16(group_id, &stpg_data[6]);
  160. /* Prepare the command. */
  161. memset(cdb, 0x0, COMMAND_SIZE(MAINTENANCE_OUT));
  162. cdb[0] = MAINTENANCE_OUT;
  163. cdb[1] = MO_SET_TARGET_PGS;
  164. put_unaligned_be32(stpg_len, &cdb[6]);
  165. return scsi_execute_req_flags(sdev, cdb, DMA_TO_DEVICE,
  166. stpg_data, stpg_len,
  167. sshdr, ALUA_FAILOVER_TIMEOUT * HZ,
  168. ALUA_FAILOVER_RETRIES, NULL, req_flags);
  169. }
  170. static struct alua_port_group *alua_find_get_pg(char *id_str, size_t id_size,
  171. int group_id)
  172. {
  173. struct alua_port_group *pg;
  174. if (!id_str || !id_size || !strlen(id_str))
  175. return NULL;
  176. list_for_each_entry(pg, &port_group_list, node) {
  177. if (pg->group_id != group_id)
  178. continue;
  179. if (!pg->device_id_len || pg->device_id_len != id_size)
  180. continue;
  181. if (strncmp(pg->device_id_str, id_str, id_size))
  182. continue;
  183. if (!kref_get_unless_zero(&pg->kref))
  184. continue;
  185. return pg;
  186. }
  187. return NULL;
  188. }
  189. /*
  190. * alua_alloc_pg - Allocate a new port_group structure
  191. * @sdev: scsi device
  192. * @h: alua device_handler data
  193. * @group_id: port group id
  194. *
  195. * Allocate a new port_group structure for a given
  196. * device.
  197. */
  198. static struct alua_port_group *alua_alloc_pg(struct scsi_device *sdev,
  199. int group_id, int tpgs)
  200. {
  201. struct alua_port_group *pg, *tmp_pg;
  202. pg = kzalloc(sizeof(struct alua_port_group), GFP_KERNEL);
  203. if (!pg)
  204. return ERR_PTR(-ENOMEM);
  205. pg->device_id_len = scsi_vpd_lun_id(sdev, pg->device_id_str,
  206. sizeof(pg->device_id_str));
  207. if (pg->device_id_len <= 0) {
  208. /*
  209. * TPGS supported but no device identification found.
  210. * Generate private device identification.
  211. */
  212. sdev_printk(KERN_INFO, sdev,
  213. "%s: No device descriptors found\n",
  214. ALUA_DH_NAME);
  215. pg->device_id_str[0] = '\0';
  216. pg->device_id_len = 0;
  217. }
  218. pg->group_id = group_id;
  219. pg->tpgs = tpgs;
  220. pg->state = SCSI_ACCESS_STATE_OPTIMAL;
  221. if (optimize_stpg)
  222. pg->flags |= ALUA_OPTIMIZE_STPG;
  223. kref_init(&pg->kref);
  224. INIT_DELAYED_WORK(&pg->rtpg_work, alua_rtpg_work);
  225. INIT_LIST_HEAD(&pg->rtpg_list);
  226. INIT_LIST_HEAD(&pg->node);
  227. INIT_LIST_HEAD(&pg->dh_list);
  228. spin_lock_init(&pg->lock);
  229. spin_lock(&port_group_lock);
  230. tmp_pg = alua_find_get_pg(pg->device_id_str, pg->device_id_len,
  231. group_id);
  232. if (tmp_pg) {
  233. spin_unlock(&port_group_lock);
  234. kfree(pg);
  235. return tmp_pg;
  236. }
  237. list_add(&pg->node, &port_group_list);
  238. spin_unlock(&port_group_lock);
  239. return pg;
  240. }
  241. /*
  242. * alua_check_tpgs - Evaluate TPGS setting
  243. * @sdev: device to be checked
  244. *
  245. * Examine the TPGS setting of the sdev to find out if ALUA
  246. * is supported.
  247. */
  248. static int alua_check_tpgs(struct scsi_device *sdev)
  249. {
  250. int tpgs = TPGS_MODE_NONE;
  251. /*
  252. * ALUA support for non-disk devices is fraught with
  253. * difficulties, so disable it for now.
  254. */
  255. if (sdev->type != TYPE_DISK) {
  256. sdev_printk(KERN_INFO, sdev,
  257. "%s: disable for non-disk devices\n",
  258. ALUA_DH_NAME);
  259. return tpgs;
  260. }
  261. tpgs = scsi_device_tpgs(sdev);
  262. switch (tpgs) {
  263. case TPGS_MODE_EXPLICIT|TPGS_MODE_IMPLICIT:
  264. sdev_printk(KERN_INFO, sdev,
  265. "%s: supports implicit and explicit TPGS\n",
  266. ALUA_DH_NAME);
  267. break;
  268. case TPGS_MODE_EXPLICIT:
  269. sdev_printk(KERN_INFO, sdev, "%s: supports explicit TPGS\n",
  270. ALUA_DH_NAME);
  271. break;
  272. case TPGS_MODE_IMPLICIT:
  273. sdev_printk(KERN_INFO, sdev, "%s: supports implicit TPGS\n",
  274. ALUA_DH_NAME);
  275. break;
  276. case TPGS_MODE_NONE:
  277. sdev_printk(KERN_INFO, sdev, "%s: not supported\n",
  278. ALUA_DH_NAME);
  279. break;
  280. default:
  281. sdev_printk(KERN_INFO, sdev,
  282. "%s: unsupported TPGS setting %d\n",
  283. ALUA_DH_NAME, tpgs);
  284. tpgs = TPGS_MODE_NONE;
  285. break;
  286. }
  287. return tpgs;
  288. }
  289. /*
  290. * alua_check_vpd - Evaluate INQUIRY vpd page 0x83
  291. * @sdev: device to be checked
  292. *
  293. * Extract the relative target port and the target port group
  294. * descriptor from the list of identificators.
  295. */
  296. static int alua_check_vpd(struct scsi_device *sdev, struct alua_dh_data *h,
  297. int tpgs)
  298. {
  299. int rel_port = -1, group_id;
  300. struct alua_port_group *pg, *old_pg = NULL;
  301. bool pg_updated = false;
  302. unsigned long flags;
  303. group_id = scsi_vpd_tpg_id(sdev, &rel_port);
  304. if (group_id < 0) {
  305. /*
  306. * Internal error; TPGS supported but required
  307. * VPD identification descriptors not present.
  308. * Disable ALUA support
  309. */
  310. sdev_printk(KERN_INFO, sdev,
  311. "%s: No target port descriptors found\n",
  312. ALUA_DH_NAME);
  313. return SCSI_DH_DEV_UNSUPP;
  314. }
  315. pg = alua_alloc_pg(sdev, group_id, tpgs);
  316. if (IS_ERR(pg)) {
  317. if (PTR_ERR(pg) == -ENOMEM)
  318. return SCSI_DH_NOMEM;
  319. return SCSI_DH_DEV_UNSUPP;
  320. }
  321. if (pg->device_id_len)
  322. sdev_printk(KERN_INFO, sdev,
  323. "%s: device %s port group %x rel port %x\n",
  324. ALUA_DH_NAME, pg->device_id_str,
  325. group_id, rel_port);
  326. else
  327. sdev_printk(KERN_INFO, sdev,
  328. "%s: port group %x rel port %x\n",
  329. ALUA_DH_NAME, group_id, rel_port);
  330. /* Check for existing port group references */
  331. spin_lock(&h->pg_lock);
  332. old_pg = h->pg;
  333. if (old_pg != pg) {
  334. /* port group has changed. Update to new port group */
  335. if (h->pg) {
  336. spin_lock_irqsave(&old_pg->lock, flags);
  337. list_del_rcu(&h->node);
  338. spin_unlock_irqrestore(&old_pg->lock, flags);
  339. }
  340. rcu_assign_pointer(h->pg, pg);
  341. pg_updated = true;
  342. }
  343. spin_lock_irqsave(&pg->lock, flags);
  344. if (sdev->synchronous_alua)
  345. pg->flags |= ALUA_SYNC_STPG;
  346. if (pg_updated)
  347. list_add_rcu(&h->node, &pg->dh_list);
  348. spin_unlock_irqrestore(&pg->lock, flags);
  349. alua_rtpg_queue(h->pg, sdev, NULL, true);
  350. spin_unlock(&h->pg_lock);
  351. if (old_pg)
  352. kref_put(&old_pg->kref, release_port_group);
  353. return SCSI_DH_OK;
  354. }
  355. static char print_alua_state(unsigned char state)
  356. {
  357. switch (state) {
  358. case SCSI_ACCESS_STATE_OPTIMAL:
  359. return 'A';
  360. case SCSI_ACCESS_STATE_ACTIVE:
  361. return 'N';
  362. case SCSI_ACCESS_STATE_STANDBY:
  363. return 'S';
  364. case SCSI_ACCESS_STATE_UNAVAILABLE:
  365. return 'U';
  366. case SCSI_ACCESS_STATE_LBA:
  367. return 'L';
  368. case SCSI_ACCESS_STATE_OFFLINE:
  369. return 'O';
  370. case SCSI_ACCESS_STATE_TRANSITIONING:
  371. return 'T';
  372. default:
  373. return 'X';
  374. }
  375. }
  376. static int alua_check_sense(struct scsi_device *sdev,
  377. struct scsi_sense_hdr *sense_hdr)
  378. {
  379. switch (sense_hdr->sense_key) {
  380. case NOT_READY:
  381. if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x0a) {
  382. /*
  383. * LUN Not Accessible - ALUA state transition
  384. */
  385. alua_check(sdev, false);
  386. return NEEDS_RETRY;
  387. }
  388. break;
  389. case UNIT_ATTENTION:
  390. if (sense_hdr->asc == 0x29 && sense_hdr->ascq == 0x00) {
  391. /*
  392. * Power On, Reset, or Bus Device Reset.
  393. * Might have obscured a state transition,
  394. * so schedule a recheck.
  395. */
  396. alua_check(sdev, true);
  397. return ADD_TO_MLQUEUE;
  398. }
  399. if (sense_hdr->asc == 0x29 && sense_hdr->ascq == 0x04)
  400. /*
  401. * Device internal reset
  402. */
  403. return ADD_TO_MLQUEUE;
  404. if (sense_hdr->asc == 0x2a && sense_hdr->ascq == 0x01)
  405. /*
  406. * Mode Parameters Changed
  407. */
  408. return ADD_TO_MLQUEUE;
  409. if (sense_hdr->asc == 0x2a && sense_hdr->ascq == 0x06) {
  410. /*
  411. * ALUA state changed
  412. */
  413. alua_check(sdev, true);
  414. return ADD_TO_MLQUEUE;
  415. }
  416. if (sense_hdr->asc == 0x2a && sense_hdr->ascq == 0x07) {
  417. /*
  418. * Implicit ALUA state transition failed
  419. */
  420. alua_check(sdev, true);
  421. return ADD_TO_MLQUEUE;
  422. }
  423. if (sense_hdr->asc == 0x3f && sense_hdr->ascq == 0x03)
  424. /*
  425. * Inquiry data has changed
  426. */
  427. return ADD_TO_MLQUEUE;
  428. if (sense_hdr->asc == 0x3f && sense_hdr->ascq == 0x0e)
  429. /*
  430. * REPORTED_LUNS_DATA_HAS_CHANGED is reported
  431. * when switching controllers on targets like
  432. * Intel Multi-Flex. We can just retry.
  433. */
  434. return ADD_TO_MLQUEUE;
  435. break;
  436. }
  437. return SCSI_RETURN_NOT_HANDLED;
  438. }
  439. /*
  440. * alua_tur - Send a TEST UNIT READY
  441. * @sdev: device to which the TEST UNIT READY command should be send
  442. *
  443. * Send a TEST UNIT READY to @sdev to figure out the device state
  444. * Returns SCSI_DH_RETRY if the sense code is NOT READY/ALUA TRANSITIONING,
  445. * SCSI_DH_OK if no error occurred, and SCSI_DH_IO otherwise.
  446. */
  447. static int alua_tur(struct scsi_device *sdev)
  448. {
  449. struct scsi_sense_hdr sense_hdr;
  450. int retval;
  451. retval = scsi_test_unit_ready(sdev, ALUA_FAILOVER_TIMEOUT * HZ,
  452. ALUA_FAILOVER_RETRIES, &sense_hdr);
  453. if (sense_hdr.sense_key == NOT_READY &&
  454. sense_hdr.asc == 0x04 && sense_hdr.ascq == 0x0a)
  455. return SCSI_DH_RETRY;
  456. else if (retval)
  457. return SCSI_DH_IO;
  458. else
  459. return SCSI_DH_OK;
  460. }
  461. /*
  462. * alua_rtpg - Evaluate REPORT TARGET GROUP STATES
  463. * @sdev: the device to be evaluated.
  464. *
  465. * Evaluate the Target Port Group State.
  466. * Returns SCSI_DH_DEV_OFFLINED if the path is
  467. * found to be unusable.
  468. */
  469. static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
  470. {
  471. struct scsi_sense_hdr sense_hdr;
  472. struct alua_port_group *tmp_pg;
  473. int len, k, off, valid_states = 0, bufflen = ALUA_RTPG_SIZE;
  474. unsigned char *desc, *buff;
  475. unsigned err, retval;
  476. unsigned int tpg_desc_tbl_off;
  477. unsigned char orig_transition_tmo;
  478. unsigned long flags;
  479. if (!pg->expiry) {
  480. unsigned long transition_tmo = ALUA_FAILOVER_TIMEOUT * HZ;
  481. if (pg->transition_tmo)
  482. transition_tmo = pg->transition_tmo * HZ;
  483. pg->expiry = round_jiffies_up(jiffies + transition_tmo);
  484. }
  485. buff = kzalloc(bufflen, GFP_KERNEL);
  486. if (!buff)
  487. return SCSI_DH_DEV_TEMP_BUSY;
  488. retry:
  489. err = 0;
  490. retval = submit_rtpg(sdev, buff, bufflen, &sense_hdr, pg->flags);
  491. if (retval) {
  492. if (!scsi_sense_valid(&sense_hdr)) {
  493. sdev_printk(KERN_INFO, sdev,
  494. "%s: rtpg failed, result %d\n",
  495. ALUA_DH_NAME, retval);
  496. kfree(buff);
  497. if (driver_byte(retval) == DRIVER_ERROR)
  498. return SCSI_DH_DEV_TEMP_BUSY;
  499. return SCSI_DH_IO;
  500. }
  501. /*
  502. * submit_rtpg() has failed on existing arrays
  503. * when requesting extended header info, and
  504. * the array doesn't support extended headers,
  505. * even though it shouldn't according to T10.
  506. * The retry without rtpg_ext_hdr_req set
  507. * handles this.
  508. */
  509. if (!(pg->flags & ALUA_RTPG_EXT_HDR_UNSUPP) &&
  510. sense_hdr.sense_key == ILLEGAL_REQUEST &&
  511. sense_hdr.asc == 0x24 && sense_hdr.ascq == 0) {
  512. pg->flags |= ALUA_RTPG_EXT_HDR_UNSUPP;
  513. goto retry;
  514. }
  515. /*
  516. * Retry on ALUA state transition or if any
  517. * UNIT ATTENTION occurred.
  518. */
  519. if (sense_hdr.sense_key == NOT_READY &&
  520. sense_hdr.asc == 0x04 && sense_hdr.ascq == 0x0a)
  521. err = SCSI_DH_RETRY;
  522. else if (sense_hdr.sense_key == UNIT_ATTENTION)
  523. err = SCSI_DH_RETRY;
  524. if (err == SCSI_DH_RETRY &&
  525. pg->expiry != 0 && time_before(jiffies, pg->expiry)) {
  526. sdev_printk(KERN_ERR, sdev, "%s: rtpg retry\n",
  527. ALUA_DH_NAME);
  528. scsi_print_sense_hdr(sdev, ALUA_DH_NAME, &sense_hdr);
  529. kfree(buff);
  530. return err;
  531. }
  532. sdev_printk(KERN_ERR, sdev, "%s: rtpg failed\n",
  533. ALUA_DH_NAME);
  534. scsi_print_sense_hdr(sdev, ALUA_DH_NAME, &sense_hdr);
  535. kfree(buff);
  536. pg->expiry = 0;
  537. return SCSI_DH_IO;
  538. }
  539. len = get_unaligned_be32(&buff[0]) + 4;
  540. if (len > bufflen) {
  541. /* Resubmit with the correct length */
  542. kfree(buff);
  543. bufflen = len;
  544. buff = kmalloc(bufflen, GFP_KERNEL);
  545. if (!buff) {
  546. sdev_printk(KERN_WARNING, sdev,
  547. "%s: kmalloc buffer failed\n",__func__);
  548. /* Temporary failure, bypass */
  549. pg->expiry = 0;
  550. return SCSI_DH_DEV_TEMP_BUSY;
  551. }
  552. goto retry;
  553. }
  554. orig_transition_tmo = pg->transition_tmo;
  555. if ((buff[4] & RTPG_FMT_MASK) == RTPG_FMT_EXT_HDR && buff[5] != 0)
  556. pg->transition_tmo = buff[5];
  557. else
  558. pg->transition_tmo = ALUA_FAILOVER_TIMEOUT;
  559. if (orig_transition_tmo != pg->transition_tmo) {
  560. sdev_printk(KERN_INFO, sdev,
  561. "%s: transition timeout set to %d seconds\n",
  562. ALUA_DH_NAME, pg->transition_tmo);
  563. pg->expiry = jiffies + pg->transition_tmo * HZ;
  564. }
  565. if ((buff[4] & RTPG_FMT_MASK) == RTPG_FMT_EXT_HDR)
  566. tpg_desc_tbl_off = 8;
  567. else
  568. tpg_desc_tbl_off = 4;
  569. for (k = tpg_desc_tbl_off, desc = buff + tpg_desc_tbl_off;
  570. k < len;
  571. k += off, desc += off) {
  572. u16 group_id = get_unaligned_be16(&desc[2]);
  573. spin_lock_irqsave(&port_group_lock, flags);
  574. tmp_pg = alua_find_get_pg(pg->device_id_str, pg->device_id_len,
  575. group_id);
  576. spin_unlock_irqrestore(&port_group_lock, flags);
  577. if (tmp_pg) {
  578. if (spin_trylock_irqsave(&tmp_pg->lock, flags)) {
  579. if ((tmp_pg == pg) ||
  580. !(tmp_pg->flags & ALUA_PG_RUNNING)) {
  581. struct alua_dh_data *h;
  582. tmp_pg->state = desc[0] & 0x0f;
  583. tmp_pg->pref = desc[0] >> 7;
  584. rcu_read_lock();
  585. list_for_each_entry_rcu(h,
  586. &tmp_pg->dh_list, node) {
  587. /* h->sdev should always be valid */
  588. BUG_ON(!h->sdev);
  589. h->sdev->access_state = desc[0];
  590. }
  591. rcu_read_unlock();
  592. }
  593. if (tmp_pg == pg)
  594. valid_states = desc[1];
  595. spin_unlock_irqrestore(&tmp_pg->lock, flags);
  596. }
  597. kref_put(&tmp_pg->kref, release_port_group);
  598. }
  599. off = 8 + (desc[7] * 4);
  600. }
  601. spin_lock_irqsave(&pg->lock, flags);
  602. sdev_printk(KERN_INFO, sdev,
  603. "%s: port group %02x state %c %s supports %c%c%c%c%c%c%c\n",
  604. ALUA_DH_NAME, pg->group_id, print_alua_state(pg->state),
  605. pg->pref ? "preferred" : "non-preferred",
  606. valid_states&TPGS_SUPPORT_TRANSITION?'T':'t',
  607. valid_states&TPGS_SUPPORT_OFFLINE?'O':'o',
  608. valid_states&TPGS_SUPPORT_LBA_DEPENDENT?'L':'l',
  609. valid_states&TPGS_SUPPORT_UNAVAILABLE?'U':'u',
  610. valid_states&TPGS_SUPPORT_STANDBY?'S':'s',
  611. valid_states&TPGS_SUPPORT_NONOPTIMIZED?'N':'n',
  612. valid_states&TPGS_SUPPORT_OPTIMIZED?'A':'a');
  613. switch (pg->state) {
  614. case SCSI_ACCESS_STATE_TRANSITIONING:
  615. if (time_before(jiffies, pg->expiry)) {
  616. /* State transition, retry */
  617. pg->interval = 2;
  618. err = SCSI_DH_RETRY;
  619. } else {
  620. struct alua_dh_data *h;
  621. /* Transitioning time exceeded, set port to standby */
  622. err = SCSI_DH_IO;
  623. pg->state = SCSI_ACCESS_STATE_STANDBY;
  624. pg->expiry = 0;
  625. rcu_read_lock();
  626. list_for_each_entry_rcu(h, &pg->dh_list, node) {
  627. BUG_ON(!h->sdev);
  628. h->sdev->access_state =
  629. (pg->state & SCSI_ACCESS_STATE_MASK);
  630. if (pg->pref)
  631. h->sdev->access_state |=
  632. SCSI_ACCESS_STATE_PREFERRED;
  633. }
  634. rcu_read_unlock();
  635. }
  636. break;
  637. case SCSI_ACCESS_STATE_OFFLINE:
  638. /* Path unusable */
  639. err = SCSI_DH_DEV_OFFLINED;
  640. pg->expiry = 0;
  641. break;
  642. default:
  643. /* Useable path if active */
  644. err = SCSI_DH_OK;
  645. pg->expiry = 0;
  646. break;
  647. }
  648. spin_unlock_irqrestore(&pg->lock, flags);
  649. kfree(buff);
  650. return err;
  651. }
  652. /*
  653. * alua_stpg - Issue a SET TARGET PORT GROUP command
  654. *
  655. * Issue a SET TARGET PORT GROUP command and evaluate the
  656. * response. Returns SCSI_DH_RETRY per default to trigger
  657. * a re-evaluation of the target group state or SCSI_DH_OK
  658. * if no further action needs to be taken.
  659. */
  660. static unsigned alua_stpg(struct scsi_device *sdev, struct alua_port_group *pg)
  661. {
  662. int retval;
  663. struct scsi_sense_hdr sense_hdr;
  664. if (!(pg->tpgs & TPGS_MODE_EXPLICIT)) {
  665. /* Only implicit ALUA supported, retry */
  666. return SCSI_DH_RETRY;
  667. }
  668. switch (pg->state) {
  669. case SCSI_ACCESS_STATE_OPTIMAL:
  670. return SCSI_DH_OK;
  671. case SCSI_ACCESS_STATE_ACTIVE:
  672. if ((pg->flags & ALUA_OPTIMIZE_STPG) &&
  673. !pg->pref &&
  674. (pg->tpgs & TPGS_MODE_IMPLICIT))
  675. return SCSI_DH_OK;
  676. break;
  677. case SCSI_ACCESS_STATE_STANDBY:
  678. case SCSI_ACCESS_STATE_UNAVAILABLE:
  679. break;
  680. case SCSI_ACCESS_STATE_OFFLINE:
  681. return SCSI_DH_IO;
  682. case SCSI_ACCESS_STATE_TRANSITIONING:
  683. break;
  684. default:
  685. sdev_printk(KERN_INFO, sdev,
  686. "%s: stpg failed, unhandled TPGS state %d",
  687. ALUA_DH_NAME, pg->state);
  688. return SCSI_DH_NOSYS;
  689. }
  690. retval = submit_stpg(sdev, pg->group_id, &sense_hdr);
  691. if (retval) {
  692. if (!scsi_sense_valid(&sense_hdr)) {
  693. sdev_printk(KERN_INFO, sdev,
  694. "%s: stpg failed, result %d",
  695. ALUA_DH_NAME, retval);
  696. if (driver_byte(retval) == DRIVER_ERROR)
  697. return SCSI_DH_DEV_TEMP_BUSY;
  698. } else {
  699. sdev_printk(KERN_INFO, sdev, "%s: stpg failed\n",
  700. ALUA_DH_NAME);
  701. scsi_print_sense_hdr(sdev, ALUA_DH_NAME, &sense_hdr);
  702. }
  703. }
  704. /* Retry RTPG */
  705. return SCSI_DH_RETRY;
  706. }
  707. static void alua_rtpg_work(struct work_struct *work)
  708. {
  709. struct alua_port_group *pg =
  710. container_of(work, struct alua_port_group, rtpg_work.work);
  711. struct scsi_device *sdev;
  712. LIST_HEAD(qdata_list);
  713. int err = SCSI_DH_OK;
  714. struct alua_queue_data *qdata, *tmp;
  715. unsigned long flags;
  716. struct workqueue_struct *alua_wq = kaluad_wq;
  717. spin_lock_irqsave(&pg->lock, flags);
  718. sdev = pg->rtpg_sdev;
  719. if (!sdev) {
  720. WARN_ON(pg->flags & ALUA_PG_RUN_RTPG);
  721. WARN_ON(pg->flags & ALUA_PG_RUN_STPG);
  722. spin_unlock_irqrestore(&pg->lock, flags);
  723. kref_put(&pg->kref, release_port_group);
  724. return;
  725. }
  726. if (pg->flags & ALUA_SYNC_STPG)
  727. alua_wq = kaluad_sync_wq;
  728. pg->flags |= ALUA_PG_RUNNING;
  729. if (pg->flags & ALUA_PG_RUN_RTPG) {
  730. int state = pg->state;
  731. pg->flags &= ~ALUA_PG_RUN_RTPG;
  732. spin_unlock_irqrestore(&pg->lock, flags);
  733. if (state == SCSI_ACCESS_STATE_TRANSITIONING) {
  734. if (alua_tur(sdev) == SCSI_DH_RETRY) {
  735. spin_lock_irqsave(&pg->lock, flags);
  736. pg->flags &= ~ALUA_PG_RUNNING;
  737. pg->flags |= ALUA_PG_RUN_RTPG;
  738. spin_unlock_irqrestore(&pg->lock, flags);
  739. queue_delayed_work(alua_wq, &pg->rtpg_work,
  740. pg->interval * HZ);
  741. return;
  742. }
  743. /* Send RTPG on failure or if TUR indicates SUCCESS */
  744. }
  745. err = alua_rtpg(sdev, pg);
  746. spin_lock_irqsave(&pg->lock, flags);
  747. if (err == SCSI_DH_RETRY || pg->flags & ALUA_PG_RUN_RTPG) {
  748. pg->flags &= ~ALUA_PG_RUNNING;
  749. pg->flags |= ALUA_PG_RUN_RTPG;
  750. spin_unlock_irqrestore(&pg->lock, flags);
  751. queue_delayed_work(alua_wq, &pg->rtpg_work,
  752. pg->interval * HZ);
  753. return;
  754. }
  755. if (err != SCSI_DH_OK)
  756. pg->flags &= ~ALUA_PG_RUN_STPG;
  757. }
  758. if (pg->flags & ALUA_PG_RUN_STPG) {
  759. pg->flags &= ~ALUA_PG_RUN_STPG;
  760. spin_unlock_irqrestore(&pg->lock, flags);
  761. err = alua_stpg(sdev, pg);
  762. spin_lock_irqsave(&pg->lock, flags);
  763. if (err == SCSI_DH_RETRY || pg->flags & ALUA_PG_RUN_RTPG) {
  764. pg->flags |= ALUA_PG_RUN_RTPG;
  765. pg->interval = 0;
  766. pg->flags &= ~ALUA_PG_RUNNING;
  767. spin_unlock_irqrestore(&pg->lock, flags);
  768. queue_delayed_work(alua_wq, &pg->rtpg_work,
  769. pg->interval * HZ);
  770. return;
  771. }
  772. }
  773. list_splice_init(&pg->rtpg_list, &qdata_list);
  774. pg->rtpg_sdev = NULL;
  775. spin_unlock_irqrestore(&pg->lock, flags);
  776. list_for_each_entry_safe(qdata, tmp, &qdata_list, entry) {
  777. list_del(&qdata->entry);
  778. if (qdata->callback_fn)
  779. qdata->callback_fn(qdata->callback_data, err);
  780. kfree(qdata);
  781. }
  782. spin_lock_irqsave(&pg->lock, flags);
  783. pg->flags &= ~ALUA_PG_RUNNING;
  784. spin_unlock_irqrestore(&pg->lock, flags);
  785. scsi_device_put(sdev);
  786. kref_put(&pg->kref, release_port_group);
  787. }
  788. /**
  789. * alua_rtpg_queue() - cause RTPG to be submitted asynchronously
  790. *
  791. * Returns true if and only if alua_rtpg_work() will be called asynchronously.
  792. * That function is responsible for calling @qdata->fn().
  793. */
  794. static bool alua_rtpg_queue(struct alua_port_group *pg,
  795. struct scsi_device *sdev,
  796. struct alua_queue_data *qdata, bool force)
  797. {
  798. int start_queue = 0;
  799. unsigned long flags;
  800. struct workqueue_struct *alua_wq = kaluad_wq;
  801. if (!pg || scsi_device_get(sdev))
  802. return false;
  803. spin_lock_irqsave(&pg->lock, flags);
  804. if (qdata) {
  805. list_add_tail(&qdata->entry, &pg->rtpg_list);
  806. pg->flags |= ALUA_PG_RUN_STPG;
  807. force = true;
  808. }
  809. if (pg->rtpg_sdev == NULL) {
  810. pg->interval = 0;
  811. pg->flags |= ALUA_PG_RUN_RTPG;
  812. kref_get(&pg->kref);
  813. pg->rtpg_sdev = sdev;
  814. start_queue = 1;
  815. } else if (!(pg->flags & ALUA_PG_RUN_RTPG) && force) {
  816. pg->flags |= ALUA_PG_RUN_RTPG;
  817. /* Do not queue if the worker is already running */
  818. if (!(pg->flags & ALUA_PG_RUNNING)) {
  819. kref_get(&pg->kref);
  820. start_queue = 1;
  821. }
  822. }
  823. if (pg->flags & ALUA_SYNC_STPG)
  824. alua_wq = kaluad_sync_wq;
  825. spin_unlock_irqrestore(&pg->lock, flags);
  826. if (start_queue) {
  827. if (queue_delayed_work(alua_wq, &pg->rtpg_work,
  828. msecs_to_jiffies(ALUA_RTPG_DELAY_MSECS)))
  829. sdev = NULL;
  830. else
  831. kref_put(&pg->kref, release_port_group);
  832. }
  833. if (sdev)
  834. scsi_device_put(sdev);
  835. return true;
  836. }
  837. /*
  838. * alua_initialize - Initialize ALUA state
  839. * @sdev: the device to be initialized
  840. *
  841. * For the prep_fn to work correctly we have
  842. * to initialize the ALUA state for the device.
  843. */
  844. static int alua_initialize(struct scsi_device *sdev, struct alua_dh_data *h)
  845. {
  846. int err = SCSI_DH_DEV_UNSUPP, tpgs;
  847. mutex_lock(&h->init_mutex);
  848. tpgs = alua_check_tpgs(sdev);
  849. if (tpgs != TPGS_MODE_NONE)
  850. err = alua_check_vpd(sdev, h, tpgs);
  851. h->init_error = err;
  852. mutex_unlock(&h->init_mutex);
  853. return err;
  854. }
  855. /*
  856. * alua_set_params - set/unset the optimize flag
  857. * @sdev: device on the path to be activated
  858. * params - parameters in the following format
  859. * "no_of_params\0param1\0param2\0param3\0...\0"
  860. * For example, to set the flag pass the following parameters
  861. * from multipath.conf
  862. * hardware_handler "2 alua 1"
  863. */
  864. static int alua_set_params(struct scsi_device *sdev, const char *params)
  865. {
  866. struct alua_dh_data *h = sdev->handler_data;
  867. struct alua_port_group __rcu *pg = NULL;
  868. unsigned int optimize = 0, argc;
  869. const char *p = params;
  870. int result = SCSI_DH_OK;
  871. unsigned long flags;
  872. if ((sscanf(params, "%u", &argc) != 1) || (argc != 1))
  873. return -EINVAL;
  874. while (*p++)
  875. ;
  876. if ((sscanf(p, "%u", &optimize) != 1) || (optimize > 1))
  877. return -EINVAL;
  878. rcu_read_lock();
  879. pg = rcu_dereference(h->pg);
  880. if (!pg) {
  881. rcu_read_unlock();
  882. return -ENXIO;
  883. }
  884. spin_lock_irqsave(&pg->lock, flags);
  885. if (optimize)
  886. pg->flags |= ALUA_OPTIMIZE_STPG;
  887. else
  888. pg->flags &= ~ALUA_OPTIMIZE_STPG;
  889. spin_unlock_irqrestore(&pg->lock, flags);
  890. rcu_read_unlock();
  891. return result;
  892. }
  893. /*
  894. * alua_activate - activate a path
  895. * @sdev: device on the path to be activated
  896. *
  897. * We're currently switching the port group to be activated only and
  898. * let the array figure out the rest.
  899. * There may be other arrays which require us to switch all port groups
  900. * based on a certain policy. But until we actually encounter them it
  901. * should be okay.
  902. */
  903. static int alua_activate(struct scsi_device *sdev,
  904. activate_complete fn, void *data)
  905. {
  906. struct alua_dh_data *h = sdev->handler_data;
  907. int err = SCSI_DH_OK;
  908. struct alua_queue_data *qdata;
  909. struct alua_port_group __rcu *pg;
  910. qdata = kzalloc(sizeof(*qdata), GFP_KERNEL);
  911. if (!qdata) {
  912. err = SCSI_DH_RES_TEMP_UNAVAIL;
  913. goto out;
  914. }
  915. qdata->callback_fn = fn;
  916. qdata->callback_data = data;
  917. mutex_lock(&h->init_mutex);
  918. rcu_read_lock();
  919. pg = rcu_dereference(h->pg);
  920. if (!pg || !kref_get_unless_zero(&pg->kref)) {
  921. rcu_read_unlock();
  922. kfree(qdata);
  923. err = h->init_error;
  924. mutex_unlock(&h->init_mutex);
  925. goto out;
  926. }
  927. rcu_read_unlock();
  928. mutex_unlock(&h->init_mutex);
  929. if (alua_rtpg_queue(pg, sdev, qdata, true))
  930. fn = NULL;
  931. else
  932. err = SCSI_DH_DEV_OFFLINED;
  933. kref_put(&pg->kref, release_port_group);
  934. out:
  935. if (fn)
  936. fn(data, err);
  937. return 0;
  938. }
  939. /*
  940. * alua_check - check path status
  941. * @sdev: device on the path to be checked
  942. *
  943. * Check the device status
  944. */
  945. static void alua_check(struct scsi_device *sdev, bool force)
  946. {
  947. struct alua_dh_data *h = sdev->handler_data;
  948. struct alua_port_group *pg;
  949. rcu_read_lock();
  950. pg = rcu_dereference(h->pg);
  951. if (!pg || !kref_get_unless_zero(&pg->kref)) {
  952. rcu_read_unlock();
  953. return;
  954. }
  955. rcu_read_unlock();
  956. alua_rtpg_queue(pg, sdev, NULL, force);
  957. kref_put(&pg->kref, release_port_group);
  958. }
  959. /*
  960. * alua_prep_fn - request callback
  961. *
  962. * Fail I/O to all paths not in state
  963. * active/optimized or active/non-optimized.
  964. */
  965. static int alua_prep_fn(struct scsi_device *sdev, struct request *req)
  966. {
  967. struct alua_dh_data *h = sdev->handler_data;
  968. struct alua_port_group __rcu *pg;
  969. unsigned char state = SCSI_ACCESS_STATE_OPTIMAL;
  970. int ret = BLKPREP_OK;
  971. rcu_read_lock();
  972. pg = rcu_dereference(h->pg);
  973. if (pg)
  974. state = pg->state;
  975. rcu_read_unlock();
  976. if (state == SCSI_ACCESS_STATE_TRANSITIONING)
  977. ret = BLKPREP_DEFER;
  978. else if (state != SCSI_ACCESS_STATE_OPTIMAL &&
  979. state != SCSI_ACCESS_STATE_ACTIVE &&
  980. state != SCSI_ACCESS_STATE_LBA) {
  981. ret = BLKPREP_KILL;
  982. req->cmd_flags |= REQ_QUIET;
  983. }
  984. return ret;
  985. }
  986. static void alua_rescan(struct scsi_device *sdev)
  987. {
  988. struct alua_dh_data *h = sdev->handler_data;
  989. alua_initialize(sdev, h);
  990. }
  991. /*
  992. * alua_bus_attach - Attach device handler
  993. * @sdev: device to be attached to
  994. */
  995. static int alua_bus_attach(struct scsi_device *sdev)
  996. {
  997. struct alua_dh_data *h;
  998. int err, ret = -EINVAL;
  999. h = kzalloc(sizeof(*h) , GFP_KERNEL);
  1000. if (!h)
  1001. return -ENOMEM;
  1002. spin_lock_init(&h->pg_lock);
  1003. rcu_assign_pointer(h->pg, NULL);
  1004. h->init_error = SCSI_DH_OK;
  1005. h->sdev = sdev;
  1006. INIT_LIST_HEAD(&h->node);
  1007. mutex_init(&h->init_mutex);
  1008. err = alua_initialize(sdev, h);
  1009. if (err == SCSI_DH_NOMEM)
  1010. ret = -ENOMEM;
  1011. if (err != SCSI_DH_OK && err != SCSI_DH_DEV_OFFLINED)
  1012. goto failed;
  1013. sdev->handler_data = h;
  1014. return 0;
  1015. failed:
  1016. kfree(h);
  1017. return ret;
  1018. }
  1019. /*
  1020. * alua_bus_detach - Detach device handler
  1021. * @sdev: device to be detached from
  1022. */
  1023. static void alua_bus_detach(struct scsi_device *sdev)
  1024. {
  1025. struct alua_dh_data *h = sdev->handler_data;
  1026. struct alua_port_group *pg;
  1027. spin_lock(&h->pg_lock);
  1028. pg = h->pg;
  1029. rcu_assign_pointer(h->pg, NULL);
  1030. h->sdev = NULL;
  1031. spin_unlock(&h->pg_lock);
  1032. if (pg) {
  1033. spin_lock_irq(&pg->lock);
  1034. list_del_rcu(&h->node);
  1035. spin_unlock_irq(&pg->lock);
  1036. kref_put(&pg->kref, release_port_group);
  1037. }
  1038. sdev->handler_data = NULL;
  1039. kfree(h);
  1040. }
  1041. static struct scsi_device_handler alua_dh = {
  1042. .name = ALUA_DH_NAME,
  1043. .module = THIS_MODULE,
  1044. .attach = alua_bus_attach,
  1045. .detach = alua_bus_detach,
  1046. .prep_fn = alua_prep_fn,
  1047. .check_sense = alua_check_sense,
  1048. .activate = alua_activate,
  1049. .rescan = alua_rescan,
  1050. .set_params = alua_set_params,
  1051. };
  1052. static int __init alua_init(void)
  1053. {
  1054. int r;
  1055. kaluad_wq = alloc_workqueue("kaluad", WQ_MEM_RECLAIM, 0);
  1056. if (!kaluad_wq) {
  1057. /* Temporary failure, bypass */
  1058. return SCSI_DH_DEV_TEMP_BUSY;
  1059. }
  1060. kaluad_sync_wq = create_workqueue("kaluad_sync");
  1061. if (!kaluad_sync_wq) {
  1062. destroy_workqueue(kaluad_wq);
  1063. return SCSI_DH_DEV_TEMP_BUSY;
  1064. }
  1065. r = scsi_register_device_handler(&alua_dh);
  1066. if (r != 0) {
  1067. printk(KERN_ERR "%s: Failed to register scsi device handler",
  1068. ALUA_DH_NAME);
  1069. destroy_workqueue(kaluad_sync_wq);
  1070. destroy_workqueue(kaluad_wq);
  1071. }
  1072. return r;
  1073. }
  1074. static void __exit alua_exit(void)
  1075. {
  1076. scsi_unregister_device_handler(&alua_dh);
  1077. destroy_workqueue(kaluad_sync_wq);
  1078. destroy_workqueue(kaluad_wq);
  1079. }
  1080. module_init(alua_init);
  1081. module_exit(alua_exit);
  1082. MODULE_DESCRIPTION("DM Multipath ALUA support");
  1083. MODULE_AUTHOR("Hannes Reinecke <hare@suse.de>");
  1084. MODULE_LICENSE("GPL");
  1085. MODULE_VERSION(ALUA_DH_VER);