diff mbox series

[7/9] mirror: return mirror-specific information upon query

Message ID 20230224144825.466375-8-f.ebner@proxmox.com (mailing list archive)
State New, archived
Headers show
Series mirror: allow switching from background to active mode | expand

Commit Message

Fiona Ebner Feb. 24, 2023, 2:48 p.m. UTC
To start out, only actively-synced is returned.

For example, this is useful for jobs that started out in background
mode and switched to active mode. Once actively-synced is true, it's
clear that the mode switch has been completed. Note that completion of
the switch might happen much earlier, e.g. if the switch happens
before the job is ready, once all background operations have finished.
It's assumed that whether the disks are actively-synced or not is more
interesting than whether the mode switch completed. That information
can still be added if required in the future.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 block/mirror.c       | 10 ++++++++++
 qapi/block-core.json | 15 ++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/block/mirror.c b/block/mirror.c
index 961aaa5cd6..02b5bd8bd2 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -1253,6 +1253,15 @@  static void mirror_change(BlockJob *job, BlockJobChangeOptions *opts,
     s->in_drain = false;
 }
 
+static void mirror_query(BlockJob *job, BlockJobInfo *info)
+{
+    MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
+
+    info->u.mirror = (BlockJobInfoMirror) {
+        .actively_synced = s->actively_synced,
+    };
+}
+
 static const BlockJobDriver mirror_job_driver = {
     .job_driver = {
         .instance_size          = sizeof(MirrorBlockJob),
@@ -1268,6 +1277,7 @@  static const BlockJobDriver mirror_job_driver = {
     },
     .drained_poll           = mirror_drained_poll,
     .change                 = mirror_change,
+    .query                  = mirror_query,
 };
 
 static const BlockJobDriver commit_active_job_driver = {
diff --git a/qapi/block-core.json b/qapi/block-core.json
index adb43a4592..07e0f30492 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -1300,6 +1300,19 @@ 
 { 'enum': 'MirrorCopyMode',
   'data': ['background', 'write-blocking'] }
 
+##
+# @BlockJobInfoMirror:
+#
+# Information specific to mirror block jobs.
+#
+# @actively-synced: Whether the source is actively synced to the target, i.e.
+#                   same data and new writes are done synchronously to both.
+#
+# Since 8.0
+##
+{ 'struct': 'BlockJobInfoMirror',
+  'data': { 'actively-synced': 'bool' } }
+
 ##
 # @BlockJobInfo:
 #
@@ -1350,7 +1363,7 @@ 
            'auto-finalize': 'bool', 'auto-dismiss': 'bool',
            '*error': 'str' },
   'discriminator': 'type',
-  'data': {} }
+  'data': { 'mirror': 'BlockJobInfoMirror' } }
 
 ##
 # @query-block-jobs: