Blame SOURCES/0019-qmp-add-__com.redhat_reason-to-the-BLOCK_IO_ERROR-ev.patch

4a2fec
From e2bf476c86cf5697ef3ea6aab2249aa85b8be2cd Mon Sep 17 00:00:00 2001
4a2fec
From: Luiz Capitulino <lcapitulino@redhat.com>
4a2fec
Date: Wed, 15 Mar 2017 13:25:17 +0100
4a2fec
Subject: qmp: add __com.redhat_reason to the BLOCK_IO_ERROR event
4a2fec
4a2fec
Patchwork-id: 64969
4a2fec
O-Subject: [RHEL7.2 qemu-kvm-rhev PATCH 1/2] qmp: add error reason to the BLOCK_IO_ERROR event
4a2fec
Bugzilla: 1199174
4a2fec
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
4a2fec
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
4a2fec
RH-Acked-by: Eric Blake <eblake@redhat.com>
4a2fec
4a2fec
This commit forward ports the following RHEL-7.0 commit to RHEL-7.2:
4a2fec
4a2fec
  commit 771a3a333eb0c9299a69a78ddb9c4181850b827d
4a2fec
  Author: Laszlo Ersek <lersek@redhat.com>
4a2fec
  Date:   Thu Nov 21 16:27:18 2013 +0100
4a2fec
4a2fec
  error reason in BLOCK_IO_ERROR / BLOCK_JOB_ERROR events (RHEL 6->7 fwd)
4a2fec
4a2fec
I had to redo the work because now events use the QAPI, but it
4a2fec
was straightforward.
4a2fec
4a2fec
There's one significant difference though: this commit does not
4a2fec
extend the BLOCK_JOB_ERROR event as did the RHEL-7.0 commit. The
4a2fec
reason is that this extension was supposed to be used only by vdsm
4a2fec
and I don't think there's a requirement to have the extension
4a2fec
in BLOCK_JOB_ERROR too. Let's not spread it.
4a2fec
4a2fec
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
4a2fec
Rebase notes (2.10.0):
4a2fec
- Properly updated example
4a2fec
4a2fec
Rebase notes (2.9.0):
4a2fec
- moved documentation to schema
4a2fec
4a2fec
(cherry picked from commit 2f9487b60f700de33551208c543f5d3b4fa89236)
4a2fec
---
4a2fec
 block/block-backend.c | 27 +++++++++++++++++++++++----
4a2fec
 qapi/block-core.json  | 20 ++++++++++++++++++--
4a2fec
 2 files changed, 41 insertions(+), 6 deletions(-)
4a2fec
4a2fec
diff --git a/block/block-backend.c b/block/block-backend.c
4a2fec
index 1031742..0819b3a 100644
4a2fec
--- a/block/block-backend.c
4a2fec
+++ b/block/block-backend.c
4a2fec
@@ -1510,9 +1510,25 @@ BlockErrorAction blk_get_error_action(BlockBackend *blk, bool is_read,
4a2fec
     }
4a2fec
 }
4a2fec
 
4a2fec
+/* https://bugzilla.redhat.com/show_bug.cgi?id=1199174 */
4a2fec
+static RHEL7BlockErrorReason get_rhel7_error_reason(int error)
4a2fec
+{
4a2fec
+	switch (error) {
4a2fec
+	case ENOSPC:
4a2fec
+        return RHEL7_BLOCK_ERROR_REASON_ENOSPC;
4a2fec
+	case EPERM:
4a2fec
+        return RHEL7_BLOCK_ERROR_REASON_EPERM;
4a2fec
+	case EIO:
4a2fec
+        return RHEL7_BLOCK_ERROR_REASON_EIO;
4a2fec
+	default:
4a2fec
+        return RHEL7_BLOCK_ERROR_REASON_EOTHER;
4a2fec
+    }
4a2fec
+}
4a2fec
+
4a2fec
 static void send_qmp_error_event(BlockBackend *blk,
4a2fec
                                  BlockErrorAction action,
4a2fec
-                                 bool is_read, int error)
4a2fec
+                                 bool is_read, int error,
4a2fec
+                                 RHEL7BlockErrorReason res)
4a2fec
 {
4a2fec
     IoOperationType optype;
4a2fec
 
4a2fec
@@ -1521,7 +1537,7 @@ static void send_qmp_error_event(BlockBackend *blk,
4a2fec
                                    bdrv_get_node_name(blk_bs(blk)), optype,
4a2fec
                                    action, blk_iostatus_is_enabled(blk),
4a2fec
                                    error == ENOSPC, strerror(error),
4a2fec
-                                   &error_abort);
4a2fec
+                                   res, &error_abort);
4a2fec
 }
