[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC 14/15] qapi: query-job: add block-job specific information
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[RFC 14/15] qapi: query-job: add block-job specific information |
Date: |
Wed, 13 Mar 2024 18:09:06 +0300 |
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(-)
diff --git a/block/backup.c b/block/backup.c
index bf086dc5f9..55bbe85bf6 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -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,
};
diff --git a/block/commit.c b/block/commit.c
index ccb6097679..9199a6adc8 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -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,
},
};
diff --git a/block/mirror.c b/block/mirror.c
index 8e672f3309..e8092d56be 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -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,
};
diff --git a/block/stream.c b/block/stream.c
index 34f4588537..e5e4d0bc77 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -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,
},
};
diff --git a/blockjob.c b/blockjob.c
index de1dd03b2d..7dd1ed3ff2 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -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();
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
index fd7ba1a285..bc33c2ba77 100644
--- a/include/block/blockjob.h
+++ b/include/block/blockjob.h
@@ -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
diff --git a/qapi/job.json b/qapi/job.json
index 036fec1b57..7bd9f8112c 100644
--- a/qapi/job.json
+++ b/qapi/job.json
@@ -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:
--
2.34.1
- Re: [RFC 01/15] scripts/qapi: support type-based unions, (continued)
- [RFC 03/15] blockjob: block_job_change_locked(): check job type, Vladimir Sementsov-Ogievskiy, 2024/03/13
- [RFC 07/15] qapi: add job-change, Vladimir Sementsov-Ogievskiy, 2024/03/13
- [RFC 12/15] qapi: rename BlockDeviceIoStatus to IoStatus, Vladimir Sementsov-Ogievskiy, 2024/03/13
- [RFC 13/15] qapi: move IoStatus to common.json, Vladimir Sementsov-Ogievskiy, 2024/03/13
- [RFC 08/15] qapi: job-change: support speed parameter, Vladimir Sementsov-Ogievskiy, 2024/03/13
- [RFC 09/15] qapi: job-complete: introduce no-block-replace option for mirror, Vladimir Sementsov-Ogievskiy, 2024/03/13
- [RFC 02/15] qapi: rename BlockJobChangeOptions to JobChangeOptions, Vladimir Sementsov-Ogievskiy, 2024/03/13
- [RFC 06/15] blockjob: move change action implementation to job from block-job, Vladimir Sementsov-Ogievskiy, 2024/03/13
- [RFC 10/15] qapi: query-jobs: add information specific for job type, Vladimir Sementsov-Ogievskiy, 2024/03/13
- [RFC 14/15] qapi: query-job: add block-job specific information,
Vladimir Sementsov-Ogievskiy <=
- [RFC 04/15] qapi: block-job-change: make copy-mode parameter optional, Vladimir Sementsov-Ogievskiy, 2024/03/13
- [RFC 15/15] qapi/block-core: derpecate block-job- APIs, Vladimir Sementsov-Ogievskiy, 2024/03/13
- [RFC 05/15] qapi: JobChangeOptions: make type member optional and deprecated, Vladimir Sementsov-Ogievskiy, 2024/03/13
- [RFC 11/15] job-qmp: job_query_single_locked: add assertion on job ret, Vladimir Sementsov-Ogievskiy, 2024/03/13