Commit f27bac27 authored by Tejun Heo's avatar Tejun Heo Committed by James Bottomley

[SCSI] sd: update index allocation and use ida instead of idr

Update index allocation as follows.

* sd_index_idr is used only for ID allocation and mapping
  functionality is not used.  Use more memory efficient ida instead.

* idr and ida have their own locks inside them and don't need them for
  operation.  Drop it.

* index wasn't freed if probing failed after index allocation.  fix
  it.

* ida allocation should be repeated if it fails with -EAGAIN.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
parent ecefe8a9
...@@ -99,8 +99,7 @@ static void scsi_disk_release(struct device *cdev); ...@@ -99,8 +99,7 @@ static void scsi_disk_release(struct device *cdev);
static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *); static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *);
static void sd_print_result(struct scsi_disk *, int); static void sd_print_result(struct scsi_disk *, int);
static DEFINE_IDR(sd_index_idr); static DEFINE_IDA(sd_index_ida);
static DEFINE_SPINLOCK(sd_index_lock);
/* This semaphore is used to mediate the 0->1 reference get in the /* This semaphore is used to mediate the 0->1 reference get in the
* face of object destruction (i.e. we can't allow a get on an * face of object destruction (i.e. we can't allow a get on an
...@@ -1643,18 +1642,20 @@ static int sd_probe(struct device *dev) ...@@ -1643,18 +1642,20 @@ static int sd_probe(struct device *dev)
if (!gd) if (!gd)
goto out_free; goto out_free;
if (!idr_pre_get(&sd_index_idr, GFP_KERNEL)) do {
if (!ida_pre_get(&sd_index_ida, GFP_KERNEL))
goto out_put; goto out_put;
spin_lock(&sd_index_lock); error = ida_get_new(&sd_index_ida, &index);
error = idr_get_new(&sd_index_idr, NULL, &index); } while (error == -EAGAIN);
spin_unlock(&sd_index_lock);
if (index >= SD_MAX_DISKS)
error = -EBUSY;
if (error) if (error)
goto out_put; goto out_put;
error = -EBUSY;
if (index >= SD_MAX_DISKS)
goto out_free_index;
sdkp->device = sdp; sdkp->device = sdp;
sdkp->driver = &sd_template; sdkp->driver = &sd_template;
sdkp->disk = gd; sdkp->disk = gd;
...@@ -1675,7 +1676,7 @@ static int sd_probe(struct device *dev) ...@@ -1675,7 +1676,7 @@ static int sd_probe(struct device *dev)
strncpy(sdkp->dev.bus_id, sdp->sdev_gendev.bus_id, BUS_ID_SIZE); strncpy(sdkp->dev.bus_id, sdp->sdev_gendev.bus_id, BUS_ID_SIZE);
if (device_add(&sdkp->dev)) if (device_add(&sdkp->dev))
goto out_put; goto out_free_index;
get_device(&sdp->sdev_gendev); get_device(&sdp->sdev_gendev);
...@@ -1717,6 +1718,8 @@ static int sd_probe(struct device *dev) ...@@ -1717,6 +1718,8 @@ static int sd_probe(struct device *dev)
return 0; return 0;
out_free_index:
ida_remove(&sd_index_ida, index);
out_put: out_put:
put_disk(gd); put_disk(gd);
out_free: out_free:
...@@ -1766,9 +1769,7 @@ static void scsi_disk_release(struct device *dev) ...@@ -1766,9 +1769,7 @@ static void scsi_disk_release(struct device *dev)
struct scsi_disk *sdkp = to_scsi_disk(dev); struct scsi_disk *sdkp = to_scsi_disk(dev);
struct gendisk *disk = sdkp->disk; struct gendisk *disk = sdkp->disk;
spin_lock(&sd_index_lock); ida_remove(&sd_index_ida, sdkp->index);
idr_remove(&sd_index_idr, sdkp->index);
spin_unlock(&sd_index_lock);
disk->private_data = NULL; disk->private_data = NULL;
put_disk(disk); put_disk(disk);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment