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_dbg.h>
27 #include <scsi/scsi_eh.h>
28 #include <scsi/scsi_dh.h>
30 #define ALUA_DH_NAME "alua"
31 #define ALUA_DH_VER "1.3"
33 #define TPGS_STATE_OPTIMIZED 0x0
34 #define TPGS_STATE_NONOPTIMIZED 0x1
35 #define TPGS_STATE_STANDBY 0x2
36 #define TPGS_STATE_UNAVAILABLE 0x3
37 #define TPGS_STATE_LBA_DEPENDENT 0x4
38 #define TPGS_STATE_OFFLINE 0xe
39 #define TPGS_STATE_TRANSITIONING 0xf
41 #define TPGS_SUPPORT_NONE 0x00
42 #define TPGS_SUPPORT_OPTIMIZED 0x01
43 #define TPGS_SUPPORT_NONOPTIMIZED 0x02
44 #define TPGS_SUPPORT_STANDBY 0x04
45 #define TPGS_SUPPORT_UNAVAILABLE 0x08
46 #define TPGS_SUPPORT_LBA_DEPENDENT 0x10
47 #define TPGS_SUPPORT_OFFLINE 0x40
48 #define TPGS_SUPPORT_TRANSITION 0x80
50 #define RTPG_FMT_MASK 0x70
51 #define RTPG_FMT_EXT_HDR 0x10
53 #define TPGS_MODE_UNINITIALIZED -1
54 #define TPGS_MODE_NONE 0x0
55 #define TPGS_MODE_IMPLICIT 0x1
56 #define TPGS_MODE_EXPLICIT 0x2
58 #define ALUA_INQUIRY_SIZE 36
59 #define ALUA_FAILOVER_TIMEOUT 60
60 #define ALUA_FAILOVER_RETRIES 5
62 /* device handler flags */
63 #define ALUA_OPTIMIZE_STPG 1
64 #define ALUA_RTPG_EXT_HDR_UNSUPP 2
72 unsigned flags
; /* used for optimizing STPG */
73 unsigned char inq
[ALUA_INQUIRY_SIZE
];
76 unsigned char transition_tmo
;
77 unsigned char sense
[SCSI_SENSE_BUFFERSIZE
];
78 struct scsi_device
*sdev
;
79 activate_complete callback_fn
;
83 #define ALUA_POLICY_SWITCH_CURRENT 0
84 #define ALUA_POLICY_SWITCH_ALL 1
86 static char print_alua_state(int);
87 static int alua_check_sense(struct scsi_device
*, struct scsi_sense_hdr
*);
89 static int realloc_buffer(struct alua_dh_data
*h
, unsigned len
)
91 if (h
->buff
&& h
->buff
!= h
->inq
)
94 h
->buff
= kmalloc(len
, GFP_NOIO
);
97 h
->bufflen
= ALUA_INQUIRY_SIZE
;
104 static struct request
*get_alua_req(struct scsi_device
*sdev
,
105 void *buffer
, unsigned buflen
, int rw
)
108 struct request_queue
*q
= sdev
->request_queue
;
110 rq
= blk_get_request(q
, rw
, GFP_NOIO
);
113 sdev_printk(KERN_INFO
, sdev
,
114 "%s: blk_get_request failed\n", __func__
);
117 blk_rq_set_block_pc(rq
);
119 if (buflen
&& blk_rq_map_kern(q
, rq
, buffer
, buflen
, GFP_NOIO
)) {
121 sdev_printk(KERN_INFO
, sdev
,
122 "%s: blk_rq_map_kern failed\n", __func__
);
126 rq
->cmd_flags
|= REQ_FAILFAST_DEV
| REQ_FAILFAST_TRANSPORT
|
128 rq
->retries
= ALUA_FAILOVER_RETRIES
;
129 rq
->timeout
= ALUA_FAILOVER_TIMEOUT
* HZ
;
135 * submit_rtpg - Issue a REPORT TARGET GROUP STATES command
136 * @sdev: sdev the command should be sent to
138 static unsigned submit_rtpg(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
143 rq
= get_alua_req(sdev
, h
->buff
, h
->bufflen
, READ
);
145 err
= DRIVER_BUSY
<< 24;
149 /* Prepare the command. */
150 rq
->cmd
[0] = MAINTENANCE_IN
;
151 if (!(h
->flags
& ALUA_RTPG_EXT_HDR_UNSUPP
))
152 rq
->cmd
[1] = MI_REPORT_TARGET_PGS
| MI_EXT_HDR_PARAM_FMT
;
154 rq
->cmd
[1] = MI_REPORT_TARGET_PGS
;
155 rq
->cmd
[6] = (h
->bufflen
>> 24) & 0xff;
156 rq
->cmd
[7] = (h
->bufflen
>> 16) & 0xff;
157 rq
->cmd
[8] = (h
->bufflen
>> 8) & 0xff;
158 rq
->cmd
[9] = h
->bufflen
& 0xff;
159 rq
->cmd_len
= COMMAND_SIZE(MAINTENANCE_IN
);
161 rq
->sense
= h
->sense
;
162 memset(rq
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
165 blk_execute_rq(rq
->q
, NULL
, rq
, 1);
174 * stpg_endio - Evaluate SET TARGET GROUP STATES
175 * @sdev: the device to be evaluated
176 * @state: the new target group state
178 * Evaluate a SET TARGET GROUP STATES command response.
180 static void stpg_endio(struct request
*req
, int error
)
182 struct alua_dh_data
*h
= req
->end_io_data
;
183 struct scsi_sense_hdr sense_hdr
;
184 unsigned err
= SCSI_DH_OK
;
186 if (host_byte(req
->errors
) != DID_OK
||
187 msg_byte(req
->errors
) != COMMAND_COMPLETE
) {
192 if (scsi_normalize_sense(h
->sense
, SCSI_SENSE_BUFFERSIZE
,
194 err
= alua_check_sense(h
->sdev
, &sense_hdr
);
195 if (err
== ADD_TO_MLQUEUE
) {
199 sdev_printk(KERN_INFO
, h
->sdev
, "%s: stpg failed\n",
201 scsi_print_sense_hdr(h
->sdev
, ALUA_DH_NAME
, &sense_hdr
);
206 if (err
== SCSI_DH_OK
) {
207 h
->state
= TPGS_STATE_OPTIMIZED
;
208 sdev_printk(KERN_INFO
, h
->sdev
,
209 "%s: port group %02x switched to state %c\n",
210 ALUA_DH_NAME
, h
->group_id
,
211 print_alua_state(h
->state
));
214 req
->end_io_data
= NULL
;
215 __blk_put_request(req
->q
, req
);
216 if (h
->callback_fn
) {
217 h
->callback_fn(h
->callback_data
, err
);
218 h
->callback_fn
= h
->callback_data
= NULL
;
224 * submit_stpg - Issue a SET TARGET GROUP STATES command
226 * Currently we're only setting the current target port group state
227 * to 'active/optimized' and let the array firmware figure out
228 * the states of the remaining groups.
230 static unsigned submit_stpg(struct alua_dh_data
*h
)
234 struct scsi_device
*sdev
= h
->sdev
;
236 /* Prepare the data buffer */
237 memset(h
->buff
, 0, stpg_len
);
238 h
->buff
[4] = TPGS_STATE_OPTIMIZED
& 0x0f;
239 h
->buff
[6] = (h
->group_id
>> 8) & 0xff;
240 h
->buff
[7] = h
->group_id
& 0xff;
242 rq
= get_alua_req(sdev
, h
->buff
, stpg_len
, WRITE
);
244 return SCSI_DH_RES_TEMP_UNAVAIL
;
246 /* Prepare the command. */
247 rq
->cmd
[0] = MAINTENANCE_OUT
;
248 rq
->cmd
[1] = MO_SET_TARGET_PGS
;
249 rq
->cmd
[6] = (stpg_len
>> 24) & 0xff;
250 rq
->cmd
[7] = (stpg_len
>> 16) & 0xff;
251 rq
->cmd
[8] = (stpg_len
>> 8) & 0xff;
252 rq
->cmd
[9] = stpg_len
& 0xff;
253 rq
->cmd_len
= COMMAND_SIZE(MAINTENANCE_OUT
);
255 rq
->sense
= h
->sense
;
256 memset(rq
->sense
, 0, SCSI_SENSE_BUFFERSIZE
);
260 blk_execute_rq_nowait(rq
->q
, NULL
, rq
, 1, stpg_endio
);
265 * alua_check_tpgs - Evaluate TPGS setting
266 * @sdev: device to be checked
268 * Examine the TPGS setting of the sdev to find out if ALUA
271 static int alua_check_tpgs(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
273 int err
= SCSI_DH_OK
;
276 * ALUA support for non-disk devices is fraught with
277 * difficulties, so disable it for now.
279 if (sdev
->type
!= TYPE_DISK
) {
280 h
->tpgs
= TPGS_MODE_NONE
;
281 sdev_printk(KERN_INFO
, sdev
,
282 "%s: disable for non-disk devices\n",
284 return SCSI_DH_DEV_UNSUPP
;
287 h
->tpgs
= scsi_device_tpgs(sdev
);
289 case TPGS_MODE_EXPLICIT
|TPGS_MODE_IMPLICIT
:
290 sdev_printk(KERN_INFO
, sdev
,
291 "%s: supports implicit and explicit TPGS\n",
294 case TPGS_MODE_EXPLICIT
:
295 sdev_printk(KERN_INFO
, sdev
, "%s: supports explicit TPGS\n",
298 case TPGS_MODE_IMPLICIT
:
299 sdev_printk(KERN_INFO
, sdev
, "%s: supports implicit TPGS\n",
303 sdev_printk(KERN_INFO
, sdev
, "%s: not supported\n",
305 err
= SCSI_DH_DEV_UNSUPP
;
308 sdev_printk(KERN_INFO
, sdev
,
309 "%s: unsupported TPGS setting %d\n",
310 ALUA_DH_NAME
, h
->tpgs
);
311 h
->tpgs
= TPGS_MODE_NONE
;
312 err
= SCSI_DH_DEV_UNSUPP
;
320 * alua_check_vpd - Evaluate INQUIRY vpd page 0x83
321 * @sdev: device to be checked
323 * Extract the relative target port and the target port group
324 * descriptor from the list of identificators.
326 static int alua_check_vpd(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
329 unsigned char __rcu
*vpd_pg83
;
332 if (!rcu_dereference(sdev
->vpd_pg83
)) {
334 return SCSI_DH_DEV_UNSUPP
;
338 * Look for the correct descriptor.
340 vpd_pg83
= rcu_dereference(sdev
->vpd_pg83
);
342 while (d
< vpd_pg83
+ sdev
->vpd_pg83_len
) {
343 switch (d
[1] & 0xf) {
345 /* Relative target port */
346 h
->rel_port
= (d
[6] << 8) + d
[7];
349 /* Target port group */
350 h
->group_id
= (d
[6] << 8) + d
[7];
359 if (h
->group_id
== -1) {
361 * Internal error; TPGS supported but required
362 * VPD identification descriptors not present.
363 * Disable ALUA support
365 sdev_printk(KERN_INFO
, sdev
,
366 "%s: No target port descriptors found\n",
368 h
->state
= TPGS_STATE_OPTIMIZED
;
369 h
->tpgs
= TPGS_MODE_NONE
;
370 return SCSI_DH_DEV_UNSUPP
;
372 sdev_printk(KERN_INFO
, sdev
,
373 "%s: port group %02x rel port %02x\n",
374 ALUA_DH_NAME
, h
->group_id
, h
->rel_port
);
379 static char print_alua_state(int state
)
382 case TPGS_STATE_OPTIMIZED
:
384 case TPGS_STATE_NONOPTIMIZED
:
386 case TPGS_STATE_STANDBY
:
388 case TPGS_STATE_UNAVAILABLE
:
390 case TPGS_STATE_LBA_DEPENDENT
:
392 case TPGS_STATE_OFFLINE
:
394 case TPGS_STATE_TRANSITIONING
:
401 static int alua_check_sense(struct scsi_device
*sdev
,
402 struct scsi_sense_hdr
*sense_hdr
)
404 switch (sense_hdr
->sense_key
) {
406 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x0a)
408 * LUN Not Accessible - ALUA state transition
410 return ADD_TO_MLQUEUE
;
411 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x0b)
413 * LUN Not Accessible -- Target port in standby state
416 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x0c)
418 * LUN Not Accessible -- Target port in unavailable state
421 if (sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x12)
423 * LUN Not Ready -- Offline
426 if (sdev
->allow_restart
&&
427 sense_hdr
->asc
== 0x04 && sense_hdr
->ascq
== 0x02)
429 * if the device is not started, we need to wake
430 * the error handler to start the motor
435 if (sense_hdr
->asc
== 0x29 && sense_hdr
->ascq
== 0x00)
437 * Power On, Reset, or Bus Device Reset, just retry.
439 return ADD_TO_MLQUEUE
;
440 if (sense_hdr
->asc
== 0x29 && sense_hdr
->ascq
== 0x04)
442 * Device internal reset
444 return ADD_TO_MLQUEUE
;
445 if (sense_hdr
->asc
== 0x2a && sense_hdr
->ascq
== 0x01)
447 * Mode Parameters Changed
449 return ADD_TO_MLQUEUE
;
450 if (sense_hdr
->asc
== 0x2a && sense_hdr
->ascq
== 0x06)
454 return ADD_TO_MLQUEUE
;
455 if (sense_hdr
->asc
== 0x2a && sense_hdr
->ascq
== 0x07)
457 * Implicit ALUA state transition failed
459 return ADD_TO_MLQUEUE
;
460 if (sense_hdr
->asc
== 0x3f && sense_hdr
->ascq
== 0x03)
462 * Inquiry data has changed
464 return ADD_TO_MLQUEUE
;
465 if (sense_hdr
->asc
== 0x3f && sense_hdr
->ascq
== 0x0e)
467 * REPORTED_LUNS_DATA_HAS_CHANGED is reported
468 * when switching controllers on targets like
469 * Intel Multi-Flex. We can just retry.
471 return ADD_TO_MLQUEUE
;
475 return SCSI_RETURN_NOT_HANDLED
;
479 * alua_rtpg - Evaluate REPORT TARGET GROUP STATES
480 * @sdev: the device to be evaluated.
481 * @wait_for_transition: if nonzero, wait ALUA_FAILOVER_TIMEOUT seconds for device to exit transitioning state
483 * Evaluate the Target Port Group State.
484 * Returns SCSI_DH_DEV_OFFLINED if the path is
485 * found to be unusable.
487 static int alua_rtpg(struct scsi_device
*sdev
, struct alua_dh_data
*h
, int wait_for_transition
)
489 struct scsi_sense_hdr sense_hdr
;
490 int len
, k
, off
, valid_states
= 0;
492 unsigned err
, retval
;
493 unsigned long expiry
, interval
= 0;
494 unsigned int tpg_desc_tbl_off
;
495 unsigned char orig_transition_tmo
;
497 if (!h
->transition_tmo
)
498 expiry
= round_jiffies_up(jiffies
+ ALUA_FAILOVER_TIMEOUT
* HZ
);
500 expiry
= round_jiffies_up(jiffies
+ h
->transition_tmo
* HZ
);
503 retval
= submit_rtpg(sdev
, h
);
505 if (!scsi_normalize_sense(h
->sense
, SCSI_SENSE_BUFFERSIZE
,
507 sdev_printk(KERN_INFO
, sdev
,
508 "%s: rtpg failed, result %d\n",
509 ALUA_DH_NAME
, retval
);
510 if (driver_byte(retval
) == DRIVER_BUSY
)
511 return SCSI_DH_DEV_TEMP_BUSY
;
516 * submit_rtpg() has failed on existing arrays
517 * when requesting extended header info, and
518 * the array doesn't support extended headers,
519 * even though it shouldn't according to T10.
520 * The retry without rtpg_ext_hdr_req set
523 if (!(h
->flags
& ALUA_RTPG_EXT_HDR_UNSUPP
) &&
524 sense_hdr
.sense_key
== ILLEGAL_REQUEST
&&
525 sense_hdr
.asc
== 0x24 && sense_hdr
.ascq
== 0) {
526 h
->flags
|= ALUA_RTPG_EXT_HDR_UNSUPP
;
530 err
= alua_check_sense(sdev
, &sense_hdr
);
531 if (err
== ADD_TO_MLQUEUE
&& time_before(jiffies
, expiry
)) {
532 sdev_printk(KERN_ERR
, sdev
, "%s: rtpg retry\n",
534 scsi_print_sense_hdr(sdev
, ALUA_DH_NAME
, &sense_hdr
);
537 sdev_printk(KERN_ERR
, sdev
, "%s: rtpg failed\n",
539 scsi_print_sense_hdr(sdev
, ALUA_DH_NAME
, &sense_hdr
);
543 len
= (h
->buff
[0] << 24) + (h
->buff
[1] << 16) +
544 (h
->buff
[2] << 8) + h
->buff
[3] + 4;
546 if (len
> h
->bufflen
) {
547 /* Resubmit with the correct length */
548 if (realloc_buffer(h
, len
)) {
549 sdev_printk(KERN_WARNING
, sdev
,
550 "%s: kmalloc buffer failed\n",__func__
);
551 /* Temporary failure, bypass */
552 return SCSI_DH_DEV_TEMP_BUSY
;
557 orig_transition_tmo
= h
->transition_tmo
;
558 if ((h
->buff
[4] & RTPG_FMT_MASK
) == RTPG_FMT_EXT_HDR
&& h
->buff
[5] != 0)
559 h
->transition_tmo
= h
->buff
[5];
561 h
->transition_tmo
= ALUA_FAILOVER_TIMEOUT
;
563 if (wait_for_transition
&& (orig_transition_tmo
!= h
->transition_tmo
)) {
564 sdev_printk(KERN_INFO
, sdev
,
565 "%s: transition timeout set to %d seconds\n",
566 ALUA_DH_NAME
, h
->transition_tmo
);
567 expiry
= jiffies
+ h
->transition_tmo
* HZ
;
570 if ((h
->buff
[4] & RTPG_FMT_MASK
) == RTPG_FMT_EXT_HDR
)
571 tpg_desc_tbl_off
= 8;
573 tpg_desc_tbl_off
= 4;
575 for (k
= tpg_desc_tbl_off
, ucp
= h
->buff
+ tpg_desc_tbl_off
;
577 k
+= off
, ucp
+= off
) {
579 if (h
->group_id
== (ucp
[2] << 8) + ucp
[3]) {
580 h
->state
= ucp
[0] & 0x0f;
581 h
->pref
= ucp
[0] >> 7;
582 valid_states
= ucp
[1];
584 off
= 8 + (ucp
[7] * 4);
587 sdev_printk(KERN_INFO
, sdev
,
588 "%s: port group %02x state %c %s supports %c%c%c%c%c%c%c\n",
589 ALUA_DH_NAME
, h
->group_id
, print_alua_state(h
->state
),
590 h
->pref
? "preferred" : "non-preferred",
591 valid_states
&TPGS_SUPPORT_TRANSITION
?'T':'t',
592 valid_states
&TPGS_SUPPORT_OFFLINE
?'O':'o',
593 valid_states
&TPGS_SUPPORT_LBA_DEPENDENT
?'L':'l',
594 valid_states
&TPGS_SUPPORT_UNAVAILABLE
?'U':'u',
595 valid_states
&TPGS_SUPPORT_STANDBY
?'S':'s',
596 valid_states
&TPGS_SUPPORT_NONOPTIMIZED
?'N':'n',
597 valid_states
&TPGS_SUPPORT_OPTIMIZED
?'A':'a');
600 case TPGS_STATE_TRANSITIONING
:
601 if (wait_for_transition
) {
602 if (time_before(jiffies
, expiry
)) {
603 /* State transition, retry */
613 /* Transitioning time exceeded, set port to standby */
614 h
->state
= TPGS_STATE_STANDBY
;
616 case TPGS_STATE_OFFLINE
:
618 err
= SCSI_DH_DEV_OFFLINED
;
621 /* Useable path if active */
629 * alua_initialize - Initialize ALUA state
630 * @sdev: the device to be initialized
632 * For the prep_fn to work correctly we have
633 * to initialize the ALUA state for the device.
635 static int alua_initialize(struct scsi_device
*sdev
, struct alua_dh_data
*h
)
639 err
= alua_check_tpgs(sdev
, h
);
640 if (err
!= SCSI_DH_OK
)
643 err
= alua_check_vpd(sdev
, h
);
644 if (err
!= SCSI_DH_OK
)
647 err
= alua_rtpg(sdev
, h
, 0);
648 if (err
!= SCSI_DH_OK
)
655 * alua_set_params - set/unset the optimize flag
656 * @sdev: device on the path to be activated
657 * params - parameters in the following format
658 * "no_of_params\0param1\0param2\0param3\0...\0"
659 * For example, to set the flag pass the following parameters
660 * from multipath.conf
661 * hardware_handler "2 alua 1"
663 static int alua_set_params(struct scsi_device
*sdev
, const char *params
)
665 struct alua_dh_data
*h
= sdev
->handler_data
;
666 unsigned int optimize
= 0, argc
;
667 const char *p
= params
;
668 int result
= SCSI_DH_OK
;
670 if ((sscanf(params
, "%u", &argc
) != 1) || (argc
!= 1))
675 if ((sscanf(p
, "%u", &optimize
) != 1) || (optimize
> 1))
679 h
->flags
|= ALUA_OPTIMIZE_STPG
;
681 h
->flags
&= ~ALUA_OPTIMIZE_STPG
;
686 static uint optimize_stpg
;
687 module_param(optimize_stpg
, uint
, S_IRUGO
|S_IWUSR
);
688 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.");
691 * alua_activate - activate a path
692 * @sdev: device on the path to be activated
694 * We're currently switching the port group to be activated only and
695 * let the array figure out the rest.
696 * There may be other arrays which require us to switch all port groups
697 * based on a certain policy. But until we actually encounter them it
700 static int alua_activate(struct scsi_device
*sdev
,
701 activate_complete fn
, void *data
)
703 struct alua_dh_data
*h
= sdev
->handler_data
;
704 int err
= SCSI_DH_OK
;
707 err
= alua_rtpg(sdev
, h
, 1);
708 if (err
!= SCSI_DH_OK
)
712 h
->flags
|= ALUA_OPTIMIZE_STPG
;
714 if (h
->tpgs
& TPGS_MODE_EXPLICIT
) {
716 case TPGS_STATE_NONOPTIMIZED
:
718 if ((h
->flags
& ALUA_OPTIMIZE_STPG
) &&
720 (h
->tpgs
& TPGS_MODE_IMPLICIT
))
723 case TPGS_STATE_STANDBY
:
724 case TPGS_STATE_UNAVAILABLE
:
727 case TPGS_STATE_OFFLINE
:
730 case TPGS_STATE_TRANSITIONING
:
740 h
->callback_data
= data
;
741 err
= submit_stpg(h
);
742 if (err
== SCSI_DH_OK
)
744 h
->callback_fn
= h
->callback_data
= NULL
;
754 * alua_prep_fn - request callback
756 * Fail I/O to all paths not in state
757 * active/optimized or active/non-optimized.
759 static int alua_prep_fn(struct scsi_device
*sdev
, struct request
*req
)
761 struct alua_dh_data
*h
= sdev
->handler_data
;
762 int ret
= BLKPREP_OK
;
764 if (h
->state
== TPGS_STATE_TRANSITIONING
)
766 else if (h
->state
!= TPGS_STATE_OPTIMIZED
&&
767 h
->state
!= TPGS_STATE_NONOPTIMIZED
&&
768 h
->state
!= TPGS_STATE_LBA_DEPENDENT
) {
770 req
->cmd_flags
|= REQ_QUIET
;
777 * alua_bus_attach - Attach device handler
778 * @sdev: device to be attached to
780 static int alua_bus_attach(struct scsi_device
*sdev
)
782 struct alua_dh_data
*h
;
785 h
= kzalloc(sizeof(*h
) , GFP_KERNEL
);
788 h
->tpgs
= TPGS_MODE_UNINITIALIZED
;
789 h
->state
= TPGS_STATE_OPTIMIZED
;
793 h
->bufflen
= ALUA_INQUIRY_SIZE
;
796 err
= alua_initialize(sdev
, h
);
797 if (err
!= SCSI_DH_OK
&& err
!= SCSI_DH_DEV_OFFLINED
)
800 sdev
->handler_data
= h
;
808 * alua_bus_detach - Detach device handler
809 * @sdev: device to be detached from
811 static void alua_bus_detach(struct scsi_device
*sdev
)
813 struct alua_dh_data
*h
= sdev
->handler_data
;
815 if (h
->buff
&& h
->inq
!= h
->buff
)
817 sdev
->handler_data
= NULL
;
821 static struct scsi_device_handler alua_dh
= {
822 .name
= ALUA_DH_NAME
,
823 .module
= THIS_MODULE
,
824 .attach
= alua_bus_attach
,
825 .detach
= alua_bus_detach
,
826 .prep_fn
= alua_prep_fn
,
827 .check_sense
= alua_check_sense
,
828 .activate
= alua_activate
,
829 .set_params
= alua_set_params
,
832 static int __init
alua_init(void)
836 r
= scsi_register_device_handler(&alua_dh
);
838 printk(KERN_ERR
"%s: Failed to register scsi device handler",
843 static void __exit
alua_exit(void)
845 scsi_unregister_device_handler(&alua_dh
);
848 module_init(alua_init
);
849 module_exit(alua_exit
);
851 MODULE_DESCRIPTION("DM Multipath ALUA support");
852 MODULE_AUTHOR("Hannes Reinecke <hare@suse.de>");
853 MODULE_LICENSE("GPL");
854 MODULE_VERSION(ALUA_DH_VER
);