scsi: use container_of to get at device handler private data

Signed-off-by: NChristoph Hellwig <hch@lst.de>
Reviewed-by: NMike Christie <michaelc@cs.wisc.edu>
Reviewed-by: NHannes Reinecke <hare@suse.de>
上级 27c888f0
master alk-4.19.24 alk-4.19.30 alk-4.19.34 alk-4.19.36 alk-4.19.43 alk-4.19.48 alk-4.19.57 ck-4.19.67 ck-4.19.81 ck-4.19.91 github/fork/deepanshu1422/fix-typo-in-comment github/fork/haosdent/fix-typo linux-next v4.19.91 v4.19.90 v4.19.89 v4.19.88 v4.19.87 v4.19.86 v4.19.85 v4.19.84 v4.19.83 v4.19.82 v4.19.81 v4.19.80 v4.19.79 v4.19.78 v4.19.77 v4.19.76 v4.19.75 v4.19.74 v4.19.73 v4.19.72 v4.19.71 v4.19.70 v4.19.69 v4.19.68 v4.19.67 v4.19.66 v4.19.65 v4.19.64 v4.19.63 v4.19.62 v4.19.61 v4.19.60 v4.19.59 v4.19.58 v4.19.57 v4.19.56 v4.19.55 v4.19.54 v4.19.53 v4.19.52 v4.19.51 v4.19.50 v4.19.49 v4.19.48 v4.19.47 v4.19.46 v4.19.45 v4.19.44 v4.19.43 v4.19.42 v4.19.41 v4.19.40 v4.19.39 v4.19.38 v4.19.37 v4.19.36 v4.19.35 v4.19.34 v4.19.33 v4.19.32 v4.19.31 v4.19.30 v4.19.29 v4.19.28 v4.19.27 v4.19.26 v4.19.25 v4.19.24 v4.19.23 v4.19.22 v4.19.21 v4.19.20 v4.19.19 v4.19.18 v4.19.17 v4.19.16 v4.19.15 v4.19.14 v4.19.13 v4.19.12 v4.19.11 v4.19.10 v4.19.9 v4.19.8 v4.19.7 v4.19.6 v4.19.5 v4.19.4 v4.19.3 v4.19.2 v4.19.1 v4.19 v4.19-rc8 v4.19-rc7 v4.19-rc6 v4.19-rc5 v4.19-rc4 v4.19-rc3 v4.19-rc2 v4.19-rc1 ck-release-21 ck-release-20 ck-release-19.2 ck-release-19.1 ck-release-19 ck-release-18 ck-release-17.2 ck-release-17.1 ck-release-17 ck-release-16 ck-release-15.1 ck-release-15 ck-release-14 ck-release-13.2 ck-release-13 ck-release-12 ck-release-11 ck-release-10 ck-release-9 ck-release-7 alk-release-15 alk-release-14 alk-release-13.2 alk-release-13 alk-release-12 alk-release-11 alk-release-10 alk-release-9 alk-release-7
无相关合并请求
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
#define ALUA_OPTIMIZE_STPG 1 #define ALUA_OPTIMIZE_STPG 1
struct alua_dh_data { struct alua_dh_data {
struct scsi_dh_data dh_data;
int group_id; int group_id;
int rel_port; int rel_port;
int tpgs; int tpgs;
...@@ -87,9 +88,7 @@ static int alua_check_sense(struct scsi_device *, struct scsi_sense_hdr *); ...@@ -87,9 +88,7 @@ static int alua_check_sense(struct scsi_device *, struct scsi_sense_hdr *);
static inline struct alua_dh_data *get_alua_data(struct scsi_device *sdev) static inline struct alua_dh_data *get_alua_data(struct scsi_device *sdev)
{ {
struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; return container_of(sdev->scsi_dh_data, struct alua_dh_data, dh_data);
BUG_ON(scsi_dh_data == NULL);
return ((struct alua_dh_data *) scsi_dh_data->buf);
} }
static int realloc_buffer(struct alua_dh_data *h, unsigned len) static int realloc_buffer(struct alua_dh_data *h, unsigned len)
...@@ -846,21 +845,18 @@ static struct scsi_device_handler alua_dh = { ...@@ -846,21 +845,18 @@ static struct scsi_device_handler alua_dh = {
*/ */
static int alua_bus_attach(struct scsi_device *sdev) static int alua_bus_attach(struct scsi_device *sdev)
{ {
struct scsi_dh_data *scsi_dh_data;
struct alua_dh_data *h; struct alua_dh_data *h;
unsigned long flags; unsigned long flags;
int err = SCSI_DH_OK; int err = SCSI_DH_OK;
scsi_dh_data = kzalloc(sizeof(*scsi_dh_data) h = kzalloc(sizeof(*h) , GFP_KERNEL);
+ sizeof(*h) , GFP_KERNEL); if (!h) {
if (!scsi_dh_data) {
sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n", sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
ALUA_DH_NAME); ALUA_DH_NAME);
return -ENOMEM; return -ENOMEM;
} }
scsi_dh_data->scsi_dh = &alua_dh; h->dh_data.scsi_dh = &alua_dh;
h = (struct alua_dh_data *) scsi_dh_data->buf;
h->tpgs = TPGS_MODE_UNINITIALIZED; h->tpgs = TPGS_MODE_UNINITIALIZED;
h->state = TPGS_STATE_OPTIMIZED; h->state = TPGS_STATE_OPTIMIZED;
h->group_id = -1; h->group_id = -1;
...@@ -874,14 +870,14 @@ static int alua_bus_attach(struct scsi_device *sdev) ...@@ -874,14 +870,14 @@ static int alua_bus_attach(struct scsi_device *sdev)
goto failed; goto failed;
spin_lock_irqsave(sdev->request_queue->queue_lock, flags); spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
sdev->scsi_dh_data = scsi_dh_data; sdev->scsi_dh_data = &h->dh_data;
spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
sdev_printk(KERN_NOTICE, sdev, "%s: Attached\n", ALUA_DH_NAME); sdev_printk(KERN_NOTICE, sdev, "%s: Attached\n", ALUA_DH_NAME);
return 0; return 0;
failed: failed:
kfree(scsi_dh_data); kfree(h);
sdev_printk(KERN_ERR, sdev, "%s: not attached\n", ALUA_DH_NAME); sdev_printk(KERN_ERR, sdev, "%s: not attached\n", ALUA_DH_NAME);
return -EINVAL; return -EINVAL;
} }
...@@ -892,19 +888,16 @@ static int alua_bus_attach(struct scsi_device *sdev) ...@@ -892,19 +888,16 @@ static int alua_bus_attach(struct scsi_device *sdev)
*/ */
static void alua_bus_detach(struct scsi_device *sdev) static void alua_bus_detach(struct scsi_device *sdev)
{ {
struct scsi_dh_data *scsi_dh_data; struct alua_dh_data *h = get_alua_data(sdev);
struct alua_dh_data *h;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(sdev->request_queue->queue_lock, flags); spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
scsi_dh_data = sdev->scsi_dh_data;
sdev->scsi_dh_data = NULL; sdev->scsi_dh_data = NULL;
spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
h = (struct alua_dh_data *) scsi_dh_data->buf;
if (h->buff && h->inq != h->buff) if (h->buff && h->inq != h->buff)
kfree(h->buff); kfree(h->buff);
kfree(scsi_dh_data); kfree(h);
sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", ALUA_DH_NAME); sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", ALUA_DH_NAME);
} }
......
...@@ -72,6 +72,7 @@ static const char * lun_state[] = ...@@ -72,6 +72,7 @@ static const char * lun_state[] =
}; };
struct clariion_dh_data { struct clariion_dh_data {
struct scsi_dh_data dh_data;
/* /*
* Flags: * Flags:
* CLARIION_SHORT_TRESPASS * CLARIION_SHORT_TRESPASS
...@@ -116,9 +117,8 @@ struct clariion_dh_data { ...@@ -116,9 +117,8 @@ struct clariion_dh_data {
static inline struct clariion_dh_data static inline struct clariion_dh_data
*get_clariion_data(struct scsi_device *sdev) *get_clariion_data(struct scsi_device *sdev)
{ {
struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; return container_of(sdev->scsi_dh_data, struct clariion_dh_data,
BUG_ON(scsi_dh_data == NULL); dh_data);
return ((struct clariion_dh_data *) scsi_dh_data->buf);
} }
/* /*
...@@ -665,21 +665,18 @@ static struct scsi_device_handler clariion_dh = { ...@@ -665,21 +665,18 @@ static struct scsi_device_handler clariion_dh = {
static int clariion_bus_attach(struct scsi_device *sdev) static int clariion_bus_attach(struct scsi_device *sdev)
{ {
struct scsi_dh_data *scsi_dh_data;
struct clariion_dh_data *h; struct clariion_dh_data *h;
unsigned long flags; unsigned long flags;
int err; int err;
scsi_dh_data = kzalloc(sizeof(*scsi_dh_data) h = kzalloc(sizeof(*h) , GFP_KERNEL);
+ sizeof(*h) , GFP_KERNEL); if (!h) {
if (!scsi_dh_data) {
sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n", sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
CLARIION_NAME); CLARIION_NAME);
return -ENOMEM; return -ENOMEM;
} }
scsi_dh_data->scsi_dh = &clariion_dh; h->dh_data.scsi_dh = &clariion_dh;
h = (struct clariion_dh_data *) scsi_dh_data->buf;
h->lun_state = CLARIION_LUN_UNINITIALIZED; h->lun_state = CLARIION_LUN_UNINITIALIZED;
h->default_sp = CLARIION_UNBOUND_LU; h->default_sp = CLARIION_UNBOUND_LU;
h->current_sp = CLARIION_UNBOUND_LU; h->current_sp = CLARIION_UNBOUND_LU;
...@@ -693,7 +690,7 @@ static int clariion_bus_attach(struct scsi_device *sdev) ...@@ -693,7 +690,7 @@ static int clariion_bus_attach(struct scsi_device *sdev)
goto failed; goto failed;
spin_lock_irqsave(sdev->request_queue->queue_lock, flags); spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
sdev->scsi_dh_data = scsi_dh_data; sdev->scsi_dh_data = &h->dh_data;
spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
sdev_printk(KERN_INFO, sdev, sdev_printk(KERN_INFO, sdev,
...@@ -705,7 +702,7 @@ static int clariion_bus_attach(struct scsi_device *sdev) ...@@ -705,7 +702,7 @@ static int clariion_bus_attach(struct scsi_device *sdev)
return 0; return 0;
failed: failed:
kfree(scsi_dh_data); kfree(h);
sdev_printk(KERN_ERR, sdev, "%s: not attached\n", sdev_printk(KERN_ERR, sdev, "%s: not attached\n",
CLARIION_NAME); CLARIION_NAME);
return -EINVAL; return -EINVAL;
...@@ -713,18 +710,17 @@ static int clariion_bus_attach(struct scsi_device *sdev) ...@@ -713,18 +710,17 @@ static int clariion_bus_attach(struct scsi_device *sdev)
static void clariion_bus_detach(struct scsi_device *sdev) static void clariion_bus_detach(struct scsi_device *sdev)
{ {
struct scsi_dh_data *scsi_dh_data; struct clariion_dh_data *h = get_clariion_data(sdev);
unsigned long flags; unsigned long flags;
spin_lock_irqsave(sdev->request_queue->queue_lock, flags); spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
scsi_dh_data = sdev->scsi_dh_data;
sdev->scsi_dh_data = NULL; sdev->scsi_dh_data = NULL;
spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n",
CLARIION_NAME); CLARIION_NAME);
kfree(scsi_dh_data); kfree(h);
} }
static int __init clariion_init(void) static int __init clariion_init(void)
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#define HP_SW_PATH_PASSIVE 1 #define HP_SW_PATH_PASSIVE 1
struct hp_sw_dh_data { struct hp_sw_dh_data {
struct scsi_dh_data dh_data;
unsigned char sense[SCSI_SENSE_BUFFERSIZE]; unsigned char sense[SCSI_SENSE_BUFFERSIZE];
int path_state; int path_state;
int retries; int retries;
...@@ -51,9 +52,7 @@ static int hp_sw_start_stop(struct hp_sw_dh_data *); ...@@ -51,9 +52,7 @@ static int hp_sw_start_stop(struct hp_sw_dh_data *);
static inline struct hp_sw_dh_data *get_hp_sw_data(struct scsi_device *sdev) static inline struct hp_sw_dh_data *get_hp_sw_data(struct scsi_device *sdev)
{ {
struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; return container_of(sdev->scsi_dh_data, struct hp_sw_dh_data, dh_data);
BUG_ON(scsi_dh_data == NULL);
return ((struct hp_sw_dh_data *) scsi_dh_data->buf);
} }
/* /*
...@@ -354,21 +353,18 @@ static struct scsi_device_handler hp_sw_dh = { ...@@ -354,21 +353,18 @@ static struct scsi_device_handler hp_sw_dh = {
static int hp_sw_bus_attach(struct scsi_device *sdev) static int hp_sw_bus_attach(struct scsi_device *sdev)
{ {
struct scsi_dh_data *scsi_dh_data;
struct hp_sw_dh_data *h; struct hp_sw_dh_data *h;
unsigned long flags; unsigned long flags;
int ret; int ret;
scsi_dh_data = kzalloc(sizeof(*scsi_dh_data) h = kzalloc(sizeof(*h), GFP_KERNEL);
+ sizeof(*h) , GFP_KERNEL); if (!h) {
if (!scsi_dh_data) {
sdev_printk(KERN_ERR, sdev, "%s: Attach Failed\n", sdev_printk(KERN_ERR, sdev, "%s: Attach Failed\n",
HP_SW_NAME); HP_SW_NAME);
return -ENOMEM; return -ENOMEM;
} }
scsi_dh_data->scsi_dh = &hp_sw_dh; h->dh_data.scsi_dh = &hp_sw_dh;
h = (struct hp_sw_dh_data *) scsi_dh_data->buf;
h->path_state = HP_SW_PATH_UNINITIALIZED; h->path_state = HP_SW_PATH_UNINITIALIZED;
h->retries = HP_SW_RETRIES; h->retries = HP_SW_RETRIES;
h->sdev = sdev; h->sdev = sdev;
...@@ -378,7 +374,7 @@ static int hp_sw_bus_attach(struct scsi_device *sdev) ...@@ -378,7 +374,7 @@ static int hp_sw_bus_attach(struct scsi_device *sdev)
goto failed; goto failed;
spin_lock_irqsave(sdev->request_queue->queue_lock, flags); spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
sdev->scsi_dh_data = scsi_dh_data; sdev->scsi_dh_data = &h->dh_data;
spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
sdev_printk(KERN_INFO, sdev, "%s: attached to %s path\n", 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,7 +384,7 @@ static int hp_sw_bus_attach(struct scsi_device *sdev)
return 0; return 0;
failed: failed:
kfree(scsi_dh_data); kfree(h);
sdev_printk(KERN_ERR, sdev, "%s: not attached\n", sdev_printk(KERN_ERR, sdev, "%s: not attached\n",
HP_SW_NAME); HP_SW_NAME);
return -EINVAL; return -EINVAL;
...@@ -396,17 +392,16 @@ static int hp_sw_bus_attach(struct scsi_device *sdev) ...@@ -396,17 +392,16 @@ static int hp_sw_bus_attach(struct scsi_device *sdev)
static void hp_sw_bus_detach( struct scsi_device *sdev ) static void hp_sw_bus_detach( struct scsi_device *sdev )
{ {
struct scsi_dh_data *scsi_dh_data; struct hp_sw_dh_data *h = get_hp_sw_data(sdev);
unsigned long flags; unsigned long flags;
spin_lock_irqsave(sdev->request_queue->queue_lock, flags); spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
scsi_dh_data = sdev->scsi_dh_data;
sdev->scsi_dh_data = NULL; sdev->scsi_dh_data = NULL;
spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", HP_SW_NAME); sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", HP_SW_NAME);
kfree(scsi_dh_data); kfree(h);
} }
static int __init hp_sw_init(void) static int __init hp_sw_init(void)
......
...@@ -181,6 +181,7 @@ struct c2_inquiry { ...@@ -181,6 +181,7 @@ struct c2_inquiry {
}; };
struct rdac_dh_data { struct rdac_dh_data {
struct scsi_dh_data dh_data;
struct rdac_controller *ctlr; struct rdac_controller *ctlr;
#define UNINITIALIZED_LUN (1 << 8) #define UNINITIALIZED_LUN (1 << 8)
unsigned lun; unsigned lun;
...@@ -261,9 +262,7 @@ do { \ ...@@ -261,9 +262,7 @@ do { \
static inline struct rdac_dh_data *get_rdac_data(struct scsi_device *sdev) static inline struct rdac_dh_data *get_rdac_data(struct scsi_device *sdev)
{ {
struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; return container_of(sdev->scsi_dh_data, struct rdac_dh_data, dh_data);
BUG_ON(scsi_dh_data == NULL);
return ((struct rdac_dh_data *) scsi_dh_data->buf);
} }
static struct request *get_rdac_req(struct scsi_device *sdev, static struct request *get_rdac_req(struct scsi_device *sdev,
...@@ -842,23 +841,20 @@ static struct scsi_device_handler rdac_dh = { ...@@ -842,23 +841,20 @@ static struct scsi_device_handler rdac_dh = {
static int rdac_bus_attach(struct scsi_device *sdev) static int rdac_bus_attach(struct scsi_device *sdev)
{ {
struct scsi_dh_data *scsi_dh_data;
struct rdac_dh_data *h; struct rdac_dh_data *h;
unsigned long flags; unsigned long flags;
int err; int err;
char array_name[ARRAY_LABEL_LEN]; char array_name[ARRAY_LABEL_LEN];
char array_id[UNIQUE_ID_LEN]; char array_id[UNIQUE_ID_LEN];
scsi_dh_data = kzalloc(sizeof(*scsi_dh_data) h = kzalloc(sizeof(*h) , GFP_KERNEL);
+ sizeof(*h) , GFP_KERNEL); if (!h) {
if (!scsi_dh_data) {
sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n", sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
RDAC_NAME); RDAC_NAME);
return -ENOMEM; return -ENOMEM;
} }
scsi_dh_data->scsi_dh = &rdac_dh; h->dh_data.scsi_dh = &rdac_dh;
h = (struct rdac_dh_data *) scsi_dh_data->buf;
h->lun = UNINITIALIZED_LUN; h->lun = UNINITIALIZED_LUN;
h->state = RDAC_STATE_ACTIVE; h->state = RDAC_STATE_ACTIVE;
...@@ -879,7 +875,7 @@ static int rdac_bus_attach(struct scsi_device *sdev) ...@@ -879,7 +875,7 @@ static int rdac_bus_attach(struct scsi_device *sdev)
goto clean_ctlr; goto clean_ctlr;
spin_lock_irqsave(sdev->request_queue->queue_lock, flags); spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
sdev->scsi_dh_data = scsi_dh_data; sdev->scsi_dh_data = &h->dh_data;
spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
sdev_printk(KERN_NOTICE, sdev, sdev_printk(KERN_NOTICE, sdev,
...@@ -895,7 +891,7 @@ static int rdac_bus_attach(struct scsi_device *sdev) ...@@ -895,7 +891,7 @@ static int rdac_bus_attach(struct scsi_device *sdev)
spin_unlock(&list_lock); spin_unlock(&list_lock);
failed: failed:
kfree(scsi_dh_data); kfree(h);
sdev_printk(KERN_ERR, sdev, "%s: not attached\n", sdev_printk(KERN_ERR, sdev, "%s: not attached\n",
RDAC_NAME); RDAC_NAME);
return -EINVAL; return -EINVAL;
...@@ -903,12 +899,9 @@ static int rdac_bus_attach(struct scsi_device *sdev) ...@@ -903,12 +899,9 @@ static int rdac_bus_attach(struct scsi_device *sdev)
static void rdac_bus_detach( struct scsi_device *sdev ) static void rdac_bus_detach( struct scsi_device *sdev )
{ {
struct scsi_dh_data *scsi_dh_data; struct rdac_dh_data *h = get_rdac_data(sdev);
struct rdac_dh_data *h;
unsigned long flags; unsigned long flags;
scsi_dh_data = sdev->scsi_dh_data;
h = (struct rdac_dh_data *) scsi_dh_data->buf;
if (h->ctlr && h->ctlr->ms_queued) if (h->ctlr && h->ctlr->ms_queued)
flush_workqueue(kmpath_rdacd); flush_workqueue(kmpath_rdacd);
...@@ -920,7 +913,7 @@ static void rdac_bus_detach( struct scsi_device *sdev ) ...@@ -920,7 +913,7 @@ static void rdac_bus_detach( struct scsi_device *sdev )
if (h->ctlr) if (h->ctlr)
kref_put(&h->ctlr->kref, release_controller); kref_put(&h->ctlr->kref, release_controller);
spin_unlock(&list_lock); spin_unlock(&list_lock);
kfree(scsi_dh_data); kfree(h);
sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", RDAC_NAME); sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", RDAC_NAME);
} }
......
...@@ -228,7 +228,6 @@ struct scsi_dh_data { ...@@ -228,7 +228,6 @@ struct scsi_dh_data {
struct scsi_device_handler *scsi_dh; struct scsi_device_handler *scsi_dh;
struct scsi_device *sdev; struct scsi_device *sdev;
struct kref kref; struct kref kref;
char buf[0];
}; };
#define to_scsi_device(d) \ #define to_scsi_device(d) \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
反馈
建议
客服 返回
顶部