Blame SOURCES/kvm-qmp-improve-debuggability-of-BLOCK_IO_ERROR-event.patch

d81766
From d6b3fb3db9409f62de3735f967b46fb23e97fda2 Mon Sep 17 00:00:00 2001
d81766
From: Luiz Capitulino <lcapitulino@redhat.com>
d81766
Date: Wed, 9 Jul 2014 14:31:52 +0200
d81766
Subject: qmp: improve debuggability of BLOCK_IO_ERROR event
d81766
d81766
Message-id: <1404916312-27953-4-git-send-email-lcapitulino@redhat.com>
d81766
Patchwork-id: 59730
d81766
O-Subject: [RHEV7.1 qemu-kvm-rhev PATCH 3/3] qmp: improve debuggability of BLOCK_IO_ERROR event
d81766
Bugzilla: 1116772
d81766
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
d81766
RH-Acked-by: Eric Blake <eblake@redhat.com>
d81766
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
d81766
d81766
This commit forward ports the following RHEL-7.0 commit to RHEL-7.1:
d81766
d81766
  commit bfea65d6f229fd65c78ae4daaddf0d0711d0aedd
d81766
  Author: Laszlo Ersek <lersek@redhat.com>
d81766
  Date:   Thu Nov 21 16:27:19 2013 +0100
d81766
d81766
  improve debuggability of BLOCK_IO_ERROR / BLOCK_JOB_ERROR (RHEL 6->7 fwd)
d81766
d81766
I had to redo the work because now events use the QAPI, but it
d81766
was straightforward.
d81766
d81766
There's one significant difference though: this commit does not
d81766
extend the BLOCK_JOB_ERROR event as did the RHEL-7.0 commit. The
d81766
reason is that the original requirement was to have this only on
d81766
the BLOCK_IO_ERROR event. Let's not spread it unless we're asked to.
d81766
d81766
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
d81766
d81766
diff --git a/block.c b/block.c
d81766
index aab65d9..f1b1cd4 100644
d81766
--- a/block.c
d81766
+++ b/block.c
d81766
@@ -3611,6 +3611,13 @@ static RHEL7BlockErrorReason get_rhel7_error_reason(int error)
d81766
     }
d81766
 }
d81766
 
