[RFC 14/15] qapi: query-job: add block-job specific information

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux