Lines Matching refs:task

46 static void			 rpc_release_task(struct rpc_task *task);
60 * Disable the timer for a given RPC task. Should be called with
65 __rpc_disable_timer(struct rpc_wait_queue *queue, struct rpc_task *task)
67 if (task->tk_timeout == 0)
69 dprintk("RPC: %5u disabling timer\n", task->tk_pid);
70 task->tk_timeout = 0;
71 list_del(&task->u.tk_wait.timer_list);
84 * Set up a timer for the current task.
87 __rpc_add_timer(struct rpc_wait_queue *queue, struct rpc_task *task)
89 if (!task->tk_timeout)
93 task->tk_pid, task->tk_timeout * 1000 / HZ);
95 task->u.tk_wait.expires = jiffies + task->tk_timeout;
96 if (list_empty(&queue->timer_list.list) || time_before(task->u.tk_wait.expires, queue->timer_list.expires))
97 rpc_set_queue_timer(queue, task->u.tk_wait.expires);
98 list_add(&task->u.tk_wait.timer_list, &queue->timer_list.list);
104 struct rpc_task *task;
107 task = list_first_entry(q, struct rpc_task, u.tk_wait.list);
108 if (task->tk_owner == queue->owner)
109 list_move_tail(&task->u.tk_wait.list, q);
138 struct rpc_task *task,
144 INIT_LIST_HEAD(&task->u.tk_wait.links);
151 if (t->tk_owner == task->tk_owner) {
152 list_add_tail(&task->u.tk_wait.list, &t->u.tk_wait.links);
156 list_add_tail(&task->u.tk_wait.list, q);
168 struct rpc_task *task,
171 WARN_ON_ONCE(RPC_IS_QUEUED(task));
172 if (RPC_IS_QUEUED(task))
176 __rpc_add_wait_queue_priority(queue, task, queue_priority);
177 else if (RPC_IS_SWAPPER(task))
178 list_add(&task->u.tk_wait.list, &queue->tasks[0]);
180 list_add_tail(&task->u.tk_wait.list, &queue->tasks[0]);
181 task->tk_waitqueue = queue;
185 rpc_set_queued(task);
188 task->tk_pid, queue, rpc_qname(queue));
194 static void __rpc_remove_wait_queue_priority(struct rpc_task *task)
198 if (!list_empty(&task->u.tk_wait.links)) {
199 t = list_entry(task->u.tk_wait.links.next, struct rpc_task, u.tk_wait.list);
200 list_move(&t->u.tk_wait.list, &task->u.tk_wait.list);
201 list_splice_init(&task->u.tk_wait.links, &t->u.tk_wait.links);
209 static void __rpc_remove_wait_queue(struct rpc_wait_queue *queue, struct rpc_task *task)
211 __rpc_disable_timer(queue, task);
213 __rpc_remove_wait_queue_priority(task);
214 list_del(&task->u.tk_wait.list);
217 task->tk_pid, queue, rpc_qname(queue));
262 static void rpc_task_set_debuginfo(struct rpc_task *task)
266 task->tk_pid = atomic_inc_return(&rpc_pid);
269 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
274 static void rpc_set_active(struct rpc_task *task)
276 trace_rpc_task_begin(task->tk_client, task, NULL);
278 rpc_task_set_debuginfo(task);
279 set_bit(RPC_TASK_ACTIVE, &task->tk_runstate);
286 static int rpc_complete_task(struct rpc_task *task)
288 void *m = &task->tk_runstate;
294 trace_rpc_task_complete(task->tk_client, task, NULL);
297 clear_bit(RPC_TASK_ACTIVE, &task->tk_runstate);
298 ret = atomic_dec_and_test(&task->tk_count);
312 int __rpc_wait_for_completion_task(struct rpc_task *task, wait_bit_action_f *action)
316 return out_of_line_wait_on_bit(&task->tk_runstate, RPC_TASK_ACTIVE,
322 * Make an RPC task runnable.
324 * Note: If the task is ASYNC, and is being made runnable after sitting on an
332 static void rpc_make_runnable(struct rpc_task *task)
334 bool need_wakeup = !rpc_test_and_set_running(task);
336 rpc_clear_queued(task);
339 if (RPC_IS_ASYNC(task)) {
340 INIT_WORK(&task->u.tk_work, rpc_async_schedule);
341 queue_work(rpciod_workqueue, &task->u.tk_work);
343 wake_up_bit(&task->tk_runstate, RPC_TASK_QUEUED);
349 * NB: An RPC task will only receive interrupt-driven events as long
353 struct rpc_task *task,
358 task->tk_pid, rpc_qname(q), jiffies);
360 trace_rpc_task_sleep(task->tk_client, task, q);
362 __rpc_add_wait_queue(q, task, queue_priority);
364 WARN_ON_ONCE(task->tk_callback != NULL);
365 task->tk_callback = action;
366 __rpc_add_timer(q, task);
369 void rpc_sleep_on(struct rpc_wait_queue *q, struct rpc_task *task,
372 /* We shouldn't ever put an inactive task to sleep */
373 WARN_ON_ONCE(!RPC_IS_ACTIVATED(task));
374 if (!RPC_IS_ACTIVATED(task)) {
375 task->tk_status = -EIO;
376 rpc_put_task_async(task);
384 __rpc_sleep_on_priority(q, task, action, task->tk_priority);
389 void rpc_sleep_on_priority(struct rpc_wait_queue *q, struct rpc_task *task,
392 /* We shouldn't ever put an inactive task to sleep */
393 WARN_ON_ONCE(!RPC_IS_ACTIVATED(task));
394 if (!RPC_IS_ACTIVATED(task)) {
395 task->tk_status = -EIO;
396 rpc_put_task_async(task);
404 __rpc_sleep_on_priority(q, task, action, priority - RPC_PRIORITY_LOW);
412 * @task: task to be woken up
414 * Caller must hold queue->lock, and have cleared the task queued flag.
416 static void __rpc_do_wake_up_task(struct rpc_wait_queue *queue, struct rpc_task *task)
419 task->tk_pid, jiffies);
421 /* Has the task been executed yet? If not, we cannot wake it up! */
422 if (!RPC_IS_ACTIVATED(task)) {
423 printk(KERN_ERR "RPC: Inactive task (%p) being woken up!\n", task);
427 trace_rpc_task_wakeup(task->tk_client, task, queue);
429 __rpc_remove_wait_queue(queue, task);
431 rpc_make_runnable(task);
437 * Wake up a queued task while the queue lock is being held
439 static void rpc_wake_up_task_queue_locked(struct rpc_wait_queue *queue, struct rpc_task *task)
441 if (RPC_IS_QUEUED(task)) {
443 if (task->tk_waitqueue == queue)
444 __rpc_do_wake_up_task(queue, task);
449 * Wake up a task on a specific queue
451 void rpc_wake_up_queued_task(struct rpc_wait_queue *queue, struct rpc_task *task)
454 rpc_wake_up_task_queue_locked(queue, task);
460 * Wake up the next task on a priority queue.
465 struct rpc_task *task;
472 task = list_entry(q->next, struct rpc_task, u.tk_wait.list);
473 if (queue->owner == task->tk_owner) {
476 list_move_tail(&task->u.tk_wait.list, q);
493 task = list_entry(q->next, struct rpc_task, u.tk_wait.list);
504 rpc_set_waitqueue_owner(queue, task->tk_owner);
506 return task;
519 * Wake up the first task on the wait queue.
524 struct rpc_task *task = NULL;
529 task = __rpc_find_next_queued(queue);
530 if (task != NULL) {
531 if (func(task, data))
532 rpc_wake_up_task_queue_locked(queue, task);
534 task = NULL;
538 return task;
542 static bool rpc_wake_up_next_func(struct rpc_task *task, void *data)
548 * Wake up the next task on the wait queue.
570 struct rpc_task *task;
571 task = list_first_entry(head,
574 rpc_wake_up_task_queue_locked(queue, task);
599 struct rpc_task *task;
600 task = list_first_entry(head,
603 task->tk_status = status;
604 rpc_wake_up_task_queue_locked(queue, task);
617 struct rpc_task *task, *n;
622 list_for_each_entry_safe(task, n, &queue->timer_list.list, u.tk_wait.timer_list) {
623 timeo = task->u.tk_wait.expires;
625 dprintk("RPC: %5u timeout\n", task->tk_pid);
626 task->tk_status = -ETIMEDOUT;
627 rpc_wake_up_task_queue_locked(queue, task);
638 static void __rpc_atrun(struct rpc_task *task)
640 if (task->tk_status == -ETIMEDOUT)
641 task->tk_status = 0;
645 * Run a task at a later time
647 void rpc_delay(struct rpc_task *task, unsigned long delay)
649 task->tk_timeout = delay;
650 rpc_sleep_on(&delay_queue, task, __rpc_atrun);
655 * Helper to call task->tk_ops->rpc_call_prepare
657 void rpc_prepare_task(struct rpc_task *task)
659 task->tk_ops->rpc_call_prepare(task, task->tk_calldata);
663 rpc_init_task_statistics(struct rpc_task *task)
666 task->tk_garb_retry = 2;
667 task->tk_cred_retry = 2;
668 task->tk_rebind_retry = 2;
671 task->tk_start = ktime_get();
675 rpc_reset_task_statistics(struct rpc_task *task)
677 task->tk_timeouts = 0;
678 task->tk_flags &= ~(RPC_CALL_MAJORSEEN|RPC_TASK_KILLED|RPC_TASK_SENT);
680 rpc_init_task_statistics(task);
684 * Helper that calls task->tk_ops->rpc_call_done if it exists
686 void rpc_exit_task(struct rpc_task *task)
688 task->tk_action = NULL;
689 if (task->tk_ops->rpc_call_done != NULL) {
690 task->tk_ops->rpc_call_done(task, task->tk_calldata);
691 if (task->tk_action != NULL) {
692 WARN_ON(RPC_ASSASSINATED(task));
694 xprt_release(task);
695 rpc_reset_task_statistics(task);
700 void rpc_exit(struct rpc_task *task, int status)
702 task->tk_status = status;
703 task->tk_action = rpc_exit_task;
704 if (RPC_IS_QUEUED(task))
705 rpc_wake_up_queued_task(task->tk_waitqueue, task);
718 static void __rpc_execute(struct rpc_task *task)
721 int task_is_async = RPC_IS_ASYNC(task);
725 task->tk_pid, task->tk_flags);
727 WARN_ON_ONCE(RPC_IS_QUEUED(task));
728 if (RPC_IS_QUEUED(task))
737 do_action = task->tk_callback;
738 task->tk_callback = NULL;
742 * tk_action may be NULL if the task has been killed.
746 do_action = task->tk_action;
750 trace_rpc_task_run_action(task->tk_client, task, task->tk_action);
751 do_action(task);
754 * Lockless check for whether task is sleeping or not.
756 if (!RPC_IS_QUEUED(task))
767 queue = task->tk_waitqueue;
769 if (!RPC_IS_QUEUED(task)) {
773 rpc_clear_running(task);
778 /* sync task: sleep here */
779 dprintk("RPC: %5u sync task going to sleep\n", task->tk_pid);
780 status = out_of_line_wait_on_bit(&task->tk_runstate,
785 * When a sync task receives a signal, it exits with
790 dprintk("RPC: %5u got signal\n", task->tk_pid);
791 task->tk_flags |= RPC_TASK_KILLED;
792 rpc_exit(task, -ERESTARTSYS);
794 dprintk("RPC: %5u sync task resuming\n", task->tk_pid);
797 dprintk("RPC: %5u return %d, status %d\n", task->tk_pid, status,
798 task->tk_status);
799 /* Release all resources associated with the task */
800 rpc_release_task(task);
806 * This may be called recursively if e.g. an async NFS task updates
808 * NOTE: Upon exit of this function the task is guaranteed to be
810 * been called, so your task memory may have been freed.
812 void rpc_execute(struct rpc_task *task)
814 bool is_async = RPC_IS_ASYNC(task);
816 rpc_set_active(task);
817 rpc_make_runnable(task);
819 __rpc_execute(task);
829 * @task: RPC task that will use this buffer
844 void *rpc_malloc(struct rpc_task *task, size_t size)
849 if (RPC_IS_SWAPPER(task))
863 task->tk_pid, size, buf);
895 * Creation and deletion of RPC task structures
897 static void rpc_init_task(struct rpc_task *task, const struct rpc_task_setup *task_setup_data)
899 memset(task, 0, sizeof(*task));
900 atomic_set(&task->tk_count, 1);
901 task->tk_flags = task_setup_data->flags;
902 task->tk_ops = task_setup_data->callback_ops;
903 task->tk_calldata = task_setup_data->callback_data;
904 INIT_LIST_HEAD(&task->tk_task);
906 task->tk_priority = task_setup_data->priority - RPC_PRIORITY_LOW;
907 task->tk_owner = current->tgid;
910 task->tk_workqueue = task_setup_data->workqueue;
912 if (task->tk_ops->rpc_call_prepare != NULL)
913 task->tk_action = rpc_prepare_task;
915 rpc_init_task_statistics(task);
917 dprintk("RPC: new task initialized, procpid %u\n",
928 * Create a new task for the specified client.
932 struct rpc_task *task = setup_data->task;
935 if (task == NULL) {
936 task = rpc_alloc_task();
937 if (task == NULL) {
945 rpc_init_task(task, setup_data);
946 task->tk_flags |= flags;
947 dprintk("RPC: allocated task %p\n", task);
948 return task;
952 * rpc_free_task - release rpc task and perform cleanups
970 static void rpc_free_task(struct rpc_task *task)
972 unsigned short tk_flags = task->tk_flags;
974 rpc_release_calldata(task->tk_ops, task->tk_calldata);
977 dprintk("RPC: %5u freeing task\n", task->tk_pid);
978 mempool_free(task, rpc_task_mempool);
987 static void rpc_release_resources_task(struct rpc_task *task)
989 xprt_release(task);
990 if (task->tk_msg.rpc_cred) {
991 put_rpccred(task->tk_msg.rpc_cred);
992 task->tk_msg.rpc_cred = NULL;
994 rpc_task_release_client(task);
997 static void rpc_final_put_task(struct rpc_task *task,
1001 INIT_WORK(&task->u.tk_work, rpc_async_release);
1002 queue_work(q, &task->u.tk_work);
1004 rpc_free_task(task);
1007 static void rpc_do_put_task(struct rpc_task *task, struct workqueue_struct *q)
1009 if (atomic_dec_and_test(&task->tk_count)) {
1010 rpc_release_resources_task(task);
1011 rpc_final_put_task(task, q);
1015 void rpc_put_task(struct rpc_task *task)
1017 rpc_do_put_task(task, NULL);
1021 void rpc_put_task_async(struct rpc_task *task)
1023 rpc_do_put_task(task, task->tk_workqueue);
1027 static void rpc_release_task(struct rpc_task *task)
1029 dprintk("RPC: %5u release task\n", task->tk_pid);
1031 WARN_ON_ONCE(RPC_IS_QUEUED(task));
1033 rpc_release_resources_task(task);
1037 * so it should be safe to use task->tk_count as a test for whether
1040 if (atomic_read(&task->tk_count) != 1 + !RPC_IS_ASYNC(task)) {
1041 /* Wake up anyone who may be waiting for task completion */
1042 if (!rpc_complete_task(task))
1045 if (!atomic_dec_and_test(&task->tk_count))
1048 rpc_final_put_task(task, task->tk_workqueue);