2 * Generic SCSI-3 ALUA SCSI Device Handler
4 * Copyright (C) 2007-2010 Hannes Reinecke, SUSE Linux Products GmbH.
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.
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.
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.
22 #include <linux/slab.h>
23 #include <linux/delay.h>
24 #include <linux/module.h>
25 #include <scsi/scsi.h>
26 #include <scsi/scsi_eh.h>
27 #include <scsi/scsi_dh.h>
29 #define ALUA_DH_NAME "alua"
30 #define ALUA_DH_VER "1.3"
32 #define TPGS_STATE_OPTIMIZED 0x0
33 #define TPGS_STATE_NONOPTIMIZED 0x1
34 #define TPGS_STATE_STANDBY 0x2
35 #define TPGS_STATE_UNAVAILABLE 0x3
36 #define TPGS_STATE_LBA_DEPENDENT 0x4
37 #define TPGS_STATE_OFFLINE 0xe
38 #define TPGS_STATE_TRANSITIONING 0xf
40 #define TPGS_SUPPORT_NONE 0x00
41 #define TPGS_SUPPORT_OPTIMIZED 0x01
42 #define TPGS_SUPPORT_NONOPTIMIZED 0x02
43 #define TPGS_SUPPORT_STANDBY 0x04
44 #define TPGS_SUPPORT_UNAVAILABLE 0x08
45 #define TPGS_SUPPORT_LBA_DEPENDENT 0x10
46 #define TPGS_SUPPORT_OFFLINE 0x40
47 #define TPGS_SUPPORT_TRANSITION 0x80
49 #define TPGS_MODE_UNINITIALIZED -1
50 #define TPGS_MODE_NONE 0x0
51 #define TPGS_MODE_IMPLICIT 0x1
52 #define TPGS_MODE_EXPLICIT 0x2
54 #define ALUA_INQUIRY_SIZE 36
55 #define ALUA_FAILOVER_TIMEOUT (60 * HZ)
56 #define ALUA_FAILOVER_RETRIES 5
63 unsigned char inq
[ALUA_INQUIRY_SIZE
];
66 unsigned char sense
[SCSI_SENSE_BUFFERSIZE
];
68 struct scsi_device
*sdev
;
69 activate_complete callback_fn
;
73 #define ALUA_POLICY_SWITCH_CURRENT 0
74 #define ALUA_POLICY_SWITCH_ALL 1
76 static char print_alua_state(int);
77 static int alua_check_sense(struct scsi_device
*, struct scsi_sense_hdr
*);
79 static inline struct alua_dh_data
*get_alua_data(struct scsi_device
*sdev
)
81 struct scsi_dh_data
*scsi_dh_data
= sdev
->scsi_dh_data
;
82 BUG_ON(scsi_dh_data
== NULL
);
83 return ((struct alua_dh_data
*) scsi_dh_data
->buf
);
86 static int realloc_buffer(struct alua_dh_data
*h
, unsigned len
)
88 if (h
->buff
&& h
->buff
!= h
->inq
)
91 h
->buff
= kmalloc(len
, GFP_NOIO
);
94 h
->bufflen
= ALUA_INQUIRY_SIZE
;
101 static struct request
*get_alua_req(struct scsi_device
*sdev
,
102 void *buffer
, unsigned buflen
, int rw
)
105 struct request_queue
*q
= sdev
->request_queue
;
107 rq
= blk_get_request(q
, rw
, GFP_NOIO
);
110 sdev_printk(KERN_INFO
, sdev
,
111 "%s: blk_get_request failed\n", __func__
);
115 if (buflen
&& blk_rq_map_kern(q
, rq
, buffer
, buflen
, GFP_NOIO
)) {
117 sdev_printk(KERN_INFO
, sdev
,
118 "%s: blk_rq_map_kern failed\n", __func__
);
122 rq
->cmd_type
= REQ_TYPE_BLOCK_PC
;
123 rq
->cmd_flags
|= REQ_FAILFAST_DEV
| REQ_FAILFAST_TRANSPORT
|
125 rq
->retries
= ALUA_FAILOVER_RETRIES
;
126 rq
->timeout
= ALUA_FAILOVER_TIMEOUT
;
132 * submit_std_inquiry - Issue a standard INQUIRY command
133 * @sdev: sdev the command should be send to
135 static int submit_std_inquiry(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
138 int err
= SCSI_DH_RES_TEMP_UNAVAIL
;
140 rq
= get_alua_req(sdev
, h
->inq
, ALUA_INQUIRY_SIZE
, READ
);
144 /* Prepare the command. */
145 rq
->cmd
[0] = INQUIRY
;
148 rq
->cmd
[4] = ALUA_INQUIRY_SIZE
;
149 rq
->cmd_len
= COMMAND_SIZE(INQUIRY
);
151 rq
->sense
= h
->sense
;
152 memset(rq
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
153 rq
->sense_len
= h
->senselen
= 0;
155 err
= blk_execute_rq(rq
->q
, NULL
, rq
, 1);
157 sdev_printk(KERN_INFO
, sdev
,
158 "%s: std inquiry failed with %x\n",
159 ALUA_DH_NAME
, rq
->errors
);
160 h
->senselen
= rq
->sense_len
;
169 * submit_vpd_inquiry - Issue an INQUIRY VPD page 0x83 command
170 * @sdev: sdev the command should be sent to
172 static int submit_vpd_inquiry(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
175 int err
= SCSI_DH_RES_TEMP_UNAVAIL
;
177 rq
= get_alua_req(sdev
, h
->buff
, h
->bufflen
, READ
);
181 /* Prepare the command. */
182 rq
->cmd
[0] = INQUIRY
;
185 rq
->cmd
[4] = h
->bufflen
;
186 rq
->cmd_len
= COMMAND_SIZE(INQUIRY
);
188 rq
->sense
= h
->sense
;
189 memset(rq
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
190 rq
->sense_len
= h
->senselen
= 0;
192 err
= blk_execute_rq(rq
->q
, NULL
, rq
, 1);
194 sdev_printk(KERN_INFO
, sdev
,
195 "%s: evpd inquiry failed with %x\n",
196 ALUA_DH_NAME
, rq
->errors
);
197 h
->senselen
= rq
->sense_len
;
206 * submit_rtpg - Issue a REPORT TARGET GROUP STATES command
207 * @sdev: sdev the command should be sent to
209 static unsigned submit_rtpg(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
212 int err
= SCSI_DH_RES_TEMP_UNAVAIL
;
214 rq
= get_alua_req(sdev
, h
->buff
, h
->bufflen
, READ
);
218 /* Prepare the command. */
219 rq
->cmd
[0] = MAINTENANCE_IN
;
220 rq
->cmd
[1] = MI_REPORT_TARGET_PGS
;
221 rq
->cmd
[6] = (h
->bufflen
>> 24) & 0xff;
222 rq
->cmd
[7] = (h
->bufflen
>> 16) & 0xff;
223 rq
->cmd
[8] = (h
->bufflen
>> 8) & 0xff;
224 rq
->cmd
[9] = h
->bufflen
& 0xff;
225 rq
->cmd_len
= COMMAND_SIZE(MAINTENANCE_IN
);
227 rq
->sense
= h
->sense
;
228 memset(rq
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
229 rq
->sense_len
= h
->senselen
= 0;
231 err
= blk_execute_rq(rq
->q
, NULL
, rq
, 1);
233 sdev_printk(KERN_INFO
, sdev
,
234 "%s: rtpg failed with %x\n",
235 ALUA_DH_NAME
, rq
->errors
);
236 h
->senselen
= rq
->sense_len
;
245 * alua_stpg - Evaluate SET TARGET GROUP STATES
246 * @sdev: the device to be evaluated
247 * @state: the new target group state
249 * Send a SET TARGET GROUP STATES command to the device.
250 * We only have to test here if we should resubmit the command;
251 * any other error is assumed as a failure.
253 static void stpg_endio(struct request
*req
, int error
)
255 struct alua_dh_data
*h
= req
->end_io_data
;
256 struct scsi_sense_hdr sense_hdr
;
257 unsigned err
= SCSI_DH_OK
;
259 if (error
|| host_byte(req
->errors
) != DID_OK
||
260 msg_byte(req
->errors
) != COMMAND_COMPLETE
) {
265 if (h
->senselen
> 0) {
266 err
= scsi_normalize_sense(h
->sense
, SCSI_SENSE_BUFFERSIZE
,
272 err
= alua_check_sense(h
->sdev
, &sense_hdr
);
273 if (err
== ADD_TO_MLQUEUE
) {
277 sdev_printk(KERN_INFO
, h
->sdev
,
278 "%s: stpg sense code: %02x/%02x/%02x\n",
279 ALUA_DH_NAME
, sense_hdr
.sense_key
,
280 sense_hdr
.asc
, sense_hdr
.ascq
);
283 if (err
== SCSI_DH_OK
) {
284 h
->state
= TPGS_STATE_OPTIMIZED
;
285 sdev_printk(KERN_INFO
, h
->sdev
,
286 "%s: port group %02x switched to state %c\n",
287 ALUA_DH_NAME
, h
->group_id
,
288 print_alua_state(h
->state
));
291 req
->end_io_data
= NULL
;
292 __blk_put_request(req
->q
, req
);
293 if (h
->callback_fn
) {
294 h
->callback_fn(h
->callback_data
, err
);
295 h
->callback_fn
= h
->callback_data
= NULL
;
301 * submit_stpg - Issue a SET TARGET GROUP STATES command
303 * Currently we're only setting the current target port group state
304 * to 'active/optimized' and let the array firmware figure out
305 * the states of the remaining groups.
307 static unsigned submit_stpg(struct alua_dh_data
*h
)
311 struct scsi_device
*sdev
= h
->sdev
;
313 /* Prepare the data buffer */
314 memset(h
->buff
, 0, stpg_len
);
315 h
->buff
[4] = TPGS_STATE_OPTIMIZED
& 0x0f;
316 h
->buff
[6] = (h
->group_id
>> 8) & 0xff;
317 h
->buff
[7] = h
->group_id
& 0xff;
319 rq
= get_alua_req(sdev
, h
->buff
, stpg_len
, WRITE
);
321 return SCSI_DH_RES_TEMP_UNAVAIL
;
323 /* Prepare the command. */
324 rq
->cmd
[0] = MAINTENANCE_OUT
;
325 rq
->cmd
[1] = MO_SET_TARGET_PGS
;
326 rq
->cmd
[6] = (stpg_len
>> 24) & 0xff;
327 rq
->cmd
[7] = (stpg_len
>> 16) & 0xff;
328 rq
->cmd
[8] = (stpg_len
>> 8) & 0xff;
329 rq
->cmd
[9] = stpg_len
& 0xff;
330 rq
->cmd_len
= COMMAND_SIZE(MAINTENANCE_OUT
);
332 rq
->sense
= h
->sense
;
333 memset(rq
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
334 rq
->sense_len
= h
->senselen
= 0;
337 blk_execute_rq_nowait(rq
->q
, NULL
, rq
, 1, stpg_endio
);
342 * alua_std_inquiry - Evaluate standard INQUIRY command
343 * @sdev: device to be checked
345 * Just extract the TPGS setting to find out if ALUA
348 static int alua_std_inquiry(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
352 err
= submit_std_inquiry(sdev
, h
);
354 if (err
!= SCSI_DH_OK
)
357 /* Check TPGS setting */
358 h
->tpgs
= (h
->inq
[5] >> 4) & 0x3;
360 case TPGS_MODE_EXPLICIT
|TPGS_MODE_IMPLICIT
:
361 sdev_printk(KERN_INFO
, sdev
,
362 "%s: supports implicit and explicit TPGS\n",
365 case TPGS_MODE_EXPLICIT
:
366 sdev_printk(KERN_INFO
, sdev
, "%s: supports explicit TPGS\n",
369 case TPGS_MODE_IMPLICIT
:
370 sdev_printk(KERN_INFO
, sdev
, "%s: supports implicit TPGS\n",
374 h
->tpgs
= TPGS_MODE_NONE
;
375 sdev_printk(KERN_INFO
, sdev
, "%s: not supported\n",
377 err
= SCSI_DH_DEV_UNSUPP
;
385 * alua_vpd_inquiry - Evaluate INQUIRY vpd page 0x83
386 * @sdev: device to be checked
388 * Extract the relative target port and the target port group
389 * descriptor from the list of identificators.
391 static int alua_vpd_inquiry(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
398 err
= submit_vpd_inquiry(sdev
, h
);
400 if (err
!= SCSI_DH_OK
)
403 /* Check if vpd page exceeds initial buffer */
404 len
= (h
->buff
[2] << 8) + h
->buff
[3] + 4;
405 if (len
> h
->bufflen
) {
406 /* Resubmit with the correct length */
407 if (realloc_buffer(h
, len
)) {
408 sdev_printk(KERN_WARNING
, sdev
,
409 "%s: kmalloc buffer failed\n",
411 /* Temporary failure, bypass */
412 return SCSI_DH_DEV_TEMP_BUSY
;
418 * Now look for the correct descriptor.
421 while (d
< h
->buff
+ len
) {
422 switch (d
[1] & 0xf) {
424 /* Relative target port */
425 h
->rel_port
= (d
[6] << 8) + d
[7];
428 /* Target port group */
429 h
->group_id
= (d
[6] << 8) + d
[7];
437 if (h
->group_id
== -1) {
439 * Internal error; TPGS supported but required
440 * VPD identification descriptors not present.
441 * Disable ALUA support
443 sdev_printk(KERN_INFO
, sdev
,
444 "%s: No target port descriptors found\n",
446 h
->state
= TPGS_STATE_OPTIMIZED
;
447 h
->tpgs
= TPGS_MODE_NONE
;
448 err
= SCSI_DH_DEV_UNSUPP
;
450 sdev_printk(KERN_INFO
, sdev
,
451 "%s: port group %02x rel port %02x\n",
452 ALUA_DH_NAME
, h
->group_id
, h
->rel_port
);
458 static char print_alua_state(int state
)
461 case TPGS_STATE_OPTIMIZED
:
463 case TPGS_STATE_NONOPTIMIZED
:
465 case TPGS_STATE_STANDBY
:
467 case TPGS_STATE_UNAVAILABLE
:
469 case TPGS_STATE_LBA_DEPENDENT
:
471 case TPGS_STATE_OFFLINE
:
473 case TPGS_STATE_TRANSITIONING
:
480 static int alua_check_sense(struct scsi_device
*sdev
,
481 struct scsi_sense_hdr
*sense_hdr
)
483 switch (sense_hdr
->sense_key
) {
485 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x0a)
487 * LUN Not Accessible - ALUA state transition
489 return ADD_TO_MLQUEUE
;
490 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x0b)
492 * LUN Not Accessible -- Target port in standby state
495 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x0c)
497 * LUN Not Accessible -- Target port in unavailable state
500 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x12)
502 * LUN Not Ready -- Offline
507 if (sense_hdr
->asc
== 0x29 && sense_hdr
->ascq
== 0x00)
509 * Power On, Reset, or Bus Device Reset, just retry.
511 return ADD_TO_MLQUEUE
;
512 if (sense_hdr
->asc
== 0x2a && sense_hdr
->ascq
== 0x06) {
516 return ADD_TO_MLQUEUE
;
518 if (sense_hdr
->asc
== 0x2a && sense_hdr
->ascq
== 0x07) {
520 * Implicit ALUA state transition failed
522 return ADD_TO_MLQUEUE
;
524 if (sense_hdr
->asc
== 0x3f && sense_hdr
->ascq
== 0x0e) {
526 * REPORTED_LUNS_DATA_HAS_CHANGED is reported
527 * when switching controllers on targets like
528 * Intel Multi-Flex. We can just retry.
530 return ADD_TO_MLQUEUE
;
536 return SCSI_RETURN_NOT_HANDLED
;
540 * alua_rtpg - Evaluate REPORT TARGET GROUP STATES
541 * @sdev: the device to be evaluated.
543 * Evaluate the Target Port Group State.
544 * Returns SCSI_DH_DEV_OFFLINED if the path is
545 * found to be unusable.
547 static int alua_rtpg(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
549 struct scsi_sense_hdr sense_hdr
;
550 int len
, k
, off
, valid_states
= 0;
553 unsigned long expiry
, interval
= 10;
555 expiry
= round_jiffies_up(jiffies
+ ALUA_FAILOVER_TIMEOUT
);
557 err
= submit_rtpg(sdev
, h
);
559 if (err
== SCSI_DH_IO
&& h
->senselen
> 0) {
560 err
= scsi_normalize_sense(h
->sense
, SCSI_SENSE_BUFFERSIZE
,
565 err
= alua_check_sense(sdev
, &sense_hdr
);
566 if (err
== ADD_TO_MLQUEUE
&& time_before(jiffies
, expiry
))
568 sdev_printk(KERN_INFO
, sdev
,
569 "%s: rtpg sense code %02x/%02x/%02x\n",
570 ALUA_DH_NAME
, sense_hdr
.sense_key
,
571 sense_hdr
.asc
, sense_hdr
.ascq
);
574 if (err
!= SCSI_DH_OK
)
577 len
= (h
->buff
[0] << 24) + (h
->buff
[1] << 16) +
578 (h
->buff
[2] << 8) + h
->buff
[3] + 4;
580 if (len
> h
->bufflen
) {
581 /* Resubmit with the correct length */
582 if (realloc_buffer(h
, len
)) {
583 sdev_printk(KERN_WARNING
, sdev
,
584 "%s: kmalloc buffer failed\n",__func__
);
585 /* Temporary failure, bypass */
586 return SCSI_DH_DEV_TEMP_BUSY
;
591 for (k
= 4, ucp
= h
->buff
+ 4; k
< len
; k
+= off
, ucp
+= off
) {
592 if (h
->group_id
== (ucp
[2] << 8) + ucp
[3]) {
593 h
->state
= ucp
[0] & 0x0f;
594 valid_states
= ucp
[1];
596 off
= 8 + (ucp
[7] * 4);
599 sdev_printk(KERN_INFO
, sdev
,
600 "%s: port group %02x state %c supports %c%c%c%c%c%c%c\n",
601 ALUA_DH_NAME
, h
->group_id
, print_alua_state(h
->state
),
602 valid_states
&TPGS_SUPPORT_TRANSITION
?'T':'t',
603 valid_states
&TPGS_SUPPORT_OFFLINE
?'O':'o',
604 valid_states
&TPGS_SUPPORT_LBA_DEPENDENT
?'L':'l',
605 valid_states
&TPGS_SUPPORT_UNAVAILABLE
?'U':'u',
606 valid_states
&TPGS_SUPPORT_STANDBY
?'S':'s',
607 valid_states
&TPGS_SUPPORT_NONOPTIMIZED
?'N':'n',
608 valid_states
&TPGS_SUPPORT_OPTIMIZED
?'A':'a');
611 case TPGS_STATE_TRANSITIONING
:
612 if (time_before(jiffies
, expiry
)) {
613 /* State transition, retry */
618 /* Transitioning time exceeded, set port to standby */
620 h
->state
= TPGS_STATE_STANDBY
;
622 case TPGS_STATE_OFFLINE
:
623 case TPGS_STATE_UNAVAILABLE
:
624 /* Path unusable for unavailable/offline */
625 err
= SCSI_DH_DEV_OFFLINED
;
628 /* Useable path if active */
636 * alua_initialize - Initialize ALUA state
637 * @sdev: the device to be initialized
639 * For the prep_fn to work correctly we have
640 * to initialize the ALUA state for the device.
642 static int alua_initialize(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
646 err
= alua_std_inquiry(sdev
, h
);
647 if (err
!= SCSI_DH_OK
)
650 err
= alua_vpd_inquiry(sdev
, h
);
651 if (err
!= SCSI_DH_OK
)
654 err
= alua_rtpg(sdev
, h
);
655 if (err
!= SCSI_DH_OK
)
663 * alua_activate - activate a path
664 * @sdev: device on the path to be activated
666 * We're currently switching the port group to be activated only and
667 * let the array figure out the rest.
668 * There may be other arrays which require us to switch all port groups
669 * based on a certain policy. But until we actually encounter them it
672 static int alua_activate(struct scsi_device
*sdev
,
673 activate_complete fn
, void *data
)
675 struct alua_dh_data
*h
= get_alua_data(sdev
);
676 int err
= SCSI_DH_OK
;
678 if (h
->group_id
!= -1) {
679 err
= alua_rtpg(sdev
, h
);
680 if (err
!= SCSI_DH_OK
)
684 if (h
->tpgs
& TPGS_MODE_EXPLICIT
&&
685 h
->state
!= TPGS_STATE_OPTIMIZED
&&
686 h
->state
!= TPGS_STATE_LBA_DEPENDENT
) {
688 h
->callback_data
= data
;
689 err
= submit_stpg(h
);
690 if (err
== SCSI_DH_OK
)
692 h
->callback_fn
= h
->callback_data
= NULL
;
702 * alua_prep_fn - request callback
704 * Fail I/O to all paths not in state
705 * active/optimized or active/non-optimized.
707 static int alua_prep_fn(struct scsi_device
*sdev
, struct request
*req
)
709 struct alua_dh_data
*h
= get_alua_data(sdev
);
710 int ret
= BLKPREP_OK
;
712 if (h
->state
== TPGS_STATE_TRANSITIONING
)
714 else if (h
->state
!= TPGS_STATE_OPTIMIZED
&&
715 h
->state
!= TPGS_STATE_NONOPTIMIZED
&&
716 h
->state
!= TPGS_STATE_LBA_DEPENDENT
) {
718 req
->cmd_flags
|= REQ_QUIET
;
724 static const struct scsi_dh_devlist alua_dev_list
[] = {
725 {"HP", "MSA VOLUME" },
733 {"Pillar", "Axiom" },
734 {"Intel", "Multi-Flex"},
736 {"NETAPP", "LUN C-Mode"},
738 {"Promise", "VTrak"},
742 static int alua_bus_attach(struct scsi_device
*sdev
);
743 static void alua_bus_detach(struct scsi_device
*sdev
);
745 static struct scsi_device_handler alua_dh
= {
746 .name
= ALUA_DH_NAME
,
747 .module
= THIS_MODULE
,
748 .devlist
= alua_dev_list
,
749 .attach
= alua_bus_attach
,
750 .detach
= alua_bus_detach
,
751 .prep_fn
= alua_prep_fn
,
752 .check_sense
= alua_check_sense
,
753 .activate
= alua_activate
,
757 * alua_bus_attach - Attach device handler
758 * @sdev: device to be attached to
760 static int alua_bus_attach(struct scsi_device
*sdev
)
762 struct scsi_dh_data
*scsi_dh_data
;
763 struct alua_dh_data
*h
;
765 int err
= SCSI_DH_OK
;
767 scsi_dh_data
= kzalloc(sizeof(*scsi_dh_data
)
768 + sizeof(*h
) , GFP_KERNEL
);
770 sdev_printk(KERN_ERR
, sdev
, "%s: Attach failed\n",
775 scsi_dh_data
->scsi_dh
= &alua_dh
;
776 h
= (struct alua_dh_data
*) scsi_dh_data
->buf
;
777 h
->tpgs
= TPGS_MODE_UNINITIALIZED
;
778 h
->state
= TPGS_STATE_OPTIMIZED
;
782 h
->bufflen
= ALUA_INQUIRY_SIZE
;
785 err
= alua_initialize(sdev
, h
);
786 if ((err
!= SCSI_DH_OK
) && (err
!= SCSI_DH_DEV_OFFLINED
))
789 if (!try_module_get(THIS_MODULE
))
792 spin_lock_irqsave(sdev
->request_queue
->queue_lock
, flags
);
793 sdev
->scsi_dh_data
= scsi_dh_data
;
794 spin_unlock_irqrestore(sdev
->request_queue
->queue_lock
, flags
);
800 sdev_printk(KERN_ERR
, sdev
, "%s: not attached\n", ALUA_DH_NAME
);
805 * alua_bus_detach - Detach device handler
806 * @sdev: device to be detached from
808 static void alua_bus_detach(struct scsi_device
*sdev
)
810 struct scsi_dh_data
*scsi_dh_data
;
811 struct alua_dh_data
*h
;
814 spin_lock_irqsave(sdev
->request_queue
->queue_lock
, flags
);
815 scsi_dh_data
= sdev
->scsi_dh_data
;
816 sdev
->scsi_dh_data
= NULL
;
817 spin_unlock_irqrestore(sdev
->request_queue
->queue_lock
, flags
);
819 h
= (struct alua_dh_data
*) scsi_dh_data
->buf
;
820 if (h
->buff
&& h
->inq
!= h
->buff
)
823 module_put(THIS_MODULE
);
824 sdev_printk(KERN_NOTICE
, sdev
, "%s: Detached\n", ALUA_DH_NAME
);
827 static int __init
alua_init(void)
831 r
= scsi_register_device_handler(&alua_dh
);
833 printk(KERN_ERR
"%s: Failed to register scsi device handler",
838 static void __exit
alua_exit(void)
840 scsi_unregister_device_handler(&alua_dh
);
843 module_init(alua_init
);
844 module_exit(alua_exit
);
846 MODULE_DESCRIPTION("DM Multipath ALUA support");
847 MODULE_AUTHOR("Hannes Reinecke <hare@suse.de>");
848 MODULE_LICENSE("GPL");
849 MODULE_VERSION(ALUA_DH_VER
);