qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com
Subject: [Qemu-devel] [PATCH 2/5] block: BLOCK_IO_ERROR QMP event
Date: Wed,  3 Feb 2010 12:41:01 -0200	[thread overview]
Message-ID: <1265208064-16039-3-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1265208064-16039-1-git-send-email-lcapitulino@redhat.com>

This commit introduces the bdrv_mon_event() function, which
should be called by block subsystems (eg. IDE) when a I/O
error occurs, so that an QMP event is emitted.

The following information is currently provided in the event:

- device name
- operation (ie. "read" or "write")
- action taken (eg. "stop")

Event example:

{ "event": "BLOCK_IO_ERROR",
    "data": { "device": "ide0-hd1",
              "operation": "write",
              "action": "stop" },
    "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 block.c |   29 +++++++++++++++++++++++++++++
 block.h |    6 ++++++
 2 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index 1919d19..2913124 100644
--- a/block.c
+++ b/block.c
@@ -1164,6 +1164,35 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
     return bs->drv->bdrv_is_allocated(bs, sector_num, nb_sectors, pnum);
 }
 
+void bdrv_mon_event(const BlockDriverState *bdrv,
+                    BlockMonEventAction action, int is_read)
+{
+    QObject *data;
+    const char *action_str;
+
+    switch (action) {
+    case BDRV_ACTION_REPORT:
+        action_str = "report";
+        break;
+    case BDRV_ACTION_IGNORE:
+        action_str = "ignore";
+        break;
+    case BDRV_ACTION_STOP:
+        action_str = "stop";
+        break;
+    default:
+        abort();
+    }
+
+    data = qobject_from_jsonf("{ 'device': %s, 'action': %s, 'operation': %s }",
+                              bdrv->device_name,
+                              action_str,
+                              is_read ? "read" : "write");
+    monitor_protocol_event(QEVENT_BLOCK_IO_ERROR, data);
+
+    qobject_decref(data);
+}
+
 static void bdrv_print_dict(QObject *obj, void *opaque)
 {
     QDict *bs_dict;
diff --git a/block.h b/block.h
index ecf66c5..a834300 100644
--- a/block.h
+++ b/block.h
@@ -44,6 +44,12 @@ typedef struct QEMUSnapshotInfo {
 #define BDRV_SECTOR_SIZE   (1 << BDRV_SECTOR_BITS)
 #define BDRV_SECTOR_MASK   ~(BDRV_SECTOR_SIZE - 1);
 
+typedef enum {
+    BDRV_ACTION_REPORT, BDRV_ACTION_IGNORE, BDRV_ACTION_STOP
+} BlockMonEventAction;
+
+void bdrv_mon_event(const BlockDriverState *bdrv,
+                    BlockMonEventAction action, int is_read);
 void bdrv_info_print(Monitor *mon, const QObject *data);
 void bdrv_info(Monitor *mon, QObject **ret_data);
 void bdrv_stats_print(Monitor *mon, const QObject *data);
-- 
1.6.6

  parent reply	other threads:[~2010-02-03 14:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-03 14:40 [Qemu-devel] [PATCH v1 0/5]: BLOCK_IO_ERROR QMP event Luiz Capitulino
2010-02-03 14:41 ` [Qemu-devel] [PATCH 1/5] QMP: BLOCK_IO_ERROR event handling Luiz Capitulino
2010-02-10 18:32   ` Anthony Liguori
2010-02-03 14:41 ` Luiz Capitulino [this message]
2010-02-03 14:41 ` [Qemu-devel] [PATCH 3/5] ide: Generate BLOCK_IO_ERROR QMP event Luiz Capitulino
2010-02-03 14:41 ` [Qemu-devel] [PATCH 4/5] scsi: " Luiz Capitulino
2010-02-03 14:41 ` [Qemu-devel] [PATCH 5/5] virtio-blk: " Luiz Capitulino
  -- strict thread matches above, loose matches on Subject: below --
2010-02-02 21:10 [Qemu-devel] [PATCH v0 0/5]: " Luiz Capitulino
2010-02-02 21:10 ` [Qemu-devel] [PATCH 2/5] block: " Luiz Capitulino

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=1265208064-16039-3-git-send-email-lcapitulino@redhat.com \
    --to=lcapitulino@redhat.com \
    --cc=kwolf@redhat.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).