Blame SOURCES/kvm-improve-debuggability-of-BLOCK_IO_ERROR-BLOCK_JOB_ER.patch

0a122b
From bfea65d6f229fd65c78ae4daaddf0d0711d0aedd Mon Sep 17 00:00:00 2001
0a122b
From: Laszlo Ersek <lersek@redhat.com>
0a122b
Date: Thu, 21 Nov 2013 16:27:19 +0100
0a122b
Subject: [PATCH 09/14] improve debuggability of BLOCK_IO_ERROR / BLOCK_JOB_ERROR (RHEL 6->7 fwd)
0a122b
0a122b
RH-Author: Laszlo Ersek <lersek@redhat.com>
0a122b
Message-id: <1385051239-3677-4-git-send-email-lersek@redhat.com>
0a122b
Patchwork-id: 55837
0a122b
O-Subject: [RHEL-7.0 qemu-kvm PATCH 3/3] improve debuggability of BLOCK_IO_ERROR / BLOCK_JOB_ERROR (RHEL 6->7 fwd)
0a122b
Bugzilla: 895041
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
RH-Acked-by: Jiri Denemark <jdenemar@redhat.com>
0a122b
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
0a122b
0a122b
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=895041
0a122b
0a122b
Forward-port of RHEL-6-only commit
0a122b
0a122b
  commit 1a2b98f958fb770b70fa5a244e86c93655400858
0a122b
  Author: Luiz Capitulino <lcapitulino@redhat.com>
0a122b
  Date:   Thu Nov 4 13:51:42 2010 -0200
0a122b
0a122b
      QMP: Improve debuggability of the BLOCK_IO_ERROR event
0a122b
0a122b
Again, the code & docs are extended to BLOCK_JOB_ERROR.
0a122b
0a122b
In the printf() added to bdrv_emit_qmp_error_event() I could have
0a122b
scavenged the static global "monitor_event_names", but I would have had
0a122b
to make it extern (or rather add a public getter function), which I deemed
0a122b
too much.
0a122b
0a122b
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
0a122b
---
0a122b
 block.c            | 19 +++++++++++++++++++
0a122b
 QMP/qmp-events.txt | 20 ++++++++++++++++++--
0a122b
 2 files changed, 37 insertions(+), 2 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 QMP/qmp-events.txt |   20 ++++++++++++++++++--
0a122b
 block.c            |   19 +++++++++++++++++++
0a122b
 2 files changed, 37 insertions(+), 2 deletions(-)
0a122b
0a122b
diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt
0a122b
index c8c6d75..fc4b7db 100644
0a122b
--- a/QMP/qmp-events.txt
0a122b
+++ b/QMP/qmp-events.txt
0a122b
@@ -59,6 +59,11 @@ Data:
0a122b
     "eperm": errno EPERM
0a122b
     "enospc": errno ENOSPC
0a122b
     "eother": any other errno (other than EIO, EPERM, ENOSPC)
0a122b
+- "__com.redhat_debug_info": RHEL7 extension containing debug information for
0a122b
+                             humans, applications should NOT read any
0a122b
+                             information from this member (json-object):
0a122b
+    - "errno": errno value (json-int)
0a122b
+    - "message": error message returned by strerror() (json-string)
0a122b
 
0a122b
 Example:
0a122b
 
0a122b
@@ -66,7 +71,10 @@ Example:
0a122b
     "data": { "device": "ide0-hd1",
0a122b
               "operation": "write",
0a122b
               "action": "stop",
0a122b
-              "__com.redhat_reason": "enospc" },
0a122b
+              "__com.redhat_reason": "enospc",
0a122b
+              "__com.redhat_debug_info": {
0a122b
+                  "message": "No space left on device",
0a122b
+                  "errno": 28 } }
0a122b
     "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
0a122b
 
0a122b
 Note: If action is "stop", a STOP event will eventually follow the
0a122b
@@ -144,6 +152,11 @@ Data:
0a122b
     "eperm": errno EPERM
0a122b
     "enospc": errno ENOSPC
0a122b
     "eother": any other errno (other than EIO, EPERM, ENOSPC)
0a122b
+- "__com.redhat_debug_info": RHEL7 extension containing debug information for
0a122b
+                             humans, applications should NOT read any
0a122b
+                             information from this member (json-object):
0a122b
+    - "errno": errno value (json-int)
0a122b
+    - "message": error message returned by strerror() (json-string)
0a122b
 
0a122b
 Example:
0a122b
 
0a122b
@@ -151,7 +164,10 @@ Example:
0a122b
     "data": { "device": "ide0-hd1",
0a122b
               "operation": "write",
0a122b
               "action": "stop",
0a122b
-              "__com.redhat_reason": "enospc" },
0a122b
+              "__com.redhat_reason": "enospc",
0a122b
+              "__com.redhat_debug_info": {
0a122b
+                  "message": "No space left on device",
0a122b
+                  "errno": 28 } }
0a122b
     "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
0a122b
 
0a122b
 BLOCK_JOB_READY
0a122b
diff --git a/block.c b/block.c
0a122b
index 68755bf..8ef07bb 100644
0a122b
--- a/block.c
0a122b
+++ b/block.c
0a122b
@@ -1748,6 +1748,18 @@ static void bdrv_put_rhel7_reason(QDict *event, int error)
0a122b
     qdict_put(event, BDRV_REASON_KEY, qstring_from_str(reason));
0a122b
 }
0a122b
 
0a122b
+#define BDRV_DEBUG_KEY  RFQDN_REDHAT "debug_info"
0a122b
+
0a122b
+/* RHEL7 vendor extension */
0a122b
+static void bdrv_put_rhel7_debug_info(QDict *event, int error)
0a122b
+{
0a122b
+    QObject *info;
0a122b
+
0a122b
+    info = qobject_from_jsonf("{ 'errno': %d, 'message': %s }", error,
0a122b
+                               strerror(error));
0a122b
+    qdict_put_obj(event, BDRV_DEBUG_KEY, info);
0a122b
+}
0a122b
+
0a122b
 void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
0a122b
                                enum MonitorEvent ev,
0a122b
                                BlockErrorAction action,
0a122b
@@ -1771,11 +1783,18 @@ void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
0a122b
         abort();
0a122b
     }
0a122b
 
0a122b
+    fprintf(stderr, "%s error in device '%s': %s (%d)\n",
0a122b
+                     ev == QEVENT_BLOCK_IO_ERROR  ? "block I/O" :
0a122b
+                     ev == QEVENT_BLOCK_JOB_ERROR ? "block job" :
0a122b
+                     "other block",
0a122b
+                     bdrv->device_name, strerror(error), error);
0a122b
+
0a122b
     data = qobject_from_jsonf("{ 'device': %s, 'action': %s, 'operation': %s }",
0a122b
                               bdrv->device_name,
0a122b
                               action_str,
0a122b
                               is_read ? "read" : "write");
0a122b
     bdrv_put_rhel7_reason(qobject_to_qdict(data), error);
0a122b
+    bdrv_put_rhel7_debug_info(qobject_to_qdict(data), error);
0a122b
     monitor_protocol_event(ev, data);
0a122b
 
0a122b
     qobject_decref(data);
0a122b
-- 
0a122b
1.7.1
0a122b