aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2015-08-27 08:16:59 -0400
committerJames Bottomley <JBottomley@Odin.com>2015-08-28 16:14:57 -0400
commitee14c674e8fc57251223054fb52dc0ecfe711028 (patch)
tree6f65bb8fd2380c4abed006139c8d6c820ae3d08f
parentd95dbff2a41e934cd8789734b34dc591e78ba11c (diff)
scsi_dh: kill struct scsi_dh_data
Add a ->handler and a ->handler_data field to struct scsi_device and kill this indirection. Also move struct scsi_device_handler to scsi_dh.h so that changes to it don't require rebuilding every SCSI LLDD. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Reviewed-by: Hannes Reinecke <hare@suse.de> Signed-off-by: James Bottomley <JBottomley@Odin.com>
-rw-r--r--drivers/scsi/device_handler/scsi_dh_alua.c25
-rw-r--r--drivers/scsi/device_handler/scsi_dh_emc.c29
-rw-r--r--drivers/scsi/device_handler/scsi_dh_hp_sw.c25
-rw-r--r--drivers/scsi/device_handler/scsi_dh_rdac.c30
-rw-r--r--drivers/scsi/scsi_dh.c75
-rw-r--r--drivers/scsi/scsi_error.c6
-rw-r--r--drivers/scsi/scsi_lib.c6
-rw-r--r--include/scsi/scsi_device.h25
-rw-r--r--include/scsi/scsi_dh.h17
9 files changed, 98 insertions, 140 deletions
diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
index ace2457747a7..cc2773b5de68 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -62,7 +62,6 @@
62#define ALUA_OPTIMIZE_STPG 1 62#define ALUA_OPTIMIZE_STPG 1
63 63
64struct alua_dh_data { 64struct alua_dh_data {
65 struct scsi_dh_data dh_data;
66 int group_id; 65 int group_id;
67 int rel_port; 66 int rel_port;
68 int tpgs; 67 int tpgs;
@@ -86,11 +85,6 @@ struct alua_dh_data {
86static char print_alua_state(int); 85static char print_alua_state(int);
87static int alua_check_sense(struct scsi_device *, struct scsi_sense_hdr *); 86static int alua_check_sense(struct scsi_device *, struct scsi_sense_hdr *);
88 87
89static inline struct alua_dh_data *get_alua_data(struct scsi_device *sdev)
90{
91 return container_of(sdev->scsi_dh_data, struct alua_dh_data, dh_data);
92}
93
94static int realloc_buffer(struct alua_dh_data *h, unsigned len) 88static int realloc_buffer(struct alua_dh_data *h, unsigned len)
95{ 89{
96 if (h->buff && h->buff != h->inq) 90 if (h->buff && h->buff != h->inq)
@@ -708,7 +702,7 @@ out:
708 */ 702 */
709static int alua_set_params(struct scsi_device *sdev, const char *params) 703static int alua_set_params(struct scsi_device *sdev, const char *params)
710{ 704{
711 struct alua_dh_data *h = get_alua_data(sdev); 705 struct alua_dh_data *h = sdev->handler_data;
712 unsigned int optimize = 0, argc; 706 unsigned int optimize = 0, argc;
713 const char *p = params; 707 const char *p = params;
714 int result = SCSI_DH_OK; 708 int result = SCSI_DH_OK;
@@ -746,7 +740,7 @@ MODULE_PARM_DESC(optimize_stpg, "Allow use of a non-optimized path, rather than
746static int alua_activate(struct scsi_device *sdev, 740static int alua_activate(struct scsi_device *sdev,
747 activate_complete fn, void *data) 741 activate_complete fn, void *data)
748{ 742{
749 struct alua_dh_data *h = get_alua_data(sdev); 743 struct alua_dh_data *h = sdev->handler_data;
750 int err = SCSI_DH_OK; 744 int err = SCSI_DH_OK;
751 int stpg = 0; 745 int stpg = 0;
752 746
@@ -804,7 +798,7 @@ out:
804 */ 798 */
805static int alua_prep_fn(struct scsi_device *sdev, struct request *req) 799static int alua_prep_fn(struct scsi_device *sdev, struct request *req)
806{ 800{
807 struct alua_dh_data *h = get_alua_data(sdev); 801 struct alua_dh_data *h = sdev->handler_data;
808 int ret = BLKPREP_OK; 802 int ret = BLKPREP_OK;
809 803
810 if (h->state == TPGS_STATE_TRANSITIONING) 804 if (h->state == TPGS_STATE_TRANSITIONING)
@@ -823,14 +817,14 @@ static int alua_prep_fn(struct scsi_device *sdev, struct request *req)
823 * alua_bus_attach - Attach device handler 817 * alua_bus_attach - Attach device handler
824 * @sdev: device to be attached to 818 * @sdev: device to be attached to
825 */ 819 */
826static struct scsi_dh_data *alua_bus_attach(struct scsi_device *sdev) 820static int alua_bus_attach(struct scsi_device *sdev)
827{ 821{
828 struct alua_dh_data *h; 822 struct alua_dh_data *h;
829 int err; 823 int err;
830 824
831 h = kzalloc(sizeof(*h) , GFP_KERNEL); 825 h = kzalloc(sizeof(*h) , GFP_KERNEL);
832 if (!h) 826 if (!h)
833 return ERR_PTR(-ENOMEM); 827 return -ENOMEM;
834 h->tpgs = TPGS_MODE_UNINITIALIZED; 828 h->tpgs = TPGS_MODE_UNINITIALIZED;
835 h->state = TPGS_STATE_OPTIMIZED; 829 h->state = TPGS_STATE_OPTIMIZED;
836 h->group_id = -1; 830 h->group_id = -1;
@@ -843,11 +837,11 @@ static struct scsi_dh_data *alua_bus_attach(struct scsi_device *sdev)
843 if (err != SCSI_DH_OK && err != SCSI_DH_DEV_OFFLINED) 837 if (err != SCSI_DH_OK && err != SCSI_DH_DEV_OFFLINED)
844 goto failed; 838 goto failed;
845 839
846 sdev_printk(KERN_NOTICE, sdev, "%s: Attached\n", ALUA_DH_NAME); 840 sdev->handler_data = h;
847 return &h->dh_data; 841 return 0;
848failed: 842failed:
849 kfree(h); 843 kfree(h);
850 return ERR_PTR(-EINVAL); 844 return -EINVAL;
851} 845}
852 846
853/* 847/*
@@ -856,10 +850,11 @@ failed:
856 */ 850 */
857static void alua_bus_detach(struct scsi_device *sdev) 851static void alua_bus_detach(struct scsi_device *sdev)
858{ 852{
859 struct alua_dh_data *h = get_alua_data(sdev); 853 struct alua_dh_data *h = sdev->handler_data;
860 854
861 if (h->buff && h->inq != h->buff) 855 if (h->buff && h->inq != h->buff)
862 kfree(h->buff); 856 kfree(h->buff);
857 sdev->handler_data = NULL;
863 kfree(h); 858 kfree(h);
864} 859}
865 860
diff --git a/drivers/scsi/device_handler/scsi_dh_emc.c b/drivers/scsi/device_handler/scsi_dh_emc.c
index fd31e67e9f50..e6fb97cb12f4 100644
--- a/drivers/scsi/device_handler/scsi_dh_emc.c
+++ b/drivers/scsi/device_handler/scsi_dh_emc.c
@@ -72,7 +72,6 @@ static const char * lun_state[] =
72}; 72};
73 73
74struct clariion_dh_data { 74struct clariion_dh_data {
75 struct scsi_dh_data dh_data;
76 /* 75 /*
77 * Flags: 76 * Flags:
78 * CLARIION_SHORT_TRESPASS 77 * CLARIION_SHORT_TRESPASS
@@ -114,13 +113,6 @@ struct clariion_dh_data {
114 int current_sp; 113 int current_sp;
115}; 114};
116 115
117static inline struct clariion_dh_data
118 *get_clariion_data(struct scsi_device *sdev)
119{
120 return container_of(sdev->scsi_dh_data, struct clariion_dh_data,
121 dh_data);
122}
123
124/* 116/*
125 * Parse MODE_SELECT cmd reply. 117 * Parse MODE_SELECT cmd reply.
126 */ 118 */
@@ -450,7 +442,7 @@ static int clariion_check_sense(struct scsi_device *sdev,
450 442
451static int clariion_prep_fn(struct scsi_device *sdev, struct request *req) 443static int clariion_prep_fn(struct scsi_device *sdev, struct request *req)
452{ 444{
453 struct clariion_dh_data *h = get_clariion_data(sdev); 445 struct clariion_dh_data *h = sdev->handler_data;
454 int ret = BLKPREP_OK; 446 int ret = BLKPREP_OK;
455 447
456 if (h->lun_state != CLARIION_LUN_OWNED) { 448 if (h->lun_state != CLARIION_LUN_OWNED) {
@@ -533,7 +525,7 @@ retry:
533static int clariion_activate(struct scsi_device *sdev, 525static int clariion_activate(struct scsi_device *sdev,
534 activate_complete fn, void *data) 526 activate_complete fn, void *data)
535{ 527{
536 struct clariion_dh_data *csdev = get_clariion_data(sdev); 528 struct clariion_dh_data *csdev = sdev->handler_data;
537 int result; 529 int result;
538 530
539 result = clariion_send_inquiry(sdev, csdev); 531 result = clariion_send_inquiry(sdev, csdev);
@@ -574,7 +566,7 @@ done:
574 */ 566 */
575static int clariion_set_params(struct scsi_device *sdev, const char *params) 567static int clariion_set_params(struct scsi_device *sdev, const char *params)
576{ 568{
577 struct clariion_dh_data *csdev = get_clariion_data(sdev); 569 struct clariion_dh_data *csdev = sdev->handler_data;
578 unsigned int hr = 0, st = 0, argc; 570 unsigned int hr = 0, st = 0, argc;
579 const char *p = params; 571 const char *p = params;
580 int result = SCSI_DH_OK; 572 int result = SCSI_DH_OK;
@@ -622,14 +614,14 @@ done:
622 return result; 614 return result;
623} 615}
624 616
625static struct scsi_dh_data *clariion_bus_attach(struct scsi_device *sdev) 617static int clariion_bus_attach(struct scsi_device *sdev)
626{ 618{
627 struct clariion_dh_data *h; 619 struct clariion_dh_data *h;
628 int err; 620 int err;
629 621
630 h = kzalloc(sizeof(*h) , GFP_KERNEL); 622 h = kzalloc(sizeof(*h) , GFP_KERNEL);
631 if (!h) 623 if (!h)
632 return ERR_PTR(-ENOMEM); 624 return -ENOMEM;
633 h->lun_state = CLARIION_LUN_UNINITIALIZED; 625 h->lun_state = CLARIION_LUN_UNINITIALIZED;
634 h->default_sp = CLARIION_UNBOUND_LU; 626 h->default_sp = CLARIION_UNBOUND_LU;
635 h->current_sp = CLARIION_UNBOUND_LU; 627 h->current_sp = CLARIION_UNBOUND_LU;
@@ -647,18 +639,19 @@ static struct scsi_dh_data *clariion_bus_attach(struct scsi_device *sdev)
647 CLARIION_NAME, h->current_sp + 'A', 639 CLARIION_NAME, h->current_sp + 'A',
648 h->port, lun_state[h->lun_state], 640 h->port, lun_state[h->lun_state],
649 h->default_sp + 'A'); 641 h->default_sp + 'A');
650 return &h->dh_data; 642
643 sdev->handler_data = h;
644 return 0;
651 645
652failed: 646failed:
653 kfree(h); 647 kfree(h);
654 return ERR_PTR(-EINVAL); 648 return -EINVAL;
655} 649}
656 650
657static void clariion_bus_detach(struct scsi_device *sdev) 651static void clariion_bus_detach(struct scsi_device *sdev)
658{ 652{
659 struct clariion_dh_data *h = get_clariion_data(sdev); 653 kfree(sdev->handler_data);
660 654 sdev->handler_data = NULL;
661 kfree(h);
662} 655}
663 656
664static struct scsi_device_handler clariion_dh = { 657static struct scsi_device_handler clariion_dh = {
diff --git a/drivers/scsi/device_handler/scsi_dh_hp_sw.c b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
index 1bf10d37289a..9406d5f4a3d3 100644
--- a/drivers/scsi/device_handler/scsi_dh_hp_sw.c
+++ b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
@@ -38,7 +38,6 @@
38#define HP_SW_PATH_PASSIVE 1 38#define HP_SW_PATH_PASSIVE 1
39 39
40struct hp_sw_dh_data { 40struct hp_sw_dh_data {
41 struct scsi_dh_data dh_data;
42 unsigned char sense[SCSI_SENSE_BUFFERSIZE]; 41 unsigned char sense[SCSI_SENSE_BUFFERSIZE];
43 int path_state; 42 int path_state;
44 int retries; 43 int retries;
@@ -50,11 +49,6 @@ struct hp_sw_dh_data {
50 49
51static int hp_sw_start_stop(struct hp_sw_dh_data *); 50static int hp_sw_start_stop(struct hp_sw_dh_data *);
52 51
53static inline struct hp_sw_dh_data *get_hp_sw_data(struct scsi_device *sdev)
54{
55 return container_of(sdev->scsi_dh_data, struct hp_sw_dh_data, dh_data);
56}
57
58/* 52/*
59 * tur_done - Handle TEST UNIT READY return status 53 * tur_done - Handle TEST UNIT READY return status
60 * @sdev: sdev the command has been sent to 54 * @sdev: sdev the command has been sent to
@@ -267,7 +261,7 @@ static int hp_sw_start_stop(struct hp_sw_dh_data *h)
267 261
268static int hp_sw_prep_fn(struct scsi_device *sdev, struct request *req) 262static int hp_sw_prep_fn(struct scsi_device *sdev, struct request *req)
269{ 263{
270 struct hp_sw_dh_data *h = get_hp_sw_data(sdev); 264 struct hp_sw_dh_data *h = sdev->handler_data;
271 int ret = BLKPREP_OK; 265 int ret = BLKPREP_OK;
272 266
273 if (h->path_state != HP_SW_PATH_ACTIVE) { 267 if (h->path_state != HP_SW_PATH_ACTIVE) {
@@ -292,7 +286,7 @@ static int hp_sw_activate(struct scsi_device *sdev,
292 activate_complete fn, void *data) 286 activate_complete fn, void *data)
293{ 287{
294 int ret = SCSI_DH_OK; 288 int ret = SCSI_DH_OK;
295 struct hp_sw_dh_data *h = get_hp_sw_data(sdev); 289 struct hp_sw_dh_data *h = sdev->handler_data;
296 290
297 ret = hp_sw_tur(sdev, h); 291 ret = hp_sw_tur(sdev, h);
298 292
@@ -311,14 +305,14 @@ static int hp_sw_activate(struct scsi_device *sdev,
311 return 0; 305 return 0;
312} 306}
313 307
314static struct scsi_dh_data *hp_sw_bus_attach(struct scsi_device *sdev) 308static int hp_sw_bus_attach(struct scsi_device *sdev)
315{ 309{
316 struct hp_sw_dh_data *h; 310 struct hp_sw_dh_data *h;
317 int ret; 311 int ret;
318 312
319 h = kzalloc(sizeof(*h), GFP_KERNEL); 313 h = kzalloc(sizeof(*h), GFP_KERNEL);
320 if (!h) 314 if (!h)
321 return ERR_PTR(-ENOMEM); 315 return -ENOMEM;
322 h->path_state = HP_SW_PATH_UNINITIALIZED; 316 h->path_state = HP_SW_PATH_UNINITIALIZED;
323 h->retries = HP_SW_RETRIES; 317 h->retries = HP_SW_RETRIES;
324 h->sdev = sdev; 318 h->sdev = sdev;
@@ -330,17 +324,18 @@ static struct scsi_dh_data *hp_sw_bus_attach(struct scsi_device *sdev)
330 sdev_printk(KERN_INFO, sdev, "%s: attached to %s path\n", 324 sdev_printk(KERN_INFO, sdev, "%s: attached to %s path\n",
331 HP_SW_NAME, h->path_state == HP_SW_PATH_ACTIVE? 325 HP_SW_NAME, h->path_state == HP_SW_PATH_ACTIVE?
332 "active":"passive"); 326 "active":"passive");
333 return &h->dh_data; 327
328 sdev->handler_data = h;
329 return 0;
334failed: 330failed:
335 kfree(h); 331 kfree(h);
336 return ERR_PTR(-EINVAL); 332 return -EINVAL;
337} 333}
338 334
339static void hp_sw_bus_detach( struct scsi_device *sdev ) 335static void hp_sw_bus_detach( struct scsi_device *sdev )
340{ 336{
341 struct hp_sw_dh_data *h = get_hp_sw_data(sdev); 337 kfree(sdev->handler_data);
342 338 sdev->handler_data = NULL;
343 kfree(h);
344} 339}
345 340
346static struct scsi_device_handler hp_sw_dh = { 341static struct scsi_device_handler hp_sw_dh = {
diff --git a/drivers/scsi/device_handler/scsi_dh_rdac.c b/drivers/scsi/device_handler/scsi_dh_rdac.c
index d89616fe3ffa..361358134315 100644
--- a/drivers/scsi/device_handler/scsi_dh_rdac.c
+++ b/drivers/scsi/device_handler/scsi_dh_rdac.c
@@ -181,7 +181,6 @@ struct c2_inquiry {
181}; 181};
182 182
183struct rdac_dh_data { 183struct rdac_dh_data {
184 struct scsi_dh_data dh_data;
185 struct rdac_controller *ctlr; 184 struct rdac_controller *ctlr;
186#define UNINITIALIZED_LUN (1 << 8) 185#define UNINITIALIZED_LUN (1 << 8)
187 unsigned lun; 186 unsigned lun;
@@ -260,11 +259,6 @@ do { \
260 sdev_printk(KERN_INFO, sdev, RDAC_NAME ": " f "\n", ## arg); \ 259 sdev_printk(KERN_INFO, sdev, RDAC_NAME ": " f "\n", ## arg); \
261} while (0); 260} while (0);
262 261
263static inline struct rdac_dh_data *get_rdac_data(struct scsi_device *sdev)
264{
265 return container_of(sdev->scsi_dh_data, struct rdac_dh_data, dh_data);
266}
267
268static struct request *get_rdac_req(struct scsi_device *sdev, 262static struct request *get_rdac_req(struct scsi_device *sdev,
269 void *buffer, unsigned buflen, int rw) 263 void *buffer, unsigned buflen, int rw)
270{ 264{
@@ -544,7 +538,7 @@ static int mode_select_handle_sense(struct scsi_device *sdev,
544{ 538{
545 struct scsi_sense_hdr sense_hdr; 539 struct scsi_sense_hdr sense_hdr;
546 int err = SCSI_DH_IO, ret; 540 int err = SCSI_DH_IO, ret;
547 struct rdac_dh_data *h = get_rdac_data(sdev); 541 struct rdac_dh_data *h = sdev->handler_data;
548 542
549 ret = scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE, &sense_hdr); 543 ret = scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE, &sense_hdr);
550 if (!ret) 544 if (!ret)
@@ -589,7 +583,7 @@ static void send_mode_select(struct work_struct *work)
589 container_of(work, struct rdac_controller, ms_work); 583 container_of(work, struct rdac_controller, ms_work);
590 struct request *rq; 584 struct request *rq;
591 struct scsi_device *sdev = ctlr->ms_sdev; 585 struct scsi_device *sdev = ctlr->ms_sdev;
592 struct rdac_dh_data *h = get_rdac_data(sdev); 586 struct rdac_dh_data *h = sdev->handler_data;
593 struct request_queue *q = sdev->request_queue; 587 struct request_queue *q = sdev->request_queue;
594 int err, retry_cnt = RDAC_RETRY_COUNT; 588 int err, retry_cnt = RDAC_RETRY_COUNT;
595 struct rdac_queue_data *tmp, *qdata; 589 struct rdac_queue_data *tmp, *qdata;
@@ -648,7 +642,7 @@ static int queue_mode_select(struct scsi_device *sdev,
648 if (!qdata) 642 if (!qdata)
649 return SCSI_DH_RETRY; 643 return SCSI_DH_RETRY;
650 644
651 qdata->h = get_rdac_data(sdev); 645 qdata->h = sdev->handler_data;
652 qdata->callback_fn = fn; 646 qdata->callback_fn = fn;
653 qdata->callback_data = data; 647 qdata->callback_data = data;
654 648
@@ -667,7 +661,7 @@ static int queue_mode_select(struct scsi_device *sdev,
667static int rdac_activate(struct scsi_device *sdev, 661static int rdac_activate(struct scsi_device *sdev,
668 activate_complete fn, void *data) 662 activate_complete fn, void *data)
669{ 663{
670 struct rdac_dh_data *h = get_rdac_data(sdev); 664 struct rdac_dh_data *h = sdev->handler_data;
671 int err = SCSI_DH_OK; 665 int err = SCSI_DH_OK;
672 int act = 0; 666 int act = 0;
673 667
@@ -702,7 +696,7 @@ done:
702 696
703static int rdac_prep_fn(struct scsi_device *sdev, struct request *req) 697static int rdac_prep_fn(struct scsi_device *sdev, struct request *req)
704{ 698{
705 struct rdac_dh_data *h = get_rdac_data(sdev); 699 struct rdac_dh_data *h = sdev->handler_data;
706 int ret = BLKPREP_OK; 700 int ret = BLKPREP_OK;
707 701
708 if (h->state != RDAC_STATE_ACTIVE) { 702 if (h->state != RDAC_STATE_ACTIVE) {
@@ -716,7 +710,7 @@ static int rdac_prep_fn(struct scsi_device *sdev, struct request *req)
716static int rdac_check_sense(struct scsi_device *sdev, 710static int rdac_check_sense(struct scsi_device *sdev,
717 struct scsi_sense_hdr *sense_hdr) 711 struct scsi_sense_hdr *sense_hdr)
718{ 712{
719 struct rdac_dh_data *h = get_rdac_data(sdev); 713 struct rdac_dh_data *h = sdev->handler_data;
720 714
721 RDAC_LOG(RDAC_LOG_SENSE, sdev, "array %s, ctlr %d, " 715 RDAC_LOG(RDAC_LOG_SENSE, sdev, "array %s, ctlr %d, "
722 "I/O returned with sense %02x/%02x/%02x", 716 "I/O returned with sense %02x/%02x/%02x",
@@ -778,7 +772,7 @@ static int rdac_check_sense(struct scsi_device *sdev,
778 return SCSI_RETURN_NOT_HANDLED; 772 return SCSI_RETURN_NOT_HANDLED;
779} 773}
780 774
781static struct scsi_dh_data *rdac_bus_attach(struct scsi_device *sdev) 775static int rdac_bus_attach(struct scsi_device *sdev)
782{ 776{
783 struct rdac_dh_data *h; 777 struct rdac_dh_data *h;
784 int err; 778 int err;
@@ -787,7 +781,7 @@ static struct scsi_dh_data *rdac_bus_attach(struct scsi_device *sdev)
787 781
788 h = kzalloc(sizeof(*h) , GFP_KERNEL); 782 h = kzalloc(sizeof(*h) , GFP_KERNEL);
789 if (!h) 783 if (!h)
790 return ERR_PTR(-ENOMEM); 784 return -ENOMEM;
791 h->lun = UNINITIALIZED_LUN; 785 h->lun = UNINITIALIZED_LUN;
792 h->state = RDAC_STATE_ACTIVE; 786 h->state = RDAC_STATE_ACTIVE;
793 787
@@ -812,7 +806,8 @@ static struct scsi_dh_data *rdac_bus_attach(struct scsi_device *sdev)
812 RDAC_NAME, h->lun, mode[(int)h->mode], 806 RDAC_NAME, h->lun, mode[(int)h->mode],
813 lun_state[(int)h->lun_state]); 807 lun_state[(int)h->lun_state]);
814 808
815 return &h->dh_data; 809 sdev->handler_data = h;
810 return 0;
816 811
817clean_ctlr: 812clean_ctlr:
818 spin_lock(&list_lock); 813 spin_lock(&list_lock);
@@ -821,12 +816,12 @@ clean_ctlr:
821 816
822failed: 817failed:
823 kfree(h); 818 kfree(h);
824 return ERR_PTR(-EINVAL); 819 return -EINVAL;
825} 820}
826 821
827static void rdac_bus_detach( struct scsi_device *sdev ) 822static void rdac_bus_detach( struct scsi_device *sdev )
828{ 823{
829 struct rdac_dh_data *h = get_rdac_data(sdev); 824 struct rdac_dh_data *h = sdev->handler_data;
830 825
831 if (h->ctlr && h->ctlr->ms_queued) 826 if (h->ctlr && h->ctlr->ms_queued)
832 flush_workqueue(kmpath_rdacd); 827 flush_workqueue(kmpath_rdacd);
@@ -835,6 +830,7 @@ static void rdac_bus_detach( struct scsi_device *sdev )
835 if (h->ctlr) 830 if (h->ctlr)
836 kref_put(&h->ctlr->kref, release_controller); 831 kref_put(&h->ctlr->kref, release_controller);
837 spin_unlock(&list_lock); 832 spin_unlock(&list_lock);
833 sdev->handler_data = NULL;
838 kfree(h); 834 kfree(h);
839} 835}
840 836
diff --git a/drivers/scsi/scsi_dh.c b/drivers/scsi/scsi_dh.c
index 9c153309c96b..33c1148ff3b5 100644
--- a/drivers/scsi/scsi_dh.c
+++ b/drivers/scsi/scsi_dh.c
@@ -126,26 +126,20 @@ static struct scsi_device_handler *scsi_dh_lookup(const char *name)
126static int scsi_dh_handler_attach(struct scsi_device *sdev, 126static int scsi_dh_handler_attach(struct scsi_device *sdev,
127 struct scsi_device_handler *scsi_dh) 127 struct scsi_device_handler *scsi_dh)
128{ 128{
129 struct scsi_dh_data *d; 129 int error;
130 130
131 if (!try_module_get(scsi_dh->module)) 131 if (!try_module_get(scsi_dh->module))
132 return -EINVAL; 132 return -EINVAL;
133 133
134 d = scsi_dh->attach(sdev); 134 error = scsi_dh->attach(sdev);
135 if (IS_ERR(d)) { 135 if (error) {
136 sdev_printk(KERN_ERR, sdev, "%s: Attach failed (%ld)\n", 136 sdev_printk(KERN_ERR, sdev, "%s: Attach failed (%d)\n",
137 scsi_dh->name, PTR_ERR(d)); 137 scsi_dh->name, error);
138 module_put(scsi_dh->module); 138 module_put(scsi_dh->module);
139 return PTR_ERR(d); 139 } else
140 } 140 sdev->handler = scsi_dh;
141
142 d->scsi_dh = scsi_dh;
143 d->sdev = sdev;
144 141
145 spin_lock_irq(sdev->request_queue->queue_lock); 142 return error;
146 sdev->scsi_dh_data = d;
147 spin_unlock_irq(sdev->request_queue->queue_lock);
148 return 0;
149} 143}
150 144
151/* 145/*
@@ -154,17 +148,9 @@ static int scsi_dh_handler_attach(struct scsi_device *sdev,
154 */ 148 */
155static void scsi_dh_handler_detach(struct scsi_device *sdev) 149static void scsi_dh_handler_detach(struct scsi_device *sdev)
156{ 150{
157 struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; 151 sdev->handler->detach(sdev);
158 struct scsi_device_handler *scsi_dh = scsi_dh_data->scsi_dh; 152 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", sdev->handler->name);
159 153 module_put(sdev->handler->module);
160 scsi_dh->detach(sdev);
161
162 spin_lock_irq(sdev->request_queue->queue_lock);
163 sdev->scsi_dh_data = NULL;
164 spin_unlock_irq(sdev->request_queue->queue_lock);
165
166 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", scsi_dh->name);
167 module_put(scsi_dh->module);
168} 154}
169 155
170/* 156/*
@@ -182,7 +168,7 @@ store_dh_state(struct device *dev, struct device_attribute *attr,
182 sdev->sdev_state == SDEV_DEL) 168 sdev->sdev_state == SDEV_DEL)
183 return -ENODEV; 169 return -ENODEV;
184 170
185 if (!sdev->scsi_dh_data) { 171 if (!sdev->handler) {
186 /* 172 /*
187 * Attach to a device handler 173 * Attach to a device handler
188 */ 174 */
@@ -191,7 +177,6 @@ store_dh_state(struct device *dev, struct device_attribute *attr,
191 return err; 177 return err;
192 err = scsi_dh_handler_attach(sdev, scsi_dh); 178 err = scsi_dh_handler_attach(sdev, scsi_dh);
193 } else { 179 } else {
194 scsi_dh = sdev->scsi_dh_data->scsi_dh;
195 if (!strncmp(buf, "detach", 6)) { 180 if (!strncmp(buf, "detach", 6)) {
196 /* 181 /*
197 * Detach from a device handler 182 * Detach from a device handler
@@ -202,8 +187,8 @@ store_dh_state(struct device *dev, struct device_attribute *attr,
202 /* 187 /*
203 * Activate a device handler 188 * Activate a device handler
204 */ 189 */
205 if (scsi_dh->activate) 190 if (sdev->handler->activate)
206 err = scsi_dh->activate(sdev, NULL, NULL); 191 err = sdev->handler->activate(sdev, NULL, NULL);
207 else 192 else
208 err = 0; 193 err = 0;
209 } 194 }
@@ -217,10 +202,10 @@ show_dh_state(struct device *dev, struct device_attribute *attr, char *buf)
217{ 202{
218 struct scsi_device *sdev = to_scsi_device(dev); 203 struct scsi_device *sdev = to_scsi_device(dev);
219 204
220 if (!sdev->scsi_dh_data) 205 if (!sdev->handler)
221 return snprintf(buf, 20, "detached\n"); 206 return snprintf(buf, 20, "detached\n");
222 207
223 return snprintf(buf, 20, "%s\n", sdev->scsi_dh_data->scsi_dh->name); 208 return snprintf(buf, 20, "%s\n", sdev->handler->name);
224} 209}
225 210
226static struct device_attribute scsi_dh_state_attr = 211static struct device_attribute scsi_dh_state_attr =
@@ -247,7 +232,7 @@ int scsi_dh_add_device(struct scsi_device *sdev)
247 232
248void scsi_dh_remove_device(struct scsi_device *sdev) 233void scsi_dh_remove_device(struct scsi_device *sdev)
249{ 234{
250 if (sdev->scsi_dh_data) 235 if (sdev->handler)
251 scsi_dh_handler_detach(sdev); 236 scsi_dh_handler_detach(sdev);
252 device_remove_file(&sdev->sdev_gendev, &scsi_dh_state_attr); 237 device_remove_file(&sdev->sdev_gendev, &scsi_dh_state_attr);
253} 238}
@@ -316,7 +301,6 @@ int scsi_dh_activate(struct request_queue *q, activate_complete fn, void *data)
316 int err = 0; 301 int err = 0;
317 unsigned long flags; 302 unsigned long flags;
318 struct scsi_device *sdev; 303 struct scsi_device *sdev;
319 struct scsi_device_handler *scsi_dh = NULL;
320 struct device *dev = NULL; 304 struct device *dev = NULL;
321 305
322 spin_lock_irqsave(q->queue_lock, flags); 306 spin_lock_irqsave(q->queue_lock, flags);
@@ -329,10 +313,8 @@ int scsi_dh_activate(struct request_queue *q, activate_complete fn, void *data)
329 return err; 313 return err;
330 } 314 }
331 315
332 if (sdev->scsi_dh_data)
333 scsi_dh = sdev->scsi_dh_data->scsi_dh;
334 dev = get_device(&sdev->sdev_gendev); 316 dev = get_device(&sdev->sdev_gendev);
335 if (!scsi_dh || !dev || 317 if (!sdev->handler || !dev ||
336 sdev->sdev_state == SDEV_CANCEL || 318 sdev->sdev_state == SDEV_CANCEL ||
337 sdev->sdev_state == SDEV_DEL) 319 sdev->sdev_state == SDEV_DEL)
338 err = SCSI_DH_NOSYS; 320 err = SCSI_DH_NOSYS;
@@ -346,8 +328,8 @@ int scsi_dh_activate(struct request_queue *q, activate_complete fn, void *data)
346 goto out; 328 goto out;
347 } 329 }
348 330
349 if (scsi_dh->activate) 331 if (sdev->handler->activate)
350 err = scsi_dh->activate(sdev, fn, data); 332 err = sdev->handler->activate(sdev, fn, data);
351out: 333out:
352 put_device(dev); 334 put_device(dev);
353 return err; 335 return err;
@@ -369,19 +351,18 @@ int scsi_dh_set_params(struct request_queue *q, const char *params)
369 int err = -SCSI_DH_NOSYS; 351 int err = -SCSI_DH_NOSYS;
370 unsigned long flags; 352 unsigned long flags;
371 struct scsi_device *sdev; 353 struct scsi_device *sdev;
372 struct scsi_device_handler *scsi_dh = NULL;
373 354
374 spin_lock_irqsave(q->queue_lock, flags); 355 spin_lock_irqsave(q->queue_lock, flags);
375 sdev = q->queuedata; 356 sdev = q->queuedata;
376 if (sdev && sdev->scsi_dh_data) 357 if (sdev->handler &&
377 scsi_dh = sdev->scsi_dh_data->scsi_dh; 358 sdev->handler->set_params &&
378 if (scsi_dh && scsi_dh->set_params && get_device(&sdev->sdev_gendev)) 359 get_device(&sdev->sdev_gendev))
379 err = 0; 360 err = 0;
380 spin_unlock_irqrestore(q->queue_lock, flags); 361 spin_unlock_irqrestore(q->queue_lock, flags);
381 362
382 if (err) 363 if (err)
383 return err; 364 return err;
384 err = scsi_dh->set_params(sdev, params); 365 err = sdev->handler->set_params(sdev, params);
385 put_device(&sdev->sdev_gendev); 366 put_device(&sdev->sdev_gendev);
386 return err; 367 return err;
387} 368}
@@ -413,8 +394,8 @@ int scsi_dh_attach(struct request_queue *q, const char *name)
413 if (err) 394 if (err)
414 return err; 395 return err;
415 396
416 if (sdev->scsi_dh_data) { 397 if (sdev->handler) {
417 if (sdev->scsi_dh_data->scsi_dh != scsi_dh) 398 if (sdev->handler != scsi_dh)
418 err = -EBUSY; 399 err = -EBUSY;
419 goto out_put_device; 400 goto out_put_device;
420 } 401 }
@@ -451,8 +432,8 @@ const char *scsi_dh_attached_handler_name(struct request_queue *q, gfp_t gfp)
451 if (!sdev) 432 if (!sdev)
452 return NULL; 433 return NULL;
453 434
454 if (sdev->scsi_dh_data) 435 if (sdev->handler)
455 handler_name = kstrdup(sdev->scsi_dh_data->scsi_dh->name, gfp); 436 handler_name = kstrdup(sdev->handler->name, gfp);
456 437
457 put_device(&sdev->sdev_gendev); 438 put_device(&sdev->sdev_gendev);
458 return handler_name; 439 return handler_name;
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 3aacd96d63f3..410911c31c67 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -37,6 +37,7 @@
37#include <scsi/scsi_transport.h> 37#include <scsi/scsi_transport.h>
38#include <scsi/scsi_host.h> 38#include <scsi/scsi_host.h>
39#include <scsi/scsi_ioctl.h> 39#include <scsi/scsi_ioctl.h>
40#include <scsi/scsi_dh.h>
40#include <scsi/sg.h> 41#include <scsi/sg.h>
41 42
42#include "scsi_priv.h" 43#include "scsi_priv.h"
@@ -464,11 +465,10 @@ static int scsi_check_sense(struct scsi_cmnd *scmd)
464 if (scsi_sense_is_deferred(&sshdr)) 465 if (scsi_sense_is_deferred(&sshdr))
465 return NEEDS_RETRY; 466 return NEEDS_RETRY;
466 467
467 if (sdev->scsi_dh_data && sdev->scsi_dh_data->scsi_dh && 468 if (sdev->handler && sdev->handler->check_sense) {
468 sdev->scsi_dh_data->scsi_dh->check_sense) {
469 int rc; 469 int rc;
470 470
471 rc = sdev->scsi_dh_data->scsi_dh->check_sense(sdev, &sshdr); 471 rc = sdev->handler->check_sense(sdev, &sshdr);
472 if (rc != SCSI_RETURN_NOT_HANDLED) 472 if (rc != SCSI_RETURN_NOT_HANDLED)
473 return rc; 473 return rc;
474 /* handler does not care. Drop down to default handling */ 474 /* handler does not care. Drop down to default handling */
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 882864f5cbae..cbfc5990052b 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -31,6 +31,7 @@
31#include <scsi/scsi_driver.h> 31#include <scsi/scsi_driver.h>
32#include <scsi/scsi_eh.h> 32#include <scsi/scsi_eh.h>
33#include <scsi/scsi_host.h> 33#include <scsi/scsi_host.h>
34#include <scsi/scsi_dh.h>
34 35
35#include <trace/events/scsi.h> 36#include <trace/events/scsi.h>
36 37
@@ -1248,9 +1249,8 @@ static int scsi_setup_fs_cmnd(struct scsi_device *sdev, struct request *req)
1248{ 1249{
1249 struct scsi_cmnd *cmd = req->special; 1250 struct scsi_cmnd *cmd = req->special;
1250 1251
1251 if (unlikely(sdev->scsi_dh_data && sdev->scsi_dh_data->scsi_dh 1252 if (unlikely(sdev->handler && sdev->handler->prep_fn)) {
1252 && sdev->scsi_dh_data->scsi_dh->prep_fn)) { 1253 int ret = sdev->handler->prep_fn(sdev, req);
1253 int ret = sdev->scsi_dh_data->scsi_dh->prep_fn(sdev, req);
1254 if (ret != BLKPREP_OK) 1254 if (ret != BLKPREP_OK)
1255 return ret; 1255 return ret;
1256 } 1256 }
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 4d501b7baa9b..fe89d7cd67b9 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -196,32 +196,13 @@ struct scsi_device {
196 struct execute_work ew; /* used to get process context on put */ 196 struct execute_work ew; /* used to get process context on put */
197 struct work_struct requeue_work; 197 struct work_struct requeue_work;
198 198
199 struct scsi_dh_data *scsi_dh_data; 199 struct scsi_device_handler *handler;
200 void *handler_data;
201
200 enum scsi_device_state sdev_state; 202 enum scsi_device_state sdev_state;
201 unsigned long sdev_data[0]; 203 unsigned long sdev_data[0];
202} __attribute__((aligned(sizeof(unsigned long)))); 204} __attribute__((aligned(sizeof(unsigned long))));
203 205
204typedef void (*activate_complete)(void *, int);
205struct scsi_device_handler {
206 /* Used by the infrastructure */
207 struct list_head list; /* list of scsi_device_handlers */
208
209 /* Filled by the hardware handler */
210 struct module *module;
211 const char *name;
212 int (*check_sense)(struct scsi_device *, struct scsi_sense_hdr *);
213 struct scsi_dh_data *(*attach)(struct scsi_device *);
214 void (*detach)(struct scsi_device *);
215 int (*activate)(struct scsi_device *, activate_complete, void *);
216 int (*prep_fn)(struct scsi_device *, struct request *);
217 int (*set_params)(struct scsi_device *, const char *);
218};
219
220struct scsi_dh_data {
221 struct scsi_device_handler *scsi_dh;
222 struct scsi_device *sdev;
223};
224
225#define to_scsi_device(d) \ 206#define to_scsi_device(d) \
226 container_of(d, struct scsi_device, sdev_gendev) 207 container_of(d, struct scsi_device, sdev_gendev)
227#define class_to_sdev(d) \ 208#define class_to_sdev(d) \
diff --git a/include/scsi/scsi_dh.h b/include/scsi/scsi_dh.h
index 3a37b4c45997..85d731746834 100644
--- a/include/scsi/scsi_dh.h
+++ b/include/scsi/scsi_dh.h
@@ -55,6 +55,23 @@ enum {
55 SCSI_DH_NOSYS, 55 SCSI_DH_NOSYS,
56 SCSI_DH_DRIVER_MAX, 56 SCSI_DH_DRIVER_MAX,
57}; 57};
58
59typedef void (*activate_complete)(void *, int);
60struct scsi_device_handler {
61 /* Used by the infrastructure */
62 struct list_head list; /* list of scsi_device_handlers */
63
64 /* Filled by the hardware handler */
65 struct module *module;
66 const char *name;
67 int (*check_sense)(struct scsi_device *, struct scsi_sense_hdr *);
68 int (*attach)(struct scsi_device *);
69 void (*detach)(struct scsi_device *);
70 int (*activate)(struct scsi_device *, activate_complete, void *);
71 int (*prep_fn)(struct scsi_device *, struct request *);
72 int (*set_params)(struct scsi_device *, const char *);
73};
74
58#ifdef CONFIG_SCSI_DH 75#ifdef CONFIG_SCSI_DH
59extern int scsi_dh_activate(struct request_queue *, activate_complete, void *); 76extern int scsi_dh_activate(struct request_queue *, activate_complete, void *);
60extern int scsi_dh_attach(struct request_queue *, const char *); 77extern int scsi_dh_attach(struct request_queue *, const char *);