diff --git a/block.c b/block.c index 43abe96db6..ff44e76c87 100644 --- a/block.c +++ b/block.c @@ -3626,10 +3626,27 @@ void bdrv_error_action(BlockDriverState *bs, BlockErrorAction action, bool is_read, int error) { assert(error >= 0); - bdrv_emit_qmp_error_event(bs, QEVENT_BLOCK_IO_ERROR, action, is_read); + if (action == BDRV_ACTION_STOP) { - vm_stop(RUN_STATE_IO_ERROR); + /* First set the iostatus, so that "info block" returns an iostatus + * that matches the events raised so far (an additional error iostatus + * is fine, but not a lost one). + */ bdrv_iostatus_set_err(bs, error); + + /* Then raise the request to stop the VM and the event. + * qemu_system_vmstop_request_prepare has two effects. First, + * it ensures that the STOP event always comes after the + * BLOCK_IO_ERROR event. Second, it ensures that even if management + * can observe the STOP event and do a "cont" before the STOP + * event is issued, the VM will not stop. In this case, vm_start() + * 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); + qemu_system_vmstop_request(RUN_STATE_IO_ERROR); + } else { + bdrv_emit_qmp_error_event(bs, QEVENT_BLOCK_IO_ERROR, action, is_read); } } diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt index 019db53ec8..22fea580a9 100644 --- a/docs/qmp/qmp-events.txt +++ b/docs/qmp/qmp-events.txt @@ -62,7 +62,7 @@ Data: - "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": error caused VM to be stopped + "stop": the VM is going to stop because of the error Example: diff --git a/stubs/vm-stop.c b/stubs/vm-stop.c index f82c897dfe..69fd86b2e8 100644 --- a/stubs/vm-stop.c +++ b/stubs/vm-stop.c @@ -1,7 +1,12 @@ #include "qemu-common.h" #include "sysemu/sysemu.h" -int vm_stop(RunState state) +void qemu_system_vmstop_request_prepare(void) +{ + abort(); +} + +void qemu_system_vmstop_request(RunState state) { abort(); }