Skip to content

Commit

Permalink
scsi: don't allow setting of queue_depth bigger than can_queue
Browse files Browse the repository at this point in the history
We won't ever queue more commands than the host allows.  Instead of
letting drivers either reject or ignore this case handle it in
common code.  Note that various driver use internal constant or
variables that are assigned to both shost->can_queue and checked
in ->change_queue_depth - I did remove those checks as well.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Mike Christie <michaelc@cs.wisc.edu>
Reviewed-by: Hannes Reinecke <hare@suse.de>
  • Loading branch information
Christoph Hellwig committed Nov 24, 2014
1 parent c40ecc1 commit 1e6f241
Show file tree
Hide file tree
Showing 9 changed files with 3 additions and 30 deletions.
8 changes: 1 addition & 7 deletions drivers/infiniband/ulp/srp/ib_srp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2410,14 +2410,8 @@ static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
static int
srp_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
{
struct Scsi_Host *shost = sdev->host;
int max_depth;

max_depth = shost->can_queue;
if (!sdev->tagged_supported)
max_depth = 1;
if (qdepth > max_depth)
qdepth = max_depth;
qdepth = 1;
scsi_adjust_queue_depth(sdev, qdepth);
return sdev->queue_depth;
}
Expand Down
2 changes: 0 additions & 2 deletions drivers/scsi/3w-9xxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@ static int twa_change_queue_depth(struct scsi_device *sdev, int queue_depth,
if (reason != SCSI_QDEPTH_DEFAULT)
return -EOPNOTSUPP;

if (queue_depth > TW_Q_LENGTH-2)
queue_depth = TW_Q_LENGTH-2;
scsi_adjust_queue_depth(sdev, queue_depth);
return queue_depth;
} /* End twa_change_queue_depth() */
Expand Down
2 changes: 0 additions & 2 deletions drivers/scsi/3w-sas.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ static int twl_change_queue_depth(struct scsi_device *sdev, int queue_depth,
if (reason != SCSI_QDEPTH_DEFAULT)
return -EOPNOTSUPP;

if (queue_depth > TW_Q_LENGTH-2)
queue_depth = TW_Q_LENGTH-2;
scsi_adjust_queue_depth(sdev, queue_depth);
return queue_depth;
} /* End twl_change_queue_depth() */
Expand Down
2 changes: 0 additions & 2 deletions drivers/scsi/3w-xxxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,6 @@ static int tw_change_queue_depth(struct scsi_device *sdev, int queue_depth,
if (reason != SCSI_QDEPTH_DEFAULT)
return -EOPNOTSUPP;

if (queue_depth > TW_Q_LENGTH-2)
queue_depth = TW_Q_LENGTH-2;
scsi_adjust_queue_depth(sdev, queue_depth);
return queue_depth;
} /* End tw_change_queue_depth() */
Expand Down
5 changes: 0 additions & 5 deletions drivers/scsi/hpsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -4082,11 +4082,6 @@ static int hpsa_change_queue_depth(struct scsi_device *sdev,
if (reason != SCSI_QDEPTH_DEFAULT)
return -ENOTSUPP;

if (qdepth < 1)
qdepth = 1;
else
if (qdepth > h->nr_cmds)
qdepth = h->nr_cmds;
scsi_adjust_queue_depth(sdev, qdepth);
return sdev->queue_depth;
}
Expand Down
2 changes: 0 additions & 2 deletions drivers/scsi/megaraid/megaraid_mbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,6 @@ static int megaraid_change_queue_depth(struct scsi_device *sdev, int qdepth,
if (reason != SCSI_QDEPTH_DEFAULT)
return -EOPNOTSUPP;

if (qdepth > MBOX_MAX_SCSI_CMDS)
qdepth = MBOX_MAX_SCSI_CMDS;
scsi_adjust_queue_depth(sdev, qdepth);
return sdev->queue_depth;
}
Expand Down
2 changes: 0 additions & 2 deletions drivers/scsi/megaraid/megaraid_sas_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -2597,8 +2597,6 @@ static int megasas_change_queue_depth(struct scsi_device *sdev,
if (reason != SCSI_QDEPTH_DEFAULT)
return -EOPNOTSUPP;

if (queue_depth > sdev->host->can_queue)
queue_depth = sdev->host->can_queue;
scsi_adjust_queue_depth(sdev, queue_depth);

return queue_depth;
Expand Down
2 changes: 1 addition & 1 deletion drivers/scsi/scsi_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ sdev_store_queue_depth(struct device *dev, struct device_attribute *attr,

depth = simple_strtoul(buf, NULL, 0);

if (depth < 1)
if (depth < 1 || depth > sht->can_queue)
return -EINVAL;

retval = sht->change_queue_depth(sdev, depth,
Expand Down
8 changes: 1 addition & 7 deletions drivers/scsi/vmw_pvscsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,20 +508,14 @@ static int pvscsi_change_queue_depth(struct scsi_device *sdev,
int qdepth,
int reason)
{
int max_depth;
struct Scsi_Host *shost = sdev->host;

if (reason != SCSI_QDEPTH_DEFAULT)
/*
* We support only changing default.
*/
return -EOPNOTSUPP;

max_depth = shost->can_queue;
if (!sdev->tagged_supported)
max_depth = 1;
if (qdepth > max_depth)
qdepth = max_depth;
qdepth = 1;
scsi_adjust_queue_depth(sdev, qdepth);

if (sdev->inquiry_len > 7)
Expand Down

0 comments on commit 1e6f241

Please sign in to comment.