Browse Source

blockjob: Remove AioContext notifiers

The notifiers made sure that the job is quiesced and that the
job->aio_context field is updated. The first part is unnecessary today
since bdrv_set_aio_context_ignore() drains the block node, and this
means drainig the block job, too. The second part can be done in the
.set_aio_ctx callback of the block job BdrvChildRole.

The notifiers were problematic because they poll the AioContext while
the graph is in an inconsistent state with some nodes already in the new
context, but others still in the old context. So removing the notifiers
not only simplifies the code, but actually makes the code safer.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
master
Kevin Wolf 1 month ago
parent
commit
657e120320
1 changed files with 2 additions and 41 deletions
  1. 2
    41
      blockjob.c

+ 2
- 41
blockjob.c View File

@@ -81,10 +81,6 @@ BlockJob *block_job_get(const char *id)
81 81
     }
82 82
 }
83 83
 
84
-static void block_job_attached_aio_context(AioContext *new_context,
85
-                                           void *opaque);
86
-static void block_job_detach_aio_context(void *opaque);
87
-
88 84
 void block_job_free(Job *job)
89 85
 {
90 86
     BlockJob *bjob = container_of(job, BlockJob, job);
@@ -92,28 +88,10 @@ void block_job_free(Job *job)
92 88
 
93 89
     bs->job = NULL;
94 90
     block_job_remove_all_bdrv(bjob);
95
-    blk_remove_aio_context_notifier(bjob->blk,
96
-                                    block_job_attached_aio_context,
97
-                                    block_job_detach_aio_context, bjob);
98 91
     blk_unref(bjob->blk);
99 92
     error_free(bjob->blocker);
100 93
 }
101 94
 
102
-static void block_job_attached_aio_context(AioContext *new_context,
103
-                                           void *opaque)
104
-{
105
-    BlockJob *job = opaque;
106
-    const JobDriver *drv = job->job.driver;
107
-    BlockJobDriver *bjdrv = container_of(drv, BlockJobDriver, job_driver);
108
-
109
-    job->job.aio_context = new_context;
110
-    if (bjdrv->attached_aio_context) {
111
-        bjdrv->attached_aio_context(job, new_context);
112
-    }
113
-
114
-    job_resume(&job->job);
115
-}
116
-
117 95
 void block_job_drain(Job *job)
118 96
 {
119 97
     BlockJob *bjob = container_of(job, BlockJob, job);
@@ -126,23 +104,6 @@ void block_job_drain(Job *job)
126 104
     }
127 105
 }
128 106
 
129
-static void block_job_detach_aio_context(void *opaque)
130
-{
131
-    BlockJob *job = opaque;
132
-
133
-    /* In case the job terminates during aio_poll()... */
134
-    job_ref(&job->job);
135
-
136
-    job_pause(&job->job);
137
-
138
-    while (!job->job.paused && !job_is_completed(&job->job)) {
139
-        job_drain(&job->job);
140
-    }
141
-
142
-    job->job.aio_context = NULL;
143
-    job_unref(&job->job);
144
-}
145
-
146 107
 static char *child_job_get_parent_desc(BdrvChild *c)
147 108
 {
148 109
     BlockJob *job = c->opaque;
@@ -212,6 +173,8 @@ static void child_job_set_aio_ctx(BdrvChild *c, AioContext *ctx,
212 173
         *ignore = g_slist_prepend(*ignore, sibling);
213 174
         bdrv_set_aio_context_ignore(sibling->bs, ctx, ignore);
214 175
     }
176
+
177
+    job->job.aio_context = ctx;
215 178
 }
216 179
 
217 180
 static const BdrvChildRole child_job = {
@@ -471,8 +434,6 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,
471 434
 
472 435
     bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker);
473 436
 
474
-    blk_add_aio_context_notifier(blk, block_job_attached_aio_context,
475
-                                 block_job_detach_aio_context, job);
476 437
     blk_set_allow_aio_context_change(blk, true);
477 438
 
478 439
     /* Only set speed when necessary to avoid NotSupported error */

Loading…
Cancel
Save