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
58 /* flags passed from user level */
59 #define ALUA_OPTIMIZE_STPG 1
67 unsigned flags
; /* used for optimizing STPG */
68 unsigned char inq
[ALUA_INQUIRY_SIZE
];
71 unsigned char sense
[SCSI_SENSE_BUFFERSIZE
];
73 struct scsi_device
*sdev
;
74 activate_complete callback_fn
;
78 #define ALUA_POLICY_SWITCH_CURRENT 0
79 #define ALUA_POLICY_SWITCH_ALL 1
81 static char print_alua_state(int);
82 static int alua_check_sense(struct scsi_device
*, struct scsi_sense_hdr
*);
84 static inline struct alua_dh_data
*get_alua_data(struct scsi_device
*sdev
)
86 struct scsi_dh_data
*scsi_dh_data
= sdev
->scsi_dh_data
;
87 BUG_ON(scsi_dh_data
== NULL
);
88 return ((struct alua_dh_data
*) scsi_dh_data
->buf
);
91 static int realloc_buffer(struct alua_dh_data
*h
, unsigned len
)
93 if (h
->buff
&& h
->buff
!= h
->inq
)
96 h
->buff
= kmalloc(len
, GFP_NOIO
);
99 h
->bufflen
= ALUA_INQUIRY_SIZE
;
106 static struct request
*get_alua_req(struct scsi_device
*sdev
,
107 void *buffer
, unsigned buflen
, int rw
)
110 struct request_queue
*q
= sdev
->request_queue
;
112 rq
= blk_get_request(q
, rw
, GFP_NOIO
);
115 sdev_printk(KERN_INFO
, sdev
,
116 "%s: blk_get_request failed\n", __func__
);
120 if (buflen
&& blk_rq_map_kern(q
, rq
, buffer
, buflen
, GFP_NOIO
)) {
122 sdev_printk(KERN_INFO
, sdev
,
123 "%s: blk_rq_map_kern failed\n", __func__
);
127 rq
->cmd_type
= REQ_TYPE_BLOCK_PC
;
128 rq
->cmd_flags
|= REQ_FAILFAST_DEV
| REQ_FAILFAST_TRANSPORT
|
130 rq
->retries
= ALUA_FAILOVER_RETRIES
;
131 rq
->timeout
= ALUA_FAILOVER_TIMEOUT
;
137 * submit_vpd_inquiry - Issue an INQUIRY VPD page 0x83 command
138 * @sdev: sdev the command should be sent to
140 static int submit_vpd_inquiry(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
143 int err
= SCSI_DH_RES_TEMP_UNAVAIL
;
145 rq
= get_alua_req(sdev
, h
->buff
, h
->bufflen
, READ
);
149 /* Prepare the command. */
150 rq
->cmd
[0] = INQUIRY
;
153 rq
->cmd
[4] = h
->bufflen
;
154 rq
->cmd_len
= COMMAND_SIZE(INQUIRY
);
156 rq
->sense
= h
->sense
;
157 memset(rq
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
158 rq
->sense_len
= h
->senselen
= 0;
160 err
= blk_execute_rq(rq
->q
, NULL
, rq
, 1);
162 sdev_printk(KERN_INFO
, sdev
,
163 "%s: evpd inquiry failed with %x\n",
164 ALUA_DH_NAME
, rq
->errors
);
165 h
->senselen
= rq
->sense_len
;
174 * submit_rtpg - Issue a REPORT TARGET GROUP STATES command
175 * @sdev: sdev the command should be sent to
177 static unsigned submit_rtpg(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
180 int err
= SCSI_DH_RES_TEMP_UNAVAIL
;
182 rq
= get_alua_req(sdev
, h
->buff
, h
->bufflen
, READ
);
186 /* Prepare the command. */
187 rq
->cmd
[0] = MAINTENANCE_IN
;
188 rq
->cmd
[1] = MI_REPORT_TARGET_PGS
;
189 rq
->cmd
[6] = (h
->bufflen
>> 24) & 0xff;
190 rq
->cmd
[7] = (h
->bufflen
>> 16) & 0xff;
191 rq
->cmd
[8] = (h
->bufflen
>> 8) & 0xff;
192 rq
->cmd
[9] = h
->bufflen
& 0xff;
193 rq
->cmd_len
= COMMAND_SIZE(MAINTENANCE_IN
);
195 rq
->sense
= h
->sense
;
196 memset(rq
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
197 rq
->sense_len
= h
->senselen
= 0;
199 err
= blk_execute_rq(rq
->q
, NULL
, rq
, 1);
201 sdev_printk(KERN_INFO
, sdev
,
202 "%s: rtpg failed with %x\n",
203 ALUA_DH_NAME
, rq
->errors
);
204 h
->senselen
= rq
->sense_len
;
213 * alua_stpg - Evaluate SET TARGET GROUP STATES
214 * @sdev: the device to be evaluated
215 * @state: the new target group state
217 * Send a SET TARGET GROUP STATES command to the device.
218 * We only have to test here if we should resubmit the command;
219 * any other error is assumed as a failure.
221 static void stpg_endio(struct request
*req
, int error
)
223 struct alua_dh_data
*h
= req
->end_io_data
;
224 struct scsi_sense_hdr sense_hdr
;
225 unsigned err
= SCSI_DH_OK
;
227 if (error
|| host_byte(req
->errors
) != DID_OK
||
228 msg_byte(req
->errors
) != COMMAND_COMPLETE
) {
233 if (h
->senselen
> 0) {
234 err
= scsi_normalize_sense(h
->sense
, SCSI_SENSE_BUFFERSIZE
,
240 err
= alua_check_sense(h
->sdev
, &sense_hdr
);
241 if (err
== ADD_TO_MLQUEUE
) {
245 sdev_printk(KERN_INFO
, h
->sdev
,
246 "%s: stpg sense code: %02x/%02x/%02x\n",
247 ALUA_DH_NAME
, sense_hdr
.sense_key
,
248 sense_hdr
.asc
, sense_hdr
.ascq
);
251 if (err
== SCSI_DH_OK
) {
252 h
->state
= TPGS_STATE_OPTIMIZED
;
253 sdev_printk(KERN_INFO
, h
->sdev
,
254 "%s: port group %02x switched to state %c\n",
255 ALUA_DH_NAME
, h
->group_id
,
256 print_alua_state(h
->state
));
259 req
->end_io_data
= NULL
;
260 __blk_put_request(req
->q
, req
);
261 if (h
->callback_fn
) {
262 h
->callback_fn(h
->callback_data
, err
);
263 h
->callback_fn
= h
->callback_data
= NULL
;
269 * submit_stpg - Issue a SET TARGET GROUP STATES command
271 * Currently we're only setting the current target port group state
272 * to 'active/optimized' and let the array firmware figure out
273 * the states of the remaining groups.
275 static unsigned submit_stpg(struct alua_dh_data
*h
)
279 struct scsi_device
*sdev
= h
->sdev
;
281 /* Prepare the data buffer */
282 memset(h
->buff
, 0, stpg_len
);
283 h
->buff
[4] = TPGS_STATE_OPTIMIZED
& 0x0f;
284 h
->buff
[6] = (h
->group_id
>> 8) & 0xff;
285 h
->buff
[7] = h
->group_id
& 0xff;
287 rq
= get_alua_req(sdev
, h
->buff
, stpg_len
, WRITE
);
289 return SCSI_DH_RES_TEMP_UNAVAIL
;
291 /* Prepare the command. */
292 rq
->cmd
[0] = MAINTENANCE_OUT
;
293 rq
->cmd
[1] = MO_SET_TARGET_PGS
;
294 rq
->cmd
[6] = (stpg_len
>> 24) & 0xff;
295 rq
->cmd
[7] = (stpg_len
>> 16) & 0xff;
296 rq
->cmd
[8] = (stpg_len
>> 8) & 0xff;
297 rq
->cmd
[9] = stpg_len
& 0xff;
298 rq
->cmd_len
= COMMAND_SIZE(MAINTENANCE_OUT
);
300 rq
->sense
= h
->sense
;
301 memset(rq
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
302 rq
->sense_len
= h
->senselen
= 0;
305 blk_execute_rq_nowait(rq
->q
, NULL
, rq
, 1, stpg_endio
);
310 * alua_check_tpgs - Evaluate TPGS setting
311 * @sdev: device to be checked
313 * Examine the TPGS setting of the sdev to find out if ALUA
316 static int alua_check_tpgs(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
318 int err
= SCSI_DH_OK
;
320 h
->tpgs
= scsi_device_tpgs(sdev
);
322 case TPGS_MODE_EXPLICIT
|TPGS_MODE_IMPLICIT
:
323 sdev_printk(KERN_INFO
, sdev
,
324 "%s: supports implicit and explicit TPGS\n",
327 case TPGS_MODE_EXPLICIT
:
328 sdev_printk(KERN_INFO
, sdev
, "%s: supports explicit TPGS\n",
331 case TPGS_MODE_IMPLICIT
:
332 sdev_printk(KERN_INFO
, sdev
, "%s: supports implicit TPGS\n",
336 h
->tpgs
= TPGS_MODE_NONE
;
337 sdev_printk(KERN_INFO
, sdev
, "%s: not supported\n",
339 err
= SCSI_DH_DEV_UNSUPP
;
347 * alua_vpd_inquiry - Evaluate INQUIRY vpd page 0x83
348 * @sdev: device to be checked
350 * Extract the relative target port and the target port group
351 * descriptor from the list of identificators.
353 static int alua_vpd_inquiry(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
360 err
= submit_vpd_inquiry(sdev
, h
);
362 if (err
!= SCSI_DH_OK
)
365 /* Check if vpd page exceeds initial buffer */
366 len
= (h
->buff
[2] << 8) + h
->buff
[3] + 4;
367 if (len
> h
->bufflen
) {
368 /* Resubmit with the correct length */
369 if (realloc_buffer(h
, len
)) {
370 sdev_printk(KERN_WARNING
, sdev
,
371 "%s: kmalloc buffer failed\n",
373 /* Temporary failure, bypass */
374 return SCSI_DH_DEV_TEMP_BUSY
;
380 * Now look for the correct descriptor.
383 while (d
< h
->buff
+ len
) {
384 switch (d
[1] & 0xf) {
386 /* Relative target port */
387 h
->rel_port
= (d
[6] << 8) + d
[7];
390 /* Target port group */
391 h
->group_id
= (d
[6] << 8) + d
[7];
399 if (h
->group_id
== -1) {
401 * Internal error; TPGS supported but required
402 * VPD identification descriptors not present.
403 * Disable ALUA support
405 sdev_printk(KERN_INFO
, sdev
,
406 "%s: No target port descriptors found\n",
408 h
->state
= TPGS_STATE_OPTIMIZED
;
409 h
->tpgs
= TPGS_MODE_NONE
;
410 err
= SCSI_DH_DEV_UNSUPP
;
412 sdev_printk(KERN_INFO
, sdev
,
413 "%s: port group %02x rel port %02x\n",
414 ALUA_DH_NAME
, h
->group_id
, h
->rel_port
);
420 static char print_alua_state(int state
)
423 case TPGS_STATE_OPTIMIZED
:
425 case TPGS_STATE_NONOPTIMIZED
:
427 case TPGS_STATE_STANDBY
:
429 case TPGS_STATE_UNAVAILABLE
:
431 case TPGS_STATE_LBA_DEPENDENT
:
433 case TPGS_STATE_OFFLINE
:
435 case TPGS_STATE_TRANSITIONING
:
442 static int alua_check_sense(struct scsi_device
*sdev
,
443 struct scsi_sense_hdr
*sense_hdr
)
445 switch (sense_hdr
->sense_key
) {
447 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x0a)
449 * LUN Not Accessible - ALUA state transition
451 return ADD_TO_MLQUEUE
;
452 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x0b)
454 * LUN Not Accessible -- Target port in standby state
457 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x0c)
459 * LUN Not Accessible -- Target port in unavailable state
462 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x12)
464 * LUN Not Ready -- Offline
469 if (sense_hdr
->asc
== 0x29 && sense_hdr
->ascq
== 0x00)
471 * Power On, Reset, or Bus Device Reset, just retry.
473 return ADD_TO_MLQUEUE
;
474 if (sense_hdr
->asc
== 0x2a && sense_hdr
->ascq
== 0x01)
476 * Mode Parameters Changed
478 return ADD_TO_MLQUEUE
;
479 if (sense_hdr
->asc
== 0x2a && sense_hdr
->ascq
== 0x06)
483 return ADD_TO_MLQUEUE
;
484 if (sense_hdr
->asc
== 0x2a && sense_hdr
->ascq
== 0x07)
486 * Implicit ALUA state transition failed
488 return ADD_TO_MLQUEUE
;
489 if (sense_hdr
->asc
== 0x3f && sense_hdr
->ascq
== 0x03)
491 * Inquiry data has changed
493 return ADD_TO_MLQUEUE
;
494 if (sense_hdr
->asc
== 0x3f && sense_hdr
->ascq
== 0x0e)
496 * REPORTED_LUNS_DATA_HAS_CHANGED is reported
497 * when switching controllers on targets like
498 * Intel Multi-Flex. We can just retry.
500 return ADD_TO_MLQUEUE
;
504 return SCSI_RETURN_NOT_HANDLED
;
508 * alua_rtpg - Evaluate REPORT TARGET GROUP STATES
509 * @sdev: the device to be evaluated.
511 * Evaluate the Target Port Group State.
512 * Returns SCSI_DH_DEV_OFFLINED if the path is
513 * found to be unusable.
515 static int alua_rtpg(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
517 struct scsi_sense_hdr sense_hdr
;
518 int len
, k
, off
, valid_states
= 0;
521 unsigned long expiry
, interval
= 1000;
523 expiry
= round_jiffies_up(jiffies
+ ALUA_FAILOVER_TIMEOUT
);
525 err
= submit_rtpg(sdev
, h
);
527 if (err
== SCSI_DH_IO
&& h
->senselen
> 0) {
528 err
= scsi_normalize_sense(h
->sense
, SCSI_SENSE_BUFFERSIZE
,
533 err
= alua_check_sense(sdev
, &sense_hdr
);
534 if (err
== ADD_TO_MLQUEUE
&& time_before(jiffies
, expiry
))
536 sdev_printk(KERN_INFO
, sdev
,
537 "%s: rtpg sense code %02x/%02x/%02x\n",
538 ALUA_DH_NAME
, sense_hdr
.sense_key
,
539 sense_hdr
.asc
, sense_hdr
.ascq
);
542 if (err
!= SCSI_DH_OK
)
545 len
= (h
->buff
[0] << 24) + (h
->buff
[1] << 16) +
546 (h
->buff
[2] << 8) + h
->buff
[3] + 4;
548 if (len
> h
->bufflen
) {
549 /* Resubmit with the correct length */
550 if (realloc_buffer(h
, len
)) {
551 sdev_printk(KERN_WARNING
, sdev
,
552 "%s: kmalloc buffer failed\n",__func__
);
553 /* Temporary failure, bypass */
554 return SCSI_DH_DEV_TEMP_BUSY
;
559 for (k
= 4, ucp
= h
->buff
+ 4; k
< len
; k
+= off
, ucp
+= off
) {
560 if (h
->group_id
== (ucp
[2] << 8) + ucp
[3]) {
561 h
->state
= ucp
[0] & 0x0f;
562 h
->pref
= ucp
[0] >> 7;
563 valid_states
= ucp
[1];
565 off
= 8 + (ucp
[7] * 4);
568 sdev_printk(KERN_INFO
, sdev
,
569 "%s: port group %02x state %c %s supports %c%c%c%c%c%c%c\n",
570 ALUA_DH_NAME
, h
->group_id
, print_alua_state(h
->state
),
571 h
->pref
? "preferred" : "non-preferred",
572 valid_states
&TPGS_SUPPORT_TRANSITION
?'T':'t',
573 valid_states
&TPGS_SUPPORT_OFFLINE
?'O':'o',
574 valid_states
&TPGS_SUPPORT_LBA_DEPENDENT
?'L':'l',
575 valid_states
&TPGS_SUPPORT_UNAVAILABLE
?'U':'u',
576 valid_states
&TPGS_SUPPORT_STANDBY
?'S':'s',
577 valid_states
&TPGS_SUPPORT_NONOPTIMIZED
?'N':'n',
578 valid_states
&TPGS_SUPPORT_OPTIMIZED
?'A':'a');
581 case TPGS_STATE_TRANSITIONING
:
582 if (time_before(jiffies
, expiry
)) {
583 /* State transition, retry */
588 /* Transitioning time exceeded, set port to standby */
590 h
->state
= TPGS_STATE_STANDBY
;
592 case TPGS_STATE_OFFLINE
:
593 case TPGS_STATE_UNAVAILABLE
:
594 /* Path unusable for unavailable/offline */
595 err
= SCSI_DH_DEV_OFFLINED
;
598 /* Useable path if active */
606 * alua_initialize - Initialize ALUA state
607 * @sdev: the device to be initialized
609 * For the prep_fn to work correctly we have
610 * to initialize the ALUA state for the device.
612 static int alua_initialize(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
616 err
= alua_check_tpgs(sdev
, h
);
617 if (err
!= SCSI_DH_OK
)
620 err
= alua_vpd_inquiry(sdev
, h
);
621 if (err
!= SCSI_DH_OK
)
624 err
= alua_rtpg(sdev
, h
);
625 if (err
!= SCSI_DH_OK
)
632 * alua_set_params - set/unset the optimize flag
633 * @sdev: device on the path to be activated
634 * params - parameters in the following format
635 * "no_of_params\0param1\0param2\0param3\0...\0"
636 * For example, to set the flag pass the following parameters
637 * from multipath.conf
638 * hardware_handler "2 alua 1"
640 static int alua_set_params(struct scsi_device
*sdev
, const char *params
)
642 struct alua_dh_data
*h
= get_alua_data(sdev
);
643 unsigned int optimize
= 0, argc
;
644 const char *p
= params
;
645 int result
= SCSI_DH_OK
;
647 if ((sscanf(params
, "%u", &argc
) != 1) || (argc
!= 1))
652 if ((sscanf(p
, "%u", &optimize
) != 1) || (optimize
> 1))
656 h
->flags
|= ALUA_OPTIMIZE_STPG
;
658 h
->flags
&= ~ALUA_OPTIMIZE_STPG
;
664 * alua_activate - activate a path
665 * @sdev: device on the path to be activated
667 * We're currently switching the port group to be activated only and
668 * let the array figure out the rest.
669 * There may be other arrays which require us to switch all port groups
670 * based on a certain policy. But until we actually encounter them it
673 static int alua_activate(struct scsi_device
*sdev
,
674 activate_complete fn
, void *data
)
676 struct alua_dh_data
*h
= get_alua_data(sdev
);
677 int err
= SCSI_DH_OK
;
680 err
= alua_rtpg(sdev
, h
);
681 if (err
!= SCSI_DH_OK
)
684 if (h
->tpgs
& TPGS_MODE_EXPLICIT
) {
686 case TPGS_STATE_NONOPTIMIZED
:
688 if ((h
->flags
& ALUA_OPTIMIZE_STPG
) &&
690 (h
->tpgs
& TPGS_MODE_IMPLICIT
))
693 case TPGS_STATE_STANDBY
:
696 case TPGS_STATE_UNAVAILABLE
:
697 case TPGS_STATE_OFFLINE
:
700 case TPGS_STATE_TRANSITIONING
:
710 h
->callback_data
= data
;
711 err
= submit_stpg(h
);
712 if (err
== SCSI_DH_OK
)
714 h
->callback_fn
= h
->callback_data
= NULL
;
724 * alua_prep_fn - request callback
726 * Fail I/O to all paths not in state
727 * active/optimized or active/non-optimized.
729 static int alua_prep_fn(struct scsi_device
*sdev
, struct request
*req
)
731 struct alua_dh_data
*h
= get_alua_data(sdev
);
732 int ret
= BLKPREP_OK
;
734 if (h
->state
== TPGS_STATE_TRANSITIONING
)
736 else if (h
->state
!= TPGS_STATE_OPTIMIZED
&&
737 h
->state
!= TPGS_STATE_NONOPTIMIZED
&&
738 h
->state
!= TPGS_STATE_LBA_DEPENDENT
) {
740 req
->cmd_flags
|= REQ_QUIET
;
746 static bool alua_match(struct scsi_device
*sdev
)
748 return (scsi_device_tpgs(sdev
) != 0);
751 static int alua_bus_attach(struct scsi_device
*sdev
);
752 static void alua_bus_detach(struct scsi_device
*sdev
);
754 static struct scsi_device_handler alua_dh
= {
755 .name
= ALUA_DH_NAME
,
756 .module
= THIS_MODULE
,
757 .attach
= alua_bus_attach
,
758 .detach
= alua_bus_detach
,
759 .prep_fn
= alua_prep_fn
,
760 .check_sense
= alua_check_sense
,
761 .activate
= alua_activate
,
762 .set_params
= alua_set_params
,
767 * alua_bus_attach - Attach device handler
768 * @sdev: device to be attached to
770 static int alua_bus_attach(struct scsi_device
*sdev
)
772 struct scsi_dh_data
*scsi_dh_data
;
773 struct alua_dh_data
*h
;
775 int err
= SCSI_DH_OK
;
777 scsi_dh_data
= kzalloc(sizeof(*scsi_dh_data
)
778 + sizeof(*h
) , GFP_KERNEL
);
780 sdev_printk(KERN_ERR
, sdev
, "%s: Attach failed\n",
785 scsi_dh_data
->scsi_dh
= &alua_dh
;
786 h
= (struct alua_dh_data
*) scsi_dh_data
->buf
;
787 h
->tpgs
= TPGS_MODE_UNINITIALIZED
;
788 h
->state
= TPGS_STATE_OPTIMIZED
;
792 h
->bufflen
= ALUA_INQUIRY_SIZE
;
795 err
= alua_initialize(sdev
, h
);
796 if ((err
!= SCSI_DH_OK
) && (err
!= SCSI_DH_DEV_OFFLINED
))
799 if (!try_module_get(THIS_MODULE
))
802 spin_lock_irqsave(sdev
->request_queue
->queue_lock
, flags
);
803 sdev
->scsi_dh_data
= scsi_dh_data
;
804 spin_unlock_irqrestore(sdev
->request_queue
->queue_lock
, flags
);
805 sdev_printk(KERN_NOTICE
, sdev
, "%s: Attached\n", ALUA_DH_NAME
);
811 sdev_printk(KERN_ERR
, sdev
, "%s: not attached\n", ALUA_DH_NAME
);
816 * alua_bus_detach - Detach device handler
817 * @sdev: device to be detached from
819 static void alua_bus_detach(struct scsi_device
*sdev
)
821 struct scsi_dh_data
*scsi_dh_data
;
822 struct alua_dh_data
*h
;
825 spin_lock_irqsave(sdev
->request_queue
->queue_lock
, flags
);
826 scsi_dh_data
= sdev
->scsi_dh_data
;
827 sdev
->scsi_dh_data
= NULL
;
828 spin_unlock_irqrestore(sdev
->request_queue
->queue_lock
, flags
);
830 h
= (struct alua_dh_data
*) scsi_dh_data
->buf
;
831 if (h
->buff
&& h
->inq
!= h
->buff
)
834 module_put(THIS_MODULE
);
835 sdev_printk(KERN_NOTICE
, sdev
, "%s: Detached\n", ALUA_DH_NAME
);
838 static int __init
alua_init(void)
842 r
= scsi_register_device_handler(&alua_dh
);
844 printk(KERN_ERR
"%s: Failed to register scsi device handler",
849 static void __exit
alua_exit(void)
851 scsi_unregister_device_handler(&alua_dh
);
854 module_init(alua_init
);
855 module_exit(alua_exit
);
857 MODULE_DESCRIPTION("DM Multipath ALUA support");
858 MODULE_AUTHOR("Hannes Reinecke <hare@suse.de>");
859 MODULE_LICENSE("GPL");
860 MODULE_VERSION(ALUA_DH_VER
);