Patchwork [1/7] scsi-generic: Handle queue full

login
register
mail settings
Submitter Hannes Reinecke
Date June 15, 2010, 3:16 p.m.
Message ID <20100615151604.E13BB2B960@ochil.suse.de>
Download mbox | patch
Permalink /patch/55728/
State New
Headers show

Comments

Hannes Reinecke - June 15, 2010, 3:16 p.m.
The sg driver currently has a hardcoded limit of commands it
can handle simultaneously. When this limit is reached the
driver will return -EDOM. So we need to capture this to
enable proper return values here.
And we shouldn't forget we're using linux-style status codes,
which are shift by one.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 hw/scsi-generic.c |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)
Nicholas A. Bellinger - June 16, 2010, 8:57 a.m.
On Tue, 2010-06-15 at 17:16 +0200, Hannes Reinecke wrote:
> The sg driver currently has a hardcoded limit of commands it
> can handle simultaneously. When this limit is reached the
> driver will return -EDOM. So we need to capture this to
> enable proper return values here.
> And we shouldn't forget we're using linux-style status codes,
> which are shift by one.
> 
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
>  hw/scsi-generic.c |   20 +++++++++++++-------
>  1 files changed, 13 insertions(+), 7 deletions(-)
> 

Commited, thanks Hannes!

--nab

> diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c
> index 6c58742..af76826 100644
> --- a/hw/scsi-generic.c
> +++ b/hw/scsi-generic.c
> @@ -96,13 +96,19 @@ static void scsi_command_complete(void *opaque, int ret)
>          s->senselen = r->io_header.sb_len_wr;
>  
>      if (ret != 0) {
> -        scsi_req_print(&r->req);
> -        fprintf(stderr, "%s: ret %d (%s)\n", __FUNCTION__,
> -                ret, strerror(-ret));
> -        s->senselen = scsi_build_sense(SENSE_CODE(INVALID_FIELD),
> -				       s->sensebuf, SCSI_SENSE_BUF_SIZE, 0);
> -        s->driver_status = SG_ERR_DRIVER_SENSE;
> -        r->req.status = CHECK_CONDITION;
> +	if (ret == -EDOM) {
> +	    /* sg driver uses EDOM to signal queue busy */
> +	    fprintf(stderr, "%s: sg queue busy\n", __FUNCTION__);
> +	    r->req.status = QUEUE_FULL << 1;
> +	} else {
> +	    scsi_req_print(&r->req);
> +	    fprintf(stderr, "%s: ret %d (%s)\n", __FUNCTION__,
> +		    ret, strerror(-ret));
> +	    s->senselen = scsi_build_sense(SENSE_CODE(INVALID_FIELD),
> +					   s->sensebuf, SCSI_SENSE_BUF_SIZE, 0);
> +	    s->driver_status = SG_ERR_DRIVER_SENSE;
> +	    r->req.status = CHECK_CONDITION << 1;
> +	}
>      } else {
>          if (s->driver_status & SG_ERR_DRIVER_TIMEOUT) {
>              scsi_req_print(&r->req);

Patch

diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c
index 6c58742..af76826 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi-generic.c
@@ -96,13 +96,19 @@  static void scsi_command_complete(void *opaque, int ret)
         s->senselen = r->io_header.sb_len_wr;
 
     if (ret != 0) {
-        scsi_req_print(&r->req);
-        fprintf(stderr, "%s: ret %d (%s)\n", __FUNCTION__,
-                ret, strerror(-ret));
-        s->senselen = scsi_build_sense(SENSE_CODE(INVALID_FIELD),
-				       s->sensebuf, SCSI_SENSE_BUF_SIZE, 0);
-        s->driver_status = SG_ERR_DRIVER_SENSE;
-        r->req.status = CHECK_CONDITION;
+	if (ret == -EDOM) {
+	    /* sg driver uses EDOM to signal queue busy */
+	    fprintf(stderr, "%s: sg queue busy\n", __FUNCTION__);
+	    r->req.status = QUEUE_FULL << 1;
+	} else {
+	    scsi_req_print(&r->req);
+	    fprintf(stderr, "%s: ret %d (%s)\n", __FUNCTION__,
+		    ret, strerror(-ret));
+	    s->senselen = scsi_build_sense(SENSE_CODE(INVALID_FIELD),
+					   s->sensebuf, SCSI_SENSE_BUF_SIZE, 0);
+	    s->driver_status = SG_ERR_DRIVER_SENSE;
+	    r->req.status = CHECK_CONDITION << 1;
+	}
     } else {
         if (s->driver_status & SG_ERR_DRIVER_TIMEOUT) {
             scsi_req_print(&r->req);