4a2fec
 
4a2fec
 /* This is done by device models because, while the block layer knows
4a2fec
@@ -1531,7 +1547,10 @@ static void send_qmp_error_event(BlockBackend *blk,
4a2fec
 void blk_error_action(BlockBackend *blk, BlockErrorAction action,
4a2fec
                       bool is_read, int error)
4a2fec
 {
4a2fec
+    RHEL7BlockErrorReason res;
4a2fec
+
4a2fec
     assert(error >= 0);
4a2fec
+    res = get_rhel7_error_reason(error);
4a2fec
 
4a2fec
     if (action == BLOCK_ERROR_ACTION_STOP) {
4a2fec
         /* First set the iostatus, so that "info block" returns an iostatus
4a2fec
@@ -1549,10 +1568,10 @@ void blk_error_action(BlockBackend *blk, BlockErrorAction action,
4a2fec
          * also ensures that the STOP/RESUME pair of events is emitted.
4a2fec
          */
4a2fec
         qemu_system_vmstop_request_prepare();
4a2fec
-        send_qmp_error_event(blk, action, is_read, error);
4a2fec
+        send_qmp_error_event(blk, action, is_read, error, res);
4a2fec
         qemu_system_vmstop_request(RUN_STATE_IO_ERROR);
4a2fec
     } else {
4a2fec
-        send_qmp_error_event(blk, action, is_read, error);
4a2fec
+        send_qmp_error_event(blk, action, is_read, error, res);
4a2fec
     }
4a2fec
 }
4a2fec
 
4a2fec
diff --git a/qapi/block-core.json b/qapi/block-core.json
4a2fec
index 833c602..8f5f105 100644
4a2fec
--- a/qapi/block-core.json
4a2fec
+++ b/qapi/block-core.json
4a2fec
@@ -3552,6 +3552,19 @@
4a2fec
             'fatal'      : 'bool' } }
4a2fec
 
4a2fec
 ##
4a2fec
+# @RHEL7BlockErrorReason:
4a2fec
+#
4a2fec
+# Block I/O error reason
4a2fec
+#
4a2fec
+# @eio:  errno EIO
4a2fec
+# @eperm: errno EPERM
4a2fec
+# @enospc: errno ENOSPC
4a2fec
+# @eother: any errno other than EIO, EPERM, ENOSPC
4a2fec
+##
4a2fec
+{ 'enum': 'RHEL7BlockErrorReason',
4a2fec
+  'data': [ 'enospc', 'eperm', 'eio', 'eother' ] }
4a2fec
+
4a2fec
+##
4a2fec
 # @BLOCK_IO_ERROR:
4a2fec
 #
4a2fec
 # Emitted when a disk I/O error occurs
4a2fec
@@ -3577,6 +3590,8 @@
4a2fec
 #          (This field is a debugging aid for humans, it should not
4a2fec
 #           be parsed by applications) (since: 2.2)
4a2fec
 #
4a2fec
+# @__com.redhat_reason: error reason
4a2fec
+#
4a2fec
 # Note: If action is "stop", a STOP event will eventually follow the
4a2fec
 # BLOCK_IO_ERROR event
4a2fec
 #
4a2fec
@@ -3588,14 +3603,15 @@
4a2fec
 #      "data": { "device": "ide0-hd1",
4a2fec
 #                "node-name": "#block212",
4a2fec
 #                "operation": "write",
4a2fec
-#                "action": "stop" },
4a2fec
+#                "action": "stop",
4a2fec
+#                "__com.redhat_reason": "enospc" },
4a2fec
 #      "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
4a2fec
 #
4a2fec
 ##
4a2fec
 { 'event': 'BLOCK_IO_ERROR',
4a2fec
   'data': { 'device': 'str', 'node-name': 'str', 'operation': 'IoOperationType',
4a2fec
             'action': 'BlockErrorAction', '*nospace': 'bool',
4a2fec
-            'reason': 'str' } }
4a2fec
+            'reason': 'str', '__com.redhat_reason': 'RHEL7BlockErrorReason' } }
4a2fec
 
4a2fec
 ##
4a2fec
 # @BLOCK_JOB_COMPLETED:
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec