diff mbox series

[v2,09/10] mirror: return mirror-specific information upon query

Message ID 20231009094619.469668-10-f.ebner@proxmox.com
State New
Headers show
Series mirror: allow switching from background to active mode | expand

Commit Message

Fiona Ebner Oct. 9, 2023, 9:46 a.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>
---

Changes in v2:
    * udpate QEMU version in QAPI
    * update indentation in QAPI (like in a937b6aa73 ("qapi: Reformat
      doc comments to conform to current conventions"))

 block/mirror.c       | 10 ++++++++++
 qapi/block-core.json | 16 +++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)

Comments

Vladimir Sementsov-Ogievskiy Oct. 10, 2023, 7:53 p.m. UTC | #1
On 09.10.23 12:46, Fiona Ebner wrote:
> 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>
> ---
> 
> Changes in v2:
>      * udpate QEMU version in QAPI
>      * update indentation in QAPI (like in a937b6aa73 ("qapi: Reformat
>        doc comments to conform to current conventions"))
> 
>   block/mirror.c       | 10 ++++++++++
>   qapi/block-core.json | 16 +++++++++++++++-
>   2 files changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/block/mirror.c b/block/mirror.c
> index 83aa4176c2..33b72ec5e5 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -1267,6 +1267,15 @@ static void mirror_change(BlockJob *job, BlockJobChangeOptions *opts,
>       s->copy_mode = MIRROR_COPY_MODE_WRITE_BLOCKING;
>   }
>   
> +static void mirror_query(BlockJob *job, BlockJobInfo *info)
> +{
> +    MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
> +
> +    info->u.mirror = (BlockJobInfoMirror) {
> +        .actively_synced = s->actively_synced,

So, seems we should use atomic operations to access this field too

> +    };
> +}
> +
>   static const BlockJobDriver mirror_job_driver = {
>       .job_driver = {
>           .instance_size          = sizeof(MirrorBlockJob),
> @@ -1282,6 +1291,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 950542b735..35d67410cc 100644
> --- a/qapi/block-core.json
> +++ b/qapi/block-core.json
> @@ -1352,6 +1352,20 @@
>   { '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.2
> +##
> +{ 'struct': 'BlockJobInfoMirror',
> +  'data': { 'actively-synced': 'bool' } }
> +
>   ##
>   # @BlockJobInfo:
>   #
> @@ -1403,7 +1417,7 @@
>              'auto-finalize': 'bool', 'auto-dismiss': 'bool',
>              '*error': 'str' },
>     'discriminator': 'type',
> -  'data': {} }
> +  'data': { 'mirror': 'BlockJobInfoMirror' } }
>   
>   ##
>   # @query-block-jobs:
diff mbox series

Patch

diff --git a/block/mirror.c b/block/mirror.c
index 83aa4176c2..33b72ec5e5 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -1267,6 +1267,15 @@  static void mirror_change(BlockJob *job, BlockJobChangeOptions *opts,
     s->copy_mode = MIRROR_COPY_MODE_WRITE_BLOCKING;
 }
 
+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),
@@ -1282,6 +1291,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 950542b735..35d67410cc 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -1352,6 +1352,20 @@ 
 { '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.2
+##
+{ 'struct': 'BlockJobInfoMirror',
+  'data': { 'actively-synced': 'bool' } }
+
 ##
 # @BlockJobInfo:
 #
@@ -1403,7 +1417,7 @@ 
            'auto-finalize': 'bool', 'auto-dismiss': 'bool',
            '*error': 'str' },
   'discriminator': 'type',
-  'data': {} }
+  'data': { 'mirror': 'BlockJobInfoMirror' } }
 
 ##
 # @query-block-jobs: