From 1a2fe5a329ffe4b89dcd5c27c8f53ff87a28702b Mon Sep 17 00:00:00 2001
From: Luiz Capitulino <lcapitulino@redhat.com>
Date: Wed, 9 Jul 2014 14:31:51 +0200
Subject: qmp: add error reason to the BLOCK_IO_ERROR event
Message-id: <1404916312-27953-3-git-send-email-lcapitulino@redhat.com>
Patchwork-id: 59729
O-Subject: [RHEV7.1 qemu-kvm-rhev PATCH 2/3] qmp: add error reason to the BLOCK_IO_ERROR event
Bugzilla: 1116772
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Eric Blake <eblake@redhat.com>
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
This commit forward ports the following RHEL-7.0 commit to RHEL-7.1:
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>
diff --git a/block.c b/block.c
index 8cf519b..aab65d9 100644
--- a/block.c
+++ b/block.c
@@ -3596,6 +3596,21 @@ BlockErrorAction bdrv_get_error_action(BlockDriverState *bs, bool is_read, int e
}
}
+/* https://bugzilla.redhat.com/show_bug.cgi?id=1116772 */
+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;
+ }
+}
+
/* This is done by device models because, while the block layer knows
* about the error, it does not know whether an operation comes from
* the device or the block layer (from a job, for example).
@@ -3603,7 +3618,10 @@ BlockErrorAction bdrv_get_error_action(BlockDriverState *bs, bool is_read, int e
void bdrv_error_action(BlockDriverState *bs, 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
@@ -3624,13 +3642,13 @@ void bdrv_error_action(BlockDriverState *bs, BlockErrorAction action,
qapi_event_send_block_io_error(bdrv_get_device_name(bs),
is_read ? IO_OPERATION_TYPE_READ :
IO_OPERATION_TYPE_WRITE,
- action, &error_abort);
+ action, res, &error_abort);
qemu_system_vmstop_request(RUN_STATE_IO_ERROR);
} else {
qapi_event_send_block_io_error(bdrv_get_device_name(bs),
is_read ? IO_OPERATION_TYPE_READ :
IO_OPERATION_TYPE_WRITE,
- action, &error_abort);
+ action, res, &error_abort);
}
}
diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index d759d19..40c2917 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -63,13 +63,20 @@ Data:
"ignore": error has been ignored
"report": error has been reported to the device
"stop": the VM is going to stop because of the error
+- "__com.redhat_reason": error reason, this is a RHEL7 extension, it's one of
+ the following (json-string):
+ "eio": errno EIO
+ "eperm": errno EPERM
+ "enospc": errno ENOSPC
+ "eother": any other errno (other than EIO, EPERM, ENOSPC)
Example:
{ "event": "BLOCK_IO_ERROR",
"data": { "device": "ide0-hd1",
"operation": "write",
- "action": "stop" },
+ "action": "stop",
+ "__com.redhat_reason": "enospc" },
"timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
Note: If action is "stop", a STOP event will eventually follow the
diff --git a/qapi/block-core.json b/qapi/block-core.json
index e378653..404059b 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -1496,6 +1496,13 @@
{ 'enum': 'BlockErrorAction',
'data': [ 'ignore', 'report', 'stop' ] }
+##
+# @RHEL7BlockErrorReason
+#
+# Block I/O error reason
+##
+{ 'enum': 'RHEL7BlockErrorReason',
+ 'data': [ 'enospc', 'eperm', 'eio', 'eother' ] }
##
# @BLOCK_IMAGE_CORRUPTED
@@ -1533,6 +1540,8 @@
#
# @action: action that has been taken
#
+# @__com.redhat_reason: error reason (RHEL7 vendor extension)
+#
# Note: If action is "stop", a STOP event will eventually follow the
# BLOCK_IO_ERROR event
#
@@ -1540,7 +1549,8 @@
##
{ 'event': 'BLOCK_IO_ERROR',
'data': { 'device': 'str', 'operation': 'IoOperationType',
- 'action': 'BlockErrorAction' } }
+ 'action': 'BlockErrorAction',
+ '__com.redhat_reason': 'RHEL7BlockErrorReason' } }
##
# @BLOCK_JOB_COMPLETED