diff options
author | Lee Duncan <lduncan@suse.com> | 2016-01-20 14:48:00 -0500 |
---|---|---|
committer | Martin K. Petersen <martin.petersen@oracle.com> | 2016-02-23 21:27:02 -0500 |
commit | 126a4fe010fd86cf3eaac9a481f0698e39dc3c0d (patch) | |
tree | 1e14f372d7e8eac390dabcad683fea6fb0f19c6f /drivers/scsi | |
parent | d92ca9d3de862cb123d7ef0fd42dc1e9867dd590 (diff) |
scsi: Use ida for host number management
Update the SCSI hosts module to use ida to manage its host_no index
instead of an atomic integer. This means that the SCSI host number will
now be reclaimable.
Use the ida "simple" mechanism, since there should be no need for a
separate spin lock current usage. Ida was chosen over idr because the
hosts module already has its own instance and locking mechanisms that
aren't easily changed.
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Lee Duncan <lduncan@suse.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Diffstat (limited to 'drivers/scsi')
-rw-r--r-- | drivers/scsi/hosts.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index 82ac1cd818ac..94025c5cf797 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c | |||
@@ -33,7 +33,7 @@ | |||
33 | #include <linux/transport_class.h> | 33 | #include <linux/transport_class.h> |
34 | #include <linux/platform_device.h> | 34 | #include <linux/platform_device.h> |
35 | #include <linux/pm_runtime.h> | 35 | #include <linux/pm_runtime.h> |
36 | 36 | #include <linux/idr.h> | |
37 | #include <scsi/scsi_device.h> | 37 | #include <scsi/scsi_device.h> |
38 | #include <scsi/scsi_host.h> | 38 | #include <scsi/scsi_host.h> |
39 | #include <scsi/scsi_transport.h> | 39 | #include <scsi/scsi_transport.h> |
@@ -42,7 +42,7 @@ | |||
42 | #include "scsi_logging.h" | 42 | #include "scsi_logging.h" |
43 | 43 | ||
44 | 44 | ||
45 | static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */ | 45 | static DEFINE_IDA(host_index_ida); |
46 | 46 | ||
47 | 47 | ||
48 | static void scsi_host_cls_release(struct device *dev) | 48 | static void scsi_host_cls_release(struct device *dev) |
@@ -355,6 +355,8 @@ static void scsi_host_dev_release(struct device *dev) | |||
355 | 355 | ||
356 | kfree(shost->shost_data); | 356 | kfree(shost->shost_data); |
357 | 357 | ||
358 | ida_simple_remove(&host_index_ida, shost->host_no); | ||
359 | |||
358 | if (parent) | 360 | if (parent) |
359 | put_device(parent); | 361 | put_device(parent); |
360 | kfree(shost); | 362 | kfree(shost); |
@@ -388,6 +390,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize) | |||
388 | { | 390 | { |
389 | struct Scsi_Host *shost; | 391 | struct Scsi_Host *shost; |
390 | gfp_t gfp_mask = GFP_KERNEL; | 392 | gfp_t gfp_mask = GFP_KERNEL; |
393 | int index; | ||
391 | 394 | ||
392 | if (sht->unchecked_isa_dma && privsize) | 395 | if (sht->unchecked_isa_dma && privsize) |
393 | gfp_mask |= __GFP_DMA; | 396 | gfp_mask |= __GFP_DMA; |
@@ -406,11 +409,11 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize) | |||
406 | init_waitqueue_head(&shost->host_wait); | 409 | init_waitqueue_head(&shost->host_wait); |
407 | mutex_init(&shost->scan_mutex); | 410 | mutex_init(&shost->scan_mutex); |
408 | 411 | ||
409 | /* | 412 | index = ida_simple_get(&host_index_ida, 0, 0, GFP_KERNEL); |
410 | * subtract one because we increment first then return, but we need to | 413 | if (index < 0) |
411 | * know what the next host number was before increment | 414 | goto fail_kfree; |
412 | */ | 415 | shost->host_no = index; |
413 | shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1; | 416 | |
414 | shost->dma_channel = 0xff; | 417 | shost->dma_channel = 0xff; |
415 | 418 | ||
416 | /* These three are default values which can be overridden */ | 419 | /* These three are default values which can be overridden */ |
@@ -495,7 +498,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize) | |||
495 | shost_printk(KERN_WARNING, shost, | 498 | shost_printk(KERN_WARNING, shost, |
496 | "error handler thread failed to spawn, error = %ld\n", | 499 | "error handler thread failed to spawn, error = %ld\n", |
497 | PTR_ERR(shost->ehandler)); | 500 | PTR_ERR(shost->ehandler)); |
498 | goto fail_kfree; | 501 | goto fail_index_remove; |
499 | } | 502 | } |
500 | 503 | ||
501 | shost->tmf_work_q = alloc_workqueue("scsi_tmf_%d", | 504 | shost->tmf_work_q = alloc_workqueue("scsi_tmf_%d", |
@@ -511,6 +514,8 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize) | |||
511 | 514 | ||
512 | fail_kthread: | 515 | fail_kthread: |
513 | kthread_stop(shost->ehandler); | 516 | kthread_stop(shost->ehandler); |
517 | fail_index_remove: | ||
518 | ida_simple_remove(&host_index_ida, shost->host_no); | ||
514 | fail_kfree: | 519 | fail_kfree: |
515 | kfree(shost); | 520 | kfree(shost); |
516 | return NULL; | 521 | return NULL; |
@@ -606,6 +611,7 @@ int scsi_init_hosts(void) | |||
606 | void scsi_exit_hosts(void) | 611 | void scsi_exit_hosts(void) |
607 | { | 612 | { |
608 | class_unregister(&shost_class); | 613 | class_unregister(&shost_class); |
614 | ida_destroy(&host_index_ida); | ||
609 | } | 615 | } |
610 | 616 | ||
611 | int scsi_is_host_device(const struct device *dev) | 617 | int scsi_is_host_device(const struct device *dev) |