qapi: generalize documentation of streaming commands

Talk about background operations in general, rather than specifically
about streaming.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qerror/block: introduce QERR_BLOCK_JOB_NOT_ACTIVE

The DeviceNotActive error is not a particularly good match, add
a separate one.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: fix documentation of block_job_cancel_sync

Do this in a separate commit before we move the functions to
blockjob.h.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: move job APIs to separate files

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: add block_job_query

Extract it out of the implementation of info block-jobs.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: add support for job pause/resume

Job pausing reuses the existing support for cancellable sleeps.  A pause
happens at the next sleeping point and lasts until the coroutine is
re-entered explicitly.  Cancellation was already doing a forced resume,
so implement it explicitly in terms of resume.

Paused jobs cannot be canceled without first resuming them.  This ensures
that I/O errors are never missed by management.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qmp: add block-job-pause and block-job-resume

Add QMP commands matching the functionality.

Paused jobs cannot be canceled without first resuming them.  This
ensures that I/O errors are never missed by management.  However, an
optional force argument can be specified to allow that.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-iotests: add test for pausing a streaming operation

These check that a paused streaming job does not advance its offset.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: rename block_job_complete to block_job_completed

The imperative will be used for the QMP command.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
iostatus: rename BlockErrorAction, BlockQMPEventAction

We want to remove knowledge of BLOCK_ERR_STOP_ENOSPC from drivers, so
free up the nicer BlockErrorAction name for them.  Do not change the
enums.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
iostatus: move BlockdevOnError declaration to QAPI

This will let block-stream reuse the enum.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
iostatus: change is_read to a bool

Do this while we are touching this part of the code, before introducing
more uses of "int is_read".

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
iostatus: reorganize io error code

Move the common part of IDE/SCSI/virtio error handling to the block
layer.  The same scheme will be used for errors in block jobs.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
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.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
stream: add on-error argument

This patch adds support for error management to streaming.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
blkdebug: process all set_state rules in the old state

Currently it is impossible to write a blkdebug script that ping-pongs
between two states, because the second set-state rule will use the
state that is set in the first.  If you have

    [set-state]
    event = "..."
    state = "1"
    new_state = "2"

    [set-state]
    event = "..."
    state = "2"
    new_state = "1"

for example the state will remain locked at 1.  This can be fixed
by first processing all rules, and then setting the state.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-iotests: map underscore to dash in QMP argument names

iotests.py provides a convenience function that uses Python keyword
arguments to represent QMP command arguments.  However, almost all
QMP commands use dashes for argument names (the sole exception is
block_set_io_throttle), and dashes are not allowed in a keyword
argument name.  Hence provide automatic conversion of underscores
to dashes.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-iotests: add tests for streaming error handling

Add a test for each of report/ignore/stop.  The tests use blkdebug
to generate an error in the middle of a script.  The error is
recoverable (once = "on") so that we can test resuming a job after
stopping for an error.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: live snapshot documentation tweaks

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: add bdrv_query_info

Extract it out of the implementation of "info block".

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>