[03/18] blockjob: Make drained_{begin, end} public

Message ID 20170913181910.29688-4-mreitz@redhat.com
State New
Headers show
Series
  • block/mirror: Add active-sync mirroring
Related show

Commit Message

Max Reitz Sept. 13, 2017, 6:18 p.m.
When a block job decides to be represented as a BDS and track its
associated child nodes itself instead of having the BlockJob object
track them, it needs to implement the drained_begin/drained_end child
operations.  In order to do that, it has to be able to control drainage
of the block job (i.e. to pause and resume it).  Therefore, we need to
make these operations public.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 include/block/blockjob.h | 15 +++++++++++++++
 blockjob.c               | 20 ++++++++++++++------
 2 files changed, 29 insertions(+), 6 deletions(-)

Comments

Fam Zheng Sept. 18, 2017, 3:46 a.m. | #1
On Wed, 09/13 20:18, Max Reitz wrote:
> When a block job decides to be represented as a BDS and track its
> associated child nodes itself instead of having the BlockJob object
> track them, it needs to implement the drained_begin/drained_end child
> operations.  In order to do that, it has to be able to control drainage
> of the block job (i.e. to pause and resume it).  Therefore, we need to
> make these operations public.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  include/block/blockjob.h | 15 +++++++++++++++
>  blockjob.c               | 20 ++++++++++++++------
>  2 files changed, 29 insertions(+), 6 deletions(-)
> 
> diff --git a/include/block/blockjob.h b/include/block/blockjob.h
> index 67c0968fa5..a59f316788 100644
> --- a/include/block/blockjob.h
> +++ b/include/block/blockjob.h
> @@ -339,6 +339,21 @@ void block_job_ref(BlockJob *job);
>  void block_job_unref(BlockJob *job);
>  
>  /**
> + * block_job_drained_begin:
> + *
> + * Inhibit I/O requests initiated by the block job.
> + */
> +void block_job_drained_begin(BlockJob *job);
> +
> +/**
> + * block_job_drained_end:
> + *
> + * Resume I/O after it has been paused through
> + * block_job_drained_begin().
> + */
> +void block_job_drained_end(BlockJob *job);
> +
> +/**
>   * block_job_txn_unref:
>   *
>   * Release a reference that was previously acquired with block_job_txn_add_job
> diff --git a/blockjob.c b/blockjob.c
> index 3a0c49137e..4312a121fa 100644
> --- a/blockjob.c
> +++ b/blockjob.c
> @@ -217,21 +217,29 @@ static const BdrvChildRole child_job = {
>      .stay_at_node       = true,
>  };
>  
> -static void block_job_drained_begin(void *opaque)
> +void block_job_drained_begin(BlockJob *job)
>  {
> -    BlockJob *job = opaque;
>      block_job_pause(job);
>  }
>  
> -static void block_job_drained_end(void *opaque)
> +static void block_job_drained_begin_op(void *opaque)
> +{
> +    block_job_drained_begin(opaque);
> +}
> +
> +void block_job_drained_end(BlockJob *job)
>  {
> -    BlockJob *job = opaque;
>      block_job_resume(job);
>  }
>  
> +static void block_job_drained_end_op(void *opaque)
> +{
> +    block_job_drained_end(opaque);
> +}
> +
>  static const BlockDevOps block_job_dev_ops = {
> -    .drained_begin = block_job_drained_begin,
> -    .drained_end = block_job_drained_end,
> +    .drained_begin = block_job_drained_begin_op,
> +    .drained_end = block_job_drained_end_op,
>  };
>  
>  void block_job_remove_all_bdrv(BlockJob *job)
> -- 
> 2.13.5
> 
> 

Reviewed-by: Fam Zheng <famz@redhat.com>

Patch

diff --git a/include/block/blockjob.h b/include/block/blockjob.h
index 67c0968fa5..a59f316788 100644
--- a/include/block/blockjob.h
+++ b/include/block/blockjob.h
@@ -339,6 +339,21 @@  void block_job_ref(BlockJob *job);
 void block_job_unref(BlockJob *job);
 
 /**
+ * block_job_drained_begin:
+ *
+ * Inhibit I/O requests initiated by the block job.
+ */
+void block_job_drained_begin(BlockJob *job);
+
+/**
+ * block_job_drained_end:
+ *
+ * Resume I/O after it has been paused through
+ * block_job_drained_begin().
+ */
+void block_job_drained_end(BlockJob *job);
+
+/**
  * block_job_txn_unref:
  *
  * Release a reference that was previously acquired with block_job_txn_add_job
diff --git a/blockjob.c b/blockjob.c
index 3a0c49137e..4312a121fa 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -217,21 +217,29 @@  static const BdrvChildRole child_job = {
     .stay_at_node       = true,
 };
 
-static void block_job_drained_begin(void *opaque)
+void block_job_drained_begin(BlockJob *job)
 {
-    BlockJob *job = opaque;
     block_job_pause(job);
 }
 
-static void block_job_drained_end(void *opaque)
+static void block_job_drained_begin_op(void *opaque)
+{
+    block_job_drained_begin(opaque);
+}
+
+void block_job_drained_end(BlockJob *job)
 {
-    BlockJob *job = opaque;
     block_job_resume(job);
 }
 
+static void block_job_drained_end_op(void *opaque)
+{
+    block_job_drained_end(opaque);
+}
+
 static const BlockDevOps block_job_dev_ops = {
-    .drained_begin = block_job_drained_begin,
-    .drained_end = block_job_drained_end,
+    .drained_begin = block_job_drained_begin_op,
+    .drained_end = block_job_drained_end_op,
 };
 
 void block_job_remove_all_bdrv(BlockJob *job)