Lines Matching full:completion
6 #include "completion.h"
24 * vdo_work_queue which holds vdo_completions that are to be run in that zone. A completion may
27 * At each step of a multi-threaded operation, the completion performing the operation is given a
28 * callback, error handler, and thread id for the next step. A completion is "run" when it is
32 * will be invoked. Generally, a completion will not be run directly, but rather will be
35 * completion's "callback_thread_id". When it is dequeued, it will be on the correct thread, and
36 * will get run. In some cases, the completion should get queued instead of running immediately,
39 * the completion's "requeue" field should be set to true. Doing so will skip the current thread
40 * check and simply enqueue the completion.
42 * A completion may be "finished," in which case its "complete" field will be set to true before it
43 * is next run. It is a bug to attempt to set the result or re-finish a finished completion.
44 * Because a completion's fields are not safe to examine from any thread other than the one on
45 * which the completion is currently operating, this field is used only to aid in detecting
47 * A completion must be "reset" before it can be reused after it has been finished. Resetting will
51 void vdo_initialize_completion(struct vdo_completion *completion, in vdo_initialize_completion() argument
55 memset(completion, 0, sizeof(*completion)); in vdo_initialize_completion()
56 completion->vdo = vdo; in vdo_initialize_completion()
57 completion->type = type; in vdo_initialize_completion()
58 vdo_reset_completion(completion); in vdo_initialize_completion()
61 static inline void assert_incomplete(struct vdo_completion *completion) in assert_incomplete() argument
63 VDO_ASSERT_LOG_ONLY(!completion->complete, "completion is not complete"); in assert_incomplete()
67 * vdo_set_completion_result() - Set the result of a completion.
71 void vdo_set_completion_result(struct vdo_completion *completion, int result) in vdo_set_completion_result() argument
73 assert_incomplete(completion); in vdo_set_completion_result()
74 if (completion->result == VDO_SUCCESS) in vdo_set_completion_result()
75 completion->result = result; in vdo_set_completion_result()
79 * vdo_launch_completion_with_priority() - Run or enqueue a completion.
80 * @priority: The priority at which to enqueue the completion.
82 * If called on the correct thread (i.e. the one specified in the completion's callback_thread_id
83 * field) and not marked for requeue, the completion will be run immediately. Otherwise, the
84 * completion will be enqueued on the specified thread.
86 void vdo_launch_completion_with_priority(struct vdo_completion *completion, in vdo_launch_completion_with_priority() argument
89 thread_id_t callback_thread = completion->callback_thread_id; in vdo_launch_completion_with_priority()
91 if (completion->requeue || (callback_thread != vdo_get_callback_thread_id())) { in vdo_launch_completion_with_priority()
92 vdo_enqueue_completion(completion, priority); in vdo_launch_completion_with_priority()
96 vdo_run_completion(completion); in vdo_launch_completion_with_priority()
99 /** vdo_finish_completion() - Mark a completion as complete and then launch it. */
100 void vdo_finish_completion(struct vdo_completion *completion) in vdo_finish_completion() argument
102 assert_incomplete(completion); in vdo_finish_completion()
103 completion->complete = true; in vdo_finish_completion()
104 if (completion->callback != NULL) in vdo_finish_completion()
105 vdo_launch_completion(completion); in vdo_finish_completion()
108 void vdo_enqueue_completion(struct vdo_completion *completion, in vdo_enqueue_completion() argument
111 struct vdo *vdo = completion->vdo; in vdo_enqueue_completion()
112 thread_id_t thread_id = completion->callback_thread_id; in vdo_enqueue_completion()
115 "thread_id %u (completion type %d) is less than thread count %u", in vdo_enqueue_completion()
116 thread_id, completion->type, in vdo_enqueue_completion()
120 completion->requeue = false; in vdo_enqueue_completion()
121 completion->priority = priority; in vdo_enqueue_completion()
122 completion->my_queue = NULL; in vdo_enqueue_completion()
123 vdo_enqueue_work_queue(vdo->threads[thread_id].queue, completion); in vdo_enqueue_completion()
127 * vdo_requeue_completion_if_needed() - Requeue a completion if not called on the specified thread.
129 * Return: True if the completion was requeued; callers may not access the completion in this case.
131 bool vdo_requeue_completion_if_needed(struct vdo_completion *completion, in vdo_requeue_completion_if_needed() argument
137 completion->callback_thread_id = callback_thread_id; in vdo_requeue_completion_if_needed()
138 vdo_enqueue_completion(completion, VDO_WORK_Q_DEFAULT_PRIORITY); in vdo_requeue_completion_if_needed()