diff options
Diffstat (limited to 'blockjob.c')
-rw-r--r-- | blockjob.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/blockjob.c b/blockjob.c index c286fc3a98..309ef9a35c 100644 --- a/blockjob.c +++ b/blockjob.c @@ -38,6 +38,9 @@ #include "qemu/timer.h" #include "qapi-event.h" +static void block_job_event_cancelled(BlockJob *job); +static void block_job_event_completed(BlockJob *job, const char *msg); + /* Transactional group of block jobs */ struct BlockJobTxn { @@ -127,7 +130,6 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, BlockBackend *blk; BlockJob *job; - assert(cb); if (bs->job) { error_setg(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs)); return NULL; @@ -239,7 +241,20 @@ static void block_job_completed_single(BlockJob *job) job->driver->abort(job); } } - job->cb(job->opaque, job->ret); + + if (job->cb) { + job->cb(job->opaque, job->ret); + } + if (block_job_is_cancelled(job)) { + block_job_event_cancelled(job); + } else { + const char *msg = NULL; + if (job->ret < 0) { + msg = strerror(-job->ret); + } + block_job_event_completed(job, msg); + } + if (job->txn) { block_job_txn_unref(job->txn); } @@ -553,7 +568,7 @@ static void block_job_iostatus_set_err(BlockJob *job, int error) } } -void block_job_event_cancelled(BlockJob *job) +static void block_job_event_cancelled(BlockJob *job) { if (block_job_is_internal(job)) { return; @@ -567,7 +582,7 @@ void block_job_event_cancelled(BlockJob *job) &error_abort); } -void block_job_event_completed(BlockJob *job, const char *msg) +static void block_job_event_completed(BlockJob *job, const char *msg) { if (block_job_is_internal(job)) { return; |