Skip to content

Commit

Permalink
qapi event: convert BLOCK_IO_ERROR and BLOCK_JOB_ERROR
Browse files Browse the repository at this point in the history
Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
  • Loading branch information
Wenchao Xia authored and Luiz Capitulino committed Jun 23, 2014
1 parent a5ee7bd commit 5a2d2cb
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 84 deletions.
41 changes: 8 additions & 33 deletions block.c
Expand Up @@ -24,7 +24,6 @@
#include "config-host.h"
#include "qemu-common.h"
#include "trace.h"
#include "monitor/monitor.h"
#include "block/block_int.h"
#include "block/blockjob.h"
#include "qemu/module.h"
Expand Down Expand Up @@ -2133,36 +2132,6 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
bs->dev_opaque = opaque;
}

void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
enum MonitorEvent ev,
BlockErrorAction action, bool is_read)
{
QObject *data;
const char *action_str;

switch (action) {
case BLOCK_ERROR_ACTION_REPORT:
action_str = "report";
break;
case BLOCK_ERROR_ACTION_IGNORE:
action_str = "ignore";
break;
case BLOCK_ERROR_ACTION_STOP:
action_str = "stop";
break;
default:
abort();
}

data = qobject_from_jsonf("{ 'device': %s, 'action': %s, 'operation': %s }",
bdrv->device_name,
action_str,
is_read ? "read" : "write");
monitor_protocol_event(ev, data);

qobject_decref(data);
}

static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load)
{
if (bs->dev_ops && bs->dev_ops->change_media_cb) {
Expand Down Expand Up @@ -3636,10 +3605,16 @@ void bdrv_error_action(BlockDriverState *bs, BlockErrorAction action,
* also ensures that the STOP/RESUME pair of events is emitted.
*/
qemu_system_vmstop_request_prepare();
bdrv_emit_qmp_error_event(bs, QEVENT_BLOCK_IO_ERROR, action, is_read);
qapi_event_send_block_io_error(bdrv_get_device_name(bs),
is_read ? IO_OPERATION_TYPE_READ :
IO_OPERATION_TYPE_WRITE,
action, &error_abort);
qemu_system_vmstop_request(RUN_STATE_IO_ERROR);
} else {
bdrv_emit_qmp_error_event(bs, QEVENT_BLOCK_IO_ERROR, action, is_read);
qapi_event_send_block_io_error(bdrv_get_device_name(bs),
is_read ? IO_OPERATION_TYPE_READ :
IO_OPERATION_TYPE_WRITE,
action, &error_abort);
}
}

Expand Down
6 changes: 5 additions & 1 deletion blockjob.c
Expand Up @@ -34,6 +34,7 @@
#include "block/coroutine.h"
#include "qmp-commands.h"
#include "qemu/timer.h"
#include "qapi-event.h"

void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
int64_t speed, BlockDriverCompletionFunc *cb,
Expand Down Expand Up @@ -277,7 +278,10 @@ BlockErrorAction block_job_error_action(BlockJob *job, BlockDriverState *bs,
default:
abort();
}
bdrv_emit_qmp_error_event(job->bs, QEVENT_BLOCK_JOB_ERROR, action, is_read);
qapi_event_send_block_job_error(bdrv_get_device_name(bs),
is_read ? IO_OPERATION_TYPE_READ :
IO_OPERATION_TYPE_WRITE,
action, &error_abort);
if (action == BLOCK_ERROR_ACTION_STOP) {
block_job_pause(job);
block_job_iostatus_set_err(job, error);
Expand Down
47 changes: 0 additions & 47 deletions docs/qmp/qmp-events.txt
Expand Up @@ -50,31 +50,6 @@ Example:
"size": 65536 },
"timestamp": { "seconds": 1378126126, "microseconds": 966463 } }

BLOCK_IO_ERROR
--------------

Emitted when a disk I/O error occurs.

Data:

- "device": device name (json-string)
- "operation": I/O operation (json-string, "read" or "write")
- "action": action that has been taken, it's one of the following (json-string):
"ignore": error has been ignored
"report": error has been reported to the device
"stop": the VM is going to stop because of the error

Example:

{ "event": "BLOCK_IO_ERROR",
"data": { "device": "ide0-hd1",
"operation": "write",
"action": "stop" },
"timestamp": { "seconds": 1265044230, "microseconds": 450486 } }

Note: If action is "stop", a STOP event will eventually follow the
BLOCK_IO_ERROR event.

BLOCK_JOB_CANCELLED
-------------------

Expand Down Expand Up @@ -128,28 +103,6 @@ Example:
"speed": 0 },
"timestamp": { "seconds": 1267061043, "microseconds": 959568 } }

BLOCK_JOB_ERROR
---------------

Emitted when a block job encounters an error.

Data:

- "device": device name (json-string)
- "operation": I/O operation (json-string, "read" or "write")
- "action": action that has been taken, it's one of the following (json-string):
"ignore": error has been ignored, the job may fail later
"report": error will be reported and the job canceled
"stop": error caused job to be paused

Example:

{ "event": "BLOCK_JOB_ERROR",
"data": { "device": "ide0-hd1",
"operation": "write",
"action": "stop" },
"timestamp": { "seconds": 1265044230, "microseconds": 450486 } }

BLOCK_JOB_READY
---------------

Expand Down
3 changes: 0 additions & 3 deletions include/block/block_int.h
Expand Up @@ -425,9 +425,6 @@ void bdrv_attach_aio_context(BlockDriverState *bs,
#ifdef _WIN32
int is_windows_drive(const char *filename);
#endif
void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
enum MonitorEvent ev,
BlockErrorAction action, bool is_read);

/**
* stream_start:
Expand Down
14 changes: 14 additions & 0 deletions qapi-schema.json
Expand Up @@ -3371,4 +3371,18 @@
{ 'enum': 'WatchdogExpirationAction',
'data': [ 'reset', 'shutdown', 'poweroff', 'pause', 'debug', 'none' ] }

##
# @IoOperationType
#
# An enumeration of the I/O operation types
#
# @read: read operation
#
# @write: write operation
#
# Since: 2.1
##
{ 'enum': 'IoOperationType',
'data': [ 'read', 'write' ] }

{ 'include': 'qapi-event.json' }
39 changes: 39 additions & 0 deletions qapi/block-core.json
Expand Up @@ -1426,3 +1426,42 @@
##
{ 'enum': 'BlockErrorAction',
'data': [ 'ignore', 'report', 'stop' ] }


##
# @BLOCK_IO_ERROR
#
# Emitted when a disk I/O error occurs
#
# @device: device name
#
# @operation: I/O operation
#
# @action: action that has been taken
#
# Note: If action is "stop", a STOP event will eventually follow the
# BLOCK_IO_ERROR event
#
# Since: 0.13.0
##
{ 'event': 'BLOCK_IO_ERROR',
'data': { 'device': 'str', 'operation': 'IoOperationType',
'action': 'BlockErrorAction' } }

##
# @BLOCK_JOB_ERROR
#
# Emitted when a block job encounters an error
#
# @device: device name
#
# @operation: I/O operation
#
# @action: action that has been taken
#
# Since: 1.3
##
{ 'event': 'BLOCK_JOB_ERROR',
'data': { 'device' : 'str',
'operation': 'IoOperationType',
'action' : 'BlockdevOnError' } }

0 comments on commit 5a2d2cb

Please sign in to comment.