aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2014-09-13 22:59:51 -0400
committerChristoph Hellwig <hch@lst.de>2014-11-12 05:19:25 -0500
commitcd37743fc978a14fee75a4e662582e15d16038a3 (patch)
tree7b050076efb8a9dbf263ce593f30823445fb672a
parent27c888f0bb889693c6a3b6d39eba3265c16c072f (diff)
scsi: use container_of to get at device handler private data
Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Mike Christie <michaelc@cs.wisc.edu> Reviewed-by: Hannes Reinecke <hare@suse.de>
-rw-r--r--drivers/scsi/device_handler/scsi_dh_alua.c25
-rw-r--r--drivers/scsi/device_handler/scsi_dh_emc.c24
-rw-r--r--drivers/scsi/device_handler/scsi_dh_hp_sw.c23
-rw-r--r--drivers/scsi/device_handler/scsi_dh_rdac.c25
-rw-r--r--include/scsi/scsi_device.h1
5 files changed, 37 insertions, 61 deletions
diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
index 9115c31f26e9..d9781045c4ee 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -62,6 +62,7 @@
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;
65 int group_id; 66 int group_id;
66 int rel_port; 67 int rel_port;
67 int tpgs; 68 int tpgs;
@@ -87,9 +88,7 @@ static int alua_check_sense(struct scsi_device *, struct scsi_sense_hdr *);
87 88
88static inline struct alua_dh_data *get_alua_data(struct scsi_device *sdev) 89static inline struct alua_dh_data *get_alua_data(struct scsi_device *sdev)
89{ 90{
90 struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; 91 return container_of(sdev->scsi_dh_data, struct alua_dh_data, dh_data);
91 BUG_ON(scsi_dh_data == NULL);
92 return ((struct alua_dh_data *) scsi_dh_data->buf);
93} 92}
94 93
95static int realloc_buffer(struct alua_dh_data *h, unsigned len) 94static int realloc_buffer(struct alua_dh_data *h, unsigned len)
@@ -846,21 +845,18 @@ static struct scsi_device_handler alua_dh = {
846 */ 845 */
847static int alua_bus_attach(struct scsi_device *sdev) 846static int alua_bus_attach(struct scsi_device *sdev)
848{ 847{
849 struct scsi_dh_data *scsi_dh_data;
850 struct alua_dh_data *h; 848 struct alua_dh_data *h;
851 unsigned long flags; 849 unsigned long flags;
852 int err = SCSI_DH_OK; 850 int err = SCSI_DH_OK;
853 851
854 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data) 852 h = kzalloc(sizeof(*h) , GFP_KERNEL);
855 + sizeof(*h) , GFP_KERNEL); 853 if (!h) {
856 if (!scsi_dh_data) {
857 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n", 854 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
858 ALUA_DH_NAME); 855 ALUA_DH_NAME);
859 return -ENOMEM; 856 return -ENOMEM;
860 } 857 }
861 858
862 scsi_dh_data->scsi_dh = &alua_dh; 859 h->dh_data.scsi_dh = &alua_dh;
863 h = (struct alua_dh_data *) scsi_dh_data->buf;
864 h->tpgs = TPGS_MODE_UNINITIALIZED; 860 h->tpgs = TPGS_MODE_UNINITIALIZED;
865 h->state = TPGS_STATE_OPTIMIZED; 861 h->state = TPGS_STATE_OPTIMIZED;
866 h->group_id = -1; 862 h->group_id = -1;
@@ -874,14 +870,14 @@ static int alua_bus_attach(struct scsi_device *sdev)
874 goto failed; 870 goto failed;
875 871
876 spin_lock_irqsave(sdev->request_queue->queue_lock, flags); 872 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
877 sdev->scsi_dh_data = scsi_dh_data; 873 sdev->scsi_dh_data = &h->dh_data;
878 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); 874 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
879 sdev_printk(KERN_NOTICE, sdev, "%s: Attached\n", ALUA_DH_NAME); 875 sdev_printk(KERN_NOTICE, sdev, "%s: Attached\n", ALUA_DH_NAME);
880 876
881 return 0; 877 return 0;
882 878
883failed: 879failed:
884 kfree(scsi_dh_data); 880 kfree(h);
885 sdev_printk(KERN_ERR, sdev, "%s: not attached\n", ALUA_DH_NAME); 881 sdev_printk(KERN_ERR, sdev, "%s: not attached\n", ALUA_DH_NAME);
886 return -EINVAL; 882 return -EINVAL;
887} 883}
@@ -892,19 +888,16 @@ failed:
892 */ 888 */
893static void alua_bus_detach(struct scsi_device *sdev) 889static void alua_bus_detach(struct scsi_device *sdev)
894{ 890{
895 struct scsi_dh_data *scsi_dh_data; 891 struct alua_dh_data *h = get_alua_data(sdev);
896 struct alua_dh_data *h;
897 unsigned long flags; 892 unsigned long flags;
898 893
899 spin_lock_irqsave(sdev->request_queue->queue_lock, flags); 894 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
900 scsi_dh_data = sdev->scsi_dh_data;
901 sdev->scsi_dh_data = NULL; 895 sdev->scsi_dh_data = NULL;
902 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); 896 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
903 897
904 h = (struct alua_dh_data *) scsi_dh_data->buf;
905 if (h->buff && h->inq != h->buff) 898 if (h->buff && h->inq != h->buff)
906 kfree(h->buff); 899 kfree(h->buff);
907 kfree(scsi_dh_data); 900 kfree(h);
908 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", ALUA_DH_NAME); 901 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", ALUA_DH_NAME);
909} 902}
910 903
diff --git a/drivers/scsi/device_handler/scsi_dh_emc.c b/drivers/scsi/device_handler/scsi_dh_emc.c
index 153b4c3547a2..c2e26cdef21a 100644
--- a/drivers/scsi/device_handler/scsi_dh_emc.c
+++ b/drivers/scsi/device_handler/scsi_dh_emc.c
@@ -72,6 +72,7 @@ static const char * lun_state[] =
72}; 72};
73 73
74struct clariion_dh_data { 74struct clariion_dh_data {
75 struct scsi_dh_data dh_data;
75 /* 76 /*
76 * Flags: 77 * Flags:
77 * CLARIION_SHORT_TRESPASS 78 * CLARIION_SHORT_TRESPASS
@@ -116,9 +117,8 @@ struct clariion_dh_data {
116static inline struct clariion_dh_data 117static inline struct clariion_dh_data
117 *get_clariion_data(struct scsi_device *sdev) 118 *get_clariion_data(struct scsi_device *sdev)
118{ 119{
119 struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; 120 return container_of(sdev->scsi_dh_data, struct clariion_dh_data,
120 BUG_ON(scsi_dh_data == NULL); 121 dh_data);
121 return ((struct clariion_dh_data *) scsi_dh_data->buf);
122} 122}
123 123
124/* 124/*
@@ -665,21 +665,18 @@ static struct scsi_device_handler clariion_dh = {
665 665
666static int clariion_bus_attach(struct scsi_device *sdev) 666static int clariion_bus_attach(struct scsi_device *sdev)
667{ 667{
668 struct scsi_dh_data *scsi_dh_data;
669 struct clariion_dh_data *h; 668 struct clariion_dh_data *h;
670 unsigned long flags; 669 unsigned long flags;
671 int err; 670 int err;
672 671
673 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data) 672 h = kzalloc(sizeof(*h) , GFP_KERNEL);
674 + sizeof(*h) , GFP_KERNEL); 673 if (!h) {
675 if (!scsi_dh_data) {
676 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n", 674 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
677 CLARIION_NAME); 675 CLARIION_NAME);
678 return -ENOMEM; 676 return -ENOMEM;
679 } 677 }
680 678
681 scsi_dh_data->scsi_dh = &clariion_dh; 679 h->dh_data.scsi_dh = &clariion_dh;
682 h = (struct clariion_dh_data *) scsi_dh_data->buf;
683 h->lun_state = CLARIION_LUN_UNINITIALIZED; 680 h->lun_state = CLARIION_LUN_UNINITIALIZED;
684 h->default_sp = CLARIION_UNBOUND_LU; 681 h->default_sp = CLARIION_UNBOUND_LU;
685 h->current_sp = CLARIION_UNBOUND_LU; 682 h->current_sp = CLARIION_UNBOUND_LU;
@@ -693,7 +690,7 @@ static int clariion_bus_attach(struct scsi_device *sdev)
693 goto failed; 690 goto failed;
694 691
695 spin_lock_irqsave(sdev->request_queue->queue_lock, flags); 692 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
696 sdev->scsi_dh_data = scsi_dh_data; 693 sdev->scsi_dh_data = &h->dh_data;
697 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); 694 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
698 695
699 sdev_printk(KERN_INFO, sdev, 696 sdev_printk(KERN_INFO, sdev,
@@ -705,7 +702,7 @@ static int clariion_bus_attach(struct scsi_device *sdev)
705 return 0; 702 return 0;
706 703
707failed: 704failed:
708 kfree(scsi_dh_data); 705 kfree(h);
709 sdev_printk(KERN_ERR, sdev, "%s: not attached\n", 706 sdev_printk(KERN_ERR, sdev, "%s: not attached\n",
710 CLARIION_NAME); 707 CLARIION_NAME);
711 return -EINVAL; 708 return -EINVAL;
@@ -713,18 +710,17 @@ failed:
713 710
714static void clariion_bus_detach(struct scsi_device *sdev) 711static void clariion_bus_detach(struct scsi_device *sdev)
715{ 712{
716 struct scsi_dh_data *scsi_dh_data; 713 struct clariion_dh_data *h = get_clariion_data(sdev);
717 unsigned long flags; 714 unsigned long flags;
718 715
719 spin_lock_irqsave(sdev->request_queue->queue_lock, flags); 716 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
720 scsi_dh_data = sdev->scsi_dh_data;
721 sdev->scsi_dh_data = NULL; 717 sdev->scsi_dh_data = NULL;
722 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); 718 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
723 719
724 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", 720 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n",
725 CLARIION_NAME); 721 CLARIION_NAME);
726 722
727 kfree(scsi_dh_data); 723 kfree(h);
728} 724}
729 725
730static int __init clariion_init(void) 726static int __init clariion_init(void)
diff --git a/drivers/scsi/device_handler/scsi_dh_hp_sw.c b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
index cf36557a1d4d..37dedcae0aa4 100644
--- a/drivers/scsi/device_handler/scsi_dh_hp_sw.c
+++ b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
@@ -38,6 +38,7 @@
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;
41 unsigned char sense[SCSI_SENSE_BUFFERSIZE]; 42 unsigned char sense[SCSI_SENSE_BUFFERSIZE];
42 int path_state; 43 int path_state;
43 int retries; 44 int retries;
@@ -51,9 +52,7 @@ static int hp_sw_start_stop(struct hp_sw_dh_data *);
51 52
52static inline struct hp_sw_dh_data *get_hp_sw_data(struct scsi_device *sdev) 53static inline struct hp_sw_dh_data *get_hp_sw_data(struct scsi_device *sdev)
53{ 54{
54 struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; 55 return container_of(sdev->scsi_dh_data, struct hp_sw_dh_data, dh_data);
55 BUG_ON(scsi_dh_data == NULL);
56 return ((struct hp_sw_dh_data *) scsi_dh_data->buf);
57} 56}
58 57
59/* 58/*
@@ -354,21 +353,18 @@ static struct scsi_device_handler hp_sw_dh = {
354 353
355static int hp_sw_bus_attach(struct scsi_device *sdev) 354static int hp_sw_bus_attach(struct scsi_device *sdev)
356{ 355{
357 struct scsi_dh_data *scsi_dh_data;
358 struct hp_sw_dh_data *h; 356 struct hp_sw_dh_data *h;
359 unsigned long flags; 357 unsigned long flags;
360 int ret; 358 int ret;
361 359
362 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data) 360 h = kzalloc(sizeof(*h), GFP_KERNEL);
363 + sizeof(*h) , GFP_KERNEL); 361 if (!h) {
364 if (!scsi_dh_data) {
365 sdev_printk(KERN_ERR, sdev, "%s: Attach Failed\n", 362 sdev_printk(KERN_ERR, sdev, "%s: Attach Failed\n",
366 HP_SW_NAME); 363 HP_SW_NAME);
367 return -ENOMEM; 364 return -ENOMEM;
368 } 365 }
369 366
370 scsi_dh_data->scsi_dh = &hp_sw_dh; 367 h->dh_data.scsi_dh = &hp_sw_dh;
371 h = (struct hp_sw_dh_data *) scsi_dh_data->buf;
372 h->path_state = HP_SW_PATH_UNINITIALIZED; 368 h->path_state = HP_SW_PATH_UNINITIALIZED;
373 h->retries = HP_SW_RETRIES; 369 h->retries = HP_SW_RETRIES;
374 h->sdev = sdev; 370 h->sdev = sdev;
@@ -378,7 +374,7 @@ static int hp_sw_bus_attach(struct scsi_device *sdev)
378 goto failed; 374 goto failed;
379 375
380 spin_lock_irqsave(sdev->request_queue->queue_lock, flags); 376 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
381 sdev->scsi_dh_data = scsi_dh_data; 377 sdev->scsi_dh_data = &h->dh_data;
382 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); 378 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
383 379
384 sdev_printk(KERN_INFO, sdev, "%s: attached to %s path\n", 380 sdev_printk(KERN_INFO, sdev, "%s: attached to %s path\n",
@@ -388,7 +384,7 @@ static int hp_sw_bus_attach(struct scsi_device *sdev)
388 return 0; 384 return 0;
389 385
390failed: 386failed:
391 kfree(scsi_dh_data); 387 kfree(h);
392 sdev_printk(KERN_ERR, sdev, "%s: not attached\n", 388 sdev_printk(KERN_ERR, sdev, "%s: not attached\n",
393 HP_SW_NAME); 389 HP_SW_NAME);
394 return -EINVAL; 390 return -EINVAL;
@@ -396,17 +392,16 @@ failed:
396 392
397static void hp_sw_bus_detach( struct scsi_device *sdev ) 393static void hp_sw_bus_detach( struct scsi_device *sdev )
398{ 394{
399 struct scsi_dh_data *scsi_dh_data; 395 struct hp_sw_dh_data *h = get_hp_sw_data(sdev);
400 unsigned long flags; 396 unsigned long flags;
401 397
402 spin_lock_irqsave(sdev->request_queue->queue_lock, flags); 398 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
403 scsi_dh_data = sdev->scsi_dh_data;
404 sdev->scsi_dh_data = NULL; 399 sdev->scsi_dh_data = NULL;
405 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); 400 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
406 401
407 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", HP_SW_NAME); 402 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", HP_SW_NAME);
408 403
409 kfree(scsi_dh_data); 404 kfree(h);
410} 405}
411 406
412static int __init hp_sw_init(void) 407static int __init hp_sw_init(void)
diff --git a/drivers/scsi/device_handler/scsi_dh_rdac.c b/drivers/scsi/device_handler/scsi_dh_rdac.c
index b850954c4e22..ef8caaaad76f 100644
--- a/drivers/scsi/device_handler/scsi_dh_rdac.c
+++ b/drivers/scsi/device_handler/scsi_dh_rdac.c
@@ -181,6 +181,7 @@ struct c2_inquiry {
181}; 181};
182 182
183struct rdac_dh_data { 183struct rdac_dh_data {
184 struct scsi_dh_data dh_data;
184 struct rdac_controller *ctlr; 185 struct rdac_controller *ctlr;
185#define UNINITIALIZED_LUN (1 << 8) 186#define UNINITIALIZED_LUN (1 << 8)
186 unsigned lun; 187 unsigned lun;
@@ -261,9 +262,7 @@ do { \
261 262
262static inline struct rdac_dh_data *get_rdac_data(struct scsi_device *sdev) 263static inline struct rdac_dh_data *get_rdac_data(struct scsi_device *sdev)
263{ 264{
264 struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; 265 return container_of(sdev->scsi_dh_data, struct rdac_dh_data, dh_data);
265 BUG_ON(scsi_dh_data == NULL);
266 return ((struct rdac_dh_data *) scsi_dh_data->buf);
267} 266}
268 267
269static struct request *get_rdac_req(struct scsi_device *sdev, 268static struct request *get_rdac_req(struct scsi_device *sdev,
@@ -842,23 +841,20 @@ static struct scsi_device_handler rdac_dh = {
842 841
843static int rdac_bus_attach(struct scsi_device *sdev) 842static int rdac_bus_attach(struct scsi_device *sdev)
844{ 843{
845 struct scsi_dh_data *scsi_dh_data;
846 struct rdac_dh_data *h; 844 struct rdac_dh_data *h;
847 unsigned long flags; 845 unsigned long flags;
848 int err; 846 int err;
849 char array_name[ARRAY_LABEL_LEN]; 847 char array_name[ARRAY_LABEL_LEN];
850 char array_id[UNIQUE_ID_LEN]; 848 char array_id[UNIQUE_ID_LEN];
851 849
852 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data) 850 h = kzalloc(sizeof(*h) , GFP_KERNEL);
853 + sizeof(*h) , GFP_KERNEL); 851 if (!h) {
854 if (!scsi_dh_data) {
855 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n", 852 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
856 RDAC_NAME); 853 RDAC_NAME);
857 return -ENOMEM; 854 return -ENOMEM;
858 } 855 }
859 856
860 scsi_dh_data->scsi_dh = &rdac_dh; 857 h->dh_data.scsi_dh = &rdac_dh;
861 h = (struct rdac_dh_data *) scsi_dh_data->buf;
862 h->lun = UNINITIALIZED_LUN; 858 h->lun = UNINITIALIZED_LUN;
863 h->state = RDAC_STATE_ACTIVE; 859 h->state = RDAC_STATE_ACTIVE;
864 860
@@ -879,7 +875,7 @@ static int rdac_bus_attach(struct scsi_device *sdev)
879 goto clean_ctlr; 875 goto clean_ctlr;
880 876
881 spin_lock_irqsave(sdev->request_queue->queue_lock, flags); 877 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
882 sdev->scsi_dh_data = scsi_dh_data; 878 sdev->scsi_dh_data = &h->dh_data;
883 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); 879 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
884 880
885 sdev_printk(KERN_NOTICE, sdev, 881 sdev_printk(KERN_NOTICE, sdev,
@@ -895,7 +891,7 @@ clean_ctlr:
895 spin_unlock(&list_lock); 891 spin_unlock(&list_lock);
896 892
897failed: 893failed:
898 kfree(scsi_dh_data); 894 kfree(h);
899 sdev_printk(KERN_ERR, sdev, "%s: not attached\n", 895 sdev_printk(KERN_ERR, sdev, "%s: not attached\n",
900 RDAC_NAME); 896 RDAC_NAME);
901 return -EINVAL; 897 return -EINVAL;
@@ -903,12 +899,9 @@ failed:
903 899
904static void rdac_bus_detach( struct scsi_device *sdev ) 900static void rdac_bus_detach( struct scsi_device *sdev )
905{ 901{
906 struct scsi_dh_data *scsi_dh_data; 902 struct rdac_dh_data *h = get_rdac_data(sdev);
907 struct rdac_dh_data *h;
908 unsigned long flags; 903 unsigned long flags;
909 904
910 scsi_dh_data = sdev->scsi_dh_data;
911 h = (struct rdac_dh_data *) scsi_dh_data->buf;
912 if (h->ctlr && h->ctlr->ms_queued) 905 if (h->ctlr && h->ctlr->ms_queued)
913 flush_workqueue(kmpath_rdacd); 906 flush_workqueue(kmpath_rdacd);
914 907
@@ -920,7 +913,7 @@ static void rdac_bus_detach( struct scsi_device *sdev )
920 if (h->ctlr) 913 if (h->ctlr)
921 kref_put(&h->ctlr->kref, release_controller); 914 kref_put(&h->ctlr->kref, release_controller);
922 spin_unlock(&list_lock); 915 spin_unlock(&list_lock);
923 kfree(scsi_dh_data); 916 kfree(h);
924 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", RDAC_NAME); 917 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", RDAC_NAME);
925} 918}
926 919
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 0b18a097c1ba..04cd5ad8289e 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -228,7 +228,6 @@ struct scsi_dh_data {
228 struct scsi_device_handler *scsi_dh; 228 struct scsi_device_handler *scsi_dh;
229 struct scsi_device *sdev; 229 struct scsi_device *sdev;
230 struct kref kref; 230 struct kref kref;
231 char buf[0];
232}; 231};
233 232
234#define to_scsi_device(d) \ 233#define to_scsi_device(d) \