Patchwork [4/5] ide: Support I/O status

login
register
mail settings
Submitter Luiz Capitulino
Date Aug. 3, 2011, 3:19 p.m.
Message ID <1312384765-721-5-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/108293/
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/ide/core.c     |   16 ++++++++++++++++
 hw/ide/internal.h |    2 ++
 2 files changed, 18 insertions(+), 0 deletions(-)

Patch

diff --git a/hw/ide/core.c b/hw/ide/core.c
index ffb6500..3f075a1 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -58,6 +58,11 @@  static const int smart_attributes[][12] = {
 static int ide_handle_rw_error(IDEState *s, int error, int op);
 static void ide_dummy_transfer_stop(IDEState *s);
 
+static void ide_update_iostatus(IDEState *s, int error)
+{
+    s->iostatus = bdrv_iostatus_from_error(error);
+}
+
 static void padstr(char *str, const char *src, int len)
 {
     int i, v;
@@ -474,6 +479,7 @@  void ide_sector_read(IDEState *s)
         if (n > s->req_nb_sectors)
             n = s->req_nb_sectors;
         ret = bdrv_read(s->bs, sector_num, s->io_buffer, n);
+        ide_update_iostatus(s, ret);
         if (ret != 0) {
             if (ide_handle_rw_error(s, -ret,
                 BM_STATUS_PIO_RETRY | BM_STATUS_RETRY_READ))
@@ -544,6 +550,7 @@  void ide_dma_cb(void *opaque, int ret)
     int64_t sector_num;
 
 handle_rw_error:
+    ide_update_iostatus(s, ret);
     if (ret < 0) {
         int op = BM_STATUS_DMA_RETRY;
 
@@ -643,6 +650,7 @@  void ide_sector_write(IDEState *s)
         n = s->req_nb_sectors;
     ret = bdrv_write(s->bs, sector_num, s->io_buffer, n);
 
+    ide_update_iostatus(s, ret);
     if (ret != 0) {
         if (ide_handle_rw_error(s, -ret, BM_STATUS_PIO_RETRY))
             return;
@@ -678,6 +686,7 @@  static void ide_flush_cb(void *opaque, int ret)
 {
     IDEState *s = opaque;
 
+    ide_update_iostatus(s, ret);
     if (ret < 0) {
         /* XXX: What sector number to set here? */
         if (ide_handle_rw_error(s, -ret, BM_STATUS_RETRY_FLUSH)) {
@@ -1780,10 +1789,16 @@  static bool ide_cd_is_medium_locked(void *opaque)
     return ((IDEState *)opaque)->tray_locked;
 }
 
+static BlockDevIOStatus ide_iostatus(void *opaque)
+{
+    return ((IDEState *)opaque)->iostatus;
+}
+
 static const BlockDevOps ide_cd_block_ops = {
     .change_media_cb = ide_cd_change_cb,
     .is_medium_ejected = ide_cd_medium_ejected,
     .is_medium_locked = ide_cd_is_medium_locked,
+    .get_iostatus = ide_iostatus,
 };
 
 int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
@@ -1843,6 +1858,7 @@  int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
     } else {
         pstrcpy(s->version, sizeof(s->version), QEMU_VERSION);
     }
+    s->iostatus = BDRV_IOS_INVAL;
 
     ide_reset(s);
     if (s->drive_kind == IDE_CD) {
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 2feae25..3a9a2cf 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -480,6 +480,8 @@  struct IDEState {
     uint8_t *smart_selftest_data;
     /* AHCI */
     int ncq_queues;
+
+    BlockDevIOStatus iostatus;
 };
 
 struct IDEDMAOps {