scsi_dh_alua.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  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 void 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. return;
  724. }
  725. if (pg->flags & ALUA_SYNC_STPG)
  726. alua_wq = kaluad_sync_wq;
  727. pg->flags |= ALUA_PG_RUNNING;
  728. if (pg->flags & ALUA_PG_RUN_RTPG) {
  729. int state = pg->state;
  730. pg->flags &= ~ALUA_PG_RUN_RTPG;
  731. spin_unlock_irqrestore(&pg->lock, flags);
  732. if (state == SCSI_ACCESS_STATE_TRANSITIONING) {
  733. if (alua_tur(sdev) == SCSI_DH_RETRY) {
  734. spin_lock_irqsave(&pg->lock, flags);
  735. pg->flags &= ~ALUA_PG_RUNNING;
  736. pg->flags |= ALUA_PG_RUN_RTPG;
  737. spin_unlock_irqrestore(&pg->lock, flags);
  738. queue_delayed_work(alua_wq, &pg->rtpg_work,
  739. pg->interval * HZ);
  740. return;
  741. }
  742. /* Send RTPG on failure or if TUR indicates SUCCESS */
  743. }
  744. err = alua_rtpg(sdev, pg);
  745. spin_lock_irqsave(&pg->lock, flags);
  746. if (err == SCSI_DH_RETRY || pg->flags & ALUA_PG_RUN_RTPG) {
  747. pg->flags &= ~ALUA_PG_RUNNING;
  748. pg->flags |= ALUA_PG_RUN_RTPG;
  749. spin_unlock_irqrestore(&pg->lock, flags);
  750. queue_delayed_work(alua_wq, &pg->rtpg_work,
  751. pg->interval * HZ);
  752. return;
  753. }
  754. if (err != SCSI_DH_OK)
  755. pg->flags &= ~ALUA_PG_RUN_STPG;
  756. }
  757. if (pg->flags & ALUA_PG_RUN_STPG) {
  758. pg->flags &= ~ALUA_PG_RUN_STPG;
  759. spin_unlock_irqrestore(&pg->lock, flags);
  760. err = alua_stpg(sdev, pg);
  761. spin_lock_irqsave(&pg->lock, flags);
  762. if (err == SCSI_DH_RETRY || pg->flags & ALUA_PG_RUN_RTPG) {
  763. pg->flags |= ALUA_PG_RUN_RTPG;
  764. pg->interval = 0;
  765. pg->flags &= ~ALUA_PG_RUNNING;
  766. spin_unlock_irqrestore(&pg->lock, flags);
  767. queue_delayed_work(alua_wq, &pg->rtpg_work,
  768. pg->interval * HZ);
  769. return;
  770. }
  771. }
  772. list_splice_init(&pg->rtpg_list, &qdata_list);
  773. pg->rtpg_sdev = NULL;
  774. spin_unlock_irqrestore(&pg->lock, flags);
  775. list_for_each_entry_safe(qdata, tmp, &qdata_list, entry) {
  776. list_del(&qdata->entry);
  777. if (qdata->callback_fn)
  778. qdata->callback_fn(qdata->callback_data, err);
  779. kfree(qdata);
  780. }
  781. spin_lock_irqsave(&pg->lock, flags);
  782. pg->flags &= ~ALUA_PG_RUNNING;
  783. spin_unlock_irqrestore(&pg->lock, flags);
  784. scsi_device_put(sdev);
  785. kref_put(&pg->kref, release_port_group);
  786. }
  787. static void alua_rtpg_queue(struct alua_port_group *pg,
  788. struct scsi_device *sdev,
  789. struct alua_queue_data *qdata, bool force)
  790. {
  791. int start_queue = 0;
  792. unsigned long flags;
  793. struct workqueue_struct *alua_wq = kaluad_wq;
  794. if (!pg)
  795. return;
  796. spin_lock_irqsave(&pg->lock, flags);
  797. if (qdata) {
  798. list_add_tail(&qdata->entry, &pg->rtpg_list);
  799. pg->flags |= ALUA_PG_RUN_STPG;
  800. force = true;
  801. }
  802. if (pg->rtpg_sdev == NULL) {
  803. pg->interval = 0;
  804. pg->flags |= ALUA_PG_RUN_RTPG;
  805. kref_get(&pg->kref);
  806. pg->rtpg_sdev = sdev;
  807. scsi_device_get(sdev);
  808. start_queue = 1;
  809. } else if (!(pg->flags & ALUA_PG_RUN_RTPG) && force) {
  810. pg->flags |= ALUA_PG_RUN_RTPG;
  811. /* Do not queue if the worker is already running */
  812. if (!(pg->flags & ALUA_PG_RUNNING)) {
  813. kref_get(&pg->kref);
  814. start_queue = 1;
  815. }
  816. }
  817. if (pg->flags & ALUA_SYNC_STPG)
  818. alua_wq = kaluad_sync_wq;
  819. spin_unlock_irqrestore(&pg->lock, flags);
  820. if (start_queue &&
  821. !queue_delayed_work(alua_wq, &pg->rtpg_work,
  822. msecs_to_jiffies(ALUA_RTPG_DELAY_MSECS))) {
  823. scsi_device_put(sdev);
  824. kref_put(&pg->kref, release_port_group);
  825. }
  826. }
  827. /*
  828. * alua_initialize - Initialize ALUA state
  829. * @sdev: the device to be initialized
  830. *
  831. * For the prep_fn to work correctly we have
  832. * to initialize the ALUA state for the device.
  833. */
  834. static int alua_initialize(struct scsi_device *sdev, struct alua_dh_data *h)
  835. {
  836. int err = SCSI_DH_DEV_UNSUPP, tpgs;
  837. mutex_lock(&h->init_mutex);
  838. tpgs = alua_check_tpgs(sdev);
  839. if (tpgs != TPGS_MODE_NONE)
  840. err = alua_check_vpd(sdev, h, tpgs);
  841. h->init_error = err;
  842. mutex_unlock(&h->init_mutex);
  843. return err;
  844. }
  845. /*
  846. * alua_set_params - set/unset the optimize flag
  847. * @sdev: device on the path to be activated
  848. * params - parameters in the following format
  849. * "no_of_params\0param1\0param2\0param3\0...\0"
  850. * For example, to set the flag pass the following parameters
  851. * from multipath.conf
  852. * hardware_handler "2 alua 1"
  853. */
  854. static int alua_set_params(struct scsi_device *sdev, const char *params)
  855. {
  856. struct alua_dh_data *h = sdev->handler_data;
  857. struct alua_port_group __rcu *pg = NULL;
  858. unsigned int optimize = 0, argc;
  859. const char *p = params;
  860. int result = SCSI_DH_OK;
  861. unsigned long flags;
  862. if ((sscanf(params, "%u", &argc) != 1) || (argc != 1))
  863. return -EINVAL;
  864. while (*p++)
  865. ;
  866. if ((sscanf(p, "%u", &optimize) != 1) || (optimize > 1))
  867. return -EINVAL;
  868. rcu_read_lock();
  869. pg = rcu_dereference(h->pg);
  870. if (!pg) {
  871. rcu_read_unlock();
  872. return -ENXIO;
  873. }
  874. spin_lock_irqsave(&pg->lock, flags);
  875. if (optimize)
  876. pg->flags |= ALUA_OPTIMIZE_STPG;
  877. else
  878. pg->flags &= ~ALUA_OPTIMIZE_STPG;
  879. spin_unlock_irqrestore(&pg->lock, flags);
  880. rcu_read_unlock();
  881. return result;
  882. }
  883. /*
  884. * alua_activate - activate a path
  885. * @sdev: device on the path to be activated
  886. *
  887. * We're currently switching the port group to be activated only and
  888. * let the array figure out the rest.
  889. * There may be other arrays which require us to switch all port groups
  890. * based on a certain policy. But until we actually encounter them it
  891. * should be okay.
  892. */
  893. static int alua_activate(struct scsi_device *sdev,
  894. activate_complete fn, void *data)
  895. {
  896. struct alua_dh_data *h = sdev->handler_data;
  897. int err = SCSI_DH_OK;
  898. struct alua_queue_data *qdata;
  899. struct alua_port_group __rcu *pg;
  900. qdata = kzalloc(sizeof(*qdata), GFP_KERNEL);
  901. if (!qdata) {
  902. err = SCSI_DH_RES_TEMP_UNAVAIL;
  903. goto out;
  904. }
  905. qdata->callback_fn = fn;
  906. qdata->callback_data = data;
  907. mutex_lock(&h->init_mutex);
  908. rcu_read_lock();
  909. pg = rcu_dereference(h->pg);
  910. if (!pg || !kref_get_unless_zero(&pg->kref)) {
  911. rcu_read_unlock();
  912. kfree(qdata);
  913. err = h->init_error;
  914. mutex_unlock(&h->init_mutex);
  915. goto out;
  916. }
  917. fn = NULL;
  918. rcu_read_unlock();
  919. mutex_unlock(&h->init_mutex);
  920. alua_rtpg_queue(pg, sdev, qdata, true);
  921. kref_put(&pg->kref, release_port_group);
  922. out:
  923. if (fn)
  924. fn(data, err);
  925. return 0;
  926. }
  927. /*
  928. * alua_check - check path status
  929. * @sdev: device on the path to be checked
  930. *
  931. * Check the device status
  932. */
  933. static void alua_check(struct scsi_device *sdev, bool force)
  934. {
  935. struct alua_dh_data *h = sdev->handler_data;
  936. struct alua_port_group *pg;
  937. rcu_read_lock();
  938. pg = rcu_dereference(h->pg);
  939. if (!pg || !kref_get_unless_zero(&pg->kref)) {
  940. rcu_read_unlock();
  941. return;
  942. }
  943. rcu_read_unlock();
  944. alua_rtpg_queue(pg, sdev, NULL, force);
  945. kref_put(&pg->kref, release_port_group);
  946. }
  947. /*
  948. * alua_prep_fn - request callback
  949. *
  950. * Fail I/O to all paths not in state
  951. * active/optimized or active/non-optimized.
  952. */
  953. static int alua_prep_fn(struct scsi_device *sdev, struct request *req)
  954. {
  955. struct alua_dh_data *h = sdev->handler_data;
  956. struct alua_port_group __rcu *pg;
  957. unsigned char state = SCSI_ACCESS_STATE_OPTIMAL;
  958. int ret = BLKPREP_OK;
  959. rcu_read_lock();
  960. pg = rcu_dereference(h->pg);
  961. if (pg)
  962. state = pg->state;
  963. rcu_read_unlock();
  964. if (state == SCSI_ACCESS_STATE_TRANSITIONING)
  965. ret = BLKPREP_DEFER;
  966. else if (state != SCSI_ACCESS_STATE_OPTIMAL &&
  967. state != SCSI_ACCESS_STATE_ACTIVE &&
  968. state != SCSI_ACCESS_STATE_LBA) {
  969. ret = BLKPREP_KILL;
  970. req->cmd_flags |= REQ_QUIET;
  971. }
  972. return ret;
  973. }
  974. static void alua_rescan(struct scsi_device *sdev)
  975. {
  976. struct alua_dh_data *h = sdev->handler_data;
  977. alua_initialize(sdev, h);
  978. }
  979. /*
  980. * alua_bus_attach - Attach device handler
  981. * @sdev: device to be attached to
  982. */
  983. static int alua_bus_attach(struct scsi_device *sdev)
  984. {
  985. struct alua_dh_data *h;
  986. int err, ret = -EINVAL;
  987. h = kzalloc(sizeof(*h) , GFP_KERNEL);
  988. if (!h)
  989. return -ENOMEM;
  990. spin_lock_init(&h->pg_lock);
  991. rcu_assign_pointer(h->pg, NULL);
  992. h->init_error = SCSI_DH_OK;
  993. h->sdev = sdev;
  994. INIT_LIST_HEAD(&h->node);
  995. mutex_init(&h->init_mutex);
  996. err = alua_initialize(sdev, h);
  997. if (err == SCSI_DH_NOMEM)
  998. ret = -ENOMEM;
  999. if (err != SCSI_DH_OK && err != SCSI_DH_DEV_OFFLINED)
  1000. goto failed;
  1001. sdev->handler_data = h;
  1002. return 0;
  1003. failed:
  1004. kfree(h);
  1005. return ret;
  1006. }
  1007. /*
  1008. * alua_bus_detach - Detach device handler
  1009. * @sdev: device to be detached from
  1010. */
  1011. static void alua_bus_detach(struct scsi_device *sdev)
  1012. {
  1013. struct alua_dh_data *h = sdev->handler_data;
  1014. struct alua_port_group *pg;
  1015. spin_lock(&h->pg_lock);
  1016. pg = h->pg;
  1017. rcu_assign_pointer(h->pg, NULL);
  1018. h->sdev = NULL;
  1019. spin_unlock(&h->pg_lock);
  1020. if (pg) {
  1021. spin_lock_irq(&pg->lock);
  1022. list_del_rcu(&h->node);
  1023. spin_unlock_irq(&pg->lock);
  1024. kref_put(&pg->kref, release_port_group);
  1025. }
  1026. sdev->handler_data = NULL;
  1027. kfree(h);
  1028. }
  1029. static struct scsi_device_handler alua_dh = {
  1030. .name = ALUA_DH_NAME,
  1031. .module = THIS_MODULE,
  1032. .attach = alua_bus_attach,
  1033. .detach = alua_bus_detach,
  1034. .prep_fn = alua_prep_fn,
  1035. .check_sense = alua_check_sense,
  1036. .activate = alua_activate,
  1037. .rescan = alua_rescan,
  1038. .set_params = alua_set_params,
  1039. };
  1040. static int __init alua_init(void)
  1041. {
  1042. int r;
  1043. kaluad_wq = alloc_workqueue("kaluad", WQ_MEM_RECLAIM, 0);
  1044. if (!kaluad_wq) {
  1045. /* Temporary failure, bypass */
  1046. return SCSI_DH_DEV_TEMP_BUSY;
  1047. }
  1048. kaluad_sync_wq = create_workqueue("kaluad_sync");
  1049. if (!kaluad_sync_wq) {
  1050. destroy_workqueue(kaluad_wq);
  1051. return SCSI_DH_DEV_TEMP_BUSY;
  1052. }
  1053. r = scsi_register_device_handler(&alua_dh);
  1054. if (r != 0) {
  1055. printk(KERN_ERR "%s: Failed to register scsi device handler",
  1056. ALUA_DH_NAME);
  1057. destroy_workqueue(kaluad_sync_wq);
  1058. destroy_workqueue(kaluad_wq);
  1059. }
  1060. return r;
  1061. }
  1062. static void __exit alua_exit(void)
  1063. {
  1064. scsi_unregister_device_handler(&alua_dh);
  1065. destroy_workqueue(kaluad_sync_wq);
  1066. destroy_workqueue(kaluad_wq);
  1067. }
  1068. module_init(alua_init);
  1069. module_exit(alua_exit);
  1070. MODULE_DESCRIPTION("DM Multipath ALUA support");
  1071. MODULE_AUTHOR("Hannes Reinecke <hare@suse.de>");
  1072. MODULE_LICENSE("GPL");
  1073. MODULE_VERSION(ALUA_DH_VER);