d81766
+static void get_rhel7_error_debug_info(RHEL7BlockErrorDebugInfo *info,
d81766
+                                       int error)
d81766
+{
d81766
+    info->q_errno = error;
d81766
+    info->message = strerror(error);
d81766
+}
d81766
+
d81766
 /* This is done by device models because, while the block layer knows
d81766
  * about the error, it does not know whether an operation comes from
d81766
  * the device or the block layer (from a job, for example).
d81766
@@ -3619,9 +3626,14 @@ void bdrv_error_action(BlockDriverState *bs, BlockErrorAction action,
d81766
                        bool is_read, int error)
d81766
 {
d81766
     RHEL7BlockErrorReason res;
d81766
+    RHEL7BlockErrorDebugInfo info;
d81766
 
d81766
     assert(error >= 0);
d81766
     res = get_rhel7_error_reason(error);
d81766
+    get_rhel7_error_debug_info(&info, error);
d81766
+
d81766
+    fprintf(stderr, "block I/O error in device '%s': %s (%d)\n",
d81766
+                    bdrv_get_device_name(bs), info.message, (int) info.q_errno);
d81766
 
d81766
     if (action == BLOCK_ERROR_ACTION_STOP) {
d81766
         /* First set the iostatus, so that "info block" returns an iostatus
d81766
@@ -3642,13 +3654,13 @@ void bdrv_error_action(BlockDriverState *bs, BlockErrorAction action,
d81766
         qapi_event_send_block_io_error(bdrv_get_device_name(bs),
d81766
                                        is_read ? IO_OPERATION_TYPE_READ :
d81766
                                        IO_OPERATION_TYPE_WRITE,
d81766
-                                       action, res, &error_abort);
d81766
+                                       action, res, &info, &error_abort);
d81766
         qemu_system_vmstop_request(RUN_STATE_IO_ERROR);
d81766
     } else {
d81766
         qapi_event_send_block_io_error(bdrv_get_device_name(bs),
d81766
                                        is_read ? IO_OPERATION_TYPE_READ :
d81766
                                        IO_OPERATION_TYPE_WRITE,
d81766
-                                       action, res, &error_abort);
d81766
+                                       action, res, &info, &error_abort);
d81766
     }
d81766
 }
d81766
 
d81766
diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
d81766
index 40c2917..c9dec63 100644
d81766
--- a/docs/qmp/qmp-events.txt
d81766
+++ b/docs/qmp/qmp-events.txt
d81766
@@ -69,6 +69,11 @@ Data:
d81766
 	"eperm": errno EPERM
d81766
 	"enospc": errno ENOSPC
d81766
 	"eother": any other errno (other than EIO, EPERM, ENOSPC)
d81766
+- "__com.redhat_debug_info": RHEL7 extension containing debug information for
d81766
+                             humans, applications should NOT read any
d81766
+                             information from this member (json-object):
d81766
+	- "errno": errno value (json-int)
d81766
+	- "message": error message returned by strerror() (json-string)
d81766
 
d81766
 Example:
d81766
 
d81766
@@ -76,7 +81,10 @@ Example:
d81766
     "data": { "device": "ide0-hd1",
d81766
               "operation": "write",
d81766
               "action": "stop",
d81766
-              "__com.redhat_reason": "enospc" },
d81766
+              "__com.redhat_reason": "enospc",
d81766
+			  "__com.redhat_debug_info": {
d81766
+                "message": "No space left on device",
d81766
+				"errno": 28 } }
d81766
     "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
d81766
 
d81766
 Note: If action is "stop", a STOP event will eventually follow the
d81766
diff --git a/qapi/block-core.json b/qapi/block-core.json
d81766
index 404059b..706c5d9 100644
d81766
--- a/qapi/block-core.json
d81766
+++ b/qapi/block-core.json
d81766
@@ -1505,6 +1505,17 @@
d81766
   'data': [ 'enospc', 'eperm', 'eio', 'eother' ] }
d81766
 
d81766
 ##
d81766
+# @RHEL7BlockErrorDebugInfo
d81766
+#
d81766
+# Debug information for a block I/O error
d81766
+#
d81766
+# @message: error message returned by strerror()
d81766
+# @errno: errno value
d81766
+##
d81766
+{ 'type': 'RHEL7BlockErrorDebugInfo',
d81766
+  'data': { 'message': 'str', 'errno': 'int' } }
d81766
+
d81766
+##
d81766
 # @BLOCK_IMAGE_CORRUPTED
d81766
 #
d81766
 # Emitted when a disk image is being marked corrupt
d81766
@@ -1542,6 +1553,10 @@
d81766
 #
d81766
 # @__com.redhat_reason: error reason (RHEL7 vendor extension)
d81766
 #
d81766
+# @__com.redhat_debug_info: debug information for humans, applications
d81766
+#                           should NOT read any information from this
d81766
+#                           member (RHEL7 vendor extension)
d81766
+#
d81766
 # Note: If action is "stop", a STOP event will eventually follow the
d81766
 # BLOCK_IO_ERROR event
d81766
 #
d81766
@@ -1550,7 +1565,8 @@
d81766
 { 'event': 'BLOCK_IO_ERROR',
d81766
   'data': { 'device': 'str', 'operation': 'IoOperationType',
d81766
             'action': 'BlockErrorAction',
d81766
-            '__com.redhat_reason': 'RHEL7BlockErrorReason' } }
d81766
+            '__com.redhat_reason': 'RHEL7BlockErrorReason',
d81766
+            '__com.redhat_debug_info': 'RHEL7BlockErrorDebugInfo' } }
d81766
 
d81766
 ##
d81766
 # @BLOCK_JOB_COMPLETED