Give processor_t more control over the lifecycle of a job

Jobs are now destroyed by the processor, but they are allowed to
reschedule themselves.  That is, parts of the reschedule functionality
already provided by callback_job_t is moved to the processor.  Not yet
fully supported is JOB_REQUEUE_DIRECT and canceling jobs.

Note: job_t.destroy() is now called not only for queued jobs but also
after execution or cancellation of jobs.  job_t.status can be used to
decide what to do in said method.
This commit is contained in:
Tobias Brunner
2012-06-25 17:10:28 +02:00
parent 18d21a57df
commit 7fec83af28
26 changed files with 237 additions and 170 deletions
+2 -2
View File
@@ -53,12 +53,12 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_acquire_job_t *this)
{
charon->traps->acquire(charon->traps, this->reqid,
this->src_ts, this->dst_ts);
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
@@ -43,7 +43,7 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_adopt_children_job_t *this)
{
identification_t *my_id, *other_id, *xauth;
@@ -146,7 +146,7 @@ METHOD(job_t, execute, void,
}
children->destroy_offset(children, offsetof(child_sa_t, destroy));
}
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
@@ -57,7 +57,7 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_delete_child_sa_job_t *this)
{
ike_sa_t *ike_sa;
@@ -75,7 +75,7 @@ METHOD(job_t, execute, void,
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
}
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
@@ -48,7 +48,7 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_delete_ike_sa_job_t *this)
{
ike_sa_t *ike_sa;
@@ -60,7 +60,7 @@ METHOD(job_t, execute, void,
if (ike_sa->get_state(ike_sa) == IKE_PASSIVE)
{
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
return destroy(this);
return JOB_REQUEUE_NONE;
}
if (this->delete_if_established)
{
@@ -89,7 +89,7 @@ METHOD(job_t, execute, void,
}
}
}
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
@@ -51,7 +51,7 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_dpd_timeout_job_t *this)
{
time_t use_time, current;
@@ -86,7 +86,7 @@ METHOD(job_t, execute, void,
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
}
}
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
@@ -51,7 +51,7 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_inactivity_job_t *this)
{
ike_sa_t *ike_sa;
@@ -121,10 +121,11 @@ METHOD(job_t, execute, void,
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
}
}
if (!rescheduled)
if (rescheduled)
{
destroy(this);
return JOB_REQUEUE_SCHEDULED;
}
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
@@ -64,7 +64,7 @@ static bool initiate_callback(private_initiate_mediation_job_t *this,
return TRUE;
}
METHOD(job_t, initiate, void,
METHOD(job_t, initiate, job_requeue_t,
private_initiate_mediation_job_t *this)
{
ike_sa_t *mediated_sa, *mediation_sa;
@@ -93,8 +93,7 @@ METHOD(job_t, initiate, void,
mediated_cfg->destroy(mediated_cfg);
mediation_cfg->destroy(mediation_cfg);
enumerator->destroy(enumerator);
destroy(this);
return;
return JOB_REQUEUE_NONE;
}
enumerator->destroy(enumerator);
@@ -115,8 +114,7 @@ METHOD(job_t, initiate, void,
charon->ike_sa_manager->checkin(
charon->ike_sa_manager, mediated_sa);
}
destroy(this);
return;
return JOB_REQUEUE_NONE;
}
/* we need an additional reference because initiate consumes one */
mediation_cfg->get_ref(mediation_cfg);
@@ -134,8 +132,7 @@ METHOD(job_t, initiate, void,
charon->ike_sa_manager->checkin_and_destroy(
charon->ike_sa_manager, mediated_sa);
}
destroy(this);
return;
return JOB_REQUEUE_NONE;
}
mediation_cfg->destroy(mediation_cfg);
@@ -157,18 +154,17 @@ METHOD(job_t, initiate, void,
charon->ike_sa_manager->checkin_and_destroy(
charon->ike_sa_manager, mediated_sa);
}
destroy(this);
return;
return JOB_REQUEUE_NONE;
}
charon->ike_sa_manager->checkin(charon->ike_sa_manager,
mediation_sa);
}
mediated_cfg->destroy(mediated_cfg);
}
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, reinitiate, void,
METHOD(job_t, reinitiate, job_requeue_t,
private_initiate_mediation_job_t *this)
{
ike_sa_t *mediated_sa, *mediation_sa;
@@ -205,8 +201,7 @@ METHOD(job_t, reinitiate, void,
charon->ike_sa_manager,
mediated_sa);
}
destroy(this);
return;
return JOB_REQUEUE_NONE;
}
charon->ike_sa_manager->checkin(charon->ike_sa_manager,
mediation_sa);
@@ -214,7 +209,7 @@ METHOD(job_t, reinitiate, void,
mediated_cfg->destroy(mediated_cfg);
}
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
@@ -77,7 +77,7 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_mediation_job_t *this)
{
ike_sa_id_t *target_sa_id;
@@ -98,8 +98,7 @@ METHOD(job_t, execute, void,
DBG1(DBG_JOB, "callback for '%Y' to '%Y' failed",
this->source, this->target);
charon->ike_sa_manager->checkin(charon->ike_sa_manager, target_sa);
destroy(this);
return;
return JOB_REQUEUE_NONE;
}
}
else
@@ -112,8 +111,7 @@ METHOD(job_t, execute, void,
this->source, this->target);
charon->ike_sa_manager->checkin(charon->ike_sa_manager, target_sa);
/* FIXME: notify the initiator */
destroy(this);
return;
return JOB_REQUEUE_NONE;
}
}
@@ -130,7 +128,7 @@ METHOD(job_t, execute, void,
DBG1(DBG_JOB, "mediation between '%Y' and '%Y' failed: "
"peer is not online anymore", this->source, this->target);
}
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
+2 -2
View File
@@ -67,7 +67,7 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_migrate_job_t *this)
{
ike_sa_t *ike_sa = NULL;
@@ -117,7 +117,7 @@ METHOD(job_t, execute, void,
{
DBG1(DBG_JOB, "no CHILD_SA found with reqid {%d}", this->reqid);
}
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
@@ -42,7 +42,7 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_process_message_job_t *this)
{
ike_sa_t *ike_sa;
@@ -59,8 +59,7 @@ METHOD(job_t, execute, void,
this->message->get_source(this->message),
this->message->get_destination(this->message));
charon->connect_manager->process_check(charon->connect_manager, this->message);
destroy(this);
return;
return JOB_REQUEUE_NONE;
}
#endif /* ME */
@@ -81,7 +80,7 @@ METHOD(job_t, execute, void,
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
}
}
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
@@ -51,7 +51,7 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_rekey_child_sa_job_t *this)
{
ike_sa_t *ike_sa;
@@ -68,7 +68,7 @@ METHOD(job_t, execute, void,
ike_sa->rekey_child_sa(ike_sa, this->protocol, this->spi);
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
}
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
@@ -46,7 +46,7 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_rekey_ike_sa_job_t *this)
{
ike_sa_t *ike_sa;
@@ -78,7 +78,7 @@ METHOD(job_t, execute, void,
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
}
}
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
@@ -47,7 +47,7 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_retransmit_job_t *this)
{
ike_sa_t *ike_sa;
@@ -67,7 +67,7 @@ METHOD(job_t, execute, void,
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
}
}
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
@@ -41,7 +41,7 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_retry_initiate_job_t *this)
{
ike_sa_t *ike_sa;
@@ -64,7 +64,7 @@ METHOD(job_t, execute, void,
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
}
}
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
+2 -3
View File
@@ -44,7 +44,7 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_roam_job_t *this)
{
ike_sa_t *ike_sa;
@@ -82,8 +82,7 @@ METHOD(job_t, execute, void,
id->destroy(id);
}
list->destroy(list);
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
+2 -2
View File
@@ -45,7 +45,7 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_send_dpd_job_t *this)
{
ike_sa_t *ike_sa;
@@ -63,7 +63,7 @@ METHOD(job_t, execute, void,
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
}
}
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
@@ -45,7 +45,7 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_send_keepalive_job_t *this)
{
ike_sa_t *ike_sa;
@@ -57,7 +57,7 @@ METHOD(job_t, execute, void,
ike_sa->send_keepalive(ike_sa);
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
}
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
@@ -36,7 +36,7 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_start_action_job_t *this)
{
enumerator_t *enumerator, *children;
@@ -83,7 +83,7 @@ METHOD(job_t, execute, void,
children->destroy(children);
}
enumerator->destroy(enumerator);
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,
@@ -50,7 +50,7 @@ METHOD(job_t, destroy, void,
free(this);
}
METHOD(job_t, execute, void,
METHOD(job_t, execute, job_requeue_t,
private_update_sa_job_t *this)
{
ike_sa_t *ike_sa;
@@ -71,7 +71,7 @@ METHOD(job_t, execute, void,
}
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
}
destroy(this);
return JOB_REQUEUE_NONE;
}
METHOD(job_t, get_priority, job_priority_t,