Paolo Bonzini | 2f0c9fe | 2012-09-28 17:22:47 +0200 | [diff] [blame] | 1 | /* |
| 2 | * QEMU System Emulator block driver |
| 3 | * |
| 4 | * Copyright (c) 2011 IBM Corp. |
| 5 | * Copyright (c) 2012 Red Hat, Inc. |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | * of this software and associated documentation files (the "Software"), to deal |
| 9 | * in the Software without restriction, including without limitation the rights |
| 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | * copies of the Software, and to permit persons to whom the Software is |
| 12 | * furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice shall be included in |
| 15 | * all copies or substantial portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | * THE SOFTWARE. |
| 24 | */ |
| 25 | |
Peter Maydell | d38ea87 | 2016-01-29 17:50:05 +0000 | [diff] [blame] | 26 | #include "qemu/osdep.h" |
Paolo Bonzini | 2f0c9fe | 2012-09-28 17:22:47 +0200 | [diff] [blame] | 27 | #include "qemu-common.h" |
Paolo Bonzini | 737e150 | 2012-12-17 18:19:44 +0100 | [diff] [blame] | 28 | #include "block/block.h" |
John Snow | c87621e | 2016-10-27 12:07:00 -0400 | [diff] [blame] | 29 | #include "block/blockjob_int.h" |
Paolo Bonzini | 737e150 | 2012-12-17 18:19:44 +0100 | [diff] [blame] | 30 | #include "block/block_int.h" |
John Snow | c9de405 | 2018-03-10 03:27:30 -0500 | [diff] [blame] | 31 | #include "block/trace.h" |
Max Reitz | 373340b | 2015-10-19 17:53:22 +0200 | [diff] [blame] | 32 | #include "sysemu/block-backend.h" |
Markus Armbruster | e688df6 | 2018-02-01 12:18:31 +0100 | [diff] [blame] | 33 | #include "qapi/error.h" |
Markus Armbruster | 9af2398 | 2018-02-11 10:36:01 +0100 | [diff] [blame] | 34 | #include "qapi/qapi-events-block-core.h" |
Markus Armbruster | cc7a8ea | 2015-03-17 17:22:46 +0100 | [diff] [blame] | 35 | #include "qapi/qmp/qerror.h" |
Daniel P. Berrange | 10817bf | 2015-09-01 14:48:02 +0100 | [diff] [blame] | 36 | #include "qemu/coroutine.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 37 | #include "qemu/timer.h" |
Paolo Bonzini | 2f0c9fe | 2012-09-28 17:22:47 +0200 | [diff] [blame] | 38 | |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 39 | /* |
| 40 | * The block job API is composed of two categories of functions. |
| 41 | * |
| 42 | * The first includes functions used by the monitor. The monitor is |
| 43 | * peculiar in that it accesses the block job list with block_job_get, and |
| 44 | * therefore needs consistency across block_job_get and the actual operation |
| 45 | * (e.g. block_job_set_speed). The consistency is achieved with |
| 46 | * aio_context_acquire/release. These functions are declared in blockjob.h. |
| 47 | * |
| 48 | * The second includes functions used by the block job drivers and sometimes |
| 49 | * by the core block layer. These do not care about locking, because the |
| 50 | * whole coroutine runs under the AioContext lock, and are declared in |
| 51 | * blockjob_int.h. |
| 52 | */ |
| 53 | |
Kevin Wolf | e7c1d78 | 2018-04-12 17:54:37 +0200 | [diff] [blame] | 54 | static bool is_block_job(Job *job) |
Alberto Garcia | a711279 | 2016-04-04 16:43:51 +0300 | [diff] [blame] | 55 | { |
Kevin Wolf | e7c1d78 | 2018-04-12 17:54:37 +0200 | [diff] [blame] | 56 | return job_type(job) == JOB_TYPE_BACKUP || |
| 57 | job_type(job) == JOB_TYPE_COMMIT || |
| 58 | job_type(job) == JOB_TYPE_MIRROR || |
| 59 | job_type(job) == JOB_TYPE_STREAM; |
| 60 | } |
| 61 | |
| 62 | BlockJob *block_job_next(BlockJob *bjob) |
| 63 | { |
| 64 | Job *job = bjob ? &bjob->job : NULL; |
| 65 | |
| 66 | do { |
| 67 | job = job_next(job); |
| 68 | } while (job && !is_block_job(job)); |
| 69 | |
| 70 | return job ? container_of(job, BlockJob, job) : NULL; |
Alberto Garcia | a711279 | 2016-04-04 16:43:51 +0300 | [diff] [blame] | 71 | } |
| 72 | |
Alberto Garcia | ffb1f10 | 2016-07-05 17:28:54 +0300 | [diff] [blame] | 73 | BlockJob *block_job_get(const char *id) |
| 74 | { |
Kevin Wolf | e7c1d78 | 2018-04-12 17:54:37 +0200 | [diff] [blame] | 75 | Job *job = job_get(id); |
Alberto Garcia | ffb1f10 | 2016-07-05 17:28:54 +0300 | [diff] [blame] | 76 | |
Kevin Wolf | e7c1d78 | 2018-04-12 17:54:37 +0200 | [diff] [blame] | 77 | if (job && is_block_job(job)) { |
| 78 | return container_of(job, BlockJob, job); |
| 79 | } else { |
| 80 | return NULL; |
Alberto Garcia | ffb1f10 | 2016-07-05 17:28:54 +0300 | [diff] [blame] | 81 | } |
Alberto Garcia | ffb1f10 | 2016-07-05 17:28:54 +0300 | [diff] [blame] | 82 | } |
| 83 | |
Paolo Bonzini | 05b0d8e | 2017-05-08 16:13:02 +0200 | [diff] [blame] | 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 | |
Kevin Wolf | 80fa2c7 | 2018-04-13 18:50:05 +0200 | [diff] [blame] | 88 | void block_job_free(Job *job) |
Paolo Bonzini | 05b0d8e | 2017-05-08 16:13:02 +0200 | [diff] [blame] | 89 | { |
Kevin Wolf | 80fa2c7 | 2018-04-13 18:50:05 +0200 | [diff] [blame] | 90 | BlockJob *bjob = container_of(job, BlockJob, job); |
| 91 | BlockDriverState *bs = blk_bs(bjob->blk); |
| 92 | |
Kevin Wolf | 80fa2c7 | 2018-04-13 18:50:05 +0200 | [diff] [blame] | 93 | bs->job = NULL; |
| 94 | 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 | blk_unref(bjob->blk); |
| 99 | error_free(bjob->blocker); |
Paolo Bonzini | 05b0d8e | 2017-05-08 16:13:02 +0200 | [diff] [blame] | 100 | } |
| 101 | |
Stefan Hajnoczi | 463e0be | 2016-06-16 17:56:27 +0100 | [diff] [blame] | 102 | static void block_job_attached_aio_context(AioContext *new_context, |
| 103 | void *opaque) |
| 104 | { |
| 105 | BlockJob *job = opaque; |
| 106 | |
Kevin Wolf | 08be6fe | 2018-04-17 13:49:33 +0200 | [diff] [blame] | 107 | job->job.aio_context = new_context; |
Stefan Hajnoczi | 463e0be | 2016-06-16 17:56:27 +0100 | [diff] [blame] | 108 | if (job->driver->attached_aio_context) { |
| 109 | job->driver->attached_aio_context(job, new_context); |
| 110 | } |
| 111 | |
Kevin Wolf | b15de82 | 2018-04-18 17:10:26 +0200 | [diff] [blame] | 112 | job_resume(&job->job); |
Stefan Hajnoczi | 463e0be | 2016-06-16 17:56:27 +0100 | [diff] [blame] | 113 | } |
| 114 | |
Kevin Wolf | b69f777 | 2018-04-20 17:00:29 +0200 | [diff] [blame] | 115 | void block_job_drain(Job *job) |
Paolo Bonzini | bae8196 | 2016-10-27 12:48:50 +0200 | [diff] [blame] | 116 | { |
Kevin Wolf | b69f777 | 2018-04-20 17:00:29 +0200 | [diff] [blame] | 117 | BlockJob *bjob = container_of(job, BlockJob, job); |
Paolo Bonzini | bae8196 | 2016-10-27 12:48:50 +0200 | [diff] [blame] | 118 | |
Kevin Wolf | b69f777 | 2018-04-20 17:00:29 +0200 | [diff] [blame] | 119 | blk_drain(bjob->blk); |
| 120 | if (bjob->driver->drain) { |
| 121 | bjob->driver->drain(bjob); |
Paolo Bonzini | bae8196 | 2016-10-27 12:48:50 +0200 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
Stefan Hajnoczi | 463e0be | 2016-06-16 17:56:27 +0100 | [diff] [blame] | 125 | static void block_job_detach_aio_context(void *opaque) |
| 126 | { |
| 127 | BlockJob *job = opaque; |
| 128 | |
| 129 | /* In case the job terminates during aio_poll()... */ |
Kevin Wolf | 80fa2c7 | 2018-04-13 18:50:05 +0200 | [diff] [blame] | 130 | job_ref(&job->job); |
Stefan Hajnoczi | 463e0be | 2016-06-16 17:56:27 +0100 | [diff] [blame] | 131 | |
Kevin Wolf | b15de82 | 2018-04-18 17:10:26 +0200 | [diff] [blame] | 132 | job_pause(&job->job); |
Stefan Hajnoczi | 463e0be | 2016-06-16 17:56:27 +0100 | [diff] [blame] | 133 | |
Kevin Wolf | dbe5e6c | 2018-04-19 13:04:01 +0200 | [diff] [blame] | 134 | while (!job->job.paused && !job_is_completed(&job->job)) { |
Kevin Wolf | b69f777 | 2018-04-20 17:00:29 +0200 | [diff] [blame] | 135 | job_drain(&job->job); |
Stefan Hajnoczi | 463e0be | 2016-06-16 17:56:27 +0100 | [diff] [blame] | 136 | } |
| 137 | |
Kevin Wolf | 08be6fe | 2018-04-17 13:49:33 +0200 | [diff] [blame] | 138 | job->job.aio_context = NULL; |
Kevin Wolf | 80fa2c7 | 2018-04-13 18:50:05 +0200 | [diff] [blame] | 139 | job_unref(&job->job); |
Stefan Hajnoczi | 463e0be | 2016-06-16 17:56:27 +0100 | [diff] [blame] | 140 | } |
| 141 | |
Paolo Bonzini | f321dcb | 2017-05-08 16:13:03 +0200 | [diff] [blame] | 142 | static char *child_job_get_parent_desc(BdrvChild *c) |
| 143 | { |
| 144 | BlockJob *job = c->opaque; |
Kevin Wolf | 252291e | 2018-04-12 17:57:08 +0200 | [diff] [blame] | 145 | return g_strdup_printf("%s job '%s'", job_type_str(&job->job), job->job.id); |
Paolo Bonzini | f321dcb | 2017-05-08 16:13:03 +0200 | [diff] [blame] | 146 | } |
| 147 | |
Kevin Wolf | ad90feb | 2017-12-12 19:04:28 +0100 | [diff] [blame] | 148 | static void child_job_drained_begin(BdrvChild *c) |
Paolo Bonzini | f321dcb | 2017-05-08 16:13:03 +0200 | [diff] [blame] | 149 | { |
Kevin Wolf | ad90feb | 2017-12-12 19:04:28 +0100 | [diff] [blame] | 150 | BlockJob *job = c->opaque; |
Kevin Wolf | b15de82 | 2018-04-18 17:10:26 +0200 | [diff] [blame] | 151 | job_pause(&job->job); |
Paolo Bonzini | f321dcb | 2017-05-08 16:13:03 +0200 | [diff] [blame] | 152 | } |
| 153 | |
Kevin Wolf | ad90feb | 2017-12-12 19:04:28 +0100 | [diff] [blame] | 154 | static void child_job_drained_end(BdrvChild *c) |
Paolo Bonzini | f321dcb | 2017-05-08 16:13:03 +0200 | [diff] [blame] | 155 | { |
Kevin Wolf | ad90feb | 2017-12-12 19:04:28 +0100 | [diff] [blame] | 156 | BlockJob *job = c->opaque; |
Kevin Wolf | b15de82 | 2018-04-18 17:10:26 +0200 | [diff] [blame] | 157 | job_resume(&job->job); |
Paolo Bonzini | f321dcb | 2017-05-08 16:13:03 +0200 | [diff] [blame] | 158 | } |
| 159 | |
Kevin Wolf | ad90feb | 2017-12-12 19:04:28 +0100 | [diff] [blame] | 160 | static const BdrvChildRole child_job = { |
| 161 | .get_parent_desc = child_job_get_parent_desc, |
| 162 | .drained_begin = child_job_drained_begin, |
| 163 | .drained_end = child_job_drained_end, |
| 164 | .stay_at_node = true, |
Paolo Bonzini | f321dcb | 2017-05-08 16:13:03 +0200 | [diff] [blame] | 165 | }; |
| 166 | |
Kevin Wolf | bbc02b9 | 2017-02-28 12:45:58 +0100 | [diff] [blame] | 167 | void block_job_remove_all_bdrv(BlockJob *job) |
| 168 | { |
| 169 | GSList *l; |
| 170 | for (l = job->nodes; l; l = l->next) { |
| 171 | BdrvChild *c = l->data; |
| 172 | bdrv_op_unblock_all(c->bs, job->blocker); |
| 173 | bdrv_root_unref_child(c); |
| 174 | } |
| 175 | g_slist_free(job->nodes); |
| 176 | job->nodes = NULL; |
| 177 | } |
| 178 | |
Kevin Wolf | 76d554e | 2017-01-17 11:56:42 +0100 | [diff] [blame] | 179 | int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs, |
| 180 | uint64_t perm, uint64_t shared_perm, Error **errp) |
Alberto Garcia | 23d402d | 2016-10-28 10:08:04 +0300 | [diff] [blame] | 181 | { |
Kevin Wolf | 76d554e | 2017-01-17 11:56:42 +0100 | [diff] [blame] | 182 | BdrvChild *c; |
| 183 | |
| 184 | c = bdrv_root_attach_child(bs, name, &child_job, perm, shared_perm, |
| 185 | job, errp); |
| 186 | if (c == NULL) { |
| 187 | return -EPERM; |
| 188 | } |
| 189 | |
| 190 | job->nodes = g_slist_prepend(job->nodes, c); |
Alberto Garcia | 23d402d | 2016-10-28 10:08:04 +0300 | [diff] [blame] | 191 | bdrv_ref(bs); |
| 192 | bdrv_op_block_all(bs, job->blocker); |
Kevin Wolf | 76d554e | 2017-01-17 11:56:42 +0100 | [diff] [blame] | 193 | |
| 194 | return 0; |
Alberto Garcia | 23d402d | 2016-10-28 10:08:04 +0300 | [diff] [blame] | 195 | } |
| 196 | |
John Snow | 559b935 | 2016-10-27 12:06:55 -0400 | [diff] [blame] | 197 | bool block_job_is_internal(BlockJob *job) |
| 198 | { |
Kevin Wolf | 33e9e9b | 2018-04-12 17:29:59 +0200 | [diff] [blame] | 199 | return (job->job.id == NULL); |
John Snow | 559b935 | 2016-10-27 12:06:55 -0400 | [diff] [blame] | 200 | } |
| 201 | |
Kevin Wolf | bd21935 | 2018-01-19 15:54:40 +0100 | [diff] [blame] | 202 | const BlockJobDriver *block_job_driver(BlockJob *job) |
| 203 | { |
| 204 | return job->driver; |
| 205 | } |
| 206 | |
Kevin Wolf | da01ff7 | 2018-04-13 17:31:02 +0200 | [diff] [blame] | 207 | /* Assumes the job_mutex is held */ |
| 208 | static bool job_timer_pending(Job *job) |
| 209 | { |
| 210 | return timer_pending(&job->sleep_timer); |
| 211 | } |
| 212 | |
Paolo Bonzini | 2f0c9fe | 2012-09-28 17:22:47 +0200 | [diff] [blame] | 213 | void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp) |
| 214 | { |
John Snow | aa9ef2e | 2017-12-13 15:46:11 -0500 | [diff] [blame] | 215 | int64_t old_speed = job->speed; |
Paolo Bonzini | 2f0c9fe | 2012-09-28 17:22:47 +0200 | [diff] [blame] | 216 | |
Kevin Wolf | a50c2ab | 2018-04-13 17:19:31 +0200 | [diff] [blame] | 217 | if (job_apply_verb(&job->job, JOB_VERB_SET_SPEED, errp)) { |
John Snow | 0ec4dfb | 2018-03-10 03:27:32 -0500 | [diff] [blame] | 218 | return; |
| 219 | } |
Kevin Wolf | 18bb692 | 2018-01-18 20:25:40 +0100 | [diff] [blame] | 220 | if (speed < 0) { |
| 221 | error_setg(errp, QERR_INVALID_PARAMETER, "speed"); |
Paolo Bonzini | 2f0c9fe | 2012-09-28 17:22:47 +0200 | [diff] [blame] | 222 | return; |
| 223 | } |
| 224 | |
Kevin Wolf | 18bb692 | 2018-01-18 20:25:40 +0100 | [diff] [blame] | 225 | ratelimit_set_speed(&job->limit, speed, BLOCK_JOB_SLICE_TIME); |
| 226 | |
Paolo Bonzini | 2f0c9fe | 2012-09-28 17:22:47 +0200 | [diff] [blame] | 227 | job->speed = speed; |
John Snow | d4fce18 | 2018-03-10 03:27:26 -0500 | [diff] [blame] | 228 | if (speed && speed <= old_speed) { |
John Snow | aa9ef2e | 2017-12-13 15:46:11 -0500 | [diff] [blame] | 229 | return; |
| 230 | } |
| 231 | |
| 232 | /* kick only if a timer is pending */ |
Kevin Wolf | da01ff7 | 2018-04-13 17:31:02 +0200 | [diff] [blame] | 233 | job_enter_cond(&job->job, job_timer_pending); |
Paolo Bonzini | 2f0c9fe | 2012-09-28 17:22:47 +0200 | [diff] [blame] | 234 | } |
| 235 | |
Kevin Wolf | dee81d5 | 2018-01-18 21:19:38 +0100 | [diff] [blame] | 236 | int64_t block_job_ratelimit_get_delay(BlockJob *job, uint64_t n) |
| 237 | { |
| 238 | if (!job->speed) { |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | return ratelimit_calculate_delay(&job->limit, n); |
| 243 | } |
| 244 | |
John Snow | 75f7105 | 2018-03-10 03:27:36 -0500 | [diff] [blame] | 245 | void block_job_dismiss(BlockJob **jobptr, Error **errp) |
| 246 | { |
| 247 | BlockJob *job = *jobptr; |
| 248 | /* similarly to _complete, this is QMP-interface only. */ |
Kevin Wolf | 33e9e9b | 2018-04-12 17:29:59 +0200 | [diff] [blame] | 249 | assert(job->job.id); |
Kevin Wolf | a50c2ab | 2018-04-13 17:19:31 +0200 | [diff] [blame] | 250 | if (job_apply_verb(&job->job, JOB_VERB_DISMISS, errp)) { |
John Snow | 75f7105 | 2018-03-10 03:27:36 -0500 | [diff] [blame] | 251 | return; |
| 252 | } |
| 253 | |
Kevin Wolf | 4ad3518 | 2018-04-19 17:30:16 +0200 | [diff] [blame] | 254 | job_do_dismiss(&job->job); |
John Snow | 75f7105 | 2018-03-10 03:27:36 -0500 | [diff] [blame] | 255 | *jobptr = NULL; |
| 256 | } |
| 257 | |
Liang Li | b76e445 | 2018-03-13 08:12:16 -0400 | [diff] [blame] | 258 | void block_job_cancel(BlockJob *job, bool force) |
Paolo Bonzini | 8acc72a | 2012-09-28 17:22:50 +0200 | [diff] [blame] | 259 | { |
Kevin Wolf | a50c2ab | 2018-04-13 17:19:31 +0200 | [diff] [blame] | 260 | if (job->job.status == JOB_STATUS_CONCLUDED) { |
Kevin Wolf | 4ad3518 | 2018-04-19 17:30:16 +0200 | [diff] [blame] | 261 | job_do_dismiss(&job->job); |
John Snow | 11b61fb | 2018-03-10 03:27:43 -0500 | [diff] [blame] | 262 | return; |
| 263 | } |
Kevin Wolf | 004e95d | 2018-04-20 14:56:08 +0200 | [diff] [blame] | 264 | job_cancel_async(&job->job, force); |
Kevin Wolf | da01ff7 | 2018-04-13 17:31:02 +0200 | [diff] [blame] | 265 | if (!job_started(&job->job)) { |
John Snow | 5ccac6f | 2016-11-08 01:50:37 -0500 | [diff] [blame] | 266 | block_job_completed(job, -ECANCELED); |
Kevin Wolf | 1908a55 | 2018-04-17 16:41:17 +0200 | [diff] [blame] | 267 | } else if (job->job.deferred_to_main_loop) { |
Kevin Wolf | 7eaa8fb | 2018-04-23 16:06:26 +0200 | [diff] [blame^] | 268 | job_completed_txn_abort(&job->job); |
John Snow | 11b61fb | 2018-03-10 03:27:43 -0500 | [diff] [blame] | 269 | } else { |
| 270 | block_job_enter(job); |
John Snow | 5ccac6f | 2016-11-08 01:50:37 -0500 | [diff] [blame] | 271 | } |
Paolo Bonzini | 8acc72a | 2012-09-28 17:22:50 +0200 | [diff] [blame] | 272 | } |
| 273 | |
Liang Li | b76e445 | 2018-03-13 08:12:16 -0400 | [diff] [blame] | 274 | void block_job_user_cancel(BlockJob *job, bool force, Error **errp) |
John Snow | 0ec4dfb | 2018-03-10 03:27:32 -0500 | [diff] [blame] | 275 | { |
Kevin Wolf | a50c2ab | 2018-04-13 17:19:31 +0200 | [diff] [blame] | 276 | if (job_apply_verb(&job->job, JOB_VERB_CANCEL, errp)) { |
John Snow | 0ec4dfb | 2018-03-10 03:27:32 -0500 | [diff] [blame] | 277 | return; |
| 278 | } |
Liang Li | b76e445 | 2018-03-13 08:12:16 -0400 | [diff] [blame] | 279 | block_job_cancel(job, force); |
John Snow | 0ec4dfb | 2018-03-10 03:27:32 -0500 | [diff] [blame] | 280 | } |
| 281 | |
Max Reitz | 345f9e1 | 2014-10-24 15:57:33 +0200 | [diff] [blame] | 282 | /* A wrapper around block_job_cancel() taking an Error ** parameter so it may be |
Kevin Wolf | 6a74c07 | 2018-04-20 15:33:57 +0200 | [diff] [blame] | 283 | * used with job_finish_sync() without the need for (rather nasty) function |
| 284 | * pointer casts there. */ |
| 285 | static void block_job_cancel_err(Job *job, Error **errp) |
Max Reitz | 345f9e1 | 2014-10-24 15:57:33 +0200 | [diff] [blame] | 286 | { |
Kevin Wolf | 6a74c07 | 2018-04-20 15:33:57 +0200 | [diff] [blame] | 287 | BlockJob *bjob = container_of(job, BlockJob, job); |
| 288 | assert(is_block_job(job)); |
| 289 | block_job_cancel(bjob, false); |
Max Reitz | 345f9e1 | 2014-10-24 15:57:33 +0200 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | int block_job_cancel_sync(BlockJob *job) |
| 293 | { |
Kevin Wolf | 6a74c07 | 2018-04-20 15:33:57 +0200 | [diff] [blame] | 294 | return job_finish_sync(&job->job, &block_job_cancel_err, NULL); |
Max Reitz | 345f9e1 | 2014-10-24 15:57:33 +0200 | [diff] [blame] | 295 | } |
| 296 | |
Kevin Wolf | a1a2af0 | 2016-04-08 18:26:37 +0200 | [diff] [blame] | 297 | void block_job_cancel_sync_all(void) |
| 298 | { |
| 299 | BlockJob *job; |
| 300 | AioContext *aio_context; |
| 301 | |
Kevin Wolf | e7c1d78 | 2018-04-12 17:54:37 +0200 | [diff] [blame] | 302 | while ((job = block_job_next(NULL))) { |
Kevin Wolf | b6d2e59 | 2016-04-08 14:51:09 +0200 | [diff] [blame] | 303 | aio_context = blk_get_aio_context(job->blk); |
Kevin Wolf | a1a2af0 | 2016-04-08 18:26:37 +0200 | [diff] [blame] | 304 | aio_context_acquire(aio_context); |
| 305 | block_job_cancel_sync(job); |
| 306 | aio_context_release(aio_context); |
| 307 | } |
| 308 | } |
| 309 | |
Max Reitz | 345f9e1 | 2014-10-24 15:57:33 +0200 | [diff] [blame] | 310 | int block_job_complete_sync(BlockJob *job, Error **errp) |
| 311 | { |
Kevin Wolf | 6a74c07 | 2018-04-20 15:33:57 +0200 | [diff] [blame] | 312 | return job_finish_sync(&job->job, job_complete, errp); |
Max Reitz | 345f9e1 | 2014-10-24 15:57:33 +0200 | [diff] [blame] | 313 | } |
| 314 | |
Kevin Wolf | 05df8a6 | 2018-01-18 18:08:22 +0100 | [diff] [blame] | 315 | void block_job_progress_update(BlockJob *job, uint64_t done) |
| 316 | { |
| 317 | job->offset += done; |
| 318 | } |
| 319 | |
| 320 | void block_job_progress_set_remaining(BlockJob *job, uint64_t remaining) |
| 321 | { |
| 322 | job->len = job->offset + remaining; |
| 323 | } |
| 324 | |
John Snow | 559b935 | 2016-10-27 12:06:55 -0400 | [diff] [blame] | 325 | BlockJobInfo *block_job_query(BlockJob *job, Error **errp) |
Paolo Bonzini | 30e628b | 2012-09-28 17:22:48 +0200 | [diff] [blame] | 326 | { |
John Snow | 559b935 | 2016-10-27 12:06:55 -0400 | [diff] [blame] | 327 | BlockJobInfo *info; |
| 328 | |
| 329 | if (block_job_is_internal(job)) { |
| 330 | error_setg(errp, "Cannot query QEMU internal jobs"); |
| 331 | return NULL; |
| 332 | } |
| 333 | info = g_new0(BlockJobInfo, 1); |
Kevin Wolf | 252291e | 2018-04-12 17:57:08 +0200 | [diff] [blame] | 334 | info->type = g_strdup(job_type_str(&job->job)); |
Kevin Wolf | 33e9e9b | 2018-04-12 17:29:59 +0200 | [diff] [blame] | 335 | info->device = g_strdup(job->job.id); |
Paolo Bonzini | 32c81a4 | 2012-09-28 17:22:58 +0200 | [diff] [blame] | 336 | info->len = job->len; |
Kevin Wolf | da01ff7 | 2018-04-13 17:31:02 +0200 | [diff] [blame] | 337 | info->busy = atomic_read(&job->job.busy); |
| 338 | info->paused = job->job.pause_count > 0; |
Paolo Bonzini | 32c81a4 | 2012-09-28 17:22:58 +0200 | [diff] [blame] | 339 | info->offset = job->offset; |
| 340 | info->speed = job->speed; |
| 341 | info->io_status = job->iostatus; |
Max Reitz | ef6dbf1 | 2014-10-24 15:57:34 +0200 | [diff] [blame] | 342 | info->ready = job->ready; |
Kevin Wolf | a50c2ab | 2018-04-13 17:19:31 +0200 | [diff] [blame] | 343 | info->status = job->job.status; |
Kevin Wolf | bb02b65 | 2018-04-19 17:54:56 +0200 | [diff] [blame] | 344 | info->auto_finalize = job->job.auto_finalize; |
| 345 | info->auto_dismiss = job->job.auto_dismiss; |
Kevin Wolf | 4ad3518 | 2018-04-19 17:30:16 +0200 | [diff] [blame] | 346 | info->has_error = job->job.ret != 0; |
| 347 | info->error = job->job.ret ? g_strdup(strerror(-job->job.ret)) : NULL; |
Paolo Bonzini | 30e628b | 2012-09-28 17:22:48 +0200 | [diff] [blame] | 348 | return info; |
| 349 | } |
Paolo Bonzini | 32c81a4 | 2012-09-28 17:22:58 +0200 | [diff] [blame] | 350 | |
| 351 | static void block_job_iostatus_set_err(BlockJob *job, int error) |
| 352 | { |
| 353 | if (job->iostatus == BLOCK_DEVICE_IO_STATUS_OK) { |
| 354 | job->iostatus = error == ENOSPC ? BLOCK_DEVICE_IO_STATUS_NOSPACE : |
| 355 | BLOCK_DEVICE_IO_STATUS_FAILED; |
| 356 | } |
| 357 | } |
| 358 | |
Kevin Wolf | 139a9f0 | 2018-04-23 18:04:57 +0200 | [diff] [blame] | 359 | static void block_job_event_cancelled(Notifier *n, void *opaque) |
Paolo Bonzini | a66a2a3 | 2012-07-23 15:15:47 +0200 | [diff] [blame] | 360 | { |
Kevin Wolf | 139a9f0 | 2018-04-23 18:04:57 +0200 | [diff] [blame] | 361 | BlockJob *job = opaque; |
| 362 | |
John Snow | 559b935 | 2016-10-27 12:06:55 -0400 | [diff] [blame] | 363 | if (block_job_is_internal(job)) { |
| 364 | return; |
| 365 | } |
| 366 | |
Kevin Wolf | 252291e | 2018-04-12 17:57:08 +0200 | [diff] [blame] | 367 | qapi_event_send_block_job_cancelled(job_type(&job->job), |
Kevin Wolf | 33e9e9b | 2018-04-12 17:29:59 +0200 | [diff] [blame] | 368 | job->job.id, |
Wenchao Xia | bcada37b | 2014-06-18 08:43:47 +0200 | [diff] [blame] | 369 | job->len, |
| 370 | job->offset, |
| 371 | job->speed, |
| 372 | &error_abort); |
Paolo Bonzini | a66a2a3 | 2012-07-23 15:15:47 +0200 | [diff] [blame] | 373 | } |
| 374 | |
Kevin Wolf | 139a9f0 | 2018-04-23 18:04:57 +0200 | [diff] [blame] | 375 | static void block_job_event_completed(Notifier *n, void *opaque) |
Paolo Bonzini | a66a2a3 | 2012-07-23 15:15:47 +0200 | [diff] [blame] | 376 | { |
Kevin Wolf | 139a9f0 | 2018-04-23 18:04:57 +0200 | [diff] [blame] | 377 | BlockJob *job = opaque; |
| 378 | const char *msg = NULL; |
| 379 | |
John Snow | 559b935 | 2016-10-27 12:06:55 -0400 | [diff] [blame] | 380 | if (block_job_is_internal(job)) { |
| 381 | return; |
| 382 | } |
| 383 | |
Kevin Wolf | 4ad3518 | 2018-04-19 17:30:16 +0200 | [diff] [blame] | 384 | if (job->job.ret < 0) { |
| 385 | msg = strerror(-job->job.ret); |
Kevin Wolf | 139a9f0 | 2018-04-23 18:04:57 +0200 | [diff] [blame] | 386 | } |
| 387 | |
Kevin Wolf | 252291e | 2018-04-12 17:57:08 +0200 | [diff] [blame] | 388 | qapi_event_send_block_job_completed(job_type(&job->job), |
Kevin Wolf | 33e9e9b | 2018-04-12 17:29:59 +0200 | [diff] [blame] | 389 | job->job.id, |
Wenchao Xia | bcada37b | 2014-06-18 08:43:47 +0200 | [diff] [blame] | 390 | job->len, |
| 391 | job->offset, |
| 392 | job->speed, |
| 393 | !!msg, |
| 394 | msg, |
| 395 | &error_abort); |
| 396 | } |
| 397 | |
Kevin Wolf | 139a9f0 | 2018-04-23 18:04:57 +0200 | [diff] [blame] | 398 | static void block_job_event_pending(Notifier *n, void *opaque) |
John Snow | 5f24159 | 2018-03-10 03:27:42 -0500 | [diff] [blame] | 399 | { |
Kevin Wolf | 139a9f0 | 2018-04-23 18:04:57 +0200 | [diff] [blame] | 400 | BlockJob *job = opaque; |
| 401 | |
Kevin Wolf | 5d4f376 | 2018-04-23 17:09:42 +0200 | [diff] [blame] | 402 | if (block_job_is_internal(job)) { |
| 403 | return; |
John Snow | 5f24159 | 2018-03-10 03:27:42 -0500 | [diff] [blame] | 404 | } |
Kevin Wolf | 5d4f376 | 2018-04-23 17:09:42 +0200 | [diff] [blame] | 405 | |
| 406 | qapi_event_send_block_job_pending(job_type(&job->job), |
| 407 | job->job.id, |
| 408 | &error_abort); |
John Snow | 5f24159 | 2018-03-10 03:27:42 -0500 | [diff] [blame] | 409 | } |
| 410 | |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 411 | /* |
| 412 | * API for block job drivers and the block layer. These functions are |
| 413 | * declared in blockjob_int.h. |
| 414 | */ |
| 415 | |
| 416 | void *block_job_create(const char *job_id, const BlockJobDriver *driver, |
Kevin Wolf | 62c9e41 | 2018-04-19 16:09:52 +0200 | [diff] [blame] | 417 | JobTxn *txn, BlockDriverState *bs, uint64_t perm, |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 418 | uint64_t shared_perm, int64_t speed, int flags, |
| 419 | BlockCompletionFunc *cb, void *opaque, Error **errp) |
| 420 | { |
| 421 | BlockBackend *blk; |
| 422 | BlockJob *job; |
| 423 | int ret; |
| 424 | |
| 425 | if (bs->job) { |
| 426 | error_setg(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs)); |
| 427 | return NULL; |
| 428 | } |
| 429 | |
Kevin Wolf | bb02b65 | 2018-04-19 17:54:56 +0200 | [diff] [blame] | 430 | if (job_id == NULL && !(flags & JOB_INTERNAL)) { |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 431 | job_id = bdrv_get_device_name(bs); |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | blk = blk_new(perm, shared_perm); |
| 435 | ret = blk_insert_bs(blk, bs, errp); |
| 436 | if (ret < 0) { |
| 437 | blk_unref(blk); |
| 438 | return NULL; |
| 439 | } |
| 440 | |
Kevin Wolf | 7eaa8fb | 2018-04-23 16:06:26 +0200 | [diff] [blame^] | 441 | job = job_create(job_id, &driver->job_driver, txn, blk_get_aio_context(blk), |
Kevin Wolf | 4ad3518 | 2018-04-19 17:30:16 +0200 | [diff] [blame] | 442 | flags, cb, opaque, errp); |
Kevin Wolf | 33e9e9b | 2018-04-12 17:29:59 +0200 | [diff] [blame] | 443 | if (job == NULL) { |
| 444 | blk_unref(blk); |
| 445 | return NULL; |
| 446 | } |
| 447 | |
Kevin Wolf | e7c1d78 | 2018-04-12 17:54:37 +0200 | [diff] [blame] | 448 | assert(is_block_job(&job->job)); |
Kevin Wolf | 80fa2c7 | 2018-04-13 18:50:05 +0200 | [diff] [blame] | 449 | assert(job->job.driver->free == &block_job_free); |
Kevin Wolf | b15de82 | 2018-04-18 17:10:26 +0200 | [diff] [blame] | 450 | assert(job->job.driver->user_resume == &block_job_user_resume); |
Kevin Wolf | b69f777 | 2018-04-20 17:00:29 +0200 | [diff] [blame] | 451 | assert(job->job.driver->drain == &block_job_drain); |
Kevin Wolf | e7c1d78 | 2018-04-12 17:54:37 +0200 | [diff] [blame] | 452 | |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 453 | job->driver = driver; |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 454 | job->blk = blk; |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 455 | |
Kevin Wolf | 139a9f0 | 2018-04-23 18:04:57 +0200 | [diff] [blame] | 456 | job->finalize_cancelled_notifier.notify = block_job_event_cancelled; |
| 457 | job->finalize_completed_notifier.notify = block_job_event_completed; |
| 458 | job->pending_notifier.notify = block_job_event_pending; |
| 459 | |
| 460 | notifier_list_add(&job->job.on_finalize_cancelled, |
| 461 | &job->finalize_cancelled_notifier); |
| 462 | notifier_list_add(&job->job.on_finalize_completed, |
| 463 | &job->finalize_completed_notifier); |
| 464 | notifier_list_add(&job->job.on_pending, &job->pending_notifier); |
| 465 | |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 466 | error_setg(&job->blocker, "block device is in use by block job: %s", |
Kevin Wolf | 252291e | 2018-04-12 17:57:08 +0200 | [diff] [blame] | 467 | job_type_str(&job->job)); |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 468 | block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort); |
| 469 | bs->job = job; |
| 470 | |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 471 | bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker); |
| 472 | |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 473 | blk_add_aio_context_notifier(blk, block_job_attached_aio_context, |
| 474 | block_job_detach_aio_context, job); |
| 475 | |
| 476 | /* Only set speed when necessary to avoid NotSupported error */ |
| 477 | if (speed != 0) { |
| 478 | Error *local_err = NULL; |
| 479 | |
| 480 | block_job_set_speed(job, speed, &local_err); |
| 481 | if (local_err) { |
Kevin Wolf | 4ad3518 | 2018-04-19 17:30:16 +0200 | [diff] [blame] | 482 | job_early_fail(&job->job); |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 483 | error_propagate(errp, local_err); |
| 484 | return NULL; |
| 485 | } |
| 486 | } |
John Snow | 75859b9 | 2018-03-10 03:27:27 -0500 | [diff] [blame] | 487 | |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 488 | return job; |
| 489 | } |
| 490 | |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 491 | void block_job_completed(BlockJob *job, int ret) |
| 492 | { |
Kevin Wolf | 7eaa8fb | 2018-04-23 16:06:26 +0200 | [diff] [blame^] | 493 | assert(job && job->job.txn && !job_is_completed(&job->job)); |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 494 | assert(blk_bs(job->blk)->job == job); |
Kevin Wolf | 4ad3518 | 2018-04-19 17:30:16 +0200 | [diff] [blame] | 495 | job->job.ret = ret; |
| 496 | job_update_rc(&job->job); |
| 497 | trace_block_job_completed(job, ret, job->job.ret); |
| 498 | if (job->job.ret) { |
Kevin Wolf | 7eaa8fb | 2018-04-23 16:06:26 +0200 | [diff] [blame^] | 499 | job_completed_txn_abort(&job->job); |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 500 | } else { |
Kevin Wolf | 7eaa8fb | 2018-04-23 16:06:26 +0200 | [diff] [blame^] | 501 | job_completed_txn_success(&job->job); |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | |
John Snow | aa9ef2e | 2017-12-13 15:46:11 -0500 | [diff] [blame] | 505 | void block_job_enter(BlockJob *job) |
| 506 | { |
Kevin Wolf | da01ff7 | 2018-04-13 17:31:02 +0200 | [diff] [blame] | 507 | job_enter_cond(&job->job, NULL); |
John Snow | aa9ef2e | 2017-12-13 15:46:11 -0500 | [diff] [blame] | 508 | } |
| 509 | |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 510 | void block_job_yield(BlockJob *job) |
| 511 | { |
Kevin Wolf | da01ff7 | 2018-04-13 17:31:02 +0200 | [diff] [blame] | 512 | assert(job->job.busy); |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 513 | |
| 514 | /* Check cancellation *before* setting busy = false, too! */ |
Kevin Wolf | daa7f2f | 2018-04-17 12:56:07 +0200 | [diff] [blame] | 515 | if (job_is_cancelled(&job->job)) { |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 516 | return; |
| 517 | } |
| 518 | |
Kevin Wolf | da01ff7 | 2018-04-13 17:31:02 +0200 | [diff] [blame] | 519 | if (!job_should_pause(&job->job)) { |
| 520 | job_do_yield(&job->job, -1); |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 521 | } |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 522 | |
Kevin Wolf | da01ff7 | 2018-04-13 17:31:02 +0200 | [diff] [blame] | 523 | job_pause_point(&job->job); |
Paolo Bonzini | 88691b3 | 2017-05-08 16:13:04 +0200 | [diff] [blame] | 524 | } |
| 525 | |
Paolo Bonzini | 2caf63a | 2017-05-08 16:13:05 +0200 | [diff] [blame] | 526 | void block_job_iostatus_reset(BlockJob *job) |
| 527 | { |
Paolo Bonzini | 4c241cf | 2017-05-08 16:13:06 +0200 | [diff] [blame] | 528 | if (job->iostatus == BLOCK_DEVICE_IO_STATUS_OK) { |
| 529 | return; |
| 530 | } |
Kevin Wolf | b15de82 | 2018-04-18 17:10:26 +0200 | [diff] [blame] | 531 | assert(job->job.user_paused && job->job.pause_count > 0); |
Paolo Bonzini | 2caf63a | 2017-05-08 16:13:05 +0200 | [diff] [blame] | 532 | job->iostatus = BLOCK_DEVICE_IO_STATUS_OK; |
| 533 | } |
| 534 | |
Kevin Wolf | b15de82 | 2018-04-18 17:10:26 +0200 | [diff] [blame] | 535 | void block_job_user_resume(Job *job) |
| 536 | { |
| 537 | BlockJob *bjob = container_of(job, BlockJob, job); |
| 538 | block_job_iostatus_reset(bjob); |
| 539 | } |
| 540 | |
Wenchao Xia | bcada37b | 2014-06-18 08:43:47 +0200 | [diff] [blame] | 541 | void block_job_event_ready(BlockJob *job) |
| 542 | { |
Kevin Wolf | a50c2ab | 2018-04-13 17:19:31 +0200 | [diff] [blame] | 543 | job_state_transition(&job->job, JOB_STATUS_READY); |
Max Reitz | ef6dbf1 | 2014-10-24 15:57:34 +0200 | [diff] [blame] | 544 | job->ready = true; |
| 545 | |
John Snow | 559b935 | 2016-10-27 12:06:55 -0400 | [diff] [blame] | 546 | if (block_job_is_internal(job)) { |
| 547 | return; |
| 548 | } |
| 549 | |
Kevin Wolf | 252291e | 2018-04-12 17:57:08 +0200 | [diff] [blame] | 550 | qapi_event_send_block_job_ready(job_type(&job->job), |
Kevin Wolf | 33e9e9b | 2018-04-12 17:29:59 +0200 | [diff] [blame] | 551 | job->job.id, |
Markus Armbruster | 518848a | 2014-06-27 19:24:13 +0200 | [diff] [blame] | 552 | job->len, |
| 553 | job->offset, |
| 554 | job->speed, &error_abort); |
Paolo Bonzini | a66a2a3 | 2012-07-23 15:15:47 +0200 | [diff] [blame] | 555 | } |
| 556 | |
Kevin Wolf | 81e254d | 2016-04-18 11:36:38 +0200 | [diff] [blame] | 557 | BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err, |
Paolo Bonzini | 32c81a4 | 2012-09-28 17:22:58 +0200 | [diff] [blame] | 558 | int is_read, int error) |
| 559 | { |
| 560 | BlockErrorAction action; |
| 561 | |
| 562 | switch (on_err) { |
| 563 | case BLOCKDEV_ON_ERROR_ENOSPC: |
Kevin Wolf | 8c39825 | 2016-06-29 17:41:35 +0200 | [diff] [blame] | 564 | case BLOCKDEV_ON_ERROR_AUTO: |
Wenchao Xia | a589569 | 2014-06-18 08:43:30 +0200 | [diff] [blame] | 565 | action = (error == ENOSPC) ? |
| 566 | BLOCK_ERROR_ACTION_STOP : BLOCK_ERROR_ACTION_REPORT; |
Paolo Bonzini | 32c81a4 | 2012-09-28 17:22:58 +0200 | [diff] [blame] | 567 | break; |
| 568 | case BLOCKDEV_ON_ERROR_STOP: |
Wenchao Xia | a589569 | 2014-06-18 08:43:30 +0200 | [diff] [blame] | 569 | action = BLOCK_ERROR_ACTION_STOP; |
Paolo Bonzini | 32c81a4 | 2012-09-28 17:22:58 +0200 | [diff] [blame] | 570 | break; |
| 571 | case BLOCKDEV_ON_ERROR_REPORT: |
Wenchao Xia | a589569 | 2014-06-18 08:43:30 +0200 | [diff] [blame] | 572 | action = BLOCK_ERROR_ACTION_REPORT; |
Paolo Bonzini | 32c81a4 | 2012-09-28 17:22:58 +0200 | [diff] [blame] | 573 | break; |
| 574 | case BLOCKDEV_ON_ERROR_IGNORE: |
Wenchao Xia | a589569 | 2014-06-18 08:43:30 +0200 | [diff] [blame] | 575 | action = BLOCK_ERROR_ACTION_IGNORE; |
Paolo Bonzini | 32c81a4 | 2012-09-28 17:22:58 +0200 | [diff] [blame] | 576 | break; |
| 577 | default: |
| 578 | abort(); |
| 579 | } |
John Snow | 559b935 | 2016-10-27 12:06:55 -0400 | [diff] [blame] | 580 | if (!block_job_is_internal(job)) { |
Kevin Wolf | 33e9e9b | 2018-04-12 17:29:59 +0200 | [diff] [blame] | 581 | qapi_event_send_block_job_error(job->job.id, |
John Snow | 559b935 | 2016-10-27 12:06:55 -0400 | [diff] [blame] | 582 | is_read ? IO_OPERATION_TYPE_READ : |
| 583 | IO_OPERATION_TYPE_WRITE, |
| 584 | action, &error_abort); |
| 585 | } |
Wenchao Xia | a589569 | 2014-06-18 08:43:30 +0200 | [diff] [blame] | 586 | if (action == BLOCK_ERROR_ACTION_STOP) { |
Kevin Wolf | b15de82 | 2018-04-18 17:10:26 +0200 | [diff] [blame] | 587 | job_pause(&job->job); |
Fam Zheng | 751ebd7 | 2015-04-03 22:05:18 +0800 | [diff] [blame] | 588 | /* make the pause user visible, which will be resumed from QMP. */ |
Kevin Wolf | b15de82 | 2018-04-18 17:10:26 +0200 | [diff] [blame] | 589 | job->job.user_paused = true; |
Paolo Bonzini | 32c81a4 | 2012-09-28 17:22:58 +0200 | [diff] [blame] | 590 | block_job_iostatus_set_err(job, error); |
Paolo Bonzini | 32c81a4 | 2012-09-28 17:22:58 +0200 | [diff] [blame] | 591 | } |
| 592 | return action; |
| 593 | } |