stream_start now picks up a reference for its return value, a copy of the job started. callers are responsible for putting it down when they are done with it.
This removes a minor reference to bs->job in qmp_block_stream, for a simple tracing function. Reviewed-by: Kevin Wolf <kw...@redhat.com> Signed-off-by: John Snow <js...@redhat.com> --- block/stream.c | 8 +++++--- blockdev.c | 8 +++++--- include/block/block_int.h | 9 +++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/block/stream.c b/block/stream.c index cafaa07..26a2990 100644 --- a/block/stream.c +++ b/block/stream.c @@ -214,7 +214,7 @@ static const BlockJobDriver stream_job_driver = { .set_speed = stream_set_speed, }; -void stream_start(BlockDriverState *bs, BlockDriverState *base, +BlockJob *stream_start(BlockDriverState *bs, BlockDriverState *base, const char *backing_file_str, int64_t speed, BlockdevOnError on_error, BlockCompletionFunc *cb, @@ -226,19 +226,21 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base, on_error == BLOCKDEV_ON_ERROR_ENOSPC) && (!bs->blk || !blk_iostatus_is_enabled(bs->blk))) { error_setg(errp, QERR_INVALID_PARAMETER, "on-error"); - return; + return NULL; } s = block_job_create(&stream_job_driver, bs, speed, cb, opaque, errp); if (!s) { - return; + return NULL; } s->base = base; s->backing_file_str = g_strdup(backing_file_str); s->on_error = on_error; + block_job_ref(&s->common); 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); + return &s->common; } diff --git a/blockdev.c b/blockdev.c index c0b9b12..5a74c81 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2883,6 +2883,7 @@ void qmp_block_stream(const char *device, BlockBackend *blk; BlockDriverState *bs; BlockDriverState *base_bs = NULL; + BlockJob *job; AioContext *aio_context; Error *local_err = NULL; const char *base_name = NULL; @@ -2932,14 +2933,15 @@ void qmp_block_stream(const char *device, /* backing_file string overrides base bs filename */ base_name = has_backing_file ? backing_file : base_name; - stream_start(bs, base_bs, base_name, has_speed ? speed : 0, - on_error, block_job_cb, bs, &local_err); + job = stream_start(bs, base_bs, base_name, has_speed ? speed : 0, + on_error, block_job_cb, bs, &local_err); if (local_err) { error_propagate(errp, local_err); goto out; } - trace_qmp_block_stream(bs, bs->job); + trace_qmp_block_stream(bs, job); + block_job_unref(job); out: aio_context_release(aio_context); diff --git a/include/block/block_int.h b/include/block/block_int.h index de4c3c6..7a86d7f 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -598,10 +598,11 @@ int is_windows_drive(const char *filename); * streaming job, the backing file of @bs will be changed to * @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, BlockdevOnError on_error, - BlockCompletionFunc *cb, - void *opaque, Error **errp); +BlockJob *stream_start(BlockDriverState *bs, BlockDriverState *base, + const char *base_id, int64_t speed, + BlockdevOnError on_error, + BlockCompletionFunc *cb, + void *opaque, Error **errp); /** * commit_start: -- 2.4.3