]> Git Repo - qemu.git/commitdiff
blockjob: Factor out block_job_remove_all_bdrv()
authorKevin Wolf <[email protected]>
Tue, 28 Feb 2017 11:45:58 +0000 (12:45 +0100)
committerKevin Wolf <[email protected]>
Tue, 28 Feb 2017 19:40:37 +0000 (20:40 +0100)
In some cases, we want to remove op blockers on intermediate nodes
before the whole block job transaction has completed (because they block
restoring the final graph state during completion). Provide a function
for this.

The whole block job lifecycle is a bit messed up and it's hard to
actually do all things in the right order, but I'll leave simplifying
this for another day.

Signed-off-by: Kevin Wolf <[email protected]>
Acked-by: Fam Zheng <[email protected]>
Reviewed-by: Max Reitz <[email protected]>
blockjob.c
include/block/blockjob.h

index 4216cdeebf4f3c2932413b4d4fe67d3ac9dc1fae..69126af97fe82e1cb4bd72a5a424fdddeb4287ce 100644 (file)
@@ -128,6 +128,18 @@ static void block_job_detach_aio_context(void *opaque)
     block_job_unref(job);
 }
 
+void block_job_remove_all_bdrv(BlockJob *job)
+{
+    GSList *l;
+    for (l = job->nodes; l; l = l->next) {
+        BdrvChild *c = l->data;
+        bdrv_op_unblock_all(c->bs, job->blocker);
+        bdrv_root_unref_child(c);
+    }
+    g_slist_free(job->nodes);
+    job->nodes = NULL;
+}
+
 int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs,
                        uint64_t perm, uint64_t shared_perm, Error **errp)
 {
@@ -258,15 +270,9 @@ void block_job_ref(BlockJob *job)
 void block_job_unref(BlockJob *job)
 {
     if (--job->refcnt == 0) {
-        GSList *l;
         BlockDriverState *bs = blk_bs(job->blk);
         bs->job = NULL;
-        for (l = job->nodes; l; l = l->next) {
-            BdrvChild *c = l->data;
-            bdrv_op_unblock_all(c->bs, job->blocker);
-            bdrv_root_unref_child(c);
-        }
-        g_slist_free(job->nodes);
+        block_job_remove_all_bdrv(job);
         blk_remove_aio_context_notifier(job->blk,
                                         block_job_attached_aio_context,
                                         block_job_detach_aio_context, job);
index 9d65ef80b800325db471589f37c62027bc66b844..9e906f7d7e9b0c37f746c5f9b745f6ab6deae494 100644 (file)
@@ -180,6 +180,15 @@ BlockJob *block_job_get(const char *id);
 int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs,
                        uint64_t perm, uint64_t shared_perm, Error **errp);
 
+/**
+ * block_job_remove_all_bdrv:
+ * @job: The block job
+ *
+ * Remove all BlockDriverStates from the list of nodes that are involved in the
+ * job. This removes the blockers added with block_job_add_bdrv().
+ */
+void block_job_remove_all_bdrv(BlockJob *job);
+
 /**
  * block_job_set_speed:
  * @job: The job to set the speed for.
This page took 0.02906 seconds and 4 git commands to generate.