Block patches
Subsystems (2)
The following changes since commit 6f8fd2530e9a530f237240daf1c981fa5df7f978:
Merge branch 'arm-devs.for-upstream' of git://git.linaro.org/people/pmaydell/qemu-arm (2012-09-27 21:48:56 +0200)
are available in the git repository at:
git://repo.or.cz/qemu/kevin.git for-anthony
Bharata B Rao (2):
configure: Add a config option for GlusterFS as block backend
block: Support GlusterFS as a QEMU block backend.
Jeff Cody (7):
block: after creating a live snapshot, make old image read-only
block: add support functions for live commit, to find and delete images.
block: add live block commit functionality
blockdev: rename block_stream_cb to a generic block_job_cb
block: helper function, to find the base image of a chain
QAPI: add command for live block commit, 'block-commit'
qemu-iotests: add initial tests for live block commit
Kevin Wolf (1):
block-migration: Flush requests in blk_mig_cleanup
Paolo Bonzini (20):
aio: Fix qemu_aio_wait() to maintain correct walking_handlers count
qemu: URI parsing library
aio: Another fix to the walking_handlers logic qerror/block: introduce QERR_BLOCK_JOB_NOT_ACTIVE
block: fix documentation of block_job_cancel_sync
block: move job APIs to separate files
block: add block_job_query
qmp: add 'busy' member to BlockJobInfo
block: add support for job pause/resume
qmp: add block-job-pause and block-job-resume
qemu-iotests: add test for pausing a streaming operation
iostatus: rename BlockErrorAction, BlockQMPEventAction
iostatus: move BlockdevOnError declaration to QAPI
iostatus: change is_read to a bool
iostatus: reorganize io error code
block: introduce block job error
stream: add on-error argument
blkdebug: process all set_state rules in the old state
qemu-iotests: map underscore to dash in QMP argument names
qemu-iotests: add tests for streaming error handling
Makefile.objs | 5 +- QMP/qmp-events.txt | 28 +- aio.c | 14 +- block-migration.c | 2 + block.c | 346 ++++--- block.h | 25 +- block/Makefile.objs | 5 +- block/blkdebug.c | 12 +- block/commit.c | 268 +++++ block/gluster.c | 624 ++++++++++++ block/stream.c | 29 +- block_int.h | 178 +--- blockdev.c | 149 +++- blockjob.c | 249 +++++ blockjob.h | 243 +++++ configure | 35 + hmp-commands.hx | 35 +- hmp.c | 26 +- hmp.h | 2 + hw/fdc.c | 4 +- hw/ide/core.c | 22 +- hw/ide/pci.c | 4 +- hw/scsi-disk.c | 25 +- hw/scsi-generic.c | 4 +- hw/virtio-blk.c | 23 +- monitor.c | 1 + monitor.h | 1 + qapi-schema.json | 125 +++- qemu-tool.c | 6 + qerror.h | 6 + qmp-commands.hx | 20 +- tests/qemu-iotests/030 | 260 +++++- tests/qemu-iotests/030.out | 4 +- tests/qemu-iotests/040 | 178 ++++ tests/qemu-iotests/040.out | 5 + tests/qemu-iotests/group | 3 +- tests/qemu-iotests/iotests.py | 15 +- trace-events | 6 +- uri.c | 2249 +++++++++++++++++++++++++++++++++++++++++ uri.h | 113 ++ 40 files changed, 4923 insertions(+), 426 deletions(-) create mode 100644 block/commit.c create mode 100644 block/gluster.c create mode 100644 blockjob.c create mode 100644 blockjob.h create mode 100755 tests/qemu-iotests/040 create mode 100644 tests/qemu-iotests/040.out create mode 100644 uri.c create mode 100644 uri.h
PATCH 1/30 block-migration: Flush requests in blk_mig_cleanup
When cancelling block migration, all in-flight requests of the block migration must be completed before the data can be freed. This was visible as failing assertions and segfaults.
--- block-migration.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
block-migration.c +2 -0
@@ -519,6 +519,8 @@ static void blk_mig_cleanup(void)BlkMigDevState *bmds;BlkMigBlock *blk; +bdrv_drain_all (); +set_dirty_tracking (0 );while ((bmds =QSIMPLEQ_FIRST (&block_mig_state.bmds_list)) !=NULL ) {
Signature · 1 line
1.7.6.5
PATCH 2/30 block: after creating a live snapshot, make old image read-only
In reply to Kevin WolfFrom: Jeff Cody <[email protected]>
Currently, after a live snapshot of a drive, the image that has been 'demoted' to be below the new active layer remains r/w. This patch reopens it read-only.
Note that we do not check for error on the reopen(), because we will not abort the snapshots if the reopen fails.
This patch depends on the bdrv_reopen() series.
--- blockdev.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
blockdev.c +5 -0
@@ -805,6 +805,11 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp) QSIMPLEQ_FOREACH(states, &snap_bdrv_states, entry) {/* This removes our old bs from the bdrv_states, and adds the new bs */ bdrv_append (states->new_bs, states->old_bs); +/* We don't need (or want) to use the transactional +* bdrv_reopen_multiple() across all the entries at once, because we +* don't want to abort all of them if one of them fails the reopen */ +bdrv_reopen (states->new_bs, states->new_bs->open_flags & ~BDRV_O_RDWR , +NULL ); }/* success */
Signature · 1 line
1.7.6.5
PATCH 3/30 aio: Fix qemu_aio_wait() to maintain correct walking_handlers count
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
Fix qemu_aio_wait() to ensure that registered aio handlers don't get deleted when they are still active. This is ensured by maintaning the right count of walking_handlers.
--- aio.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
aio.c +4 -4
@@ -119,7 +119,7 @@ bool qemu_aio_wait(void)return true; } - walking_handlers =1 ; + walking_handlers++;FD_ZERO (&rdfds);FD_ZERO (&wrfds);
@@ -147,7 +147,7 @@ bool qemu_aio_wait(void) } } - walking_handlers =0 ; + walking_handlers--;/* No AIO operations? Get us out of here */ if (!busy) {
@@ -159,7 +159,7 @@ bool qemu_aio_wait(void)/* if we have any readable fds, dispatch event */ if (ret >0 ) { - walking_handlers =1 ; + walking_handlers++;/* we have to walk very carefully in case * qemu_aio_set_fd_handler is called while we're walking */
@@ -187,7 +187,7 @@ bool qemu_aio_wait(void) } } - walking_handlers =0 ; + walking_handlers--; }return true;
Signature · 1 line
1.7.6.5
PATCH 4/30 qemu: URI parsing library
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
Add a new URI parsing library to QEMU. The code has been borrowed from libxml2 and libvirt.
--- Makefile.objs | 2 +- uri.c | 2249 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ uri.h | 113 +++ 3 files changed, 2363 insertions(+), 1 deletions(-) create mode 100644 uri.c create mode 100644 uri.h
Makefile.objs +1 -1
@@ -42,7 +42,7 @@ coroutine-obj-$(CONFIG_WIN32) += coroutine-win32.o # block-obj-y is code used by both qemu system emulation and qemu-img block-obj-y = cutils.o iov.o cache-utils.o qemu-option.o module.o async.o -block-obj-y += nbd.o block.o aio.o aes.o qemu-config.o qemu-progress.o qemu-sockets.o +block-obj-y += nbd.o block.o aio.o aes.o qemu-config.o qemu-progress.o qemu-sockets.o uri.o block-obj-y += $(coroutine-obj-y) $(qobject-obj-y) $(version-obj-y) block-obj-$(CONFIG_POSIX) += posix-aio-compat.o block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
uri.c new file +2249 -0
2,249 lines not on this page · raw message
uri.h new file +113 -0
113 lines not on this page · raw message
Signature · 1 line
1.7.6.5
PATCH 5/30 aio: Another fix to the walking_handlers logic
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
The AIO dispatch loop will call QLIST_REMOVE and g_free even if there are other pending calls to qemu_aio_wait outside the current one.
--- aio.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
aio.c +5 -5
@@ -159,14 +159,14 @@ bool qemu_aio_wait(void)/* if we have any readable fds, dispatch event */ if (ret >0 ) { - walking_handlers++; -/* we have to walk very carefully in case * qemu_aio_set_fd_handler is called while we're walking */ node =QLIST_FIRST (&aio_handlers);while (node) {AioHandler *tmp; + walking_handlers++; +if (!node->deleted &&FD_ISSET (node->fd, &rdfds) && node->io_read) {
@@ -181,13 +181,13 @@ bool qemu_aio_wait(void) tmp = node; node =QLIST_NEXT (node, node); -if (tmp->deleted) { + walking_handlers--; + +if (!walking_handlers && tmp->deleted) {QLIST_REMOVE (tmp, node);g_free (tmp); } } - - walking_handlers--; }return true;
Signature · 1 line
1.7.6.5
PATCH 6/30 configure: Add a config option for GlusterFS as block backend
In reply to Kevin WolfFrom: Bharata B Rao <[email protected]>
GlusterFS support in QEMU depends on libgfapi, libgfrpc and libgfxdr provided by GlusterFS.
--- configure | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-)
configure +35 -0
@@ -219,6 +219,7 @@ want_tools="yes" libiscsi="" coroutine="" seccomp="" +glusterfs="" # parse CC options first for opt do
@@ -856,6 +857,10 @@ for opt do ;; --disable-seccomp) seccomp="no" ;; + --disable-glusterfs) glusterfs="no" + ;; + --enable-glusterfs) glusterfs="yes" + ;; *) echo "ERROR: unknown option $opt"; show_help="yes" ;; esac
@@ -1128,6 +1133,8 @@ echo " --disable-seccomp disable seccomp support" echo " --enable-seccomp enables seccomp support" echo " --with-coroutine=BACKEND coroutine backend. Supported options:" echo " gthread, ucontext, sigaltstack, windows" +echo " --enable-glusterfs enable GlusterFS backend" +echo " --disable-glusterfs disable GlusterFS backend" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1
@@ -2303,6 +2310,29 @@ EOF fi fi +########################################## +# glusterfs probe +if test "$glusterfs" != "no" ; then + cat > $TMPC <<EOF +#include <glusterfs/api/glfs.h> +int main(void) { + (void) glfs_new("volume"); + return 0; +} +EOF + glusterfs_libs="-lgfapi -lgfrpc -lgfxdr" + if compile_prog "" "$glusterfs_libs" ; then + glusterfs=yes + libs_tools="$glusterfs_libs $libs_tools" + libs_softmmu="$glusterfs_libs $libs_softmmu" + else + if test "$glusterfs" = "yes" ; then + feature_not_found "GlusterFS backend support" + fi + glusterfs=no + fi +fi + # # Check for xxxat() functions when we are building linux-user # emulator. This is done because older glibc versions don't
@@ -3170,6 +3200,7 @@ echo "libiscsi support $libiscsi" echo "build guest agent $guest_agent" echo "seccomp support $seccomp" echo "coroutine backend $coroutine_backend" +echo "GlusterFS support $glusterfs" if test "$sdl_too_old" = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -3516,6 +3547,10 @@ if test "$has_environ" = "yes" ; then echo "CONFIG_HAS_ENVIRON=y" >> $config_host_mak fi +if test "$glusterfs" = "yes" ; then + echo "CONFIG_GLUSTERFS=y" >> $config_host_mak +fi + # USB host support case "$usb" in linux)
Signature · 1 line
1.7.6.5
PATCH 7/30 block: Support GlusterFS as a QEMU block backend.
In reply to Kevin WolfFrom: Bharata B Rao <[email protected]>
This patch adds gluster as the new block backend in QEMU. This gives QEMU the ability to boot VM images from gluster volumes. Its already possible to boot from VM images on gluster volumes using FUSE mount, but this patchset provides the ability to boot VM images from gluster volumes by by-passing the FUSE layer in gluster. This is made possible by using libgfapi routines to perform IO on gluster volumes directly.
VM Image on gluster volume is specified like this:
file=gluster[+transport]://[server[:port]]/volname/image[?socket=...]
'gluster' is the protocol.
'transport' specifies the transport type used to connect to gluster management daemon (glusterd). Valid transport types are tcp, unix and rdma. If a transport type isn't specified, then tcp type is assumed.
'server' specifies the server where the volume file specification for the given volume resides. This can be either hostname, ipv4 address or ipv6 address. ipv6 address needs to be within square brackets [ ]. If transport type is 'unix', then 'server' field should not be specifed. The 'socket' field needs to be populated with the path to unix domain socket.
'port' is the port number on which glusterd is listening. This is optional and if not specified, QEMU will send 0 which will make gluster to use the default port. If the transport type is unix, then 'port' should not be specified.
'volname' is the name of the gluster volume which contains the VM image.
'image' is the path to the actual VM image that resides on gluster volume.
Examples:
file=gluster://1.2.3.4/testvol/a.img file=gluster+tcp://1.2.3.4/testvol/a.img file=gluster+tcp://1.2.3.4:24007/testvol/dir/a.img file=gluster+tcp://[1:2:3:4:5:6:7:8]/testvol/dir/a.img file=gluster+tcp://[1:2:3:4:5:6:7:8]:24007/testvol/dir/a.img file=gluster+tcp://server.domain.com:24007/testvol/dir/a.img file=gluster+unix:///testvol/dir/a.img?socket=/tmp/glusterd.socket file=gluster+rdma://1.2.3.4:24007/testvol/a.img
--- block/Makefile.objs | 1 + block/gluster.c | 624 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 625 insertions(+), 0 deletions(-) create mode 100644 block/gluster.c
block/Makefile.objs +1 -0
@@ -9,3 +9,4 @@ block-obj-$(CONFIG_POSIX) += raw-posix.o block-obj-$(CONFIG_LIBISCSI) += iscsi.o block-obj-$(CONFIG_CURL) += curl.o block-obj-$(CONFIG_RBD) += rbd.o +block-obj-$(CONFIG_GLUSTERFS) += gluster.o
block/gluster.c new file +624 -0
624 lines not on this page · raw message
Signature · 1 line
1.7.6.5
PATCH 8/30 block: add support functions for live commit, to find and delete images.
In reply to Kevin WolfFrom: Jeff Cody <[email protected]>
Add bdrv_find_overlay(), and bdrv_drop_intermediate().
bdrv_find_overlay(): given 'bs' and the active (topmost) BDS of an image chain,
find the image that is the immediate top of 'bs'
bdrv_drop_intermediate():
Given 3 BDS (active, top, base), drop images above base up to and including top, and set base to be the backing file of top's overlay node.
E.g., this converts:
bottom <- base <- intermediate <- top <- active
to
bottom <- base <- active
--- block.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ block.h | 4 ++ 2 files changed, 147 insertions(+), 0 deletions(-)
block.c +143 -0
@@ -1724,6 +1724,149 @@ int bdrv_change_backing_file(BlockDriverState *bs,return ret; } +/* +* Finds the image layer in the chain that has 'bs' as its backing file. +* +* active is the current topmost image. +* +* Returns NULL if bs is not found in active's image chain, +* or if active == bs. +*/ +BlockDriverState *bdrv_find_overlay (BlockDriverState *active, +BlockDriverState *bs) +{ +BlockDriverState *overlay =NULL ; +BlockDriverState *intermediate; + +assert (active !=NULL ); +assert (bs !=NULL ); + +/* if bs is the same as active, then by definition it has no overlay +*/ +if (active == bs) { +return NULL ; + } + + intermediate = active; +while (intermediate->backing_hd) { +if (intermediate->backing_hd == bs) { + overlay = intermediate; +break ; + } + intermediate = intermediate->backing_hd; + } + +return overlay; +} + +typedef struct BlkIntermediateStates { +BlockDriverState *bs; +QSIMPLEQ_ENTRY (BlkIntermediateStates) entry; +}BlkIntermediateStates ; + + +/* +* Drops images above 'base' up to and including 'top', and sets the image +* above 'top' to have base as its backing file. +* +* Requires that the overlay to 'top' is opened r/w, so that the backing file +* information in 'bs' can be properly updated. +* +* E.g., this will convert the following chain: +* bottom <- base <- intermediate <- top <- active +* +* to +* +* bottom <- base <- active +* +* It is allowed for bottom==base, in which case it converts: +* +* base <- intermediate <- top <- active +* +* to +* +* base <- active +* +* Error conditions: +* if active == top, that is considered an error +* +*/ +int bdrv_drop_intermediate (BlockDriverState *active,BlockDriverState *top, +BlockDriverState *base) +{ +BlockDriverState *intermediate; +BlockDriverState *base_bs =NULL ; +BlockDriverState *new_top_bs =NULL ; +BlkIntermediateStates *intermediate_state, *next; +int ret = -EIO ; + + QSIMPLEQ_HEAD(states_to_delete, BlkIntermediateStates) states_to_delete; +QSIMPLEQ_INIT (&states_to_delete); + +if (!top->drv || !base->drv) { + goto exit; + } + + new_top_bs =bdrv_find_overlay (active, top); + +if (new_top_bs ==NULL ) { +/* we could not find the image above 'top', this is an error */ + goto exit; + } + +/* special case of new_top_bs->backing_hd already pointing to base - nothing +* to do, no intermediate images */ +if (new_top_bs->backing_hd == base) { + ret =0 ; + goto exit; + } + + intermediate = top; + +/* now we will go down through the list, and add each BDS we find +* into our deletion queue, until we hit the 'base' +*/ +while (intermediate) { + intermediate_state =g_malloc0 (sizeof (BlkIntermediateStates)); + intermediate_state->bs = intermediate; +QSIMPLEQ_INSERT_TAIL (&states_to_delete, intermediate_state, entry); + +if (intermediate->backing_hd == base) { + base_bs = intermediate->backing_hd; +break ; + } + intermediate = intermediate->backing_hd; + } +if (base_bs ==NULL ) { +/* something went wrong, we did not end at the base. safely +* unravel everything, and exit with error */ + goto exit; + } + +/* success - we can delete the intermediate states, and link top->base */ + ret =bdrv_change_backing_file (new_top_bs, base_bs->filename, + base_bs->drv ? base_bs->drv->format_name :"" ); +if (ret) { + goto exit; + } + new_top_bs->backing_hd = base_bs; + + + QSIMPLEQ_FOREACH_SAFE(intermediate_state, &states_to_delete, entry, next) { +/* so that bdrv_close() does not recursively close the chain */ + intermediate_state->bs->backing_hd =NULL ; +bdrv_delete (intermediate_state->bs); + } + ret =0 ; + +exit: + QSIMPLEQ_FOREACH_SAFE(intermediate_state, &states_to_delete, entry, next) { +g_free (intermediate_state); + } +return ret; +} + +static int bdrv_check_byte_request (BlockDriverState *bs,int64_t offset,size_t size) {
block.h +4 -0
@@ -203,6 +203,10 @@ int bdrv_commit_all(void);int bdrv_change_backing_file (BlockDriverState *bs,const char *backing_file,const char *backing_fmt);void bdrv_register (BlockDriver *bdrv); +int bdrv_drop_intermediate (BlockDriverState *active,BlockDriverState *top, +BlockDriverState *base); +BlockDriverState *bdrv_find_overlay (BlockDriverState *active, +BlockDriverState *bs); typedef struct BdrvCheckResult {
Signature · 1 line
1.7.6.5
PATCH 9/30 block: add live block commit functionality
In reply to Kevin WolfFrom: Jeff Cody <[email protected]>
This adds the live commit coroutine. This iteration focuses on the commit only below the active layer, and not the active layer itself.
The behaviour is similar to block streaming; the sectors are walked through, and anything that exists above 'base' is committed back down into base. At the end, intermediate images are deleted, and the chain stitched together. Images are restored to their original open flags upon completion.
--- block/Makefile.objs | 1 + block/commit.c | 267 +++++++++++++++++++++++++++++++++++++++++++++++++++ block_int.h | 16 +++ trace-events | 2 + 4 files changed, 286 insertions(+), 0 deletions(-) create mode 100644 block/commit.c
block/Makefile.objs +1 -0
@@ -4,6 +4,7 @@ block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o block-obj-y += qed-check.o block-obj-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o block-obj-y += stream.o +block-obj-y += commit.o block-obj-$(CONFIG_WIN32) += raw-win32.o block-obj-$(CONFIG_POSIX) += raw-posix.o block-obj-$(CONFIG_LIBISCSI) += iscsi.o
block/commit.c new file +267 -0
267 lines not on this page · raw message
block_int.h +16 -0
@@ -463,4 +463,20 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base, BlockDriverCompletionFunc *cb, void *opaque, Error **errp); +/** +* commit_start: +* @bs: Top Block device +* @base: Block device that will be written into, and become the new top +* @speed: The maximum speed, in bytes per second, or 0 for unlimited. +* @on_error: The action to take upon error. +* @cb: Completion function for the job. +* @opaque: Opaque pointer value passed to @cb. +* @errp: Error object. +* +*/ +void commit_start (BlockDriverState *bs,BlockDriverState *base, +BlockDriverState *top,int64_t speed, +BlockErrorAction on_error,BlockDriverCompletionFunc *cb, +void *opaque,Error **errp); +#endif /* BLOCK_INT_H */
trace-events +2 -0
@@ -74,6 +74,8 @@ bdrv_co_do_copy_on_readv(void *bs, int64_t sector_num, int nb_sectors, int64_t c # block/stream.c stream_one_iteration(void *s, int64_t sector_num, int nb_sectors, int is_allocated) "s %p sector_num %"PRId64" nb_sectors %d is_allocated %d" stream_start(void *bs, void *base, void *s, void *co, void *opaque) "bs %p base %p s %p co %p opaque %p" +commit_one_iteration(void *s, int64_t sector_num, int nb_sectors, int is_allocated) "s %p sector_num %"PRId64" nb_sectors %d is_allocated %d" +commit_start(void *bs, void *base, void *top, void *s, void *co, void *opaque) "bs %p base %p top %p s %p co %p opaque %p" # blockdev.c qmp_block_job_cancel(void *job) "job %p"
Signature · 1 line
1.7.6.5
PATCH 10/30 blockdev: rename block_stream_cb to a generic block_job_cb
In reply to Kevin WolfFrom: Jeff Cody <[email protected]>
--- blockdev.c | 6 +++--- trace-events | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
blockdev.c +3 -3
@@ -1070,12 +1070,12 @@ static QObject *qobject_from_block_job(BlockJob *job) job->speed); } -static void block_stream_cb (void *opaque,int ret) +static void block_job_cb (void *opaque,int ret) {BlockDriverState *bs = opaque;QObject *obj; -trace_block_stream_cb (bs, bs->job, ret); +trace_block_job_cb (bs, bs->job, ret);assert (bs->job); obj =qobject_from_block_job (bs->job);
@@ -1117,7 +1117,7 @@ void qmp_block_stream(const char *device, bool has_base, }stream_start (bs, base_bs, base, has_speed ? speed :0 , - block_stream_cb, bs, &local_err); + block_job_cb, bs, &local_err);if (error_is_set (&local_err)) {error_propagate (errp, local_err);return ;
trace-events +1 -1
@@ -79,7 +79,7 @@ commit_start(void *bs, void *base, void *top, void *s, void *co, void *opaque) " # blockdev.c qmp_block_job_cancel(void *job) "job %p" -block_stream_cb(void *bs, void *job, int ret) "bs %p job %p ret %d" +block_job_cb(void *bs, void *job, int ret) "bs %p job %p ret %d" qmp_block_stream(void *bs, void *job) "bs %p job %p" # hw/virtio-blk.c
Signature · 1 line
1.7.6.5
PATCH 11/30 block: helper function, to find the base image of a chain
In reply to Kevin WolfFrom: Jeff Cody <[email protected]>
This is a simple helper function, that will return the base image of a given image chain.
--- block.c | 16 ++++++++++++++++ block.h | 1 + 2 files changed, 17 insertions(+), 0 deletions(-)
block.c +16 -0
@@ -3117,6 +3117,22 @@ int bdrv_get_backing_file_depth(BlockDriverState *bs)return 1 +bdrv_get_backing_file_depth (bs->backing_hd); } +BlockDriverState *bdrv_find_base (BlockDriverState *bs) +{ +BlockDriverState *curr_bs =NULL ; + +if (!bs) { +return NULL ; + } + + curr_bs = bs; + +while (curr_bs->backing_hd) { + curr_bs = curr_bs->backing_hd; + } +return curr_bs; +} +#define NB_SUFFIXES 4char *get_human_readable_size (char *buf,int buf_size,int64_t size)
block.h +1 -0
@@ -207,6 +207,7 @@ int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top, BlockDriverState *base);BlockDriverState *bdrv_find_overlay (BlockDriverState *active,BlockDriverState *bs); +BlockDriverState *bdrv_find_base (BlockDriverState *bs); typedef struct BdrvCheckResult {
Signature · 1 line
1.7.6.5
PATCH 12/30 QAPI: add command for live block commit, 'block-commit'
In reply to Kevin WolfFrom: Jeff Cody <[email protected]>
The command for live block commit is added, which has the following arguments:
device: the block device to perform the commit on (mandatory) base: the base image to commit into; optional (if not specified,
it is the underlying original image)
top: the top image of the commit - all data from inside top down
to base will be committed into base (mandatory for now; see note, below)
speed: maximum speed, in bytes/sec
Note: Eventually this command will support merging down the active layer,
but that code is not yet complete. If the active layer is passed in as top, then an error will be returned. Once merging down the active layer is supported, the 'top' argument may become optional, and default to the active layer.
The is done as a block job, so upon completion a BLOCK_JOB_COMPLETED will be emitted.
--- QMP/qmp-events.txt | 6 +++- blockdev.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ qapi-schema.json | 34 ++++++++++++++++++++++++++++++ qmp-commands.hx | 6 +++++ 4 files changed, 102 insertions(+), 2 deletions(-)
QMP/qmp-events.txt +4 -2
@@ -50,7 +50,8 @@ Emitted when a block job has been cancelled. Data: -- "type": Job type ("stream" for image streaming, json-string) +- "type": Job type (json-string; "stream" for image streaming + "commit" for block commit) - "device": Device name (json-string) - "len": Maximum progress value (json-int) - "offset": Current progress value (json-int)
@@ -73,7 +74,8 @@ Emitted when a block job has completed. Data: -- "type": Job type ("stream" for image streaming, json-string) +- "type": Job type (json-string; "stream" for image streaming + "commit" for block commit) - "device": Device name (json-string) - "len": Maximum progress value (json-int) - "offset": Current progress value (json-int)
blockdev.c +58 -0
64 lines not on this page · raw message
qapi-schema.json +34 -0
@@ -1468,6 +1468,40 @@ 'returns': 'str' } ## +# @block-commit +# +# Live commit of data from overlay image nodes into backing nodes - i.e., +# writes data between 'top' and 'base' into 'base'. +# +# @device: the name of the device +# +# @base: #optional The file name of the backing image to write data into. +# If not specified, this is the deepest backing image +# +# @top: The file name of the backing image within the image chain, +# which contains the topmost data to be committed down. +# Note, the active layer as 'top' is currently unsupported. +# +# If top == base, that is an error. +# +# +# @speed: #optional the maximum speed, in bytes per second +# +# Returns: Nothing on success +# If commit or stream is already active on this device, DeviceInUse +# If @device does not exist, DeviceNotFound +# If image commit is not supported by this device, NotSupported +# If @base or @top is invalid, a generic error is returned +# If @top is the active layer, or omitted, a generic error is returned +# If @speed is invalid, InvalidParameter +# +# Since: 1.3 +# +## +{ 'command': 'block-commit', + 'data': { 'device': 'str', '*base': 'str', 'top': 'str', + '*speed': 'int' } } + # @migrate_cancel # # Cancel the current executing migration process.
qmp-commands.hx +6 -0
@@ -792,6 +792,12 @@ EQMP }, { + .name = "block-commit", + .args_type = "device:B,base:s?,top:s,speed:o?", + .mhandler.cmd_new = qmp_marshal_input_block_commit, + }, + + { .name = "block-job-set-speed", .args_type = "device:B,speed:o", .mhandler.cmd_new = qmp_marshal_input_block_job_set_speed,
Signature · 1 line
1.7.6.5
Re: [Qemu-devel] [PATCH 12/30] QAPI: add command for live block commit, 'block-commit'
Quoted 11 lines · Kevin Wolf
From: Jeff Cody <[email protected]>
The command for live block commit is added, which has the following arguments:
device: the block device to perform the commit on (mandatory) base: the base image to commit into; optional (if not specified,it is the underlying original image)
top: the top image of the commit - all data from inside top down
to base will be committed into base (mandatory for now; see note, below)
We will need a followup patch, for this to work on chains with relative backing file names.
Quoted 9 lines
blockdev.c +9
-0+if (base && has_base) { + base_bs =bdrv_find_backing_image (bs, base); + }else { + base_bs =bdrv_find_base (bs); + } + +if (base_bs ==NULL ) { +error_set (errp,QERR_BASE_NOT_FOUND , base ? base :"NULL" ); +return ;
blockdev.c void qmp_block_stream(const char *device, bool has_base, · line 1173
Quoted 10 lines
blockdev.c +10
-0+ } + +/* default top_bs is the active layer */ + top_bs = bs; + +if (top) { +if (strcmp (bs->filename, top) !=0 ) { + top_bs =bdrv_find_backing_image (bs, top); + } + }
Right now, if I have 'base' <- 'snap1'(base) <- 'snap2'(snap1) <- 'active'(snap2), then base_bs and top_bs will be found, but later on in commit_start, we have:
Review
Quoted 9 lines
(quoted diff) +8
-0+ /* top and base may be valid, but let's make sure that base is reachable + * from top */ + if (bdrv_find_backing_image(top, base->filename) != base) { + error_setg(errp, + "Base (%s) is not reachable from top (%s)", + base->filename, top->filename); + return; + }
which uses the absolute file name base->filename and fails to find base, making it impossible to commit into a base file that was referenced via relative name in the chain. I think that bdrv_find_backing_image needs to canonicalize any relative name passed in on input relative to the directory of the bs where it is starting the search, and then search for absolute name matches rather than the current approach of searching for exact string matches (even if the exact string is a relative name).
Also, consider this case of mixed relative and absolute backing files in the chain:
/dir1/base <- /dir1/file1(base) <- /dir2/base(/dir1/file1) <- /dir2/file2(base)
The relative name 'base' appears twice in the chain, so you either have to declare it ambiguous, or else declare that relative names are canonicalized relative to the starting point (such that bdrv_find_backing_image(/dir1/file1, "base") gives a different result than bdrv_find_backing_image(/dir2/file2, "base"). Which means, if I request block-commit "top":"/dir1/file1", "base":"base", am I requesting a commit into /dir1/base (good) or into /dir2/base (swapped arguments)?
Fortunately, it looks like if I have 'base' <- 'snap1'(/path/to/base) <- 'snap2'(/path/to/snap1) <- 'active'(/path/to/snap2), then things work for committing snap2 into snap1, when I specify absolute file names for top and base. But here, it would be convenient if I could pass names relative to the location of active and have them canonicalized into absolute, so the same fix for relative chains will make absolute chains easier to use.
Sounds like we need more tests to cover these scenarios.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 12/30] QAPI: add command for live block commit, 'block-commit'
Quoted 15 lines · Eric Blake
which uses the absolute file name
base->filenameand fails to find base, making it impossible to commit into a base file that was referenced via relative name in the chain. I think thatbdrv_find_backing_imageneeds to canonicalize any relative name passed in on input relative to the directory of the bs where it is starting the search, and then search for absolute name matches rather than the current approach of searching for exact string matches (even if the exact string is a relative name).Also, consider this case of mixed relative and absolute backing files in the chain:
/dir1/base <- /dir1/file1(base) <- /dir2/base(/dir1/file1) <- /dir2/file2(base)
Quoted 7 lines
The relative name 'base' appears twice in the chain, so you either have to declare it ambiguous, or else declare that relative names are canonicalized relative to the starting point (such that
bdrv_find_backing_image(/dir1/file1, "base")gives a different result thanbdrv_find_backing_image(/dir2/file2, "base"). Which means, if I request block-commit "top":"/dir1/file1", "base":"base", am I requesting a commit into /dir1/base (good) or into /dir2/base (swapped arguments)?
Related question:
/dir/base <- /dir/snap1(base) <- /dir/active(/dir/snap1)
If I commit snap1 into base, should /dir/active encode the backing file as '/dir/base' (keep things absolute, since /dir/active had already been absolute) or as 'base' (relative, since the part of the chain previously referring to base was using relative). And if we store relative names, we need to make sure that the relative name stored in /dir/active correctly points to the correct file name, even if the ultimate base file lives in a different directory (similar problems exist with relative chains during block pull).
I'm wondering if this means 'block-stream' and 'block-commit' both need to add @mode:#optional arguments, similar to Paolo's 'drive-mirror' command [1], so that the user can request 'absolute-paths' vs. 'relative-paths' as the mode for which of two file names will be written as the backing file at the end of the operation.
[1] https://lists.gnu.org/archive/html/qemu-devel/2012-09/msg04592.html
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 12/30] QAPI: add command for live block commit, 'block-commit'
Il 05/10/2012 20:05, Eric Blake ha scritto:
Quoted 10 lines
If I commit snap1 into base, should /dir/active encode the backing file as '/dir/base' (keep things absolute, since /dir/active had already been absolute) or as 'base' (relative, since the part of the chain previously referring to base was using relative). And if we store relative names, we need to make sure that the relative name stored in /dir/active correctly points to the correct file name, even if the ultimate base file lives in a different directory (similar problems exist with relative chains during block pull).
Quoted 5 lines
I'm wondering if this means 'block-stream' and 'block-commit' both need to add @mode:#optional arguments, similar to Paolo's 'drive-mirror' command [1], so that the user can request 'absolute-paths' vs. 'relative-paths' as the mode for which of two file names will be written as the backing file at the end of the operation.
Yes, everything that calls bdrv_change_backing_file should have such a @mode argument. Good point!
Paolo
Quoted 1 line
[1] https://lists.gnu.org/archive/html/qemu-devel/2012-09/msg04592.html
Re: [Qemu-devel] [PATCH 12/30] QAPI: add command for live block commit, 'block-commit'
In reply to Kevin WolfQuoted 6 lines · Kevin Wolf
From: Jeff Cody <[email protected]>
The command for live block commit is added, which has the following arguments:
blockdev.c void qmp_block_stream(const char *device, bool has_base, · line 1173
Quoted 8 lines
blockdev.c +8
-0+/* default top_bs is the active layer */ + top_bs = bs; + +if (top) { +if (strcmp (bs->filename, top) !=0 ) { + top_bs =bdrv_find_backing_image (bs, top); + } + }
In light of Jeff's followup patches to fix bdrv_find_backing_image when dealing with relative file names, I see another bug here (but impact is limited to only a poor-quality error message, claiming that 'top was not found' instead of the intended 'commit of an active top is not supported'). That is, strcmp() on user-supplied 'top' is not guaranteed to succeed if the user provided a different spelling for the same file as was actually recorded in bs->filename, and since you have resorted to realpath() before strcmp() in bdrv_find_backing_image to cope with alternat user spellings, I think you also need to use realpath() before comparison here (probably a new helper function bdrv_is_equal() or some such name, that compares a user-supplied name with a bs). Saving this until a followup patch as part of your phase 2 series to add active image commit support is fine by me.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 13/30 qemu-iotests: add initial tests for live block commit
In reply to Kevin WolfFrom: Jeff Cody <[email protected]>
Derived from the streaming test cases (030), this adds the following 9 tests:
1. For the following image chain, commit [mid] into [backing], and use qemu-io to verify [backing] has its original data, as well as the data from [mid]
[backing] <-- [mid] <-- [test]
2. Verifies that 'block-commit' with the 'speed' parameter sets the speed parameter, as reported by 'query-block-jobs'
3. Verifies that a bogus 'device' parameter to 'block-commit' results in error
4-9: Appropriate error values returned for the following argument errors:
* top == base
* top is nonexistent
* base is nonexistent
* top == active layer (this is currently not supported)
* top and base arguments are reversed
* top argument is omitted
--- tests/qemu-iotests/040 | 178 ++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/040.out | 5 + tests/qemu-iotests/group | 1 + 3 files changed, 184 insertions(+), 0 deletions(-) create mode 100755 tests/qemu-iotests/040 create mode 100644 tests/qemu-iotests/040.out
tests/qemu-iotests/040 new file +178 -0
@@ -0,0 +1,178 @@ +#!/usr/bin/env python +# +# Tests for image block commit. +# +# Copyright (C) 2012 IBM, Corp. +# Copyright (C) 2012 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# Test for live block commit +# Derived from Image Streaming Test 030 + +import time +import os +import iotests +from iotests import qemu_img, qemu_io +import struct + +backing_img = os.path.join(iotests.test_dir, 'backing.img') +mid_img = os.path.join(iotests.test_dir, 'mid.img') +test_img = os.path.join(iotests.test_dir, 'test.img') + +class ImageCommitTestCase(iotests.QMPTestCase): + '''Abstract base class for image commit test cases''' + + def assert_no_active_commit(self): + result = self.vm.qmp('query-block-jobs') + self.assert_qmp(result, 'return', []) + + def cancel_and_wait(self, drive='drive0'): + '''Cancel a block job and wait for it to finish''' + result = self.vm.qmp('block-job-cancel', device=drive) + self.assert_qmp(result, 'return', {}) + + cancelled = False + while not cancelled: + for event in self.vm.get_qmp_events(wait=True): + if event['event'] == 'BLOCK_JOB_CANCELLED': + self.assert_qmp(event, 'data/type', 'commit') + self.assert_qmp(event, 'data/device', drive) + cancelled = True + + self.assert_no_active_commit() + + def create_image(self, name, size): + file = open(name, 'w') + i = 0 + while i < size: + sector = struct.pack('>l504xl', i / 512, i / 512) + file.write(sector) + i = i + 512 + file.close() + + +class TestSingleDrive(ImageCommitTestCase): + image_len = 1 * 1024 * 1024 + test_len = 1 * 1024 * 256 + + def setUp(self): + self.create_image(backing_img, TestSingleDrive.image_len) + qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, mid_img) + qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % mid_img, test_img) + qemu_io('-c', 'write -P 0xab 0 524288', backing_img) + qemu_io('-c', 'write -P 0xef 524288 524288', mid_img) + self.vm = iotests.VM().add_drive(test_img) + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + os.remove(test_img) + os.remove(mid_img) + os.remove(backing_img) + + def test_commit(self): + self.assert_no_active_commit() + result = self.vm.qmp('block-commit', device='drive0', top='%s' % mid_img) + self.assert_qmp(result, 'return', {}) + + completed = False + while not completed: + for event in self.vm.get_qmp_events(wait=True): + if event['event'] == 'BLOCK_JOB_COMPLETED': + self.assert_qmp(event, 'data/type', 'commit') + self.assert_qmp(event, 'data/device', 'drive0') + self.assert_qmp(event, 'data/offset', self.image_len) + self.assert_qmp(event, 'data/len', self.image_len) + completed = True + + self.assert_no_active_commit() + self.vm.shutdown() + + self.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', backing_img).find("verification failed")) + self.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed")) + + def test_device_not_found(self): + result = self.vm.qmp('block-commit', device='nonexistent', top='%s' % mid_img) + self.assert_qmp(result, 'error/class', 'DeviceNotFound') + + def test_top_same_base(self): + self.assert_no_active_commit() + result = self.vm.qmp('block-commit', device='drive0', top='%s' % backing_img, base='%s' % backing_img) + self.assert_qmp(result, 'error/class', 'GenericError') + self.assert_qmp(result, 'error/desc', 'Invalid files for merge: top and base are the same') + + def test_top_invalid(self): + self.assert_no_active_commit() + result = self.vm.qmp('block-commit', device='drive0', top='badfile', base='%s' % backing_img) + self.assert_qmp(result, 'error/class', 'GenericError') + self.assert_qmp(result, 'error/desc', 'Top image file badfile not found') + + def test_base_invalid(self): + self.assert_no_active_commit() + result = self.vm.qmp('block-commit', device='drive0', top='%s' % mid_img, base='badfile') + self.assert_qmp(result, 'error/class', 'GenericError') + self.assert_qmp(result, 'error/desc', 'Base \'badfile\' not found') + + def test_top_is_active(self): + self.assert_no_active_commit() + result = self.vm.qmp('block-commit', device='drive0', top='%s' % test_img, base='%s' % backing_img) + self.assert_qmp(result, 'error/class', 'GenericError') + self.assert_qmp(result, 'error/desc', 'Top image as the active layer is currently unsupported') + + def test_top_and_base_reversed(self): + self.assert_no_active_commit() + result = self.vm.qmp('block-commit', device='drive0', top='%s' % backing_img, base='%s' % mid_img) + self.assert_qmp(result, 'error/class', 'GenericError') + self.assert_qmp(result, 'error/desc', 'Base (%(1)s) is not reachable from top (%(2)s)' % {"1" : mid_img, "2" : backing_img}) + + def test_top_omitted(self): + self.assert_no_active_commit() + result = self.vm.qmp('block-commit', device='drive0') + self.assert_qmp(result, 'error/class', 'GenericError') + self.assert_qmp(result, 'error/desc', "Parameter 'top' is missing") + + +class TestSetSpeed(ImageCommitTestCase): + image_len = 80 * 1024 * 1024 # MB + + def setUp(self): + qemu_img('create', backing_img, str(TestSetSpeed.image_len)) + qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, mid_img) + qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % mid_img, test_img) + self.vm = iotests.VM().add_drive(test_img) + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + os.remove(test_img) + os.remove(mid_img) + os.remove(backing_img) + + def test_set_speed(self): + self.assert_no_active_commit() + + result = self.vm.qmp('block-commit', device='drive0', top=mid_img, speed=1024 * 1024) + self.assert_qmp(result, 'return', {}) + + # Ensure the speed we set was accepted + result = self.vm.qmp('query-block-jobs') + self.assert_qmp(result, 'return[0]/device', 'drive0') + self.assert_qmp(result, 'return[0]/speed', 1024 * 1024) + + self.cancel_and_wait() + + +if __name__ == '__main__': + iotests.main(supported_fmts=['qcow2', 'qed'])
tests/qemu-iotests/040.out new file +5 -0
@@ -0,0 +1,5 @@ +......... +---------------------------------------------------------------------- +Ran 9 tests + +OK
tests/qemu-iotests/group +1 -0
@@ -46,3 +46,4 @@ 037 rw auto backing 038 rw auto backing 039 rw auto +040 rw auto
Signature · 1 line
1.7.6.5
PATCH 14/30 qerror/block: introduce QERR_BLOCK_JOB_NOT_ACTIVE
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
The DeviceNotActive text is not a particularly good match, add a separate text while keeping the same class.
--- blockdev.c | 4 ++-- qerror.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)
blockdev.c +2 -2
@@ -1205,7 +1205,7 @@ void qmp_block_job_set_speed(const char *device, int64_t speed, Error **errp)BlockJob *job =find_block_job (device);if (!job) { -error_set (errp,QERR_DEVICE_NOT_ACTIVE , device); +error_set (errp,QERR_BLOCK_JOB_NOT_ACTIVE , device);return ; }
@@ -1217,7 +1217,7 @@ void qmp_block_job_cancel(const char *device, Error **errp)BlockJob *job =find_block_job (device);if (!job) { -error_set (errp,QERR_DEVICE_NOT_ACTIVE , device); +error_set (errp,QERR_BLOCK_JOB_NOT_ACTIVE , device);return ; }
qerror.h +3 -0
@@ -48,6 +48,9 @@ void assert_no_error(Error *err);#define QERR_BASE_NOT_FOUND \ ERROR_CLASS_GENERIC_ERROR, "Base '%s' not found" +#define QERR_BLOCK_JOB_NOT_ACTIVE \ + ERROR_CLASS_DEVICE_NOT_ACTIVE, "No active block job on device '%s'" +#define QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED \ ERROR_CLASS_GENERIC_ERROR, "Block format '%s' used by device '%s' does not support feature '%s'"
Signature · 1 line
1.7.6.5
PATCH 15/30 block: fix documentation of block_job_cancel_sync
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
Do this in a separate commit before we move the functions to blockjob.h.
--- block_int.h | 12 +++++------- 1 files changed, 5 insertions(+), 7 deletions(-)
block_int.h +5 -7
@@ -425,15 +425,13 @@ void block_job_cancel(BlockJob *job);bool block_job_is_cancelled (BlockJob *job);/** -* block_job_cancel: +* block_job_cancel_sync: * @job: The job to be canceled. * -* Asynchronously cancel the job and wait for it to reach a quiescent -* state. Note that the completion callback will still be called -* asynchronously, hence it is *not* valid to call #bdrv_delete -* immediately after #block_job_cancel_sync. Users of block jobs -* will usually protect the BlockDriverState objects with a reference -* count, should this be a concern. +* Synchronously cancel the job. The completion callback is called +* before the function returns. The job may actually complete +* instead of canceling itself; the circumstances under which this +* happens depend on the kind of job that is active. * * Returns the return value from the job if the job actually completed * during the call, or -ECANCELED if it was canceled.
Signature · 1 line
1.7.6.5
PATCH 16/30 block: move job APIs to separate files
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
--- Makefile.objs | 5 +- block.c | 128 +------------------------------------ block.h | 2 + block/Makefile.objs | 5 +- block/commit.c | 1 + block/stream.c | 1 + block_int.h | 151 ------------------------------------------- blockdev.c | 1 + blockjob.c | 163 ++++++++++++++++++++++++++++++++++++++++++++++ blockjob.h | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 354 insertions(+), 282 deletions(-) create mode 100644 blockjob.c create mode 100644 blockjob.h
Makefile.objs +3 -2
@@ -42,7 +42,8 @@ coroutine-obj-$(CONFIG_WIN32) += coroutine-win32.o # block-obj-y is code used by both qemu system emulation and qemu-img block-obj-y = cutils.o iov.o cache-utils.o qemu-option.o module.o async.o -block-obj-y += nbd.o block.o aio.o aes.o qemu-config.o qemu-progress.o qemu-sockets.o uri.o +block-obj-y += nbd.o block.o blockjob.o aio.o aes.o qemu-config.o +block-obj-y += qemu-progress.o qemu-sockets.o uri.o block-obj-y += $(coroutine-obj-y) $(qobject-obj-y) $(version-obj-y) block-obj-$(CONFIG_POSIX) += posix-aio-compat.o block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
@@ -59,7 +60,7 @@ endif # suppress *all* target specific code in case of system emulation, i.e. a # single QEMU executable should support all CPUs and machines. -common-obj-y = $(block-obj-y) blockdev.o +common-obj-y = $(block-obj-y) blockdev.o block/ common-obj-y += net.o net/ common-obj-y += qom/ common-obj-y += readline.o console.o cursor.o
block.c +1 -127
137 lines not on this page · raw message
block.h +2 -0
@@ -6,9 +6,11 @@#include "qemu-option.h" #include "qemu-coroutine.h" #include "qobject.h" +#include "qapi-types.h" /* block.c */ typedef struct BlockDriver BlockDriver ; +typedef struct BlockJob BlockJob ; typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */
block/Makefile.objs +3 -2
@@ -3,11 +3,12 @@ block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-c block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o block-obj-y += qed-check.o block-obj-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o -block-obj-y += stream.o -block-obj-y += commit.o block-obj-$(CONFIG_WIN32) += raw-win32.o block-obj-$(CONFIG_POSIX) += raw-posix.o block-obj-$(CONFIG_LIBISCSI) += iscsi.o block-obj-$(CONFIG_CURL) += curl.o block-obj-$(CONFIG_RBD) += rbd.o block-obj-$(CONFIG_GLUSTERFS) += gluster.o + +common-obj-y += stream.o +common-obj-y += commit.o
block/commit.c +1 -0
@@ -14,6 +14,7 @@#include "trace.h" #include "block_int.h" +#include "blockjob.h" #include "qemu/ratelimit.h" enum {
block/stream.c +1 -0
@@ -13,6 +13,7 @@#include "trace.h" #include "block_int.h" +#include "blockjob.h" #include "qemu/ratelimit.h" enum {
block_int.h +0 -151
163 lines not on this page · raw message
blockdev.c +1 -0
@@ -9,6 +9,7 @@#include "blockdev.h" #include "hw/block-common.h" +#include "blockjob.h" #include "monitor.h" #include "qerror.h" #include "qemu-option.h"
blockjob.c new file +163 -0
163 lines not on this page · raw message
blockjob.h new file +179 -0
179 lines not on this page · raw message
Signature · 1 line
1.7.6.5
PATCH 17/30 block: add block_job_query
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
Extract it out of the implementation of info block-jobs.
--- blockdev.c | 15 ++------------- blockjob.c | 11 +++++++++++ blockjob.h | 8 ++++++++ 3 files changed, 21 insertions(+), 13 deletions(-)
blockdev.c +2 -13
@@ -1232,19 +1232,8 @@ static void do_qmp_query_block_jobs_one(void *opaque, BlockDriverState *bs)BlockJob *job = bs->job;if (job) { -BlockJobInfoList *elem; -BlockJobInfo *info =g_new (BlockJobInfo,1 ); - *info = (BlockJobInfo ){ - .type =g_strdup (job->job_type->job_type), - .device =g_strdup (bdrv_get_device_name (bs)), - .len = job->len, - .offset = job->offset, - .speed = job->speed, - }; - - elem =g_new0 (BlockJobInfoList,1 ); - elem->value = info; - +BlockJobInfoList *elem =g_new0 (BlockJobInfoList,1 ); + elem->value =block_job_query (bs->job); (*prev)->next = elem; *prev = elem; }
blockjob.c +11 -0
@@ -161,3 +161,14 @@ void block_job_sleep_ns(BlockJob *job, QEMUClock *clock, int64_t ns) job->busy = true; } } + +BlockJobInfo *block_job_query (BlockJob *job) +{ +BlockJobInfo *info =g_new0 (BlockJobInfo,1 ); + info->type =g_strdup (job->job_type->job_type); + info->device =g_strdup (bdrv_get_device_name (job->bs)); + info->len = job->len; + info->offset = job->offset; + info->speed = job->speed; +return info; +}
blockjob.h +8 -0
@@ -163,6 +163,14 @@ void block_job_cancel(BlockJob *job);bool block_job_is_cancelled (BlockJob *job);/** +* block_job_query: +* @job: The job to get information about. +* +* Return information about a job. +*/ +BlockJobInfo *block_job_query (BlockJob *job); + +/** * block_job_cancel_sync: * @job: The job to be canceled. *
Signature · 1 line
1.7.6.5
PATCH 18/30 qmp: add 'busy' member to BlockJobInfo
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
Because pausing a job is asynchronous, we need to know whether it has completed. This is described by the "busy" field of BlockJob; copy it to BlockJobInfo.
--- blockjob.c | 1 + qapi-schema.json | 5 ++++- 2 files changed, 5 insertions(+), 1 deletions(-)
blockjob.c +1 -0
@@ -168,6 +168,7 @@ BlockJobInfo *block_job_query(BlockJob *job) info->type =g_strdup (job->job_type->job_type); info->device =g_strdup (bdrv_get_device_name (job->bs)); info->len = job->len; + info->busy = job->busy; info->offset = job->offset; info->speed = job->speed;return info;
qapi-schema.json +4 -1
@@ -1098,6 +1098,9 @@ # # @len: the maximum progress value # +# @busy: false if the job is known to be in a quiescent state, with +# no pending I/O. Since 1.3. +# # @offset: the current progress value # # @speed: the rate limit, bytes per second
@@ -1106,7 +1109,7 @@ ## { 'type': 'BlockJobInfo', 'data': {'type': 'str', 'device': 'str', 'len': 'int', - 'offset': 'int', 'speed': 'int'} } + 'offset': 'int', 'busy': 'bool', 'speed': 'int'} } ## # @query-block-jobs:
Signature · 1 line
1.7.6.5
PATCH 19/30 block: add support for job pause/resume
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
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.
--- blockdev.c | 4 ++++ blockjob.c | 35 ++++++++++++++++++++++++++++++----- blockjob.h | 31 +++++++++++++++++++++++++++++++ qapi-schema.json | 5 ++++- qerror.h | 3 +++ 5 files changed, 72 insertions(+), 6 deletions(-)
blockdev.c +4 -0
@@ -1221,6 +1221,10 @@ void qmp_block_job_cancel(const char *device, Error **errp)error_set (errp,QERR_BLOCK_JOB_NOT_ACTIVE , device);return ; } +if (job->paused) { +error_set (errp,QERR_BLOCK_JOB_PAUSED , device); +return ; + }trace_qmp_block_job_cancel (job);block_job_cancel (job);
blockjob.c +30 -5
@@ -99,14 +99,30 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp) job->speed = speed; } -void block_job_cancel (BlockJob *job) +void block_job_pause (BlockJob *job) { - job->cancelled = true; + job->paused = true; +} + +bool block_job_is_paused (BlockJob *job) +{ +return job->paused; +} + +void block_job_resume (BlockJob *job) +{ + job->paused = false;if (job->co && !job->busy) {qemu_coroutine_enter (job->co,NULL ); } } +void block_job_cancel (BlockJob *job) +{ + job->cancelled = true; +block_job_resume (job); +} +bool block_job_is_cancelled (BlockJob *job) {return job->cancelled;
@@ -154,12 +170,20 @@ int block_job_cancel_sync(BlockJob *job)void block_job_sleep_ns (BlockJob *job,QEMUClock *clock,int64_t ns) { +assert (job->busy); +/* Check cancellation *before* setting busy = false, too! */ -if (!block_job_is_cancelled (job)) { - job->busy = false; +if (block_job_is_cancelled (job)) { +return ; + } + + job->busy = false; +if (block_job_is_paused (job)) { +qemu_coroutine_yield (); + }else {co_sleep_ns (clock, ns); - job->busy = true; } + job->busy = true; }BlockJobInfo *block_job_query (BlockJob *job)
@@ -169,6 +193,7 @@ BlockJobInfo *block_job_query(BlockJob *job) info->device =g_strdup (bdrv_get_device_name (job->bs)); info->len = job->len; info->busy = job->busy; + info->paused = job->paused; info->offset = job->offset; info->speed = job->speed;return info;
blockjob.h +31 -0
@@ -70,6 +70,12 @@ struct BlockJob {bool cancelled;/** +* Set to true if the job is either paused, or will pause itself +* as soon as possible (if busy == true). +*/ +bool paused; + +/** * Set to false by the job while it is in a quiescent state, where * no I/O is pending and the job has yielded on any condition * that is not detected by #qemu_aio_wait, such as a timer.
@@ -171,6 +177,31 @@ bool block_job_is_cancelled(BlockJob *job);BlockJobInfo *block_job_query (BlockJob *job);/** +* block_job_pause: +* @job: The job to be paused. +* +* Asynchronously pause the specified job. +*/ +void block_job_pause (BlockJob *job); + +/** +* block_job_resume: +* @job: The job to be resumed. +* +* Resume the specified job. +*/ +void block_job_resume (BlockJob *job); + +/** +* block_job_is_paused: +* @job: The job being queried. +* +* Returns whether the job is currently paused, or will pause +* as soon as it reaches a sleeping point. +*/ +bool block_job_is_paused (BlockJob *job); + +/** * block_job_cancel_sync: * @job: The job to be canceled. *
qapi-schema.json +4 -1
@@ -1101,6 +1101,9 @@ # @busy: false if the job is known to be in a quiescent state, with # no pending I/O. Since 1.3. # +# @paused: whether the job is paused or, if @busy is true, will +# pause itself as soon as possible. Since 1.3. +# # @offset: the current progress value # # @speed: the rate limit, bytes per second
@@ -1109,7 +1112,7 @@ ## { 'type': 'BlockJobInfo', 'data': {'type': 'str', 'device': 'str', 'len': 'int', - 'offset': 'int', 'busy': 'bool', 'speed': 'int'} } + 'offset': 'int', 'busy': 'bool', 'paused': 'bool', 'speed': 'int'} } ## # @query-block-jobs:
qerror.h +3 -0
@@ -51,6 +51,9 @@ void assert_no_error(Error *err);#define QERR_BLOCK_JOB_NOT_ACTIVE \ ERROR_CLASS_DEVICE_NOT_ACTIVE, "No active block job on device '%s'" +#define QERR_BLOCK_JOB_PAUSED \ + ERROR_CLASS_GENERIC_ERROR, "The block job for device '%s' is currently paused" +#define QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED \ ERROR_CLASS_GENERIC_ERROR, "Block format '%s' used by device '%s' does not support feature '%s'"
Signature · 1 line
1.7.6.5
PATCH 20/30 qmp: add block-job-pause and block-job-resume
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
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.
--- blockdev.c | 35 +++++++++++++++++++++++++++++++++-- hmp-commands.hx | 35 ++++++++++++++++++++++++++++++++--- hmp.c | 23 ++++++++++++++++++++++- hmp.h | 2 ++ qapi-schema.json | 46 +++++++++++++++++++++++++++++++++++++++++++++- qmp-commands.hx | 12 +++++++++++- trace-events | 2 ++ 7 files changed, 147 insertions(+), 8 deletions(-)
blockdev.c +33 -2
@@ -1213,15 +1213,20 @@ void qmp_block_job_set_speed(const char *device, int64_t speed, Error **errp)block_job_set_speed (job, speed, errp); } -void qmp_block_job_cancel (const char *device,Error **errp) +void qmp_block_job_cancel (const char *device, +bool has_force,bool force,Error **errp) {BlockJob *job =find_block_job (device); +if (!has_force) { + force = false; + } +if (!job) {error_set (errp,QERR_BLOCK_JOB_NOT_ACTIVE , device);return ; } -if (job->paused) { +if (job->paused && !force) {error_set (errp,QERR_BLOCK_JOB_PAUSED , device);return ; }
@@ -1230,6 +1235,32 @@ void qmp_block_job_cancel(const char *device, Error **errp)block_job_cancel (job); } +void qmp_block_job_pause (const char *device,Error **errp) +{ +BlockJob *job =find_block_job (device); + +if (!job) { +error_set (errp,QERR_BLOCK_JOB_NOT_ACTIVE , device); +return ; + } + +trace_qmp_block_job_pause (job); +block_job_pause (job); +} + +void qmp_block_job_resume (const char *device,Error **errp) +{ +BlockJob *job =find_block_job (device); + +if (!job) { +error_set (errp,QERR_BLOCK_JOB_NOT_ACTIVE , device); +return ; + } + +trace_qmp_block_job_resume (job); +block_job_resume (job); +} +static void do_qmp_query_block_jobs_one (void *opaque,BlockDriverState *bs) {BlockJobInfoList **prev = opaque;
hmp-commands.hx +32 -3
@@ -99,9 +99,10 @@ ETEXI { .name = "block_job_cancel", - .args_type = "device:B", - .params = "device", - .help = "stop an active background block operation", + .args_type = "force:-f,device:B", + .params = "[-f] device", + .help = "stop an active background block operation (use -f" + "\n\t\t\t if the operation is currently paused)", .mhandler.cmd = hmp_block_job_cancel, },
@@ -112,6 +113,34 @@ Stop an active block streaming operation. ETEXI { + .name = "block_job_pause", + .args_type = "device:B", + .params = "device", + .help = "pause an active background block operation", + .mhandler.cmd = hmp_block_job_pause, + }, + +STEXI +@item block_job_pause +@findex block_job_pause +Pause an active block streaming operation. +ETEXI + + { + .name = "block_job_resume", + .args_type = "device:B", + .params = "device", + .help = "resume a paused background block operation", + .mhandler.cmd = hmp_block_job_resume, + }, + +STEXI +@item block_job_resume +@findex block_job_resume +Resume a paused block streaming operation. +ETEXI + + { .name = "eject", .args_type = "force:-f,device:B", .params = "[-f] device",
hmp.c +22 -1
@@ -950,8 +950,29 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) {Error *error =NULL ;const char *device =qdict_get_str (qdict,"device" ); +bool force =qdict_get_try_bool (qdict,"force" ,0 ); -qmp_block_job_cancel (device, &error); +qmp_block_job_cancel (device, true, force, &error); + +hmp_handle_error (mon, &error); +} + +void hmp_block_job_pause (Monitor *mon,const QDict *qdict) +{ +Error *error =NULL ; +const char *device =qdict_get_str (qdict,"device" ); + +qmp_block_job_pause (device, &error); + +hmp_handle_error (mon, &error); +} + +void hmp_block_job_resume (Monitor *mon,const QDict *qdict) +{ +Error *error =NULL ; +const char *device =qdict_get_str (qdict,"device" ); + +qmp_block_job_resume (device, &error);hmp_handle_error (mon, &error); }
hmp.h +2 -0
@@ -64,6 +64,8 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict);void hmp_block_stream (Monitor *mon,const QDict *qdict);void hmp_block_job_set_speed (Monitor *mon,const QDict *qdict);void hmp_block_job_cancel (Monitor *mon,const QDict *qdict); +void hmp_block_job_pause (Monitor *mon,const QDict *qdict); +void hmp_block_job_resume (Monitor *mon,const QDict *qdict);void hmp_migrate (Monitor *mon,const QDict *qdict);void hmp_device_del (Monitor *mon,const QDict *qdict);void hmp_dump_guest_memory (Monitor *mon,const QDict *qdict);
qapi-schema.json +45 -1
57 lines not on this page · raw message
qmp-commands.hx +11 -1
@@ -805,10 +805,20 @@ EQMP { .name = "block-job-cancel", - .args_type = "device:B", + .args_type = "device:B,force:b?", .mhandler.cmd_new = qmp_marshal_input_block_job_cancel, }, { + .name = "block-job-pause", + .args_type = "device:B", + .mhandler.cmd_new = qmp_marshal_input_block_job_pause, + }, + { + .name = "block-job-resume", + .args_type = "device:B", + .mhandler.cmd_new = qmp_marshal_input_block_job_resume, + }, + { .name = "transaction", .args_type = "actions:q", .mhandler.cmd_new = qmp_marshal_input_transaction,
trace-events +2 -0
@@ -79,6 +79,8 @@ commit_start(void *bs, void *base, void *top, void *s, void *co, void *opaque) " # blockdev.c qmp_block_job_cancel(void *job) "job %p" +qmp_block_job_pause(void *job) "job %p" +qmp_block_job_resume(void *job) "job %p" block_job_cb(void *bs, void *job, int ret) "bs %p job %p ret %d" qmp_block_stream(void *bs, void *job) "bs %p job %p"
Signature · 1 line
1.7.6.5
PATCH 21/30 qemu-iotests: add test for pausing a streaming operation
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
These check that a paused streaming job does not advance its offset.
Sometimes the new test fails; the map is different between the source and the destination of the streaming because qemu-io does not always pack adjacent clusters that have the same allocated/unallocated state. However, this also happens with the existing test_stream testcase, and is better fixed in qemu-io.
--- tests/qemu-iotests/030 | 40 ++++++++++++++++++++++++++++++++++++++-- tests/qemu-iotests/030.out | 4 ++-- tests/qemu-iotests/group | 2 +- 3 files changed, 41 insertions(+), 5 deletions(-)
tests/qemu-iotests/030 +38 -2
@@ -18,6 +18,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # +import time import os import iotests from iotests import qemu_img, qemu_io
@@ -98,6 +99,43 @@ class TestSingleDrive(ImageStreamingTestCase): qemu_io('-c', 'map', test_img), 'image file map does not match backing file after streaming') + def test_stream_pause(self): + self.assert_no_active_streams() + + result = self.vm.qmp('block-stream', device='drive0') + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('block-job-pause', device='drive0') + self.assert_qmp(result, 'return', {}) + + time.sleep(1) + result = self.vm.qmp('query-block-jobs') + offset = self.dictpath(result, 'return[0]/offset') + + time.sleep(1) + result = self.vm.qmp('query-block-jobs') + self.assert_qmp(result, 'return[0]/offset', offset) + + result = self.vm.qmp('block-job-resume', device='drive0') + self.assert_qmp(result, 'return', {}) + + completed = False + while not completed: + for event in self.vm.get_qmp_events(wait=True): + if event['event'] == 'BLOCK_JOB_COMPLETED': + self.assert_qmp(event, 'data/type', 'stream') + self.assert_qmp(event, 'data/device', 'drive0') + self.assert_qmp(event, 'data/offset', self.image_len) + self.assert_qmp(event, 'data/len', self.image_len) + completed = True + + self.assert_no_active_streams() + self.vm.shutdown() + + self.assertEqual(qemu_io('-c', 'map', backing_img), + qemu_io('-c', 'map', test_img), + 'image file map does not match backing file after streaming') + def test_stream_partial(self): self.assert_no_active_streams()
@@ -173,8 +211,6 @@ class TestStreamStop(ImageStreamingTestCase): os.remove(backing_img) def test_stream_stop(self): - import time - self.assert_no_active_streams() result = self.vm.qmp('block-stream', device='drive0')
tests/qemu-iotests/030.out +2 -2
@@ -1,5 +1,5 @@ -....... +........ ---------------------------------------------------------------------- -Ran 7 tests +Ran 8 tests OK
tests/qemu-iotests/group +1 -1
@@ -36,7 +36,7 @@ 027 rw auto quick 028 rw backing auto 029 rw auto quick -030 rw auto +030 rw auto backing 031 rw auto quick 032 rw auto 033 rw auto
Signature · 1 line
1.7.6.5
PATCH 22/30 iostatus: rename BlockErrorAction, BlockQMPEventAction
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
We want to remove knowledge of BLOCK_ERR_STOP_ENOSPC from drivers; drivers should only be told whether to stop/report/ignore the error. On the other hand, we want to keep using the nicer BlockErrorAction name in the drivers. So rename the enums, while leaving aside the names of the enum values for now.
--- block.c | 8 ++++---- block.h | 12 ++++++------ block_int.h | 2 +- hw/ide/core.c | 2 +- hw/scsi-disk.c | 2 +- hw/virtio-blk.c | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-)
block.c +4 -4
@@ -1387,7 +1387,7 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, }void bdrv_emit_qmp_error_event (const BlockDriverState *bdrv, -BlockQMPEventAction action,int is_read) +BlockErrorAction action,int is_read) {QObject *data;const char *action_str;
@@ -2474,14 +2474,14 @@ void bdrv_set_io_limits(BlockDriverState *bs, bs->io_limits_enabled =bdrv_io_limits_enabled (bs); } -void bdrv_set_on_error (BlockDriverState *bs,BlockErrorAction on_read_error, -BlockErrorAction on_write_error) +void bdrv_set_on_error (BlockDriverState *bs,BlockdevOnError on_read_error, +BlockdevOnError on_write_error) { bs->on_read_error = on_read_error; bs->on_write_error = on_write_error; } -BlockErrorAction bdrv_get_on_error (BlockDriverState *bs,int is_read) +BlockdevOnError bdrv_get_on_error (BlockDriverState *bs,int is_read) {return is_read ? bs->on_read_error : bs->on_write_error; }
block.h +6 -6
@@ -93,11 +93,11 @@ typedef struct BlockDevOps {typedef enum {BLOCK_ERR_REPORT ,BLOCK_ERR_IGNORE ,BLOCK_ERR_STOP_ENOSPC ,BLOCK_ERR_STOP_ANY -}BlockErrorAction ; +}BlockdevOnError ;typedef enum {BDRV_ACTION_REPORT ,BDRV_ACTION_IGNORE ,BDRV_ACTION_STOP -}BlockQMPEventAction ; +}BlockErrorAction ; typedef QSIMPLEQ_HEAD(BlockReopenQueue, BlockReopenQueueEntry) BlockReopenQueue;
@@ -114,7 +114,7 @@ void bdrv_iostatus_disable(BlockDriverState *bs);bool bdrv_iostatus_is_enabled (const BlockDriverState *bs);void bdrv_iostatus_set_err (BlockDriverState *bs,int error);void bdrv_emit_qmp_error_event (const BlockDriverState *bdrv, -BlockQMPEventAction action,int is_read); +BlockErrorAction action,int is_read);void bdrv_info_print (Monitor *mon,const QObject *data);void bdrv_info (Monitor *mon,QObject **ret_data);void bdrv_stats_print (Monitor *mon,const QObject *data);
@@ -284,9 +284,9 @@ int bdrv_has_zero_init(BlockDriverState *bs);int bdrv_is_allocated (BlockDriverState *bs,int64_t sector_num,int nb_sectors,int *pnum); -void bdrv_set_on_error (BlockDriverState *bs,BlockErrorAction on_read_error, -BlockErrorAction on_write_error); -BlockErrorAction bdrv_get_on_error (BlockDriverState *bs,int is_read); +void bdrv_set_on_error (BlockDriverState *bs,BlockdevOnError on_read_error, +BlockdevOnError on_write_error); +BlockdevOnError bdrv_get_on_error (BlockDriverState *bs,int is_read);int bdrv_is_read_only (BlockDriverState *bs);int bdrv_is_sg (BlockDriverState *bs);int bdrv_enable_write_cache (BlockDriverState *bs);
block_int.h +1 -1
@@ -262,7 +262,7 @@ struct BlockDriverState {/* NOTE: the following infos are only hints for real hardware drivers. They are not used by the block driver */ -BlockErrorAction on_read_error, on_write_error; +BlockdevOnError on_read_error, on_write_error;bool iostatus_enabled;BlockDeviceIoStatus iostatus;char device_name[32 ];
hw/ide/core.c +1 -1
@@ -557,7 +557,7 @@ void ide_dma_error(IDEState *s)static int ide_handle_rw_error (IDEState *s,int error,int op) {int is_read = (op &BM_STATUS_RETRY_READ ); -BlockErrorAction action =bdrv_get_on_error (s->bs, is_read); +BlockdevOnError action =bdrv_get_on_error (s->bs, is_read);if (action ==BLOCK_ERR_IGNORE ) {bdrv_emit_qmp_error_event (s->bs,BDRV_ACTION_IGNORE , is_read);
hw/scsi-disk.c +1 -1
@@ -388,7 +388,7 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error) {int is_read = (r->req.cmd.xfer ==SCSI_XFER_FROM_DEV );SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, r->req.dev); -BlockErrorAction action =bdrv_get_on_error (s->qdev.conf.bs, is_read); +BlockdevOnError action =bdrv_get_on_error (s->qdev.conf.bs, is_read);if (action ==BLOCK_ERR_IGNORE ) {bdrv_emit_qmp_error_event (s->qdev.conf.bs,BDRV_ACTION_IGNORE , is_read);
hw/virtio-blk.c +1 -1
@@ -66,7 +66,7 @@ static void virtio_blk_req_complete(VirtIOBlockReq *req, int status)static int virtio_blk_handle_rw_error (VirtIOBlockReq *req,int error,int is_read) { -BlockErrorAction action =bdrv_get_on_error (req->dev->bs, is_read); +BlockdevOnError action =bdrv_get_on_error (req->dev->bs, is_read);VirtIOBlock *s = req->dev;if (action ==BLOCK_ERR_IGNORE ) {
Signature · 1 line
1.7.6.5
PATCH 23/30 iostatus: move BlockdevOnError declaration to QAPI
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
This will let block-stream reuse the enum. Places that used the enums are renamed accordingly.
--- block.c | 6 +++--- block.h | 5 ----- block/commit.c | 14 +++++++------- block_int.h | 2 +- blockdev.c | 14 +++++++------- hw/fdc.c | 4 ++-- hw/ide/core.c | 6 +++--- hw/scsi-disk.c | 6 +++--- hw/scsi-generic.c | 4 ++-- hw/virtio-blk.c | 6 +++--- qapi-schema.json | 23 +++++++++++++++++++++++ 11 files changed, 54 insertions(+), 36 deletions(-)
block.c +3 -3
@@ -4209,9 +4209,9 @@ void bdrv_iostatus_enable(BlockDriverState *bs)bool bdrv_iostatus_is_enabled (const BlockDriverState *bs) {return (bs->iostatus_enabled && - (bs->on_write_error ==BLOCK_ERR_STOP_ENOSPC || - bs->on_write_error ==BLOCK_ERR_STOP_ANY || - bs->on_read_error ==BLOCK_ERR_STOP_ANY )); + (bs->on_write_error ==BLOCKDEV_ON_ERROR_ENOSPC || + bs->on_write_error ==BLOCKDEV_ON_ERROR_STOP || + bs->on_read_error ==BLOCKDEV_ON_ERROR_STOP )); }void bdrv_iostatus_disable (BlockDriverState *bs)
block.h +0 -5
@@ -91,11 +91,6 @@ typedef struct BlockDevOps {#define BDRV_SECTOR_MASK ~(BDRV_SECTOR_SIZE - 1)typedef enum { -BLOCK_ERR_REPORT ,BLOCK_ERR_IGNORE ,BLOCK_ERR_STOP_ENOSPC , -BLOCK_ERR_STOP_ANY -}BlockdevOnError ; - -typedef enum {BDRV_ACTION_REPORT ,BDRV_ACTION_IGNORE ,BDRV_ACTION_STOP }BlockErrorAction ;
block/commit.c +7 -7
@@ -34,7 +34,7 @@ typedef struct CommitBlockJob {BlockDriverState *active;BlockDriverState *top;BlockDriverState *base; -BlockErrorAction on_error; +BlockdevOnError on_error;int base_flags;int orig_overlay_flags; } CommitBlockJob;
@@ -126,9 +126,9 @@ wait: bytes_written += n *BDRV_SECTOR_SIZE ; }if (ret <0 ) { -if (s->on_error ==BLOCK_ERR_STOP_ANY || - s->on_error ==BLOCK_ERR_REPORT || - (s->on_error ==BLOCK_ERR_STOP_ENOSPC && ret == -ENOSPC )) { +if (s->on_error ==BLOCKDEV_ON_ERROR_STOP || + s->on_error ==BLOCKDEV_ON_ERROR_REPORT || + (s->on_error ==BLOCKDEV_ON_ERROR_ENOSPC && ret == -ENOSPC )) { goto exit_free_buf; }else { n =0 ;
@@ -182,7 +182,7 @@ static BlockJobType commit_job_type = {void commit_start (BlockDriverState *bs,BlockDriverState *base,BlockDriverState *top,int64_t speed, -BlockErrorAction on_error,BlockDriverCompletionFunc *cb, +BlockdevOnError on_error,BlockDriverCompletionFunc *cb,void *opaque,Error **errp) {CommitBlockJob *s;
@@ -192,8 +192,8 @@ void commit_start(BlockDriverState *bs, BlockDriverState *base,BlockDriverState *overlay_bs;Error *local_err =NULL ; -if ((on_error ==BLOCK_ERR_STOP_ANY || - on_error ==BLOCK_ERR_STOP_ENOSPC ) && +if ((on_error ==BLOCKDEV_ON_ERROR_STOP || + on_error ==BLOCKDEV_ON_ERROR_ENOSPC ) && !bdrv_iostatus_is_enabled (bs)) {error_set (errp,QERR_INVALID_PARAMETER_COMBINATION );return ;
block_int.h +1 -1
@@ -323,7 +323,7 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base,*/ void commit_start (BlockDriverState *bs,BlockDriverState *base,BlockDriverState *top,int64_t speed, -BlockErrorAction on_error,BlockDriverCompletionFunc *cb, +BlockdevOnError on_error,BlockDriverCompletionFunc *cb,void *opaque,Error **errp);#endif /* BLOCK_INT_H */
blockdev.c +7 -7
@@ -241,13 +241,13 @@ static void drive_put_ref_bh_schedule(DriveInfo *dinfo)static int parse_block_error_action (const char *buf,int is_read) {if (!strcmp (buf,"ignore" )) { -return BLOCK_ERR_IGNORE ; +return BLOCKDEV_ON_ERROR_IGNORE ; }else if (!is_read && !strcmp (buf,"enospc" )) { -return BLOCK_ERR_STOP_ENOSPC ; +return BLOCKDEV_ON_ERROR_ENOSPC ; }else if (!strcmp (buf,"stop" )) { -return BLOCK_ERR_STOP_ANY ; +return BLOCKDEV_ON_ERROR_STOP ; }else if (!strcmp (buf,"report" )) { -return BLOCK_ERR_REPORT ; +return BLOCKDEV_ON_ERROR_REPORT ; }else {error_report ("'%s' invalid %s error action" , buf, is_read ?"read" :"write" );
@@ -433,7 +433,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)return NULL ; } - on_write_error =BLOCK_ERR_STOP_ENOSPC ; + on_write_error =BLOCKDEV_ON_ERROR_ENOSPC ;if ((buf =qemu_opt_get (opts,"werror" )) !=NULL ) {if (type !=IF_IDE && type !=IF_SCSI && type !=IF_VIRTIO && type !=IF_NONE ) {error_report ("werror is not supported by this bus type" );
@@ -446,7 +446,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) } } - on_read_error =BLOCK_ERR_REPORT ; + on_read_error =BLOCKDEV_ON_ERROR_REPORT ;if ((buf =qemu_opt_get (opts,"rerror" )) !=NULL ) {if (type !=IF_IDE && type !=IF_VIRTIO && type !=IF_SCSI && type !=IF_NONE ) {error_report ("rerror is not supported by this bus type" );
@@ -1143,7 +1143,7 @@ void qmp_block_commit(const char *device,/* This will be part of the QMP command, if/when the * BlockdevOnError change for blkmirror makes it in */ -BlockErrorAction on_error =BLOCK_ERR_REPORT ; +BlockdevOnError on_error =BLOCKDEV_ON_ERROR_REPORT ;/* drain all i/o before commits */ bdrv_drain_all ();
hw/fdc.c +2 -2
@@ -1994,11 +1994,11 @@ static int fdctrl_connect_drives(FDCtrl *fdctrl) drive->fdctrl = fdctrl;if (drive->bs) { -if (bdrv_get_on_error (drive->bs,0 ) !=BLOCK_ERR_STOP_ENOSPC ) { +if (bdrv_get_on_error (drive->bs,0 ) !=BLOCKDEV_ON_ERROR_ENOSPC ) {error_report ("fdc doesn't support drive option werror" );return -1 ; } -if (bdrv_get_on_error (drive->bs,1 ) !=BLOCK_ERR_REPORT ) { +if (bdrv_get_on_error (drive->bs,1 ) !=BLOCKDEV_ON_ERROR_REPORT ) {error_report ("fdc doesn't support drive option rerror" );return -1 ; }
hw/ide/core.c +3 -3
@@ -559,13 +559,13 @@ static int ide_handle_rw_error(IDEState *s, int error, int op)int is_read = (op &BM_STATUS_RETRY_READ );BlockdevOnError action =bdrv_get_on_error (s->bs, is_read); -if (action ==BLOCK_ERR_IGNORE ) { +if (action ==BLOCKDEV_ON_ERROR_IGNORE ) {bdrv_emit_qmp_error_event (s->bs,BDRV_ACTION_IGNORE , is_read);return 0 ; } -if ((error ==ENOSPC && action ==BLOCK_ERR_STOP_ENOSPC ) - || action ==BLOCK_ERR_STOP_ANY ) { +if ((error ==ENOSPC && action ==BLOCKDEV_ON_ERROR_ENOSPC ) + || action ==BLOCKDEV_ON_ERROR_STOP ) { s->bus->dma->ops->set_unit (s->bus->dma, s->unit); s->bus->error_status = op;bdrv_emit_qmp_error_event (s->bs,BDRV_ACTION_STOP , is_read);
hw/scsi-disk.c +3 -3
@@ -390,13 +390,13 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error)SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, r->req.dev);BlockdevOnError action =bdrv_get_on_error (s->qdev.conf.bs, is_read); -if (action ==BLOCK_ERR_IGNORE ) { +if (action ==BLOCKDEV_ON_ERROR_IGNORE ) {bdrv_emit_qmp_error_event (s->qdev.conf.bs,BDRV_ACTION_IGNORE , is_read);return 0 ; } -if ((error ==ENOSPC && action ==BLOCK_ERR_STOP_ENOSPC ) - || action ==BLOCK_ERR_STOP_ANY ) { +if ((error ==ENOSPC && action ==BLOCKDEV_ON_ERROR_ENOSPC ) + || action ==BLOCKDEV_ON_ERROR_STOP ) {bdrv_emit_qmp_error_event (s->qdev.conf.bs,BDRV_ACTION_STOP , is_read);vm_stop (RUN_STATE_IO_ERROR );
hw/scsi-generic.c +2 -2
@@ -400,11 +400,11 @@ static int scsi_generic_initfn(SCSIDevice *s)return -1 ; } -if (bdrv_get_on_error (s->conf.bs,0 ) !=BLOCK_ERR_STOP_ENOSPC ) { +if (bdrv_get_on_error (s->conf.bs,0 ) !=BLOCKDEV_ON_ERROR_ENOSPC ) {error_report ("Device doesn't support drive option werror" );return -1 ; } -if (bdrv_get_on_error (s->conf.bs,1 ) !=BLOCK_ERR_REPORT ) { +if (bdrv_get_on_error (s->conf.bs,1 ) !=BLOCKDEV_ON_ERROR_REPORT ) {error_report ("Device doesn't support drive option rerror" );return -1 ; }
hw/virtio-blk.c +3 -3
@@ -69,13 +69,13 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,BlockdevOnError action =bdrv_get_on_error (req->dev->bs, is_read);VirtIOBlock *s = req->dev; -if (action ==BLOCK_ERR_IGNORE ) { +if (action ==BLOCKDEV_ON_ERROR_IGNORE ) {bdrv_emit_qmp_error_event (s->bs,BDRV_ACTION_IGNORE , is_read);return 0 ; } -if ((error ==ENOSPC && action ==BLOCK_ERR_STOP_ENOSPC ) - || action ==BLOCK_ERR_STOP_ANY ) { +if ((error ==ENOSPC && action ==BLOCKDEV_ON_ERROR_ENOSPC ) + || action ==BLOCKDEV_ON_ERROR_STOP ) { req->next = s->rq; s->rq = req;bdrv_emit_qmp_error_event (s->bs,BDRV_ACTION_STOP , is_read);
qapi-schema.json +23 -0
@@ -1088,6 +1088,29 @@ { 'command': 'query-pci', 'returns': ['PciInfo'] } ## +# @BlockdevOnError: +# +# An enumeration of possible behaviors for errors on I/O operations. +# The exact meaning depends on whether the I/O was initiated by a guest +# or by a block job +# +# @report: for guest operations, report the error to the guest; +# for jobs, cancel the job +# +# @ignore: ignore the error, only report a QMP event (BLOCK_IO_ERROR +# or BLOCK_JOB_ERROR) +# +# @enospc: same as @stop on ENOSPC, same as @report otherwise. +# +# @stop: for guest operations, stop the virtual machine; +# for jobs, pause the job +# +# Since: 1.3 +## +{ 'enum': 'BlockdevOnError', + 'data': ['report', 'ignore', 'enospc', 'stop'] } + +## # @BlockJobInfo: # # Information about a long-running block device operation.
Signature · 1 line
1.7.6.5
PATCH 24/30 iostatus: change is_read to a bool
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
Do this while we are touching this part of the code, before introducing more uses of "int is_read".
--- block.c | 4 ++-- block.h | 4 ++-- blockdev.c | 2 +- hw/ide/core.c | 2 +- hw/ide/pci.c | 4 ++-- hw/scsi-disk.c | 2 +- hw/virtio-blk.c | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-)
block.c +2 -2
@@ -1387,7 +1387,7 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, }void bdrv_emit_qmp_error_event (const BlockDriverState *bdrv, -BlockErrorAction action,int is_read) +BlockErrorAction action,bool is_read) {QObject *data;const char *action_str;
@@ -2481,7 +2481,7 @@ void bdrv_set_on_error(BlockDriverState *bs, BlockdevOnError on_read_error, bs->on_write_error = on_write_error; } -BlockdevOnError bdrv_get_on_error (BlockDriverState *bs,int is_read) +BlockdevOnError bdrv_get_on_error (BlockDriverState *bs,bool is_read) {return is_read ? bs->on_read_error : bs->on_write_error; }
block.h +2 -2
@@ -109,7 +109,7 @@ void bdrv_iostatus_disable(BlockDriverState *bs);bool bdrv_iostatus_is_enabled (const BlockDriverState *bs);void bdrv_iostatus_set_err (BlockDriverState *bs,int error);void bdrv_emit_qmp_error_event (const BlockDriverState *bdrv, -BlockErrorAction action,int is_read); +BlockErrorAction action,bool is_read);void bdrv_info_print (Monitor *mon,const QObject *data);void bdrv_info (Monitor *mon,QObject **ret_data);void bdrv_stats_print (Monitor *mon,const QObject *data);
@@ -281,7 +281,7 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,void bdrv_set_on_error (BlockDriverState *bs,BlockdevOnError on_read_error,BlockdevOnError on_write_error); -BlockdevOnError bdrv_get_on_error (BlockDriverState *bs,int is_read); +BlockdevOnError bdrv_get_on_error (BlockDriverState *bs,bool is_read);int bdrv_is_read_only (BlockDriverState *bs);int bdrv_is_sg (BlockDriverState *bs);int bdrv_enable_write_cache (BlockDriverState *bs);
blockdev.c +1 -1
@@ -238,7 +238,7 @@ static void drive_put_ref_bh_schedule(DriveInfo *dinfo)qemu_bh_schedule (s->bh); } -static int parse_block_error_action (const char *buf,int is_read) +static int parse_block_error_action (const char *buf,bool is_read) {if (!strcmp (buf,"ignore" )) {return BLOCKDEV_ON_ERROR_IGNORE ;
hw/ide/core.c +1 -1
@@ -556,7 +556,7 @@ void ide_dma_error(IDEState *s)static int ide_handle_rw_error (IDEState *s,int error,int op) { -int is_read = (op &BM_STATUS_RETRY_READ ); +bool is_read = (op &BM_STATUS_RETRY_READ ) !=0 ;BlockdevOnError action =bdrv_get_on_error (s->bs, is_read);if (action ==BLOCKDEV_ON_ERROR_IGNORE ) {
hw/ide/pci.c +2 -2
@@ -188,7 +188,7 @@ static void bmdma_restart_bh(void *opaque) {BMDMAState *bm = opaque;IDEBus *bus = bm->bus; -int is_read; +bool is_read;int error_status;qemu_bh_delete (bm->bh);
@@ -198,7 +198,7 @@ static void bmdma_restart_bh(void *opaque)return ; } - is_read = !!(bus->error_status &BM_STATUS_RETRY_READ ); + is_read = (bus->error_status &BM_STATUS_RETRY_READ ) !=0 ;/* The error status must be cleared before resubmitting the request: The * request may fail again, and this case can only be distinguished if the
hw/scsi-disk.c +1 -1
@@ -386,7 +386,7 @@ static void scsi_read_data(SCSIRequest *req)*/ static int scsi_handle_rw_error (SCSIDiskReq *r,int error) { -int is_read = (r->req.cmd.xfer ==SCSI_XFER_FROM_DEV ); +bool is_read = (r->req.cmd.xfer ==SCSI_XFER_FROM_DEV );SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, r->req.dev);BlockdevOnError action =bdrv_get_on_error (s->qdev.conf.bs, is_read);
hw/virtio-blk.c +2 -2
@@ -64,7 +64,7 @@ static void virtio_blk_req_complete(VirtIOBlockReq *req, int status) }static int virtio_blk_handle_rw_error (VirtIOBlockReq *req,int error, -int is_read) +bool is_read) {BlockdevOnError action =bdrv_get_on_error (req->dev->bs, is_read);VirtIOBlock *s = req->dev;
@@ -98,7 +98,7 @@ static void virtio_blk_rw_complete(void *opaque, int ret)trace_virtio_blk_rw_complete (req, ret);if (ret) { -int is_read = !(ldl_p (&req->out->type) &VIRTIO_BLK_T_OUT ); +bool is_read = !(ldl_p (&req->out->type) &VIRTIO_BLK_T_OUT );if (virtio_blk_handle_rw_error (req, -ret, is_read))return ; }
Signature · 1 line
1.7.6.5
PATCH 25/30 iostatus: reorganize io error code
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
Move the common part of IDE/SCSI/virtio error handling to the block layer. The new function bdrv_error_action subsumes all three of bdrv_emit_qmp_error_event, vm_stop, bdrv_iostatus_set_err.
The same scheme will be used for errors in block jobs.
--- block.c | 46 ++++++++++++++++++++++++++++++++++++++-------- block.h | 5 +++-- hw/ide/core.c | 20 +++++--------------- hw/scsi-disk.c | 23 +++++++---------------- hw/virtio-blk.c | 19 +++++-------------- qemu-tool.c | 6 ++++++ 6 files changed, 64 insertions(+), 55 deletions(-)
block.c +38 -8
@@ -29,6 +29,7 @@#include "blockjob.h" #include "module.h" #include "qjson.h" +#include "sysemu.h" #include "qemu-coroutine.h" #include "qmp-commands.h" #include "qemu-timer.h"
@@ -1386,8 +1387,8 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, } } -void bdrv_emit_qmp_error_event (const BlockDriverState *bdrv, -BlockErrorAction action,bool is_read) +static void bdrv_emit_qmp_error_event (const BlockDriverState *bdrv, +BlockErrorAction action,bool is_read) {QObject *data;const char *action_str;
@@ -2486,6 +2487,39 @@ BlockdevOnError bdrv_get_on_error(BlockDriverState *bs, bool is_read)return is_read ? bs->on_read_error : bs->on_write_error; } +BlockErrorAction bdrv_get_error_action (BlockDriverState *bs,bool is_read,int error) +{ +BlockdevOnError on_err = is_read ? bs->on_read_error : bs->on_write_error; + +switch (on_err) { +case BLOCKDEV_ON_ERROR_ENOSPC : +return (error ==ENOSPC ) ?BDRV_ACTION_STOP :BDRV_ACTION_REPORT ; +case BLOCKDEV_ON_ERROR_STOP : +return BDRV_ACTION_STOP ; +case BLOCKDEV_ON_ERROR_REPORT : +return BDRV_ACTION_REPORT ; +case BLOCKDEV_ON_ERROR_IGNORE : +return BDRV_ACTION_IGNORE ; +default : +abort (); + } +} + +/* 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). +*/ +void bdrv_error_action (BlockDriverState *bs,BlockErrorAction action, +bool is_read,int error) +{ +assert (error >=0 ); +bdrv_emit_qmp_error_event (bs, action, is_read); +if (action ==BDRV_ACTION_STOP ) { +vm_stop (RUN_STATE_IO_ERROR ); +bdrv_iostatus_set_err (bs, error); + } +} +int bdrv_is_read_only (BlockDriverState *bs) {return bs->read_only;
@@ -4226,14 +4260,10 @@ void bdrv_iostatus_reset(BlockDriverState *bs) } } -/* XXX: Today this is set by device models because it makes the implementation -quite simple. However, the block layer knows about the error, so it's -possible to implement this without device models being involved */ void bdrv_iostatus_set_err (BlockDriverState *bs,int error) { -if (bdrv_iostatus_is_enabled (bs) && - bs->iostatus ==BLOCK_DEVICE_IO_STATUS_OK ) { -assert (error >=0 ); +assert (bdrv_iostatus_is_enabled (bs)); +if (bs->iostatus ==BLOCK_DEVICE_IO_STATUS_OK ) { bs->iostatus = error ==ENOSPC ?BLOCK_DEVICE_IO_STATUS_NOSPACE :BLOCK_DEVICE_IO_STATUS_FAILED ; }
block.h +3 -2
@@ -108,8 +108,6 @@ void bdrv_iostatus_reset(BlockDriverState *bs);void bdrv_iostatus_disable (BlockDriverState *bs);bool bdrv_iostatus_is_enabled (const BlockDriverState *bs);void bdrv_iostatus_set_err (BlockDriverState *bs,int error); -void bdrv_emit_qmp_error_event (const BlockDriverState *bdrv, -BlockErrorAction action,bool is_read);void bdrv_info_print (Monitor *mon,const QObject *data);void bdrv_info (Monitor *mon,QObject **ret_data);void bdrv_stats_print (Monitor *mon,const QObject *data);
@@ -282,6 +280,9 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,void bdrv_set_on_error (BlockDriverState *bs,BlockdevOnError on_read_error,BlockdevOnError on_write_error);BlockdevOnError bdrv_get_on_error (BlockDriverState *bs,bool is_read); +BlockErrorAction bdrv_get_error_action (BlockDriverState *bs,bool is_read,int error); +void bdrv_error_action (BlockDriverState *bs,BlockErrorAction action, +bool is_read,int error);int bdrv_is_read_only (BlockDriverState *bs);int bdrv_is_sg (BlockDriverState *bs);int bdrv_enable_write_cache (BlockDriverState *bs);
hw/ide/core.c +5 -15
@@ -557,31 +557,21 @@ void ide_dma_error(IDEState *s)static int ide_handle_rw_error (IDEState *s,int error,int op) {bool is_read = (op &BM_STATUS_RETRY_READ ) !=0 ; -BlockdevOnError action =bdrv_get_on_error (s->bs, is_read); +BlockErrorAction action =bdrv_get_error_action (s->bs, is_read, error); -if (action ==BLOCKDEV_ON_ERROR_IGNORE ) { -bdrv_emit_qmp_error_event (s->bs,BDRV_ACTION_IGNORE , is_read); -return 0 ; - } - -if ((error ==ENOSPC && action ==BLOCKDEV_ON_ERROR_ENOSPC ) - || action ==BLOCKDEV_ON_ERROR_STOP ) { +if (action ==BDRV_ACTION_STOP ) { s->bus->dma->ops->set_unit (s->bus->dma, s->unit); s->bus->error_status = op; -bdrv_emit_qmp_error_event (s->bs,BDRV_ACTION_STOP , is_read); -vm_stop (RUN_STATE_IO_ERROR ); -bdrv_iostatus_set_err (s->bs, error); - }else { + }else if (action ==BDRV_ACTION_REPORT ) {if (op &BM_STATUS_DMA_RETRY ) {dma_buf_commit (s);ide_dma_error (s); }else {ide_rw_error (s); } -bdrv_emit_qmp_error_event (s->bs,BDRV_ACTION_REPORT , is_read); } - -return 1 ; +bdrv_error_action (s->bs, action, is_read, error); +return action !=BDRV_ACTION_IGNORE ; }void ide_dma_cb (void *opaque,int ret)
hw/scsi-disk.c +7 -16
@@ -388,21 +388,9 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error) {bool is_read = (r->req.cmd.xfer ==SCSI_XFER_FROM_DEV );SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, r->req.dev); -BlockdevOnError action =bdrv_get_on_error (s->qdev.conf.bs, is_read); +BlockErrorAction action =bdrv_get_error_action (s->qdev.conf.bs, is_read, error); -if (action ==BLOCKDEV_ON_ERROR_IGNORE ) { -bdrv_emit_qmp_error_event (s->qdev.conf.bs,BDRV_ACTION_IGNORE , is_read); -return 0 ; - } - -if ((error ==ENOSPC && action ==BLOCKDEV_ON_ERROR_ENOSPC ) - || action ==BLOCKDEV_ON_ERROR_STOP ) { - -bdrv_emit_qmp_error_event (s->qdev.conf.bs,BDRV_ACTION_STOP , is_read); -vm_stop (RUN_STATE_IO_ERROR ); -bdrv_iostatus_set_err (s->qdev.conf.bs, error); -scsi_req_retry (&r->req); - }else { +if (action ==BDRV_ACTION_REPORT ) {switch (error) {case ENOMEDIUM :scsi_check_condition (r,SENSE_CODE (NO_MEDIUM ));
@@ -417,9 +405,12 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error)scsi_check_condition (r,SENSE_CODE (IO_ERROR ));break ; } -bdrv_emit_qmp_error_event (s->qdev.conf.bs,BDRV_ACTION_REPORT , is_read); } -return 1 ; +bdrv_error_action (s->qdev.conf.bs, action, is_read, error); +if (action ==BDRV_ACTION_STOP ) { +scsi_req_retry (&r->req); + } +return action !=BDRV_ACTION_IGNORE ; }static void scsi_write_complete (void * opaque,int ret)
hw/virtio-blk.c +5 -14
@@ -66,29 +66,20 @@ static void virtio_blk_req_complete(VirtIOBlockReq *req, int status)static int virtio_blk_handle_rw_error (VirtIOBlockReq *req,int error,bool is_read) { -BlockdevOnError action =bdrv_get_on_error (req->dev->bs, is_read); +BlockErrorAction action =bdrv_get_error_action (req->dev->bs, is_read, error);VirtIOBlock *s = req->dev; -if (action ==BLOCKDEV_ON_ERROR_IGNORE ) { -bdrv_emit_qmp_error_event (s->bs,BDRV_ACTION_IGNORE , is_read); -return 0 ; - } - -if ((error ==ENOSPC && action ==BLOCKDEV_ON_ERROR_ENOSPC ) - || action ==BLOCKDEV_ON_ERROR_STOP ) { +if (action ==BDRV_ACTION_STOP ) { req->next = s->rq; s->rq = req; -bdrv_emit_qmp_error_event (s->bs,BDRV_ACTION_STOP , is_read); -vm_stop (RUN_STATE_IO_ERROR ); -bdrv_iostatus_set_err (s->bs, error); - }else { + }else if (action ==BDRV_ACTION_REPORT ) {virtio_blk_req_complete (req,VIRTIO_BLK_S_IOERR );bdrv_acct_done (s->bs, &req->acct);g_free (req); -bdrv_emit_qmp_error_event (s->bs,BDRV_ACTION_REPORT , is_read); } -return 1 ; +bdrv_error_action (s->bs, action, is_read, error); +return action !=BDRV_ACTION_IGNORE ; }static void virtio_blk_rw_complete (void *opaque,int ret)
qemu-tool.c +6 -0
@@ -19,6 +19,7 @@#include "qemu-log.h" #include "migration.h" #include "main-loop.h" +#include "sysemu.h" #include "qemu_socket.h" #include "slirp/libslirp.h"
@@ -37,6 +38,11 @@ const char *qemu_get_vm_name(void)Monitor *cur_mon; +void vm_stop (RunState state) +{ +abort (); +} +int monitor_cur_is_qmp (void ) {return 0 ;
Signature · 1 line
1.7.6.5
PATCH 26/30 block: introduce block job error
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
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.
--- QMP/qmp-events.txt | 22 ++++++++++++++++++ block.c | 9 ++++--- block_int.h | 4 +++ blockjob.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++----- blockjob.h | 25 ++++++++++++++++++++ monitor.c | 1 + monitor.h | 1 + qapi-schema.json | 7 +++++- 8 files changed, 120 insertions(+), 12 deletions(-)
QMP/qmp-events.txt +22 -0
@@ -96,6 +96,28 @@ 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 } } + DEVICE_TRAY_MOVED -----------------
block.c +5 -4
@@ -1387,8 +1387,9 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, } } -static void bdrv_emit_qmp_error_event (const BlockDriverState *bdrv, -BlockErrorAction action,bool is_read) +void bdrv_emit_qmp_error_event (const BlockDriverState *bdrv, +enum MonitorEvent ev, +BlockErrorAction action,bool is_read) {QObject *data;const char *action_str;
@@ -1411,7 +1412,7 @@ static void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv, bdrv->device_name, action_str, is_read ? "read" : "write"); -monitor_protocol_event (QEVENT_BLOCK_IO_ERROR , data); +monitor_protocol_event (ev, data);qobject_decref (data); }
@@ -2513,7 +2514,7 @@ void bdrv_error_action(BlockDriverState *bs, BlockErrorAction action, bool is_read, int error) {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 ) {vm_stop (RUN_STATE_IO_ERROR );bdrv_iostatus_set_err (bs, error);
block_int.h +4 -0
@@ -31,6 +31,7 @@#include "qemu-timer.h" #include "qapi-types.h" #include "qerror.h" +#include "monitor.h" #define BLOCK_FLAG_ENCRYPT 1#define BLOCK_FLAG_COMPAT6 4
@@ -286,6 +287,9 @@ void bdrv_set_io_limits(BlockDriverState *bs,#ifdef _WIN32int 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:
blockjob.c +56 -7
80 lines not on this page · raw message
blockjob.h +25 -0
@@ -82,6 +82,9 @@ struct BlockJob {*/ 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 */ int64_t offset;
@@ -215,4 +218,26 @@ bool block_job_is_paused(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
monitor.c +1 -0
@@ -450,6 +450,7 @@ static const char *monitor_event_names[] = { [QEVENT_SPICE_DISCONNECTED] = "SPICE_DISCONNECTED", [QEVENT_BLOCK_JOB_COMPLETED] = "BLOCK_JOB_COMPLETED", [QEVENT_BLOCK_JOB_CANCELLED] = "BLOCK_JOB_CANCELLED", + [QEVENT_BLOCK_JOB_ERROR] = "BLOCK_JOB_ERROR", [QEVENT_DEVICE_TRAY_MOVED] = "DEVICE_TRAY_MOVED", [QEVENT_SUSPEND] = "SUSPEND", [QEVENT_SUSPEND_DISK] = "SUSPEND_DISK",
monitor.h +1 -0
@@ -38,6 +38,7 @@ typedef enum MonitorEvent {QEVENT_SPICE_DISCONNECTED ,QEVENT_BLOCK_JOB_COMPLETED ,QEVENT_BLOCK_JOB_CANCELLED , +QEVENT_BLOCK_JOB_ERROR ,QEVENT_DEVICE_TRAY_MOVED ,QEVENT_SUSPEND , QEVENT_SUSPEND_DISK,
qapi-schema.json +6 -1
@@ -1131,11 +1131,14 @@ # # @speed: the rate limit, bytes per second # +# @io-status: the status of the job (since 1.3) +# # Since: 1.1 ## { 'type': 'BlockJobInfo', '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:
@@ -1958,6 +1961,8 @@ # operation. It is an error to call this command if no operation is in # progress. Resuming an already running job is not an error. # +# This command also clears the error status of the job. +# # @device: the device name # # Returns: Nothing on success
Signature · 1 line
1.7.6.5
PATCH 27/30 stream: add on-error argument
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
This patch adds support for error management to streaming.
--- block/stream.c | 28 +++++++++++++++++++++++++++- block_int.h | 3 ++- blockdev.c | 11 ++++++++--- hmp.c | 3 ++- qapi-schema.json | 9 +++++++-- qmp-commands.hx | 2 +- 6 files changed, 47 insertions(+), 9 deletions(-)
block/stream.c +27 -1
@@ -31,6 +31,7 @@ typedef struct StreamBlockJob {BlockJob common;RateLimit limit;BlockDriverState *base; +BlockdevOnError on_error;char backing_file_id[1024 ]; } StreamBlockJob;
@@ -78,6 +79,7 @@ static void coroutine_fn stream_run(void *opaque)BlockDriverState *bs = s->common.bs;BlockDriverState *base = s->base;int64_t sector_num, end; +int error =0 ;int ret =0 ;int n =0 ;void *buf;
@@ -142,7 +144,19 @@ wait: ret =stream_populate (bs, sector_num, n, buf); }if (ret <0 ) { -break ; +BlockErrorAction action = +block_job_error_action (&s->common, s->common.bs, s->on_error, + true, -ret); +if (action ==BDRV_ACTION_STOP ) { + n =0 ; +continue ; + } +if (error ==0 ) { + error = ret; + } +if (action ==BDRV_ACTION_REPORT ) { +break ; + } } ret =0 ;
@@ -154,6 +168,9 @@ wait:bdrv_disable_copy_on_read (bs); } +/* Do not remove the backing file if an error was there but ignored. */ + ret = error; +if (!block_job_is_cancelled (&s->common) && sector_num == end && ret ==0 ) {const char *base_id =NULL , *base_fmt =NULL ;if (base) {
@@ -189,11 +206,19 @@ static BlockJobType stream_job_type = {void stream_start (BlockDriverState *bs,BlockDriverState *base,const char *base_id,int64_t speed, +BlockdevOnError on_error,BlockDriverCompletionFunc *cb,void *opaque,Error **errp) {StreamBlockJob *s; +if ((on_error ==BLOCKDEV_ON_ERROR_STOP || + on_error ==BLOCKDEV_ON_ERROR_ENOSPC ) && + !bdrv_iostatus_is_enabled (bs)) { +error_set (errp,QERR_INVALID_PARAMETER ,"on-error" ); +return ; + } + s =block_job_create (&stream_job_type, bs, speed, cb, opaque, errp);if (!s) {return ;
@@ -204,6 +229,7 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base,pstrcpy (s->backing_file_id,sizeof (s->backing_file_id), base_id); } + s->on_error = on_error; s->common.co =qemu_coroutine_create (stream_run);trace_stream_start (bs, base, s, s->common.co, opaque);qemu_coroutine_enter (s->common.co, s);
block_int.h +2 -1
@@ -299,6 +299,7 @@ void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,* @base_id: The file name that will be written to @bs as the new * backing file if the job completes. Ignored if @base is %NULL. * @speed: The maximum speed, in bytes per second, or 0 for unlimited. +* @on_error: The action to take upon error. * @cb: Completion function for the job. * @opaque: Opaque pointer value passed to @cb. * @errp: Error object.
@@ -310,7 +311,7 @@ void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,* @base_id in the written image and to @base in the live BlockDriverState. */ void stream_start (BlockDriverState *bs,BlockDriverState *base, -const char *base_id,int64_t speed, +const char *base_id,int64_t speed,BlockdevOnError on_error,BlockDriverCompletionFunc *cb,void *opaque,Error **errp);
blockdev.c +8 -3
@@ -1096,13 +1096,18 @@ static void block_job_cb(void *opaque, int ret) }void qmp_block_stream (const char *device,bool has_base, -const char *base,bool has_speed, -int64_t speed,Error **errp) +const char *base,bool has_speed,int64_t speed, +bool has_on_error,BlockdevOnError on_error, +Error **errp) {BlockDriverState *bs;BlockDriverState *base_bs =NULL ;Error *local_err =NULL ; +if (!has_on_error) { + on_error =BLOCKDEV_ON_ERROR_REPORT ; + } + bs =bdrv_find (device);if (!bs) {error_set (errp,QERR_DEVICE_NOT_FOUND , device);
@@ -1118,7 +1123,7 @@ void qmp_block_stream(const char *device, bool has_base, }stream_start (bs, base_bs, base, has_speed ? speed :0 , - block_job_cb, bs, &local_err); + on_error, block_job_cb, bs, &local_err);if (error_is_set (&local_err)) {error_propagate (errp, local_err);return ;
hmp.c +2 -1
@@ -930,7 +930,8 @@ void hmp_block_stream(Monitor *mon, const QDict *qdict)int64_t speed =qdict_get_try_int (qdict,"speed" ,0 );qmp_block_stream (device, base !=NULL , base, -qdict_haskey (qdict,"speed" ), speed, &error); +qdict_haskey (qdict,"speed" ), speed, +BLOCKDEV_ON_ERROR_REPORT , true, &error);hmp_handle_error (mon, &error); }
qapi-schema.json +7 -2
@@ -1869,13 +1869,18 @@ # # @speed: #optional the maximum speed, in bytes per second # +# @on-error: #optional the action to take on an error (default report). +# 'stop' and 'enospc' can only be used if the block device +# supports io-status (see BlockInfo). Since 1.3. +# # Returns: Nothing on success # If @device does not exist, DeviceNotFound # # Since: 1.1 ## -{ 'command': 'block-stream', 'data': { 'device': 'str', '*base': 'str', - '*speed': 'int' } } +{ 'command': 'block-stream', + 'data': { 'device': 'str', '*base': 'str', '*speed': 'int', + '*on-error': 'BlockdevOnError' } } ## # @block-job-set-speed:
qmp-commands.hx +1 -1
@@ -787,7 +787,7 @@ EQMP { .name = "block-stream", - .args_type = "device:B,base:s?,speed:o?", + .args_type = "device:B,base:s?,speed:o?,on-error:s?", .mhandler.cmd_new = qmp_marshal_input_block_stream, },
Signature · 1 line
1.7.6.5
PATCH 28/30 blkdebug: process all set_state rules in the old state
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
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.
--- block/blkdebug.c | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-)
block/blkdebug.c +7 -5
@@ -28,6 +28,7 @@typedef struct BDRVBlkdebugState {int state; +int new_state; QLIST_HEAD(, BlkdebugRule) rules[BLKDBG_EVENT_MAX]; QSIMPLEQ_HEAD(, BlkdebugRule) active_rules; }BDRVBlkdebugState ;
@@ -403,12 +404,12 @@ static void blkdebug_close(BlockDriverState *bs) }static bool process_rule (BlockDriverState *bs,struct BlkdebugRule *rule, -int old_state,bool injected) +bool injected) {BDRVBlkdebugState *s = bs->opaque;/* Only process rules for the current state */ -if (rule->state && rule->state != old_state) { +if (rule->state && rule->state != s->state) {return injected; }
@@ -423,7 +424,7 @@ static bool process_rule(BlockDriverState *bs, struct BlkdebugRule *rule,break ;case ACTION_SET_STATE : - s->state = rule->options.set_state.new_state; + s->new_state = rule->options.set_state.new_state;break ; }return injected;
@@ -433,15 +434,16 @@ static void blkdebug_debug_event(BlockDriverState *bs, BlkDebugEvent event) {BDRVBlkdebugState *s = bs->opaque;struct BlkdebugRule *rule; -int old_state = s->state;bool injected;assert ((int )event >=0 && event <BLKDBG_EVENT_MAX ); injected = false; + s->new_state = s->state; QLIST_FOREACH(rule, &s->rules[event], next) { - injected =process_rule (bs, rule, old_state, injected); + injected =process_rule (bs, rule, injected); } + s->state = s->new_state; }static int64_t blkdebug_getlength (BlockDriverState *bs)
Signature · 1 line
1.7.6.5
PATCH 29/30 qemu-iotests: map underscore to dash in QMP argument names
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
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.
--- tests/qemu-iotests/iotests.py | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
tests/qemu-iotests/iotests.py +7 -1
@@ -19,6 +19,7 @@ import os import re import subprocess +import string import unittest import sys; sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'QMP')) import qmp
@@ -96,9 +97,14 @@ class VM(object): os.remove(self._qemu_log_path) self._popen = None + underscore_to_dash = string.maketrans('_', '-') def qmp(self, cmd, **args): '''Invoke a QMP command and return the result dict''' - return self._qmp.cmd(cmd, args=args) + qmp_args = dict() + for k in args.keys(): + qmp_args[k.translate(self.underscore_to_dash)] = args[k] + + return self._qmp.cmd(cmd, args=qmp_args) def get_qmp_events(self, wait=False): '''Poll for queued QMP events and return a list of dicts'''
Signature · 1 line
1.7.6.5
PATCH 30/30 qemu-iotests: add tests for streaming error handling
In reply to Kevin WolfFrom: Paolo Bonzini <[email protected]>
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.
--- tests/qemu-iotests/030 | 220 +++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/030.out | 4 +- tests/qemu-iotests/iotests.py | 7 ++ 3 files changed, 229 insertions(+), 2 deletions(-)
tests/qemu-iotests/030 +220 -0
@@ -195,6 +195,226 @@ class TestSmallerBackingFile(ImageStreamingTestCase): self.assert_no_active_streams() self.vm.shutdown() +class TestErrors(ImageStreamingTestCase): + image_len = 2 * 1024 * 1024 # MB + + # this should match STREAM_BUFFER_SIZE/512 in block/stream.c + STREAM_BUFFER_SIZE = 512 * 1024 + + def create_blkdebug_file(self, name, event, errno): + file = open(name, 'w') + file.write(''' +[inject-error] +state = "1" +event = "%s" +errno = "%d" +immediately = "off" +once = "on" +sector = "%d" + +[set-state] +state = "1" +event = "%s" +new_state = "2" + +[set-state] +state = "2" +event = "%s" +new_state = "1" +''' % (event, errno, self.STREAM_BUFFER_SIZE / 512, event, event)) + file.close() + +class TestEIO(TestErrors): + def setUp(self): + self.blkdebug_file = backing_img + ".blkdebug" + self.create_image(backing_img, TestErrors.image_len) + self.create_blkdebug_file(self.blkdebug_file, "read_aio", 5) + qemu_img('create', '-f', iotests.imgfmt, + '-o', 'backing_file=blkdebug:%s:%s,backing_fmt=raw' + % (self.blkdebug_file, backing_img), + test_img) + self.vm = iotests.VM().add_drive(test_img) + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + os.remove(test_img) + os.remove(backing_img) + os.remove(self.blkdebug_file) + + def test_report(self): + self.assert_no_active_streams() + + result = self.vm.qmp('block-stream', device='drive0') + self.assert_qmp(result, 'return', {}) + + completed = False + error = False + while not completed: + for event in self.vm.get_qmp_events(wait=True): + if event['event'] == 'BLOCK_JOB_ERROR': + self.assert_qmp(event, 'data/device', 'drive0') + self.assert_qmp(event, 'data/operation', 'read') + error = True + elif event['event'] == 'BLOCK_JOB_COMPLETED': + self.assertTrue(error, 'job completed unexpectedly') + self.assert_qmp(event, 'data/type', 'stream') + self.assert_qmp(event, 'data/device', 'drive0') + self.assert_qmp(event, 'data/error', 'Input/output error') + self.assert_qmp(event, 'data/offset', self.STREAM_BUFFER_SIZE) + self.assert_qmp(event, 'data/len', self.image_len) + completed = True + + self.assert_no_active_streams() + self.vm.shutdown() + + def test_ignore(self): + self.assert_no_active_streams() + + result = self.vm.qmp('block-stream', device='drive0', on_error='ignore') + self.assert_qmp(result, 'return', {}) + + error = False + completed = False + while not completed: + for event in self.vm.get_qmp_events(wait=True): + if event['event'] == 'BLOCK_JOB_ERROR': + self.assert_qmp(event, 'data/device', 'drive0') + self.assert_qmp(event, 'data/operation', 'read') + result = self.vm.qmp('query-block-jobs') + self.assert_qmp(result, 'return[0]/paused', False) + error = True + elif event['event'] == 'BLOCK_JOB_COMPLETED': + self.assertTrue(error, 'job completed unexpectedly') + self.assert_qmp(event, 'data/type', 'stream') + self.assert_qmp(event, 'data/device', 'drive0') + self.assert_qmp(event, 'data/error', 'Input/output error') + self.assert_qmp(event, 'data/offset', self.image_len) + self.assert_qmp(event, 'data/len', self.image_len) + completed = True + + self.assert_no_active_streams() + self.vm.shutdown() + + def test_stop(self): + self.assert_no_active_streams() + + result = self.vm.qmp('block-stream', device='drive0', on_error='stop') + self.assert_qmp(result, 'return', {}) + + error = False + completed = False + while not completed: + for event in self.vm.get_qmp_events(wait=True): + if event['event'] == 'BLOCK_JOB_ERROR': + self.assert_qmp(event, 'data/device', 'drive0') + self.assert_qmp(event, 'data/operation', 'read') + + result = self.vm.qmp('query-block-jobs') + self.assert_qmp(result, 'return[0]/paused', True) + self.assert_qmp(result, 'return[0]/offset', self.STREAM_BUFFER_SIZE) + self.assert_qmp(result, 'return[0]/io-status', 'failed') + + result = self.vm.qmp('block-job-resume', device='drive0') + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('query-block-jobs') + self.assert_qmp(result, 'return[0]/paused', False) + self.assert_qmp(result, 'return[0]/io-status', 'ok') + error = True + elif event['event'] == 'BLOCK_JOB_COMPLETED': + self.assertTrue(error, 'job completed unexpectedly') + self.assert_qmp(event, 'data/type', 'stream') + self.assert_qmp(event, 'data/device', 'drive0') + self.assert_qmp_absent(event, 'data/error') + self.assert_qmp(event, 'data/offset', self.image_len) + self.assert_qmp(event, 'data/len', self.image_len) + completed = True + + self.assert_no_active_streams() + self.vm.shutdown() + + def test_enospc(self): + self.assert_no_active_streams() + + result = self.vm.qmp('block-stream', device='drive0', on_error='enospc') + self.assert_qmp(result, 'return', {}) + + completed = False + error = False + while not completed: + for event in self.vm.get_qmp_events(wait=True): + if event['event'] == 'BLOCK_JOB_ERROR': + self.assert_qmp(event, 'data/device', 'drive0') + self.assert_qmp(event, 'data/operation', 'read') + error = True + elif event['event'] == 'BLOCK_JOB_COMPLETED': + self.assertTrue(error, 'job completed unexpectedly') + self.assert_qmp(event, 'data/type', 'stream') + self.assert_qmp(event, 'data/device', 'drive0') + self.assert_qmp(event, 'data/error', 'Input/output error') + self.assert_qmp(event, 'data/offset', self.STREAM_BUFFER_SIZE) + self.assert_qmp(event, 'data/len', self.image_len) + completed = True + + self.assert_no_active_streams() + self.vm.shutdown() + +class TestENOSPC(TestErrors): + def setUp(self): + self.blkdebug_file = backing_img + ".blkdebug" + self.create_image(backing_img, TestErrors.image_len) + self.create_blkdebug_file(self.blkdebug_file, "read_aio", 28) + qemu_img('create', '-f', iotests.imgfmt, + '-o', 'backing_file=blkdebug:%s:%s,backing_fmt=raw' + % (self.blkdebug_file, backing_img), + test_img) + self.vm = iotests.VM().add_drive(test_img) + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + os.remove(test_img) + os.remove(backing_img) + os.remove(self.blkdebug_file) + + def test_enospc(self): + self.assert_no_active_streams() + + result = self.vm.qmp('block-stream', device='drive0', on_error='enospc') + self.assert_qmp(result, 'return', {}) + + error = False + completed = False + while not completed: + for event in self.vm.get_qmp_events(wait=True): + if event['event'] == 'BLOCK_JOB_ERROR': + self.assert_qmp(event, 'data/device', 'drive0') + self.assert_qmp(event, 'data/operation', 'read') + + result = self.vm.qmp('query-block-jobs') + self.assert_qmp(result, 'return[0]/paused', True) + self.assert_qmp(result, 'return[0]/offset', self.STREAM_BUFFER_SIZE) + self.assert_qmp(result, 'return[0]/io-status', 'nospace') + + result = self.vm.qmp('block-job-resume', device='drive0') + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('query-block-jobs') + self.assert_qmp(result, 'return[0]/paused', False) + self.assert_qmp(result, 'return[0]/io-status', 'ok') + error = True + elif event['event'] == 'BLOCK_JOB_COMPLETED': + self.assertTrue(error, 'job completed unexpectedly') + self.assert_qmp(event, 'data/type', 'stream') + self.assert_qmp(event, 'data/device', 'drive0') + self.assert_qmp_absent(event, 'data/error') + self.assert_qmp(event, 'data/offset', self.image_len) + self.assert_qmp(event, 'data/len', self.image_len) + completed = True + + self.assert_no_active_streams() + self.vm.shutdown() class TestStreamStop(ImageStreamingTestCase): image_len = 8 * 1024 * 1024 * 1024 # GB
tests/qemu-iotests/030.out +2 -2
@@ -1,5 +1,5 @@ -........ +............. ---------------------------------------------------------------------- -Ran 8 tests +Ran 13 tests OK
tests/qemu-iotests/iotests.py +7 -0
@@ -138,6 +138,13 @@ class QMPTestCase(unittest.TestCase): self.fail('invalid index "%s" in path "%s" in "%s"' % (idx, path, str(d))) return d + def assert_qmp_absent(self, d, path): + try: + result = self.dictpath(d, path) + except AssertionError: + return + self.fail('path "%s" has value "%s"' % (path, str(result))) + def assert_qmp(self, d, path, value): '''Assert that the value for a specific path in a QMP dict matches''' result = self.dictpath(d, path)
Signature · 1 line
1.7.6.5
Quoted 8 lines · Kevin Wolf
The following changes since commit
6f8fd2530e9a530f237240daf1c981fa5df7f978:Merge branch 'arm-devs.for-upstream' of
git://git.linaro.org/people/pmaydell/qemu-arm(2012-09-27 21:48:56 +0200)are available in the git repository at:
git://repo.or.cz/qemu/kevin.gitfor-anthony
Pulled. Thanks.
Regards,
Anthony Liguori
Quoted 87 lines
Bharata B Rao (2):
configure: Add a config option for GlusterFS as block backend
block: Support GlusterFS as a QEMU block backend.Jeff Cody (7):
block: after creating a live snapshot, make old image read-only
block: add support functions for live commit, to find and delete images.
block: add live block commit functionality
blockdev: renameblock_stream_cbto a genericblock_job_cb
block: helper function, to find the base image of a chain
QAPI: add command for live block commit, 'block-commit'
qemu-iotests: add initial tests for live block commitKevin Wolf (1):
block-migration: Flush requests inblk_mig_cleanupPaolo Bonzini (20):
aio: Fixqemu_aio_wait()to maintain correctwalking_handlerscount
qemu: URI parsing library
aio: Another fix to thewalking_handlerslogic qerror/block: introduceQERR_BLOCK_JOB_NOT_ACTIVE
block: fix documentation ofblock_job_cancel_sync
block: move job APIs to separate files
block: addblock_job_query
qmp: add 'busy' member to BlockJobInfo
block: add support for job pause/resume
qmp: add block-job-pause and block-job-resume
qemu-iotests: add test for pausing a streaming operation
iostatus: rename BlockErrorAction, BlockQMPEventAction
iostatus: move BlockdevOnError declaration to QAPI
iostatus: changeis_readto a bool
iostatus: reorganize io error code
block: introduce block job error
stream: add on-error argument
blkdebug: process allset_staterules in the old state
qemu-iotests: map underscore to dash in QMP argument names
qemu-iotests: add tests for streaming error handlingMakefile.objs | 5 +- QMP/qmp-events.txt | 28 +- aio.c | 14 +- block-migration.c | 2 + block.c | 346 ++++--- block.h | 25 +- block/Makefile.objs | 5 +- block/blkdebug.c | 12 +- block/commit.c | 268 +++++ block/gluster.c | 624 ++++++++++++ block/stream.c | 29 +- block_int.h | 178 +--- blockdev.c | 149 +++- blockjob.c | 249 +++++ blockjob.h | 243 +++++ configure | 35 + hmp-commands.hx | 35 +- hmp.c | 26 +- hmp.h | 2 + hw/fdc.c | 4 +- hw/ide/core.c | 22 +- hw/ide/pci.c | 4 +- hw/scsi-disk.c | 25 +- hw/scsi-generic.c | 4 +- hw/virtio-blk.c | 23 +- monitor.c | 1 + monitor.h | 1 + qapi-schema.json | 125 +++- qemu-tool.c | 6 + qerror.h | 6 + qmp-commands.hx | 20 +- tests/qemu-iotests/030 | 260 +++++- tests/qemu-iotests/030.out | 4 +- tests/qemu-iotests/040 | 178 ++++ tests/qemu-iotests/040.out | 5 + tests/qemu-iotests/group | 3 +- tests/qemu-iotests/iotests.py | 15 +- trace-events | 6 +- uri.c | 2249 +++++++++++++++++++++++++++++++++++++++++ uri.h | 113 ++ 40 files changed, 4923 insertions(+), 426 deletions(-) create mode 100644 block/commit.c create mode 100644 block/gluster.c create mode 100644 blockjob.c create mode 100644 blockjob.h create mode 100755 tests/qemu-iotests/040 create mode 100644 tests/qemu-iotests/040.out create mode 100644 uri.c create mode 100644 uri.h