Add target queueing limit helpers to scsi-ml
Subsystems (4)
These two patches are for RFC, but could go into scsi-misc for 2.6.26 if they are ok off the bat.
They add the ability to limit queueing at the target level. This will be needed for bnx2i, but also may be useful to limit transport level commands when using bsg.
PATCH 2/2 iscsi: user per target can_queue
In reply to [email protected]From: Mike Christie <[email protected]>
This hooks iscsi_tcp and libiscsi into the target->can_queue code and it has libiscsi use SCSI_MLQUEUE_TARGET_BUSY.
--- drivers/infiniband/ulp/iser/iscsi_iser.c | 1 + drivers/scsi/iscsi_tcp.c | 1 + drivers/scsi/libiscsi.c | 19 +++++++++++++++++-- include/scsi/libiscsi.h | 1 + 4 files changed, 20 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/iser/iscsi_iser.c +1 -0
@@ -552,6 +552,7 @@ static struct scsi_host_template iscsi_iser_sht = { .sg_tablesize = ISCSI_ISER_SG_TABLESIZE, .max_sectors = 1024, .cmd_per_lun = ISCSI_MAX_CMD_PER_LUN, + .slave_alloc = iscsi_slave_alloc, .eh_abort_handler = iscsi_eh_abort, .eh_device_reset_handler= iscsi_eh_device_reset, .eh_host_reset_handler = iscsi_eh_host_reset,
drivers/scsi/iscsi_tcp.c +1 -0
@@ -1936,6 +1936,7 @@ static struct scsi_host_template iscsi_sht = { .eh_device_reset_handler= iscsi_eh_device_reset, .eh_host_reset_handler = iscsi_eh_host_reset, .use_clustering = DISABLE_CLUSTERING, + .slave_alloc = iscsi_slave_alloc, .slave_configure = iscsi_tcp_slave_configure, .proc_name = "iscsi_tcp", .this_id = -1,
drivers/scsi/libiscsi.c +17 -2
@@ -1097,7 +1097,7 @@ reject:spin_unlock (&session->lock);debug_scsi ("cmd 0x%x rejected (%d)\n" , sc->cmnd[0 ], reason);spin_lock (host->host_lock); -return SCSI_MLQUEUE_HOST_BUSY ; +return SCSI_MLQUEUE_TARGET_BUSY ; fault:spin_unlock (&session->lock);
@@ -1118,6 +1118,21 @@ int iscsi_change_queue_depth(struct scsi_device *sdev, int depth) }EXPORT_SYMBOL_GPL (iscsi_change_queue_depth); +int iscsi_slave_alloc (struct scsi_device *sdev) +{ +struct scsi_target *starget =scsi_target (sdev); +struct iscsi_cls_session *cls_session =starget_to_session (starget); +struct iscsi_session *session; + +if (!cls_session ||iscsi_session_chkready (cls_session)) +return -ENXIO ; + + session =class_to_transport_session (cls_session); + starget->can_queue = session->cmds_max; +return 0 ; +} +EXPORT_SYMBOL_GPL (iscsi_slave_alloc); +void iscsi_session_recovery_timedout (struct iscsi_cls_session *cls_session) {struct iscsi_session *session =class_to_transport_session (cls_session);
@@ -1724,7 +1739,7 @@ iscsi_session_setup(struct iscsi_transport *iscsit,return NULL ;/* the iscsi layer takes one task for reserve */ - shost->can_queue = cmds_max -1 ; + shost->can_queue = cmds_max; shost->cmd_per_lun = qdepth; shost->max_id =1 ; shost->max_channel =0 ;
include/scsi/libiscsi.h +1 -0
@@ -308,6 +308,7 @@ struct iscsi_session {/* * scsi host template */ +extern int iscsi_slave_alloc (struct scsi_device *sdev);extern int iscsi_change_queue_depth (struct scsi_device *sdev,int depth);extern int iscsi_eh_abort (struct scsi_cmnd *sc);extern int iscsi_eh_host_reset (struct scsi_cmnd *sc);
Signature · 1 line
1.5.2.1
PATCH 1/2 scsi-ml: Add helper code so transport classes can control queueing
In reply to [email protected]From: Mike Christie <[email protected]>
SCSI-ml manages the queueing limits for the device and host, but does not do so at the target level. Currently this is not needed and is probably more for the transport code to handle. However, for bnx2i we will need to be able to limit queueing at this level. bnx2i will hook into libiscsi, but will allocate a scsi host per netdevice/hba, so unlike pure software iscsi/iser which is allocating a host per session, it cannot set the scsi_host->can_queue and return SCSI_MLQUEUE_HOST_BUSY to reflect queueing limits on the transport.
This patch adds some basic helper code for scsi-ml, that the transport classes can utilize.
The patch adds code similar to the exisiting SCSI_ML_*BUSY handlers. You can now return SCSI_MLQUEUE_TARGET_BUSY when we hit
a transport level queueing issue like the hw cannot allocate some resource at the iscsi session/connection level or the target has temporarily closed or shrunk the queueing window.
The iscsi class/driver can also set a scsi_target->can_queue value which reflects the max commands the driver/class can support. For iscsi this reflects the number of commands we can support for each session due to session/connection hw limits, driver limits, and to also reflect the session/targets's queueing window.
This patch was made over the last patchset I sent. It is not for mergeing into 2.6.25 or scsi-misc yet. I just want to put it out here, and make sure it is ok and get feedback on what else I might need to do for this patch before broadcom and I push the bnx2i driver.
--- drivers/scsi/scsi.c | 11 +++++-- drivers/scsi/scsi_lib.c | 70 +++++++++++++++++++++++++++++++++++++------ drivers/scsi/scsi_scan.c | 1 + include/scsi/scsi.h | 1 + include/scsi/scsi_device.h | 10 ++++++ 5 files changed, 80 insertions(+), 13 deletions(-)
drivers/scsi/scsi.c +8 -3
@@ -628,9 +628,12 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)if (rtn) {if (scsi_delete_timer (cmd)) {atomic_inc (&cmd->device->iodone_cnt); -scsi_queue_insert (cmd, - (rtn ==SCSI_MLQUEUE_DEVICE_BUSY ) ? - rtn :SCSI_MLQUEUE_HOST_BUSY ); + +if (rtn !=SCSI_MLQUEUE_DEVICE_BUSY && + rtn !=SCSI_MLQUEUE_TARGET_BUSY ) + rtn =SCSI_MLQUEUE_HOST_BUSY ; + +scsi_queue_insert (cmd, rtn); }SCSI_LOG_MLQUEUE (3 ,printk ("queuecommand : request rejected\n" ));
@@ -729,6 +732,7 @@ static struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd)void scsi_finish_command (struct scsi_cmnd *cmd) {struct scsi_device *sdev = cmd->device; +struct scsi_target *starget =scsi_target (sdev);struct Scsi_Host *shost = sdev->host;struct scsi_driver *drv;unsigned int good_bytes;
@@ -744,6 +748,7 @@ void scsi_finish_command(struct scsi_cmnd *cmd)* XXX(hch): What about locking? */ shost->host_blocked =0 ; + starget->target_blocked =0 ; sdev->device_blocked =0 ;/*
drivers/scsi/scsi_lib.c +60 -10
118 lines not on this page · raw message
drivers/scsi/scsi_scan.c +1 -0
@@ -396,6 +396,7 @@ static struct scsi_target *scsi_alloc_target(struct device *parent, shost->host_no, channel, id); starget->id = id; starget->channel = channel; + starget->can_queue =0 ;INIT_LIST_HEAD (&starget->siblings);INIT_LIST_HEAD (&starget->devices); starget->state =STARGET_RUNNING ;
include/scsi/scsi.h +1 -0
@@ -367,6 +367,7 @@ struct scsi_lun {#define SCSI_MLQUEUE_HOST_BUSY 0x1055#define SCSI_MLQUEUE_DEVICE_BUSY 0x1056#define SCSI_MLQUEUE_EH_RETRY 0x1057 +#define SCSI_MLQUEUE_TARGET_BUSY 0x1058/* * Use these to separate status msg and our bytes
include/scsi/scsi_device.h +10 -0
@@ -205,6 +205,16 @@ struct scsi_target {* for the device at a time. */ unsigned int pdt_1f_for_no_lun;/* PDT = 0x1f */ /* means no lun present */ +/* commands actually active on LLD. protected by host lock. */ +unsigned int target_busy; +/* +* LLDs should set this in the slave_alloc host template callout. +* If set to zero then there is not limit. +*/ +unsigned int can_queue; +unsigned int target_blocked; +unsigned int max_target_blocked; +#define SCSI_DEFAULT_TARGET_BLOCKED 3char scsi_level;struct execute_work ew;
Signature · 1 line
1.5.2.1
Re: [PATCH 1/2] scsi-ml: Add helper code so transport classes can control queueing
Quoted 19 lines · [email protected] wrote:
(quoted diff) +18
-0+static inline int scsi_target_ready(struct scsi_device *sdev) +{ + struct scsi_target *starget = scsi_target(sdev); + + if (starget->single_lun) { + if (starget->starget_sdev_user && + starget->starget_sdev_user != sdev) + return 0; + starget->starget_sdev_user = sdev; + } + + if (starget->can_queue && starget->target_busy >= starget->can_queue) + return 0; + if (starget->target_busy == 0 && starget->target_blocked) { + /* + * unblock after target_blocked iterates to zero + */ + if (--starget->target_blocked == 0) {
Review
Quoted 10 lines
(quoted diff) +10
-0+ SCSI_LOG_MLQUEUE(3, + starget_printk(KERN_INFO, starget, + "unblocking target at zero depth\n")); + } else { + blk_plug_device(sdev->request_queue); + return 0; + } + } + if (starget->target_blocked) + return 0;
Sorry old patch. This one can starve devices here. An updated patch is attached.
drivers/scsi/scsi.c +8 -3
@@ -628,9 +628,12 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)if (rtn) {if (scsi_delete_timer (cmd)) {atomic_inc (&cmd->device->iodone_cnt); -scsi_queue_insert (cmd, - (rtn ==SCSI_MLQUEUE_DEVICE_BUSY ) ? - rtn :SCSI_MLQUEUE_HOST_BUSY ); + +if (rtn !=SCSI_MLQUEUE_DEVICE_BUSY && + rtn !=SCSI_MLQUEUE_TARGET_BUSY ) + rtn =SCSI_MLQUEUE_HOST_BUSY ; + +scsi_queue_insert (cmd, rtn); }SCSI_LOG_MLQUEUE (3 ,printk ("queuecommand : request rejected\n" ));
@@ -729,6 +732,7 @@ static struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd)void scsi_finish_command (struct scsi_cmnd *cmd) {struct scsi_device *sdev = cmd->device; +struct scsi_target *starget =scsi_target (sdev);struct Scsi_Host *shost = sdev->host;struct scsi_driver *drv;unsigned int good_bytes;
@@ -744,6 +748,7 @@ void scsi_finish_command(struct scsi_cmnd *cmd)* XXX(hch): What about locking? */ shost->host_blocked =0 ; + starget->target_blocked =0 ; sdev->device_blocked =0 ;/*
drivers/scsi/scsi_lib.c +66 -10
124 lines not on this page · raw message
drivers/scsi/scsi_scan.c +1 -0
@@ -396,6 +396,7 @@ static struct scsi_target *scsi_alloc_target(struct device *parent, shost->host_no, channel, id); starget->id = id; starget->channel = channel; + starget->can_queue =0 ;INIT_LIST_HEAD (&starget->siblings);INIT_LIST_HEAD (&starget->devices); starget->state =STARGET_RUNNING ;
include/scsi/scsi.h +1 -0
@@ -367,6 +367,7 @@ struct scsi_lun {#define SCSI_MLQUEUE_HOST_BUSY 0x1055#define SCSI_MLQUEUE_DEVICE_BUSY 0x1056#define SCSI_MLQUEUE_EH_RETRY 0x1057 +#define SCSI_MLQUEUE_TARGET_BUSY 0x1058/* * Use these to separate status msg and our bytes
include/scsi/scsi_device.h +10 -0
@@ -205,6 +205,16 @@ struct scsi_target {* for the device at a time. */ unsigned int pdt_1f_for_no_lun;/* PDT = 0x1f */ /* means no lun present */ +/* commands actually active on LLD. protected by host lock. */ +unsigned int target_busy; +/* +* LLDs should set this in the slave_alloc host template callout. +* If set to zero then there is not limit. +*/ +unsigned int can_queue; +unsigned int target_blocked; +unsigned int max_target_blocked; +#define SCSI_DEFAULT_TARGET_BLOCKED 3char scsi_level;struct execute_work ew;