Blob Blame History Raw
From 171f9db1f1217a217c7c13b3282b66eec7a165d1 Mon Sep 17 00:00:00 2001
From: Luiz Capitulino <lcapitulino@redhat.com>
Date: Wed, 15 Mar 2017 13:25:17 +0100
Subject: qmp: add __com.redhat_reason to the BLOCK_IO_ERROR event

Patchwork-id: 64969
O-Subject: [RHEL7.2 qemu-kvm-rhev PATCH 1/2] qmp: add error reason to the BLOCK_IO_ERROR event
Bugzilla: 1199174
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
RH-Acked-by: Eric Blake <eblake@redhat.com>

This commit forward ports the following RHEL-7.0 commit to RHEL-7.2:

  commit 771a3a333eb0c9299a69a78ddb9c4181850b827d
  Author: Laszlo Ersek <lersek@redhat.com>
  Date:   Thu Nov 21 16:27:18 2013 +0100

  error reason in BLOCK_IO_ERROR / BLOCK_JOB_ERROR events (RHEL 6->7 fwd)

I had to redo the work because now events use the QAPI, but it
was straightforward.

There's one significant difference though: this commit does not
extend the BLOCK_JOB_ERROR event as did the RHEL-7.0 commit. The
reason is that this extension was supposed to be used only by vdsm
and I don't think there's a requirement to have the extension
in BLOCK_JOB_ERROR too. Let's not spread it.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>

Rebase notes (2.10.0):
- Properly updated example

Rebase notes (2.9.0):
- moved documentation to schema

(cherry picked from commit 2f9487b60f700de33551208c543f5d3b4fa89236)
(cherry picked from commit e2bf476c86cf5697ef3ea6aab2249aa85b8be2cd)
(cherry picked from commit 025b8d9385cab3c7c00e0caf9af84722a9ac914c)
(cherry picked from commit 264ccd5fc938bc26362046a697ad0d535531e69b)
(cherry picked from commit 88802f4552223d31f0ea9cf6c943ad3b091120cd)
---
 block/block-backend.c | 27 +++++++++++++++++++++++----
 qapi/block-core.json  | 20 ++++++++++++++++++--
 2 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index 681b240..fd342db 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1650,9 +1650,25 @@ BlockErrorAction blk_get_error_action(BlockBackend *blk, bool is_read,
     }
 }
 
+/* https://bugzilla.redhat.com/show_bug.cgi?id=1199174 */
+static RHEL7BlockErrorReason get_rhel7_error_reason(int error)
+{
+	switch (error) {
+	case ENOSPC:
+        return RHEL7_BLOCK_ERROR_REASON_ENOSPC;
+	case EPERM:
+        return RHEL7_BLOCK_ERROR_REASON_EPERM;
+	case EIO:
+        return RHEL7_BLOCK_ERROR_REASON_EIO;
+	default:
+        return RHEL7_BLOCK_ERROR_REASON_EOTHER;
+    }
+}
+
 static void send_qmp_error_event(BlockBackend *blk,
                                  BlockErrorAction action,
-                                 bool is_read, int error)
+                                 bool is_read, int error,
+                                 RHEL7BlockErrorReason res)
 {
     IoOperationType optype;
     BlockDriverState *bs = blk_bs(blk);
@@ -1662,7 +1678,7 @@ static void send_qmp_error_event(BlockBackend *blk,
                                    bs ? bdrv_get_node_name(bs) : NULL, optype,
                                    action, blk_iostatus_is_enabled(blk),
                                    error == ENOSPC, strerror(error),
-                                   &error_abort);
+                                   res, &error_abort);
 }
 
 /* This is done by device models because, while the block layer knows
@@ -1672,7 +1688,10 @@ static void send_qmp_error_event(BlockBackend *blk,
 void blk_error_action(BlockBackend *blk, BlockErrorAction action,
                       bool is_read, int error)
 {
+    RHEL7BlockErrorReason res;
+
     assert(error >= 0);
+    res = get_rhel7_error_reason(error);
 
     if (action == BLOCK_ERROR_ACTION_STOP) {
         /* First set the iostatus, so that "info block" returns an iostatus
@@ -1690,10 +1709,10 @@ void blk_error_action(BlockBackend *blk, BlockErrorAction action,
          * also ensures that the STOP/RESUME pair of events is emitted.
          */
         qemu_system_vmstop_request_prepare();
-        send_qmp_error_event(blk, action, is_read, error);
+        send_qmp_error_event(blk, action, is_read, error, res);
         qemu_system_vmstop_request(RUN_STATE_IO_ERROR);
     } else {
-        send_qmp_error_event(blk, action, is_read, error);
+        send_qmp_error_event(blk, action, is_read, error, res);
     }
 }
 
diff --git a/qapi/block-core.json b/qapi/block-core.json
index c50517b..b38d5d6 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -4404,6 +4404,19 @@
             'fatal'      : 'bool' } }
 
 ##
+# @RHEL7BlockErrorReason:
+#
+# Block I/O error reason
+#
+# @eio:  errno EIO
+# @eperm: errno EPERM
+# @enospc: errno ENOSPC
+# @eother: any errno other than EIO, EPERM, ENOSPC
+##
+{ 'enum': 'RHEL7BlockErrorReason',
+  'data': [ 'enospc', 'eperm', 'eio', 'eother' ] }
+
+##
 # @BLOCK_IO_ERROR:
 #
 # Emitted when a disk I/O error occurs
@@ -4430,6 +4443,8 @@
 #          (This field is a debugging aid for humans, it should not
 #           be parsed by applications) (since: 2.2)
 #
+# @__com.redhat_reason: error reason
+#
 # Note: If action is "stop", a STOP event will eventually follow the
 # BLOCK_IO_ERROR event
 #
@@ -4441,7 +4456,8 @@
 #      "data": { "device": "ide0-hd1",
 #                "node-name": "#block212",
 #                "operation": "write",
-#                "action": "stop" },
+#                "action": "stop",
+#                "__com.redhat_reason": "enospc" },
 #      "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
 #
 ##
@@ -4449,7 +4465,7 @@
   'data': { 'device': 'str', '*node-name': 'str',
             'operation': 'IoOperationType',
             'action': 'BlockErrorAction', '*nospace': 'bool',
-            'reason': 'str' } }
+            'reason': 'str', '__com.redhat_reason': 'RHEL7BlockErrorReason' } }
 
 ##
 # @BLOCK_JOB_COMPLETED:
-- 
1.8.3.1