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 <scsi/scsi.h>
25 #include <scsi/scsi_eh.h>
26 #include <scsi/scsi_dh.h>
28 #define ALUA_DH_NAME "alua"
29 #define ALUA_DH_VER "1.3"
31 #define TPGS_STATE_OPTIMIZED 0x0
32 #define TPGS_STATE_NONOPTIMIZED 0x1
33 #define TPGS_STATE_STANDBY 0x2
34 #define TPGS_STATE_UNAVAILABLE 0x3
35 #define TPGS_STATE_LBA_DEPENDENT 0x4
36 #define TPGS_STATE_OFFLINE 0xe
37 #define TPGS_STATE_TRANSITIONING 0xf
39 #define TPGS_SUPPORT_NONE 0x00
40 #define TPGS_SUPPORT_OPTIMIZED 0x01
41 #define TPGS_SUPPORT_NONOPTIMIZED 0x02
42 #define TPGS_SUPPORT_STANDBY 0x04
43 #define TPGS_SUPPORT_UNAVAILABLE 0x08
44 #define TPGS_SUPPORT_LBA_DEPENDENT 0x10
45 #define TPGS_SUPPORT_OFFLINE 0x40
46 #define TPGS_SUPPORT_TRANSITION 0x80
48 #define TPGS_MODE_UNINITIALIZED -1
49 #define TPGS_MODE_NONE 0x0
50 #define TPGS_MODE_IMPLICIT 0x1
51 #define TPGS_MODE_EXPLICIT 0x2
53 #define ALUA_INQUIRY_SIZE 36
54 #define ALUA_FAILOVER_TIMEOUT (60 * HZ)
55 #define ALUA_FAILOVER_RETRIES 5
62 unsigned char inq
[ALUA_INQUIRY_SIZE
];
65 unsigned char sense
[SCSI_SENSE_BUFFERSIZE
];
67 struct scsi_device
*sdev
;
68 activate_complete callback_fn
;
72 #define ALUA_POLICY_SWITCH_CURRENT 0
73 #define ALUA_POLICY_SWITCH_ALL 1
75 static char print_alua_state(int);
76 static int alua_check_sense(struct scsi_device
*, struct scsi_sense_hdr
*);
78 static inline struct alua_dh_data
*get_alua_data(struct scsi_device
*sdev
)
80 struct scsi_dh_data
*scsi_dh_data
= sdev
->scsi_dh_data
;
81 BUG_ON(scsi_dh_data
== NULL
);
82 return ((struct alua_dh_data
*) scsi_dh_data
->buf
);
85 static int realloc_buffer(struct alua_dh_data
*h
, unsigned len
)
87 if (h
->buff
&& h
->buff
!= h
->inq
)
90 h
->buff
= kmalloc(len
, GFP_NOIO
);
93 h
->bufflen
= ALUA_INQUIRY_SIZE
;
100 static struct request
*get_alua_req(struct scsi_device
*sdev
,
101 void *buffer
, unsigned buflen
, int rw
)
104 struct request_queue
*q
= sdev
->request_queue
;
106 rq
= blk_get_request(q
, rw
, GFP_NOIO
);
109 sdev_printk(KERN_INFO
, sdev
,
110 "%s: blk_get_request failed\n", __func__
);
114 if (buflen
&& blk_rq_map_kern(q
, rq
, buffer
, buflen
, GFP_NOIO
)) {
116 sdev_printk(KERN_INFO
, sdev
,
117 "%s: blk_rq_map_kern failed\n", __func__
);
121 rq
->cmd_type
= REQ_TYPE_BLOCK_PC
;
122 rq
->cmd_flags
|= REQ_FAILFAST_DEV
| REQ_FAILFAST_TRANSPORT
|
124 rq
->retries
= ALUA_FAILOVER_RETRIES
;
125 rq
->timeout
= ALUA_FAILOVER_TIMEOUT
;
131 * submit_std_inquiry - Issue a standard INQUIRY command
132 * @sdev: sdev the command should be send to
134 static int submit_std_inquiry(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
137 int err
= SCSI_DH_RES_TEMP_UNAVAIL
;
139 rq
= get_alua_req(sdev
, h
->inq
, ALUA_INQUIRY_SIZE
, READ
);
143 /* Prepare the command. */
144 rq
->cmd
[0] = INQUIRY
;
147 rq
->cmd
[4] = ALUA_INQUIRY_SIZE
;
148 rq
->cmd_len
= COMMAND_SIZE(INQUIRY
);
150 rq
->sense
= h
->sense
;
151 memset(rq
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
152 rq
->sense_len
= h
->senselen
= 0;
154 err
= blk_execute_rq(rq
->q
, NULL
, rq
, 1);
156 sdev_printk(KERN_INFO
, sdev
,
157 "%s: std inquiry failed with %x\n",
158 ALUA_DH_NAME
, rq
->errors
);
159 h
->senselen
= rq
->sense_len
;
168 * submit_vpd_inquiry - Issue an INQUIRY VPD page 0x83 command
169 * @sdev: sdev the command should be sent to
171 static int submit_vpd_inquiry(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
174 int err
= SCSI_DH_RES_TEMP_UNAVAIL
;
176 rq
= get_alua_req(sdev
, h
->buff
, h
->bufflen
, READ
);
180 /* Prepare the command. */
181 rq
->cmd
[0] = INQUIRY
;
184 rq
->cmd
[4] = h
->bufflen
;
185 rq
->cmd_len
= COMMAND_SIZE(INQUIRY
);
187 rq
->sense
= h
->sense
;
188 memset(rq
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
189 rq
->sense_len
= h
->senselen
= 0;
191 err
= blk_execute_rq(rq
->q
, NULL
, rq
, 1);
193 sdev_printk(KERN_INFO
, sdev
,
194 "%s: evpd inquiry failed with %x\n",
195 ALUA_DH_NAME
, rq
->errors
);
196 h
->senselen
= rq
->sense_len
;
205 * submit_rtpg - Issue a REPORT TARGET GROUP STATES command
206 * @sdev: sdev the command should be sent to
208 static unsigned submit_rtpg(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
211 int err
= SCSI_DH_RES_TEMP_UNAVAIL
;
213 rq
= get_alua_req(sdev
, h
->buff
, h
->bufflen
, READ
);
217 /* Prepare the command. */
218 rq
->cmd
[0] = MAINTENANCE_IN
;
219 rq
->cmd
[1] = MI_REPORT_TARGET_PGS
;
220 rq
->cmd
[6] = (h
->bufflen
>> 24) & 0xff;
221 rq
->cmd
[7] = (h
->bufflen
>> 16) & 0xff;
222 rq
->cmd
[8] = (h
->bufflen
>> 8) & 0xff;
223 rq
->cmd
[9] = h
->bufflen
& 0xff;
224 rq
->cmd_len
= COMMAND_SIZE(MAINTENANCE_IN
);
226 rq
->sense
= h
->sense
;
227 memset(rq
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
228 rq
->sense_len
= h
->senselen
= 0;
230 err
= blk_execute_rq(rq
->q
, NULL
, rq
, 1);
232 sdev_printk(KERN_INFO
, sdev
,
233 "%s: rtpg failed with %x\n",
234 ALUA_DH_NAME
, rq
->errors
);
235 h
->senselen
= rq
->sense_len
;
244 * alua_stpg - Evaluate SET TARGET GROUP STATES
245 * @sdev: the device to be evaluated
246 * @state: the new target group state
248 * Send a SET TARGET GROUP STATES command to the device.
249 * We only have to test here if we should resubmit the command;
250 * any other error is assumed as a failure.
252 static void stpg_endio(struct request
*req
, int error
)
254 struct alua_dh_data
*h
= req
->end_io_data
;
255 struct scsi_sense_hdr sense_hdr
;
256 unsigned err
= SCSI_DH_IO
;
258 if (error
|| host_byte(req
->errors
) != DID_OK
||
259 msg_byte(req
->errors
) != COMMAND_COMPLETE
)
262 if (err
== SCSI_DH_IO
&& h
->senselen
> 0) {
263 err
= scsi_normalize_sense(h
->sense
, SCSI_SENSE_BUFFERSIZE
,
269 err
= alua_check_sense(h
->sdev
, &sense_hdr
);
270 if (err
== ADD_TO_MLQUEUE
) {
274 sdev_printk(KERN_INFO
, h
->sdev
,
275 "%s: stpg sense code: %02x/%02x/%02x\n",
276 ALUA_DH_NAME
, sense_hdr
.sense_key
,
277 sense_hdr
.asc
, sense_hdr
.ascq
);
280 if (err
== SCSI_DH_OK
) {
281 h
->state
= TPGS_STATE_OPTIMIZED
;
282 sdev_printk(KERN_INFO
, h
->sdev
,
283 "%s: port group %02x switched to state %c\n",
284 ALUA_DH_NAME
, h
->group_id
,
285 print_alua_state(h
->state
));
288 blk_put_request(req
);
289 if (h
->callback_fn
) {
290 h
->callback_fn(h
->callback_data
, err
);
291 h
->callback_fn
= h
->callback_data
= NULL
;
297 * submit_stpg - Issue a SET TARGET GROUP STATES command
299 * Currently we're only setting the current target port group state
300 * to 'active/optimized' and let the array firmware figure out
301 * the states of the remaining groups.
303 static unsigned submit_stpg(struct alua_dh_data
*h
)
306 int err
= SCSI_DH_RES_TEMP_UNAVAIL
;
308 struct scsi_device
*sdev
= h
->sdev
;
310 /* Prepare the data buffer */
311 memset(h
->buff
, 0, stpg_len
);
312 h
->buff
[4] = TPGS_STATE_OPTIMIZED
& 0x0f;
313 h
->buff
[6] = (h
->group_id
>> 8) & 0xff;
314 h
->buff
[7] = h
->group_id
& 0xff;
316 rq
= get_alua_req(sdev
, h
->buff
, stpg_len
, WRITE
);
318 return SCSI_DH_RES_TEMP_UNAVAIL
;
320 /* Prepare the command. */
321 rq
->cmd
[0] = MAINTENANCE_OUT
;
322 rq
->cmd
[1] = MO_SET_TARGET_PGS
;
323 rq
->cmd
[6] = (stpg_len
>> 24) & 0xff;
324 rq
->cmd
[7] = (stpg_len
>> 16) & 0xff;
325 rq
->cmd
[8] = (stpg_len
>> 8) & 0xff;
326 rq
->cmd
[9] = stpg_len
& 0xff;
327 rq
->cmd_len
= COMMAND_SIZE(MAINTENANCE_OUT
);
329 rq
->sense
= h
->sense
;
330 memset(rq
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
331 rq
->sense_len
= h
->senselen
= 0;
334 blk_execute_rq_nowait(rq
->q
, NULL
, rq
, 1, stpg_endio
);
339 * alua_std_inquiry - Evaluate standard INQUIRY command
340 * @sdev: device to be checked
342 * Just extract the TPGS setting to find out if ALUA
345 static int alua_std_inquiry(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
349 err
= submit_std_inquiry(sdev
, h
);
351 if (err
!= SCSI_DH_OK
)
354 /* Check TPGS setting */
355 h
->tpgs
= (h
->inq
[5] >> 4) & 0x3;
357 case TPGS_MODE_EXPLICIT
|TPGS_MODE_IMPLICIT
:
358 sdev_printk(KERN_INFO
, sdev
,
359 "%s: supports implicit and explicit TPGS\n",
362 case TPGS_MODE_EXPLICIT
:
363 sdev_printk(KERN_INFO
, sdev
, "%s: supports explicit TPGS\n",
366 case TPGS_MODE_IMPLICIT
:
367 sdev_printk(KERN_INFO
, sdev
, "%s: supports implicit TPGS\n",
371 h
->tpgs
= TPGS_MODE_NONE
;
372 sdev_printk(KERN_INFO
, sdev
, "%s: not supported\n",
374 err
= SCSI_DH_DEV_UNSUPP
;
382 * alua_vpd_inquiry - Evaluate INQUIRY vpd page 0x83
383 * @sdev: device to be checked
385 * Extract the relative target port and the target port group
386 * descriptor from the list of identificators.
388 static int alua_vpd_inquiry(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
395 err
= submit_vpd_inquiry(sdev
, h
);
397 if (err
!= SCSI_DH_OK
)
400 /* Check if vpd page exceeds initial buffer */
401 len
= (h
->buff
[2] << 8) + h
->buff
[3] + 4;
402 if (len
> h
->bufflen
) {
403 /* Resubmit with the correct length */
404 if (realloc_buffer(h
, len
)) {
405 sdev_printk(KERN_WARNING
, sdev
,
406 "%s: kmalloc buffer failed\n",
408 /* Temporary failure, bypass */
409 return SCSI_DH_DEV_TEMP_BUSY
;
415 * Now look for the correct descriptor.
418 while (d
< h
->buff
+ len
) {
419 switch (d
[1] & 0xf) {
421 /* Relative target port */
422 h
->rel_port
= (d
[6] << 8) + d
[7];
425 /* Target port group */
426 h
->group_id
= (d
[6] << 8) + d
[7];
434 if (h
->group_id
== -1) {
436 * Internal error; TPGS supported but required
437 * VPD identification descriptors not present.
438 * Disable ALUA support
440 sdev_printk(KERN_INFO
, sdev
,
441 "%s: No target port descriptors found\n",
443 h
->state
= TPGS_STATE_OPTIMIZED
;
444 h
->tpgs
= TPGS_MODE_NONE
;
445 err
= SCSI_DH_DEV_UNSUPP
;
447 sdev_printk(KERN_INFO
, sdev
,
448 "%s: port group %02x rel port %02x\n",
449 ALUA_DH_NAME
, h
->group_id
, h
->rel_port
);
455 static char print_alua_state(int state
)
458 case TPGS_STATE_OPTIMIZED
:
460 case TPGS_STATE_NONOPTIMIZED
:
462 case TPGS_STATE_STANDBY
:
464 case TPGS_STATE_UNAVAILABLE
:
466 case TPGS_STATE_LBA_DEPENDENT
:
468 case TPGS_STATE_OFFLINE
:
470 case TPGS_STATE_TRANSITIONING
:
477 static int alua_check_sense(struct scsi_device
*sdev
,
478 struct scsi_sense_hdr
*sense_hdr
)
480 switch (sense_hdr
->sense_key
) {
482 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x0a)
484 * LUN Not Accessible - ALUA state transition
486 return ADD_TO_MLQUEUE
;
487 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x0b)
489 * LUN Not Accessible -- Target port in standby state
492 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x0c)
494 * LUN Not Accessible -- Target port in unavailable state
497 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x12)
499 * LUN Not Ready -- Offline
504 if (sense_hdr
->asc
== 0x29 && sense_hdr
->ascq
== 0x00)
506 * Power On, Reset, or Bus Device Reset, just retry.
508 return ADD_TO_MLQUEUE
;
509 if (sense_hdr
->asc
== 0x2a && sense_hdr
->ascq
== 0x06) {
513 return ADD_TO_MLQUEUE
;
515 if (sense_hdr
->asc
== 0x2a && sense_hdr
->ascq
== 0x07) {
517 * Implicit ALUA state transition failed
519 return ADD_TO_MLQUEUE
;
521 if (sense_hdr
->asc
== 0x3f && sense_hdr
->ascq
== 0x0e) {
523 * REPORTED_LUNS_DATA_HAS_CHANGED is reported
524 * when switching controllers on targets like
525 * Intel Multi-Flex. We can just retry.
527 return ADD_TO_MLQUEUE
;
533 return SCSI_RETURN_NOT_HANDLED
;
537 * alua_rtpg - Evaluate REPORT TARGET GROUP STATES
538 * @sdev: the device to be evaluated.
540 * Evaluate the Target Port Group State.
541 * Returns SCSI_DH_DEV_OFFLINED if the path is
542 * found to be unuseable.
544 static int alua_rtpg(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
546 struct scsi_sense_hdr sense_hdr
;
547 int len
, k
, off
, valid_states
= 0;
550 unsigned long expiry
, interval
= 10;
552 expiry
= round_jiffies_up(jiffies
+ ALUA_FAILOVER_TIMEOUT
);
554 err
= submit_rtpg(sdev
, h
);
556 if (err
== SCSI_DH_IO
&& h
->senselen
> 0) {
557 err
= scsi_normalize_sense(h
->sense
, SCSI_SENSE_BUFFERSIZE
,
562 err
= alua_check_sense(sdev
, &sense_hdr
);
563 if (err
== ADD_TO_MLQUEUE
&& time_before(jiffies
, expiry
))
565 sdev_printk(KERN_INFO
, sdev
,
566 "%s: rtpg sense code %02x/%02x/%02x\n",
567 ALUA_DH_NAME
, sense_hdr
.sense_key
,
568 sense_hdr
.asc
, sense_hdr
.ascq
);
571 if (err
!= SCSI_DH_OK
)
574 len
= (h
->buff
[0] << 24) + (h
->buff
[1] << 16) +
575 (h
->buff
[2] << 8) + h
->buff
[3] + 4;
577 if (len
> h
->bufflen
) {
578 /* Resubmit with the correct length */
579 if (realloc_buffer(h
, len
)) {
580 sdev_printk(KERN_WARNING
, sdev
,
581 "%s: kmalloc buffer failed\n",__func__
);
582 /* Temporary failure, bypass */
583 return SCSI_DH_DEV_TEMP_BUSY
;
588 for (k
= 4, ucp
= h
->buff
+ 4; k
< len
; k
+= off
, ucp
+= off
) {
589 if (h
->group_id
== (ucp
[2] << 8) + ucp
[3]) {
590 h
->state
= ucp
[0] & 0x0f;
591 valid_states
= ucp
[1];
593 off
= 8 + (ucp
[7] * 4);
596 sdev_printk(KERN_INFO
, sdev
,
597 "%s: port group %02x state %c supports %c%c%c%c%c%c%c\n",
598 ALUA_DH_NAME
, h
->group_id
, print_alua_state(h
->state
),
599 valid_states
&TPGS_SUPPORT_TRANSITION
?'T':'t',
600 valid_states
&TPGS_SUPPORT_OFFLINE
?'O':'o',
601 valid_states
&TPGS_SUPPORT_LBA_DEPENDENT
?'L':'l',
602 valid_states
&TPGS_SUPPORT_UNAVAILABLE
?'U':'u',
603 valid_states
&TPGS_SUPPORT_STANDBY
?'S':'s',
604 valid_states
&TPGS_SUPPORT_NONOPTIMIZED
?'N':'n',
605 valid_states
&TPGS_SUPPORT_OPTIMIZED
?'A':'a');
608 case TPGS_STATE_TRANSITIONING
:
609 if (time_before(jiffies
, expiry
)) {
610 /* State transition, retry */
615 /* Transitioning time exceeded, set port to standby */
617 h
->state
= TPGS_STATE_STANDBY
;
619 case TPGS_STATE_OFFLINE
:
620 case TPGS_STATE_UNAVAILABLE
:
621 /* Path unuseable for unavailable/offline */
622 err
= SCSI_DH_DEV_OFFLINED
;
625 /* Useable path if active */
633 * alua_initialize - Initialize ALUA state
634 * @sdev: the device to be initialized
636 * For the prep_fn to work correctly we have
637 * to initialize the ALUA state for the device.
639 static int alua_initialize(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
643 err
= alua_std_inquiry(sdev
, h
);
644 if (err
!= SCSI_DH_OK
)
647 err
= alua_vpd_inquiry(sdev
, h
);
648 if (err
!= SCSI_DH_OK
)
651 err
= alua_rtpg(sdev
, h
);
652 if (err
!= SCSI_DH_OK
)
660 * alua_activate - activate a path
661 * @sdev: device on the path to be activated
663 * We're currently switching the port group to be activated only and
664 * let the array figure out the rest.
665 * There may be other arrays which require us to switch all port groups
666 * based on a certain policy. But until we actually encounter them it
669 static int alua_activate(struct scsi_device
*sdev
,
670 activate_complete fn
, void *data
)
672 struct alua_dh_data
*h
= get_alua_data(sdev
);
673 int err
= SCSI_DH_OK
;
675 if (h
->group_id
!= -1) {
676 err
= alua_rtpg(sdev
, h
);
677 if (err
!= SCSI_DH_OK
)
681 if (h
->tpgs
& TPGS_MODE_EXPLICIT
&&
682 h
->state
!= TPGS_STATE_OPTIMIZED
&&
683 h
->state
!= TPGS_STATE_LBA_DEPENDENT
) {
685 h
->callback_data
= data
;
686 err
= submit_stpg(h
);
687 if (err
== SCSI_DH_OK
)
689 h
->callback_fn
= h
->callback_data
= NULL
;
699 * alua_prep_fn - request callback
701 * Fail I/O to all paths not in state
702 * active/optimized or active/non-optimized.
704 static int alua_prep_fn(struct scsi_device
*sdev
, struct request
*req
)
706 struct alua_dh_data
*h
= get_alua_data(sdev
);
707 int ret
= BLKPREP_OK
;
709 if (h
->state
== TPGS_STATE_TRANSITIONING
)
711 else if (h
->state
!= TPGS_STATE_OPTIMIZED
&&
712 h
->state
!= TPGS_STATE_NONOPTIMIZED
&&
713 h
->state
!= TPGS_STATE_LBA_DEPENDENT
) {
715 req
->cmd_flags
|= REQ_QUIET
;
721 static const struct scsi_dh_devlist alua_dev_list
[] = {
722 {"HP", "MSA VOLUME" },
730 {"Pillar", "Axiom" },
731 {"Intel", "Multi-Flex"},
737 static int alua_bus_attach(struct scsi_device
*sdev
);
738 static void alua_bus_detach(struct scsi_device
*sdev
);
740 static struct scsi_device_handler alua_dh
= {
741 .name
= ALUA_DH_NAME
,
742 .module
= THIS_MODULE
,
743 .devlist
= alua_dev_list
,
744 .attach
= alua_bus_attach
,
745 .detach
= alua_bus_detach
,
746 .prep_fn
= alua_prep_fn
,
747 .check_sense
= alua_check_sense
,
748 .activate
= alua_activate
,
752 * alua_bus_attach - Attach device handler
753 * @sdev: device to be attached to
755 static int alua_bus_attach(struct scsi_device
*sdev
)
757 struct scsi_dh_data
*scsi_dh_data
;
758 struct alua_dh_data
*h
;
760 int err
= SCSI_DH_OK
;
762 scsi_dh_data
= kzalloc(sizeof(struct scsi_device_handler
*)
763 + sizeof(*h
) , GFP_KERNEL
);
765 sdev_printk(KERN_ERR
, sdev
, "%s: Attach failed\n",
770 scsi_dh_data
->scsi_dh
= &alua_dh
;
771 h
= (struct alua_dh_data
*) scsi_dh_data
->buf
;
772 h
->tpgs
= TPGS_MODE_UNINITIALIZED
;
773 h
->state
= TPGS_STATE_OPTIMIZED
;
777 h
->bufflen
= ALUA_INQUIRY_SIZE
;
780 err
= alua_initialize(sdev
, h
);
781 if (err
!= SCSI_DH_OK
)
784 if (!try_module_get(THIS_MODULE
))
787 spin_lock_irqsave(sdev
->request_queue
->queue_lock
, flags
);
788 sdev
->scsi_dh_data
= scsi_dh_data
;
789 spin_unlock_irqrestore(sdev
->request_queue
->queue_lock
, flags
);
795 sdev_printk(KERN_ERR
, sdev
, "%s: not attached\n", ALUA_DH_NAME
);
800 * alua_bus_detach - Detach device handler
801 * @sdev: device to be detached from
803 static void alua_bus_detach(struct scsi_device
*sdev
)
805 struct scsi_dh_data
*scsi_dh_data
;
806 struct alua_dh_data
*h
;
809 spin_lock_irqsave(sdev
->request_queue
->queue_lock
, flags
);
810 scsi_dh_data
= sdev
->scsi_dh_data
;
811 sdev
->scsi_dh_data
= NULL
;
812 spin_unlock_irqrestore(sdev
->request_queue
->queue_lock
, flags
);
814 h
= (struct alua_dh_data
*) scsi_dh_data
->buf
;
815 if (h
->buff
&& h
->inq
!= h
->buff
)
818 module_put(THIS_MODULE
);
819 sdev_printk(KERN_NOTICE
, sdev
, "%s: Detached\n", ALUA_DH_NAME
);
822 static int __init
alua_init(void)
826 r
= scsi_register_device_handler(&alua_dh
);
828 printk(KERN_ERR
"%s: Failed to register scsi device handler",
833 static void __exit
alua_exit(void)
835 scsi_unregister_device_handler(&alua_dh
);
838 module_init(alua_init
);
839 module_exit(alua_exit
);
841 MODULE_DESCRIPTION("DM Multipath ALUA support");
842 MODULE_AUTHOR("Hannes Reinecke <hare@suse.de>");
843 MODULE_LICENSE("GPL");
844 MODULE_VERSION(ALUA_DH_VER
);