Lines Matching refs:job

39 static bool is_block_job(Job *job)  in is_block_job()  argument
41 return job_type(job) == JOB_TYPE_BACKUP || in is_block_job()
42 job_type(job) == JOB_TYPE_COMMIT || in is_block_job()
43 job_type(job) == JOB_TYPE_MIRROR || in is_block_job()
44 job_type(job) == JOB_TYPE_STREAM; in is_block_job()
49 Job *job = bjob ? &bjob->job : NULL; in block_job_next_locked() local
53 job = job_next_locked(job); in block_job_next_locked()
54 } while (job && !is_block_job(job)); in block_job_next_locked()
56 return job ? container_of(job, BlockJob, job) : NULL; in block_job_next_locked()
61 Job *job = job_get_locked(id); in block_job_get_locked() local
64 if (job && is_block_job(job)) { in block_job_get_locked()
65 return container_of(job, BlockJob, job); in block_job_get_locked()
77 void block_job_free(Job *job) in block_job_free() argument
79 BlockJob *bjob = container_of(job, BlockJob, job); in block_job_free()
89 BlockJob *job = c->opaque; in child_job_get_parent_desc() local
90 return g_strdup_printf("%s job '%s'", job_type_str(&job->job), job->job.id); in child_job_get_parent_desc()
95 BlockJob *job = c->opaque; in child_job_drained_begin() local
96 job_pause(&job->job); in child_job_drained_begin()
102 Job *job = &bjob->job; in child_job_drained_poll() local
109 if (!job->busy || job_is_completed_locked(job)) { in child_job_drained_poll()
125 BlockJob *job = c->opaque; in child_job_drained_end() local
126 job_resume(&job->job); in child_job_drained_end()
131 BlockJob *job; member
137 BlockJob *job = s->job; in child_job_set_aio_ctx_commit() local
139 job_set_aio_context(&job->job, s->new_ctx); in child_job_set_aio_ctx_commit()
151 BlockJob *job = c->opaque; in child_job_change_aio_ctx() local
155 for (l = job->nodes; l; l = l->next) { in child_job_change_aio_ctx()
166 .job = job, in child_job_change_aio_ctx()
175 BlockJob *job = c->opaque; in child_job_get_parent_aio_context() local
179 return job->job.aio_context; in child_job_get_parent_aio_context()
192 void block_job_remove_all_bdrv(BlockJob *job) in block_job_remove_all_bdrv() argument
202 while (job->nodes) { in block_job_remove_all_bdrv()
203 GSList *l = job->nodes; in block_job_remove_all_bdrv()
206 job->nodes = l->next; in block_job_remove_all_bdrv()
208 bdrv_op_unblock_all(c->bs, job->blocker); in block_job_remove_all_bdrv()
216 bool block_job_has_bdrv(BlockJob *job, BlockDriverState *bs) in block_job_has_bdrv() argument
221 for (el = job->nodes; el; el = el->next) { in block_job_has_bdrv()
231 int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs, in block_job_add_bdrv() argument
239 c = bdrv_root_attach_child(bs, name, &child_job, 0, perm, shared_perm, job, in block_job_add_bdrv()
245 job->nodes = g_slist_prepend(job->nodes, c); in block_job_add_bdrv()
246 bdrv_op_block_all(bs, job->blocker); in block_job_add_bdrv()
257 bool block_job_is_internal(BlockJob *job) in block_job_is_internal() argument
259 return (job->job.id == NULL); in block_job_is_internal()
262 const BlockJobDriver *block_job_driver(BlockJob *job) in block_job_driver() argument
264 return container_of(job->job.driver, BlockJobDriver, job_driver); in block_job_driver()
268 static bool job_timer_pending(Job *job) in job_timer_pending() argument
270 return timer_pending(&job->sleep_timer); in job_timer_pending()
273 bool block_job_set_speed_locked(BlockJob *job, int64_t speed, Error **errp) in block_job_set_speed_locked() argument
275 const BlockJobDriver *drv = block_job_driver(job); in block_job_set_speed_locked()
276 int64_t old_speed = job->speed; in block_job_set_speed_locked()
280 if (job_apply_verb_locked(&job->job, JOB_VERB_SET_SPEED, errp) < 0) { in block_job_set_speed_locked()
289 ratelimit_set_speed(&job->limit, speed, BLOCK_JOB_SLICE_TIME); in block_job_set_speed_locked()
291 job->speed = speed; in block_job_set_speed_locked()
295 drv->set_speed(job, speed); in block_job_set_speed_locked()
304 job_enter_cond_locked(&job->job, job_timer_pending); in block_job_set_speed_locked()
309 static bool block_job_set_speed(BlockJob *job, int64_t speed, Error **errp) in block_job_set_speed() argument
312 return block_job_set_speed_locked(job, speed, errp); in block_job_set_speed()
315 void block_job_change_locked(BlockJob *job, BlockJobChangeOptions *opts, in block_job_change_locked() argument
318 const BlockJobDriver *drv = block_job_driver(job); in block_job_change_locked()
322 if (job_apply_verb_locked(&job->job, JOB_VERB_CHANGE, errp)) { in block_job_change_locked()
328 drv->change(job, opts, errp); in block_job_change_locked()
335 void block_job_ratelimit_processed_bytes(BlockJob *job, uint64_t n) in block_job_ratelimit_processed_bytes() argument
338 ratelimit_calculate_delay(&job->limit, n); in block_job_ratelimit_processed_bytes()
341 void block_job_ratelimit_sleep(BlockJob *job) in block_job_ratelimit_sleep() argument
354 delay_ns = ratelimit_calculate_delay(&job->limit, 0); in block_job_ratelimit_sleep()
355 job_sleep_ns(&job->job, delay_ns); in block_job_ratelimit_sleep()
356 } while (delay_ns && !job_is_cancelled(&job->job)); in block_job_ratelimit_sleep()
359 BlockJobInfo *block_job_query_locked(BlockJob *job, Error **errp) in block_job_query_locked() argument
363 const BlockJobDriver *drv = block_job_driver(job); in block_job_query_locked()
367 if (block_job_is_internal(job)) { in block_job_query_locked()
372 progress_get_snapshot(&job->job.progress, &progress_current, in block_job_query_locked()
376 info->type = job_type(&job->job); in block_job_query_locked()
377 info->device = g_strdup(job->job.id); in block_job_query_locked()
378 info->busy = job->job.busy; in block_job_query_locked()
379 info->paused = job->job.pause_count > 0; in block_job_query_locked()
382 info->speed = job->speed; in block_job_query_locked()
383 info->io_status = job->iostatus; in block_job_query_locked()
384 info->ready = job_is_ready_locked(&job->job), in block_job_query_locked()
385 info->status = job->job.status; in block_job_query_locked()
386 info->auto_finalize = job->job.auto_finalize; in block_job_query_locked()
387 info->auto_dismiss = job->job.auto_dismiss; in block_job_query_locked()
388 if (job->job.ret) { in block_job_query_locked()
389 info->error = job->job.err ? in block_job_query_locked()
390 g_strdup(error_get_pretty(job->job.err)) : in block_job_query_locked()
391 g_strdup(strerror(-job->job.ret)); in block_job_query_locked()
395 drv->query(job, info); in block_job_query_locked()
402 static void block_job_iostatus_set_err_locked(BlockJob *job, int error) in block_job_iostatus_set_err_locked() argument
404 if (job->iostatus == BLOCK_DEVICE_IO_STATUS_OK) { in block_job_iostatus_set_err_locked()
405 job->iostatus = error == ENOSPC ? BLOCK_DEVICE_IO_STATUS_NOSPACE : in block_job_iostatus_set_err_locked()
413 BlockJob *job = opaque; in block_job_event_cancelled_locked() local
416 if (block_job_is_internal(job)) { in block_job_event_cancelled_locked()
420 progress_get_snapshot(&job->job.progress, &progress_current, in block_job_event_cancelled_locked()
423 qapi_event_send_block_job_cancelled(job_type(&job->job), in block_job_event_cancelled_locked()
424 job->job.id, in block_job_event_cancelled_locked()
427 job->speed); in block_job_event_cancelled_locked()
433 BlockJob *job = opaque; in block_job_event_completed_locked() local
437 if (block_job_is_internal(job)) { in block_job_event_completed_locked()
441 if (job->job.ret < 0) { in block_job_event_completed_locked()
442 msg = error_get_pretty(job->job.err); in block_job_event_completed_locked()
445 progress_get_snapshot(&job->job.progress, &progress_current, in block_job_event_completed_locked()
448 qapi_event_send_block_job_completed(job_type(&job->job), in block_job_event_completed_locked()
449 job->job.id, in block_job_event_completed_locked()
452 job->speed, in block_job_event_completed_locked()
459 BlockJob *job = opaque; in block_job_event_pending_locked() local
461 if (block_job_is_internal(job)) { in block_job_event_pending_locked()
465 qapi_event_send_block_job_pending(job_type(&job->job), in block_job_event_pending_locked()
466 job->job.id); in block_job_event_pending_locked()
472 BlockJob *job = opaque; in block_job_event_ready_locked() local
475 if (block_job_is_internal(job)) { in block_job_event_ready_locked()
479 progress_get_snapshot(&job->job.progress, &progress_current, in block_job_event_ready_locked()
482 qapi_event_send_block_job_ready(job_type(&job->job), in block_job_event_ready_locked()
483 job->job.id, in block_job_event_ready_locked()
486 job->speed); in block_job_event_ready_locked()
495 BlockJob *job; in block_job_create() local
505 job = job_create(job_id, &driver->job_driver, txn, bdrv_get_aio_context(bs), in block_job_create()
507 if (job == NULL) { in block_job_create()
512 assert(is_block_job(&job->job)); in block_job_create()
513 assert(job->job.driver->free == &block_job_free); in block_job_create()
514 assert(job->job.driver->user_resume == &block_job_user_resume); in block_job_create()
516 ratelimit_init(&job->limit); in block_job_create()
518 job->finalize_cancelled_notifier.notify = block_job_event_cancelled_locked; in block_job_create()
519 job->finalize_completed_notifier.notify = block_job_event_completed_locked; in block_job_create()
520 job->pending_notifier.notify = block_job_event_pending_locked; in block_job_create()
521 job->ready_notifier.notify = block_job_event_ready_locked; in block_job_create()
522 job->idle_notifier.notify = block_job_on_idle_locked; in block_job_create()
525 notifier_list_add(&job->job.on_finalize_cancelled, in block_job_create()
526 &job->finalize_cancelled_notifier); in block_job_create()
527 notifier_list_add(&job->job.on_finalize_completed, in block_job_create()
528 &job->finalize_completed_notifier); in block_job_create()
529 notifier_list_add(&job->job.on_pending, &job->pending_notifier); in block_job_create()
530 notifier_list_add(&job->job.on_ready, &job->ready_notifier); in block_job_create()
531 notifier_list_add(&job->job.on_idle, &job->idle_notifier); in block_job_create()
534 error_setg(&job->blocker, "block device is in use by block job: %s", in block_job_create()
535 job_type_str(&job->job)); in block_job_create()
537 ret = block_job_add_bdrv(job, "main node", bs, perm, shared_perm, errp); in block_job_create()
542 bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker); in block_job_create()
544 if (!block_job_set_speed(job, speed, errp)) { in block_job_create()
549 return job; in block_job_create()
553 job_early_fail(&job->job); in block_job_create()
557 void block_job_iostatus_reset_locked(BlockJob *job) in block_job_iostatus_reset_locked() argument
560 if (job->iostatus == BLOCK_DEVICE_IO_STATUS_OK) { in block_job_iostatus_reset_locked()
563 assert(job->job.user_paused && job->job.pause_count > 0); in block_job_iostatus_reset_locked()
564 job->iostatus = BLOCK_DEVICE_IO_STATUS_OK; in block_job_iostatus_reset_locked()
567 static void block_job_iostatus_reset(BlockJob *job) in block_job_iostatus_reset() argument
570 block_job_iostatus_reset_locked(job); in block_job_iostatus_reset()
573 void block_job_user_resume(Job *job) in block_job_user_resume() argument
575 BlockJob *bjob = container_of(job, BlockJob, job); in block_job_user_resume()
580 BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err, in block_job_error_action() argument
604 if (!block_job_is_internal(job)) { in block_job_error_action()
605 qapi_event_send_block_job_error(job->job.id, in block_job_error_action()
612 if (!job->job.user_paused) { in block_job_error_action()
613 job_pause_locked(&job->job); in block_job_error_action()
618 job->job.user_paused = true; in block_job_error_action()
620 block_job_iostatus_set_err_locked(job, error); in block_job_error_action()
626 AioContext *block_job_get_aio_context(BlockJob *job) in block_job_get_aio_context() argument
629 return job->job.aio_context; in block_job_get_aio_context()