Patchwork [5/5] scsi-disk: Support I/O status

login
register
mail settings
Submitter Luiz Capitulino
Date Aug. 3, 2011, 3:19 p.m.
Message ID <1312384765-721-6-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/108297/
State New
Headers show

Comments

Luiz Capitulino - Aug. 3, 2011, 3:19 p.m.
TODO: migration

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hw/scsi-disk.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

Patch

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index db2d5a3..e4b57a7 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -77,11 +77,17 @@  struct SCSIDiskState
     bool tray_open;
     bool tray_locked;
     SCSIDriveKind drive_kind;
+    BlockDevIOStatus iostatus;
 };
 
 static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type);
 static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf);
 
+static void scsi_update_iostatus(SCSIDiskState *s, int error)
+{
+    s->iostatus = bdrv_iostatus_from_error(error);
+}
+
 static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag,
                                      uint32_t lun, void *hba_private)
 {
@@ -139,10 +145,12 @@  static void scsi_cancel_io(SCSIRequest *req)
 static void scsi_read_complete(void * opaque, int ret)
 {
     SCSIDiskReq *r = (SCSIDiskReq *)opaque;
+    SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
     int n;
 
     r->req.aiocb = NULL;
 
+    scsi_update_iostatus(s, ret);
     if (ret) {
         if (scsi_handle_rw_error(r, -ret, SCSI_REQ_STATUS_RETRY_READ)) {
             return;
@@ -247,11 +255,13 @@  static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type)
 static void scsi_write_complete(void * opaque, int ret)
 {
     SCSIDiskReq *r = (SCSIDiskReq *)opaque;
+    SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
     uint32_t len;
     uint32_t n;
 
     r->req.aiocb = NULL;
 
+    scsi_update_iostatus(s, ret);
     if (ret) {
         if (scsi_handle_rw_error(r, -ret, SCSI_REQ_STATUS_RETRY_WRITE)) {
             return;
@@ -940,6 +950,7 @@  static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
 	break;
     case SYNCHRONIZE_CACHE:
         ret = bdrv_flush(s->bs);
+        scsi_update_iostatus(s, ret);
         if (ret < 0) {
             if (scsi_handle_rw_error(r, -ret, SCSI_REQ_STATUS_RETRY_FLUSH)) {
                 return -1;
@@ -1298,10 +1309,16 @@  static bool scsi_cd_is_medium_locked(void *opaque)
     return ((SCSIDiskState *)opaque)->tray_locked;
 }
 
+static BlockDevIOStatus scsi_iostatus(void *opaque)
+{
+    return ((SCSIDiskState *)opaque)->iostatus;
+}
+
 static const BlockDevOps scsi_cd_block_ops = {
     .change_media_cb = scsi_cd_change_media_cb,
     .is_medium_ejected = scsi_cd_is_medium_ejected,
     .is_medium_locked = scsi_cd_is_medium_locked,
+    .get_iostatus = scsi_iostatus,
 };
 
 static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind kind)
@@ -1347,6 +1364,7 @@  static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind kind)
     s->cluster_size = s->qdev.blocksize / 512;
     bdrv_set_buffer_alignment(s->bs, s->qdev.blocksize);
 
+    s->iostatus = BDRV_IOS_INVAL;
     s->qdev.type = TYPE_DISK;
     qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
     if (kind == SCSI_CD) {