From: Marcelo Tosatti <mtosatti@redhat.com>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>,
Paul Brook <paul@codesourcery.com>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] [patch 1/3] Fix scsi-disk sense-key/status confusion
Date: Wed, 02 Apr 2008 15:16:00 -0300 [thread overview]
Message-ID: <20080402182831.004674679@localhost.localdomain> (raw)
In-Reply-To: 20080402181559.286859712@localhost.localdomain
[-- Attachment #1: scsi-status-code --]
[-- Type: text/plain, Size: 5190 bytes --]
The scsi-disk implementation sends out sense key information as
status code.
The sense key should be reported in the sense buffer, or later upon
REQUEST SENSE command.
Index: kvm-userspace.io/qemu/hw/scsi-disk.c
===================================================================
--- kvm-userspace.io.orig/qemu/hw/scsi-disk.c
+++ kvm-userspace.io/qemu/hw/scsi-disk.c
@@ -34,6 +34,18 @@ do { fprintf(stderr, "scsi-disk: " fmt ,
#define SENSE_HARDWARE_ERROR 4
#define SENSE_ILLEGAL_REQUEST 5
+#define SCSI_OK 0
+#define SCSI_CHECK_COND 0x2
+#define SCSI_COND_MET 0x4
+#define SCSI_BUSY 0x8
+#define SCSI_INTERMEDIATE 0x10
+#define SCSI_INTER_MET 0x14
+#define SCSI_RES_CONFLICT 0x18
+#define SCSI_CMD_TERMINATED 0x22
+#define SCSI_QUEUE_FULL 0x28
+#define SCSI_ACA_ACTIVE 0x30
+#define SCSI_TASK_ABORTED 0x40
+
#define SCSI_DMA_BUF_SIZE 65536
typedef struct SCSIRequest {
@@ -124,7 +136,7 @@ static SCSIRequest *scsi_find_request(SC
}
/* Helper function for command completion. */
-static void scsi_command_complete(SCSIRequest *r, int sense)
+static void scsi_command_complete(SCSIRequest *r, int status, int sense)
{
SCSIDeviceState *s = r->dev;
uint32_t tag;
@@ -132,7 +144,7 @@ static void scsi_command_complete(SCSIRe
s->sense = sense;
tag = r->tag;
scsi_remove_request(r);
- s->completion(s->opaque, SCSI_REASON_DONE, tag, sense);
+ s->completion(s->opaque, SCSI_REASON_DONE, tag, status);
}
/* Cancel a pending data transfer. */
@@ -157,7 +169,7 @@ static void scsi_read_complete(void * op
if (ret) {
DPRINTF("IO error\n");
- scsi_command_complete(r, SENSE_HARDWARE_ERROR);
+ scsi_command_complete(r, SCSI_CHECK_COND, SENSE_HARDWARE_ERROR);
return;
}
DPRINTF("Data ready tag=0x%x len=%d\n", r->tag, r->buf_len);
@@ -175,8 +187,7 @@ static void scsi_read_data(SCSIDevice *d
r = scsi_find_request(s, tag);
if (!r) {
BADF("Bad read tag 0x%x\n", tag);
- /* ??? This is the wrong error. */
- scsi_command_complete(r, SENSE_HARDWARE_ERROR);
+ scsi_command_complete(r, SCSI_CHECK_COND, SENSE_HARDWARE_ERROR);
return;
}
if (r->sector_count == (uint32_t)-1) {
@@ -187,7 +198,7 @@ static void scsi_read_data(SCSIDevice *d
}
DPRINTF("Read sector_count=%d\n", r->sector_count);
if (r->sector_count == 0) {
- scsi_command_complete(r, SENSE_NO_SENSE);
+ scsi_command_complete(r, SCSI_OK, SENSE_NO_SENSE);
return;
}
@@ -199,7 +210,7 @@ static void scsi_read_data(SCSIDevice *d
r->aiocb = bdrv_aio_read(s->bdrv, r->sector, r->dma_buf, n,
scsi_read_complete, r);
if (r->aiocb == NULL)
- scsi_command_complete(r, SENSE_HARDWARE_ERROR);
+ scsi_command_complete(r, SCSI_CHECK_COND, SENSE_HARDWARE_ERROR);
r->sector += n;
r->sector_count -= n;
}
@@ -217,7 +228,7 @@ static void scsi_write_complete(void * o
r->aiocb = NULL;
if (r->sector_count == 0) {
- scsi_command_complete(r, SENSE_NO_SENSE);
+ scsi_command_complete(r, SCSI_OK, SENSE_NO_SENSE);
} else {
len = r->sector_count * 512;
if (len > SCSI_DMA_BUF_SIZE) {
@@ -241,7 +252,7 @@ static int scsi_write_data(SCSIDevice *d
r = scsi_find_request(s, tag);
if (!r) {
BADF("Bad write tag 0x%x\n", tag);
- scsi_command_complete(r, SENSE_HARDWARE_ERROR);
+ scsi_command_complete(r, SCSI_CHECK_COND, SENSE_HARDWARE_ERROR);
return 1;
}
if (r->aiocb)
@@ -251,7 +262,7 @@ static int scsi_write_data(SCSIDevice *d
r->aiocb = bdrv_aio_write(s->bdrv, r->sector, r->dma_buf, n,
scsi_write_complete, r);
if (r->aiocb == NULL)
- scsi_command_complete(r, SENSE_HARDWARE_ERROR);
+ scsi_command_complete(r, SCSI_CHECK_COND, SENSE_HARDWARE_ERROR);
r->sector += n;
r->sector_count -= n;
} else {
@@ -602,7 +613,7 @@ static int32_t scsi_send_command(SCSIDev
outbuf[7] = 0;
r->buf_len = 8;
} else {
- scsi_command_complete(r, SENSE_NOT_READY);
+ scsi_command_complete(r, SCSI_CHECK_COND, SENSE_NOT_READY);
return 0;
}
break;
@@ -624,7 +635,7 @@ static int32_t scsi_send_command(SCSIDev
ret = bdrv_flush(s->bdrv);
if (ret) {
DPRINTF("IO error on bdrv_flush\n");
- scsi_command_complete(r, SENSE_HARDWARE_ERROR);
+ scsi_command_complete(r, SCSI_CHECK_COND, SENSE_HARDWARE_ERROR);
return 0;
}
break;
@@ -694,11 +705,11 @@ static int32_t scsi_send_command(SCSIDev
default:
DPRINTF("Unknown SCSI command (%2.2x)\n", buf[0]);
fail:
- scsi_command_complete(r, SENSE_ILLEGAL_REQUEST);
+ scsi_command_complete(r, SCSI_CHECK_COND, SENSE_ILLEGAL_REQUEST);
return 0;
}
if (r->sector_count == 0 && r->buf_len == 0) {
- scsi_command_complete(r, SENSE_NO_SENSE);
+ scsi_command_complete(r, SCSI_OK, SENSE_NO_SENSE);
}
len = r->sector_count * 512 + r->buf_len;
if (is_write) {
--
next prev parent reply other threads:[~2008-04-02 18:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-02 18:15 [Qemu-devel] [patch 0/3] properly report SCSI status codes Marcelo Tosatti
2008-04-02 18:16 ` Marcelo Tosatti [this message]
2008-04-02 18:16 ` [Qemu-devel] [patch 2/3] scsi-disk aio_flush Marcelo Tosatti
2008-04-02 18:16 ` [Qemu-devel] [patch 3/3] LSI rename sense variable Marcelo Tosatti
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080402182831.004674679@localhost.localdomain \
--to=mtosatti@redhat.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=paul@codesourcery.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).