提交 32c81a4a 编写于 作者: P Paolo Bonzini 提交者: Kevin Wolf

block: introduce block job error

The following behaviors are possible:

'report': The behavior is the same as in 1.1.  An I/O error,
respectively during a read or a write, will complete the job immediately
with an error code.

'ignore': An I/O error, respectively during a read or a write, will be
ignored.  For streaming, the job will complete with an error and the
backing file will be left in place.  For mirroring, the sector will be
marked again as dirty and re-examined later.

'stop': The job will be paused and the job iostatus will be set to
failed or nospace, while the VM will keep running.  This can only be
specified if the block device has rerror=stop and werror=stop or enospc.

'enospc': Behaves as 'stop' for ENOSPC errors, 'report' for others.

In all cases, even for 'report', the I/O error is reported as a QMP
event BLOCK_JOB_ERROR, with the same arguments as BLOCK_IO_ERROR.

It is possible that while stopping the VM a BLOCK_IO_ERROR event will be
reported and will clobber the event from BLOCK_JOB_ERROR, or vice versa.
This is not really avoidable since stopping the VM completes all pending
I/O requests.  In fact, it is already possible now that a series of
BLOCK_IO_ERROR events are reported with rerror=stop, because vm_stop
calls bdrv_drain_all and this can generate further errors.
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 3e1caa5f
...@@ -96,6 +96,28 @@ Example: ...@@ -96,6 +96,28 @@ Example:
"speed": 0 }, "speed": 0 },
"timestamp": { "seconds": 1267061043, "microseconds": 959568 } } "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 } }
DEVICE_TRAY_MOVED DEVICE_TRAY_MOVED
----------------- -----------------
......
...@@ -1387,7 +1387,8 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, ...@@ -1387,7 +1387,8 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
} }
} }
static void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv, void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
enum MonitorEvent ev,
BlockErrorAction action, bool is_read) BlockErrorAction action, bool is_read)
{ {
QObject *data; QObject *data;
...@@ -1411,7 +1412,7 @@ static void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv, ...@@ -1411,7 +1412,7 @@ static void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
bdrv->device_name, bdrv->device_name,
action_str, action_str,
is_read ? "read" : "write"); is_read ? "read" : "write");
monitor_protocol_event(QEVENT_BLOCK_IO_ERROR, data); monitor_protocol_event(ev, data);
qobject_decref(data); qobject_decref(data);
} }
...@@ -2513,7 +2514,7 @@ void bdrv_error_action(BlockDriverState *bs, BlockErrorAction action, ...@@ -2513,7 +2514,7 @@ void bdrv_error_action(BlockDriverState *bs, BlockErrorAction action,
bool is_read, int error) bool is_read, int error)
{ {
assert(error >= 0); assert(error >= 0);
bdrv_emit_qmp_error_event(bs, action, is_read); bdrv_emit_qmp_error_event(bs, QEVENT_BLOCK_IO_ERROR, action, is_read);
if (action == BDRV_ACTION_STOP) { if (action == BDRV_ACTION_STOP) {
vm_stop(RUN_STATE_IO_ERROR); vm_stop(RUN_STATE_IO_ERROR);
bdrv_iostatus_set_err(bs, error); bdrv_iostatus_set_err(bs, error);
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "qemu-timer.h" #include "qemu-timer.h"
#include "qapi-types.h" #include "qapi-types.h"
#include "qerror.h" #include "qerror.h"
#include "monitor.h"
#define BLOCK_FLAG_ENCRYPT 1 #define BLOCK_FLAG_ENCRYPT 1
#define BLOCK_FLAG_COMPAT6 4 #define BLOCK_FLAG_COMPAT6 4
...@@ -286,6 +287,9 @@ void bdrv_set_io_limits(BlockDriverState *bs, ...@@ -286,6 +287,9 @@ void bdrv_set_io_limits(BlockDriverState *bs,
#ifdef _WIN32 #ifdef _WIN32
int is_windows_drive(const char *filename); int is_windows_drive(const char *filename);
#endif #endif
void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
enum MonitorEvent ev,
BlockErrorAction action, bool is_read);
/** /**
* stream_start: * stream_start:
......
...@@ -112,6 +112,7 @@ bool block_job_is_paused(BlockJob *job) ...@@ -112,6 +112,7 @@ bool block_job_is_paused(BlockJob *job)
void block_job_resume(BlockJob *job) void block_job_resume(BlockJob *job)
{ {
job->paused = false; job->paused = false;
block_job_iostatus_reset(job);
if (job->co && !job->busy) { if (job->co && !job->busy) {
qemu_coroutine_enter(job->co, NULL); qemu_coroutine_enter(job->co, NULL);
} }
...@@ -128,6 +129,11 @@ bool block_job_is_cancelled(BlockJob *job) ...@@ -128,6 +129,11 @@ bool block_job_is_cancelled(BlockJob *job)
return job->cancelled; return job->cancelled;
} }
void block_job_iostatus_reset(BlockJob *job)
{
job->iostatus = BLOCK_DEVICE_IO_STATUS_OK;
}
struct BlockCancelData { struct BlockCancelData {
BlockJob *job; BlockJob *job;
BlockDriverCompletionFunc *cb; BlockDriverCompletionFunc *cb;
...@@ -196,5 +202,48 @@ BlockJobInfo *block_job_query(BlockJob *job) ...@@ -196,5 +202,48 @@ BlockJobInfo *block_job_query(BlockJob *job)
info->paused = job->paused; info->paused = job->paused;
info->offset = job->offset; info->offset = job->offset;
info->speed = job->speed; info->speed = job->speed;
info->io_status = job->iostatus;
return info; return info;
} }
static void block_job_iostatus_set_err(BlockJob *job, int error)
{
if (job->iostatus == BLOCK_DEVICE_IO_STATUS_OK) {
job->iostatus = error == ENOSPC ? BLOCK_DEVICE_IO_STATUS_NOSPACE :
BLOCK_DEVICE_IO_STATUS_FAILED;
}
}
BlockErrorAction block_job_error_action(BlockJob *job, BlockDriverState *bs,
BlockdevOnError on_err,
int is_read, int error)
{
BlockErrorAction action;
switch (on_err) {
case BLOCKDEV_ON_ERROR_ENOSPC:
action = (error == ENOSPC) ? BDRV_ACTION_STOP : BDRV_ACTION_REPORT;
break;
case BLOCKDEV_ON_ERROR_STOP:
action = BDRV_ACTION_STOP;
break;
case BLOCKDEV_ON_ERROR_REPORT:
action = BDRV_ACTION_REPORT;
break;
case BLOCKDEV_ON_ERROR_IGNORE:
action = BDRV_ACTION_IGNORE;
break;
default:
abort();
}
bdrv_emit_qmp_error_event(job->bs, QEVENT_BLOCK_JOB_ERROR, action, is_read);
if (action == BDRV_ACTION_STOP) {
block_job_pause(job);
block_job_iostatus_set_err(job, error);
if (bs != job->bs) {
bdrv_iostatus_set_err(bs, error);
}
}
return action;
}
...@@ -82,6 +82,9 @@ struct BlockJob { ...@@ -82,6 +82,9 @@ struct BlockJob {
*/ */
bool busy; bool busy;
/** Status that is published by the query-block-jobs QMP API */
BlockDeviceIoStatus iostatus;
/** Offset that is published by the query-block-jobs QMP API */ /** Offset that is published by the query-block-jobs QMP API */
int64_t offset; int64_t offset;
...@@ -215,4 +218,26 @@ bool block_job_is_paused(BlockJob *job); ...@@ -215,4 +218,26 @@ bool block_job_is_paused(BlockJob *job);
*/ */
int block_job_cancel_sync(BlockJob *job); int block_job_cancel_sync(BlockJob *job);
/**
* block_job_iostatus_reset:
* @job: The job whose I/O status should be reset.
*
* Reset I/O status on @job.
*/
void block_job_iostatus_reset(BlockJob *job);
/**
* block_job_error_action:
* @job: The job to signal an error for.
* @bs: The block device on which to set an I/O error.
* @on_err: The error action setting.
* @is_read: Whether the operation was a read.
* @error: The error that was reported.
*
* Report an I/O error for a block job and possibly stop the VM. Return the
* action that was selected based on @on_err and @error.
*/
BlockErrorAction block_job_error_action(BlockJob *job, BlockDriverState *bs,
BlockdevOnError on_err,
int is_read, int error);
#endif #endif
...@@ -450,6 +450,7 @@ static const char *monitor_event_names[] = { ...@@ -450,6 +450,7 @@ static const char *monitor_event_names[] = {
[QEVENT_SPICE_DISCONNECTED] = "SPICE_DISCONNECTED", [QEVENT_SPICE_DISCONNECTED] = "SPICE_DISCONNECTED",
[QEVENT_BLOCK_JOB_COMPLETED] = "BLOCK_JOB_COMPLETED", [QEVENT_BLOCK_JOB_COMPLETED] = "BLOCK_JOB_COMPLETED",
[QEVENT_BLOCK_JOB_CANCELLED] = "BLOCK_JOB_CANCELLED", [QEVENT_BLOCK_JOB_CANCELLED] = "BLOCK_JOB_CANCELLED",
[QEVENT_BLOCK_JOB_ERROR] = "BLOCK_JOB_ERROR",
[QEVENT_DEVICE_TRAY_MOVED] = "DEVICE_TRAY_MOVED", [QEVENT_DEVICE_TRAY_MOVED] = "DEVICE_TRAY_MOVED",
[QEVENT_SUSPEND] = "SUSPEND", [QEVENT_SUSPEND] = "SUSPEND",
[QEVENT_SUSPEND_DISK] = "SUSPEND_DISK", [QEVENT_SUSPEND_DISK] = "SUSPEND_DISK",
......
...@@ -38,6 +38,7 @@ typedef enum MonitorEvent { ...@@ -38,6 +38,7 @@ typedef enum MonitorEvent {
QEVENT_SPICE_DISCONNECTED, QEVENT_SPICE_DISCONNECTED,
QEVENT_BLOCK_JOB_COMPLETED, QEVENT_BLOCK_JOB_COMPLETED,
QEVENT_BLOCK_JOB_CANCELLED, QEVENT_BLOCK_JOB_CANCELLED,
QEVENT_BLOCK_JOB_ERROR,
QEVENT_DEVICE_TRAY_MOVED, QEVENT_DEVICE_TRAY_MOVED,
QEVENT_SUSPEND, QEVENT_SUSPEND,
QEVENT_SUSPEND_DISK, QEVENT_SUSPEND_DISK,
......
...@@ -1131,11 +1131,14 @@ ...@@ -1131,11 +1131,14 @@
# #
# @speed: the rate limit, bytes per second # @speed: the rate limit, bytes per second
# #
# @io-status: the status of the job (since 1.3)
#
# Since: 1.1 # Since: 1.1
## ##
{ 'type': 'BlockJobInfo', { 'type': 'BlockJobInfo',
'data': {'type': 'str', 'device': 'str', 'len': 'int', 'data': {'type': 'str', 'device': 'str', 'len': 'int',
'offset': 'int', 'busy': 'bool', 'paused': 'bool', 'speed': 'int'} } 'offset': 'int', 'busy': 'bool', 'paused': 'bool', 'speed': 'int',
'io-status': 'BlockDeviceIoStatus'} }
## ##
# @query-block-jobs: # @query-block-jobs:
...@@ -1958,6 +1961,8 @@ ...@@ -1958,6 +1961,8 @@
# operation. It is an error to call this command if no operation is in # operation. It is an error to call this command if no operation is in
# progress. Resuming an already running job is not an error. # progress. Resuming an already running job is not an error.
# #
# This command also clears the error status of the job.
#
# @device: the device name # @device: the device name
# #
# Returns: Nothing on success # Returns: Nothing on success
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册