@@ -343,6 +343,11 @@ static bool backup_change(Job *job, JobChangeOptions *opts, Error **errp)
return block_job_change(bjob, &opts->u.backup, errp);
}
+static void backup_query(Job *job, JobInfo *info)
+{
+ block_job_query(job, &info->u.backup);
+}
+
static const BlockJobDriver backup_job_driver = {
.job_driver = {
.instance_size = sizeof(BackupBlockJob),
@@ -356,6 +361,7 @@ static const BlockJobDriver backup_job_driver = {
.pause = backup_pause,
.cancel = backup_cancel,
.change = backup_change,
+ .query = backup_query,
},
.set_speed = backup_set_speed,
};
@@ -211,6 +211,11 @@ static bool commit_change(Job *job, JobChangeOptions *opts, Error **errp)
return block_job_change(bjob, &opts->u.commit, errp);
}
+static void commit_query(Job *job, JobInfo *info)
+{
+ block_job_query(job, &info->u.commit);
+}
+
static const BlockJobDriver commit_job_driver = {
.job_driver = {
.instance_size = sizeof(CommitBlockJob),
@@ -222,6 +227,7 @@ static const BlockJobDriver commit_job_driver = {
.abort = commit_abort,
.clean = commit_clean,
.change = commit_change,
+ .query = commit_query,
},
};
@@ -1310,6 +1310,8 @@ static void mirror_query(Job *job, JobInfo *info)
info->u.mirror = (JobInfoMirror) {
.actively_synced = qatomic_read(&s->actively_synced),
};
+
+ block_job_query(job, qapi_JobInfoMirror_base(&info->u.mirror));
}
static const BlockJobDriver mirror_job_driver = {
@@ -1338,6 +1340,11 @@ static bool commit_active_change(Job *job, JobChangeOptions *opts, Error **errp)
return block_job_change(bjob, &opts->u.commit, errp);
}
+static void commit_active_query(Job *job, JobInfo *info)
+{
+ block_job_query(job, &info->u.commit);
+}
+
static const BlockJobDriver commit_active_job_driver = {
.job_driver = {
.instance_size = sizeof(MirrorBlockJob),
@@ -1351,6 +1358,7 @@ static const BlockJobDriver commit_active_job_driver = {
.complete = mirror_complete,
.cancel = commit_active_cancel,
.change = commit_active_change,
+ .query = commit_active_query,
},
.drained_poll = mirror_drained_poll,
};
@@ -246,6 +246,11 @@ static bool stream_change(Job *job, JobChangeOptions *opts, Error **errp)
return block_job_change(bjob, &opts->u.stream, errp);
}
+static void stream_query(Job *job, JobInfo *info)
+{
+ block_job_query(job, &info->u.stream);
+}
+
static const BlockJobDriver stream_job_driver = {
.job_driver = {
.instance_size = sizeof(StreamBlockJob),
@@ -256,6 +261,7 @@ static const BlockJobDriver stream_job_driver = {
.clean = stream_clean,
.user_resume = block_job_user_resume,
.change = stream_change,
+ .query = stream_query,
},
};
@@ -306,6 +306,16 @@ bool block_job_set_speed_locked(BlockJob *job, int64_t speed, Error **errp)
return true;
}
+void block_job_query(Job *job, JobInfoBlockJob *info)
+{
+ BlockJob *bjob = container_of(job, BlockJob, job);
+
+ JOB_LOCK_GUARD();
+
+ info->speed = bjob->speed;
+ info->io_status = bjob->iostatus;
+}
+
static bool block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
{
JOB_LOCK_GUARD();
@@ -231,4 +231,10 @@ const BlockJobDriver *block_job_driver(BlockJob *job);
bool block_job_change(BlockJob *job, JobChangeOptionsBlockJob *opts,
Error **errp);
+/**
+ * Common part of .query handler for block-jobs.
+ * Adds block-job specific information to @info.
+ */
+void block_job_query(Job *job, JobInfoBlockJob *info);
+
#endif
@@ -4,6 +4,7 @@
##
# = Background jobs
##
+{ 'include': 'common.json' }
##
# @JobType:
@@ -251,6 +252,20 @@
##
{ 'command': 'job-finalize', 'data': { 'id': 'str' } }
+##
+# @JobInfoBlockJob:
+#
+# Information specific to block jobs like mirror and backup.
+#
+# @io-status: the io status of the job
+#
+# @speed: the rate limit, bytes per second
+#
+# Since: 9.1
+##
+{ 'struct': 'JobInfoBlockJob',
+ 'data': { 'io-status': 'IoStatus', 'speed': 'uint64' } }
+
##
# @JobInfoMirror:
#
@@ -263,6 +278,7 @@
# Since: 9.1
##
{ 'struct': 'JobInfoMirror',
+ 'base': 'JobInfoBlockJob',
'data': { 'actively-synced': 'bool' } }
##
@@ -300,7 +316,10 @@
'current-progress': 'int', 'total-progress': 'int',
'*error': 'str' },
'discriminator': 'type',
- 'data': { 'mirror': 'JobInfoMirror' } }
+ 'data': { 'mirror': 'JobInfoMirror',
+ 'backup': 'JobInfoBlockJob',
+ 'stream': 'JobInfoBlockJob',
+ 'commit': 'JobInfoBlockJob' } }
##
# @query-jobs:
Add io-status and speed, which make sense only for block-jobs. This allows us to finally deprecate old query-block-jobs API in the next commit. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> --- block/backup.c | 6 ++++++ block/commit.c | 6 ++++++ block/mirror.c | 8 ++++++++ block/stream.c | 6 ++++++ blockjob.c | 10 ++++++++++ include/block/blockjob.h | 6 ++++++ qapi/job.json | 21 ++++++++++++++++++++- 7 files changed, 62 insertions(+), 1 deletion(-)