Commit 65862c41 authored by Patrick Mansfield's avatar Patrick Mansfield Committed by James Bottomley

[PATCH] 7/7 fix single_lun code for per-scsi_device queue_lock

Fix single_lun code for per-scsi_device queue_lock
parent 00879482
...@@ -530,6 +530,15 @@ struct scsi_dev_info_list { ...@@ -530,6 +530,15 @@ struct scsi_dev_info_list {
extern struct list_head scsi_dev_info_list; extern struct list_head scsi_dev_info_list;
extern int scsi_dev_info_list_add_str(char *); extern int scsi_dev_info_list_add_str(char *);
/*
* scsi_target: representation of a scsi target, for now, this is only
* used for single_lun devices.
*/
struct scsi_target {
unsigned int starget_busy;
unsigned int starget_refcnt;
};
/* /*
* The scsi_device struct contains what we know about each given scsi * The scsi_device struct contains what we know about each given scsi
* device. * device.
...@@ -588,6 +597,7 @@ struct scsi_device { ...@@ -588,6 +597,7 @@ struct scsi_device {
unsigned char current_tag; /* current tag */ unsigned char current_tag; /* current tag */
// unsigned char sync_min_period; /* Not less than this period */ // unsigned char sync_min_period; /* Not less than this period */
// unsigned char sync_max_offset; /* Not greater than this offset */ // unsigned char sync_max_offset; /* Not greater than this offset */
struct scsi_target *sdev_target; /* used only for single_lun */
unsigned online:1; unsigned online:1;
unsigned writeable:1; unsigned writeable:1;
......
...@@ -327,46 +327,36 @@ void scsi_setup_cmd_retry(struct scsi_cmnd *cmd) ...@@ -327,46 +327,36 @@ void scsi_setup_cmd_retry(struct scsi_cmnd *cmd)
} }
/* /*
* Called for single_lun devices. The target associated with current_sdev can * Called for single_lun devices on IO completion. Clear starget_busy, and
* only handle one active command at a time. Scan through all of the luns * Call __blk_run_queue for all the scsi_devices on the target - including
* on the same target as current_sdev, return 1 if any are active. * current_sdev first.
*/
static int scsi_single_lun_check(struct scsi_device *current_sdev)
{
struct scsi_device *sdev;
list_for_each_entry(sdev, &current_sdev->same_target_siblings,
same_target_siblings)
if (sdev->device_busy)
return 1;
return 0;
}
/*
* Called for single_lun devices on IO completion. If no requests
* outstanding for current_sdev, call __blk_run_queue for the next
* scsi_device on the same target that has requests.
* *
* Called with *no* scsi locks held. * Called with *no* scsi locks held.
*/ */
static void scsi_single_lun_run(struct scsi_device *current_sdev, static void scsi_single_lun_run(struct scsi_device *current_sdev)
struct request_queue *q)
{ {
struct scsi_device *sdev; struct scsi_device *sdev;
struct Scsi_Host *shost; unsigned int flags, flags2;
shost = current_sdev->host; spin_lock_irqsave(current_sdev->request_queue->queue_lock, flags2);
if (blk_queue_empty(q) && current_sdev->device_busy == 0 && spin_lock_irqsave(current_sdev->host->host_lock, flags);
!shost->host_blocked && !shost->host_self_blocked && WARN_ON(!current_sdev->sdev_target->starget_busy);
!((shost->can_queue > 0) && if (current_sdev->device_busy == 0)
(shost->host_busy >= shost->can_queue))) current_sdev->sdev_target->starget_busy = 0;
list_for_each_entry(sdev, &current_sdev->same_target_siblings, spin_unlock_irqrestore(current_sdev->host->host_lock, flags);
same_target_siblings)
if (!sdev->device_blocked && /*
!blk_queue_empty(sdev->request_queue)) { * Call __blk_run_queue for all LUNs on the target, starting with
__blk_run_queue(sdev->request_queue); * current_sdev.
break; */
} __blk_run_queue(current_sdev->request_queue);
spin_unlock_irqrestore(current_sdev->request_queue->queue_lock, flags2);
list_for_each_entry(sdev, &current_sdev->same_target_siblings,
same_target_siblings) {
spin_lock_irqsave(sdev->request_queue->queue_lock, flags2);
__blk_run_queue(sdev->request_queue);
spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags2);
}
} }
/* /*
...@@ -438,7 +428,7 @@ void scsi_queue_next_request(request_queue_t *q, struct scsi_cmnd *cmd) ...@@ -438,7 +428,7 @@ void scsi_queue_next_request(request_queue_t *q, struct scsi_cmnd *cmd)
sdev = q->queuedata; sdev = q->queuedata;
if (sdev->single_lun) if (sdev->single_lun)
scsi_single_lun_run(sdev, q); scsi_single_lun_run(sdev);
shost = sdev->host; shost = sdev->host;
spin_lock_irqsave(shost->host_lock, flags); spin_lock_irqsave(shost->host_lock, flags);
...@@ -1166,7 +1156,8 @@ static void scsi_request_fn(request_queue_t *q) ...@@ -1166,7 +1156,8 @@ static void scsi_request_fn(request_queue_t *q)
if (scsi_check_shost(q, shost, sdev)) if (scsi_check_shost(q, shost, sdev))
goto after_host_lock; goto after_host_lock;
if (sdev->single_lun && scsi_single_lun_check(sdev)) if (sdev->single_lun && !sdev->device_busy &&
sdev->sdev_target->starget_busy)
goto after_host_lock; goto after_host_lock;
/* /*
...@@ -1204,6 +1195,9 @@ static void scsi_request_fn(request_queue_t *q) ...@@ -1204,6 +1195,9 @@ static void scsi_request_fn(request_queue_t *q)
if (!(blk_queue_tagged(q) && (blk_queue_start_tag(q, req) == 0))) if (!(blk_queue_tagged(q) && (blk_queue_start_tag(q, req) == 0)))
blkdev_dequeue_request(req); blkdev_dequeue_request(req);
if (sdev->single_lun)
sdev->sdev_target->starget_busy = 1;
shost->host_busy++; shost->host_busy++;
spin_unlock_irqrestore(shost->host_lock, flags); spin_unlock_irqrestore(shost->host_lock, flags);
......
...@@ -478,6 +478,8 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost, ...@@ -478,6 +478,8 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost,
**/ **/
static void scsi_free_sdev(struct scsi_device *sdev) static void scsi_free_sdev(struct scsi_device *sdev)
{ {
unsigned int flags;
list_del(&sdev->siblings); list_del(&sdev->siblings);
list_del(&sdev->same_target_siblings); list_del(&sdev->same_target_siblings);
...@@ -487,6 +489,14 @@ static void scsi_free_sdev(struct scsi_device *sdev) ...@@ -487,6 +489,14 @@ static void scsi_free_sdev(struct scsi_device *sdev)
sdev->host->hostt->slave_destroy(sdev); sdev->host->hostt->slave_destroy(sdev);
if (sdev->inquiry) if (sdev->inquiry)
kfree(sdev->inquiry); kfree(sdev->inquiry);
if (sdev->single_lun) {
spin_lock_irqsave(sdev->host->host_lock, flags);
sdev->sdev_target->starget_refcnt--;
if (sdev->sdev_target->starget_refcnt == 0)
kfree(sdev->sdev_target);
spin_unlock_irqrestore(sdev->host->host_lock, flags);
}
kfree(sdev); kfree(sdev);
} }
...@@ -1122,6 +1132,10 @@ static void scsi_probe_lun(Scsi_Request *sreq, char *inq_result, ...@@ -1122,6 +1132,10 @@ static void scsi_probe_lun(Scsi_Request *sreq, char *inq_result,
static int scsi_add_lun(Scsi_Device *sdev, Scsi_Request *sreq, static int scsi_add_lun(Scsi_Device *sdev, Scsi_Request *sreq,
char *inq_result, int *bflags) char *inq_result, int *bflags)
{ {
struct scsi_device *sdev_sibling;
struct scsi_target *starget;
unsigned int flags;
/* /*
* XXX do not save the inquiry, since it can change underneath us, * XXX do not save the inquiry, since it can change underneath us,
* save just vendor/model/rev. * save just vendor/model/rev.
...@@ -1243,10 +1257,38 @@ static int scsi_add_lun(Scsi_Device *sdev, Scsi_Request *sreq, ...@@ -1243,10 +1257,38 @@ static int scsi_add_lun(Scsi_Device *sdev, Scsi_Request *sreq,
/* /*
* If we need to allow I/O to only one of the luns attached to * If we need to allow I/O to only one of the luns attached to
* this target id at a time, then we set this flag. * this target id at a time set single_lun, and allocate or modify
* sdev_target.
*/ */
if (*bflags & BLIST_SINGLELUN) if (*bflags & BLIST_SINGLELUN) {
sdev->single_lun = 1; sdev->single_lun = 1;
spin_lock_irqsave(sdev->host->host_lock, flags);
starget = NULL;
/*
* Search for an existing target for this sdev.
*/
list_for_each_entry(sdev_sibling, &sdev->same_target_siblings,
same_target_siblings) {
if (sdev_sibling->sdev_target != NULL) {
starget = sdev_sibling->sdev_target;
break;
}
}
if (!starget) {
starget = kmalloc(sizeof(*starget), GFP_KERNEL);
if (!starget) {
printk(ALLOC_FAILURE_MSG, __FUNCTION__);
spin_unlock_irqrestore(sdev->host->host_lock,
flags);
return SCSI_SCAN_NO_RESPONSE;
}
starget->starget_refcnt = 0;
starget->starget_busy = 0;
}
starget->starget_refcnt++;
sdev->sdev_target = starget;
spin_unlock_irqrestore(sdev->host->host_lock, flags);
}
/* if the device needs this changing, it may do so in the detect /* if the device needs this changing, it may do so in the detect
* function */ * function */
......
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