aboutsummaryrefslogtreecommitdiff
path: root/blockjob.c
diff options
context:
space:
mode:
authorJohn Snow <jsnow@redhat.com>2016-10-27 12:06:58 -0400
committerJeff Cody <jcody@redhat.com>2016-11-01 07:55:57 -0400
commit8254b6d9534ba6a7d078a717e777fefe75ec27b6 (patch)
treeddecba3c1b7004fa8bc8428128668da1f7497e57 /blockjob.c
parent47970dfb0a611f6468a0ba44781b4610525d1af1 (diff)
blockjob: centralize QMP event emissions
There's no reason to leave this to blockdev; we can do it in blockjobs directly and get rid of an extra callback for most users. All non-internal events, even those created outside of QMP, will consistently emit events. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Jeff Cody <jcody@redhat.com> Message-id: 1477584421-1399-5-git-send-email-jsnow@redhat.com Signed-off-by: Jeff Cody <jcody@redhat.com>
Diffstat (limited to 'blockjob.c')
-rw-r--r--blockjob.c23
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;