[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 17/24] scsi: Implement 'get_sense' callback
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH v4 17/24] scsi: Implement 'get_sense' callback |
Date: |
Mon, 23 May 2011 18:09:02 +0200 |
From: Hannes Reinecke <address@hidden>
The get_sense callback copies existing sense information into
the provided buffer. This is required if sense information
should be transferred together with the command response.
Signed-off-by: Hannes Reinecke <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
Reviewed-by: Christoph Hellwig <address@hidden>
---
hw/scsi-bus.c | 9 +++++++++
hw/scsi-disk.c | 9 +++++++++
hw/scsi-generic.c | 18 ++++++++++++++++++
hw/scsi.h | 2 ++
hw/spapr_vscsi.c | 10 +++++++++-
5 files changed, 47 insertions(+), 1 deletions(-)
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index c6b7ee5..d4fd61d 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -156,6 +156,15 @@ uint8_t *scsi_req_get_buf(SCSIRequest *req)
return req->dev->info->get_buf(req);
}
+int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len)
+{
+ if (req->dev->info->get_sense) {
+ return req->dev->info->get_sense(req, buf, len);
+ } else {
+ return 0;
+ }
+}
+
int32_t scsi_req_enqueue(SCSIRequest *req, uint8_t *buf)
{
assert(!req->enqueued);
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 083097e..b9c8fff 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -337,6 +337,14 @@ static uint8_t *scsi_get_buf(SCSIRequest *req)
return (uint8_t *)r->iov.iov_base;
}
+/* Copy sense information into the provided buffer */
+static int scsi_get_sense(SCSIRequest *req, uint8_t *outbuf, int len)
+{
+ SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
+
+ return scsi_build_sense(s->sense, outbuf, len, len > 14);
+}
+
static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)
{
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
@@ -1224,6 +1232,7 @@ static SCSIDeviceInfo scsi_disk_info = {
.write_data = scsi_write_data,
.cancel_io = scsi_cancel_io,
.get_buf = scsi_get_buf,
+ .get_sense = scsi_get_sense,
.qdev.props = (Property[]) {
DEFINE_BLOCK_PROPERTIES(SCSIDiskState, qdev.conf),
DEFINE_PROP_STRING("ver", SCSIDiskState, version),
diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c
index 4cf8e3b..a131431 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi-generic.c
@@ -79,6 +79,23 @@ static void scsi_clear_sense(SCSIGenericState *s)
s->driver_status = 0;
}
+static int scsi_get_sense(SCSIRequest *req, uint8_t *outbuf, int len)
+{
+ SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, req->dev);
+ int size = SCSI_SENSE_BUF_SIZE;
+
+ if (!(s->driver_status & SG_ERR_DRIVER_SENSE)) {
+ size = scsi_build_sense(SENSE_CODE(NO_SENSE), s->sensebuf,
+ SCSI_SENSE_BUF_SIZE, 0);
+ }
+ if (size > len) {
+ size = len;
+ }
+ memcpy(outbuf, s->sensebuf, size);
+
+ return size;
+}
+
static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun)
{
SCSIRequest *req;
@@ -532,6 +549,7 @@ static SCSIDeviceInfo scsi_generic_info = {
.write_data = scsi_write_data,
.cancel_io = scsi_cancel_io,
.get_buf = scsi_get_buf,
+ .get_sense = scsi_get_sense,
.qdev.props = (Property[]) {
DEFINE_BLOCK_PROPERTIES(SCSIGenericState, qdev.conf),
DEFINE_PROP_END_OF_LIST(),
diff --git a/hw/scsi.h b/hw/scsi.h
index a4bdede..53efa8e 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -80,6 +80,7 @@ struct SCSIDeviceInfo {
int (*write_data)(SCSIRequest *req);
void (*cancel_io)(SCSIRequest *req);
uint8_t *(*get_buf)(SCSIRequest *req);
+ int (*get_sense)(SCSIRequest *req, uint8_t *buf, int len);
};
struct SCSIBusOps {
@@ -155,6 +156,7 @@ void scsi_req_continue(SCSIRequest *req);
void scsi_req_data(SCSIRequest *req, int len);
void scsi_req_complete(SCSIRequest *req);
uint8_t *scsi_req_get_buf(SCSIRequest *req);
+int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len);
void scsi_req_abort(SCSIRequest *req, int status);
void scsi_req_cancel(SCSIRequest *req);
void scsi_device_purge_requests(SCSIDevice *sdev);
diff --git a/hw/spapr_vscsi.c b/hw/spapr_vscsi.c
index 29ac8ef..f0e08e3 100644
--- a/hw/spapr_vscsi.c
+++ b/hw/spapr_vscsi.c
@@ -450,6 +450,15 @@ static void vscsi_send_request_sense(VSCSIState *s,
vscsi_req *req)
uint8_t *cdb = req->iu.srp.cmd.cdb;
int n;
+ n = scsi_req_get_sense(req->sreq, req->sense, sizeof(req->sense));
+ if (n) {
+ req->senselen = n;
+ vscsi_send_rsp(s, req, CHECK_CONDITION, 0, 0);
+ vscsi_put_req(s, req);
+ return;
+ }
+
+ dprintf("VSCSI: Got CHECK_CONDITION, requesting sense...\n");
cdb[0] = 3;
cdb[1] = 0;
cdb[2] = 0;
@@ -522,7 +531,6 @@ static void vscsi_command_complete(SCSIRequest *sreq, int
reason, uint32_t arg)
}
vscsi_send_rsp(s, req, 0, res_in, res_out);
} else if (arg == CHECK_CONDITION) {
- dprintf("VSCSI: Got CHECK_CONDITION, requesting sense...\n");
vscsi_send_request_sense(s, req);
return;
} else {
--
1.7.4.4
- [Qemu-devel] [PATCH v4 08/24] scsi: commonize purging requests, (continued)
- [Qemu-devel] [PATCH v4 08/24] scsi: commonize purging requests, Paolo Bonzini, 2011/05/23
- [Qemu-devel] [PATCH v4 07/24] scsi: Use 'SCSIRequest' directly, Paolo Bonzini, 2011/05/23
- [Qemu-devel] [PATCH v4 09/24] scsi: introduce scsi_req_abort, Paolo Bonzini, 2011/05/23
- [Qemu-devel] [PATCH v4 10/24] scsi: introduce scsi_req_cancel, Paolo Bonzini, 2011/05/23
- [Qemu-devel] [PATCH v4 11/24] scsi: use scsi_req_complete, Paolo Bonzini, 2011/05/23
- [Qemu-devel] [PATCH v4 12/24] scsi: Update sense code handling, Paolo Bonzini, 2011/05/23
- [Qemu-devel] [PATCH v4 14/24] scsi: introduce scsi_req_new, Paolo Bonzini, 2011/05/23
- [Qemu-devel] [PATCH v4 13/24] scsi: do not call send_command directly, Paolo Bonzini, 2011/05/23
- [Qemu-devel] [PATCH v4 15/24] scsi: introduce scsi_req_continue, Paolo Bonzini, 2011/05/23
- [Qemu-devel] [PATCH v4 16/24] scsi: introduce scsi_req_get_buf, Paolo Bonzini, 2011/05/23
- [Qemu-devel] [PATCH v4 17/24] scsi: Implement 'get_sense' callback,
Paolo Bonzini <=
- [Qemu-devel] [PATCH v4 18/24] scsi-disk: add data direction checking, Paolo Bonzini, 2011/05/23
- [Qemu-devel] [PATCH v4 19/24] scsi: make write_data return void, Paolo Bonzini, 2011/05/23
- [Qemu-devel] [PATCH v4 20/24] scsi-generic: Handle queue full, Paolo Bonzini, 2011/05/23
- [Qemu-devel] [PATCH v4 21/24] esp: rename sense to status, Paolo Bonzini, 2011/05/23
- [Qemu-devel] [PATCH v4 22/24] scsi: split command_complete callback in two, Paolo Bonzini, 2011/05/23
- [Qemu-devel] [PATCH v4 23/24] scsi: rename arguments to the new callbacks, Paolo Bonzini, 2011/05/23
- [Qemu-devel] [PATCH v4 24/24] scsi: ignore LUN field in the CDB, Paolo Bonzini, 2011/05/23