30#include "scheduler/worker.h"
31#include "scheduler/schedule.h"
51 ods_status status = ODS_STATUS_UNCHANGED;
54 ods_log_assert(rrset);
56 pthread_mutex_lock(&q->q_lock);
57 status = fifoq_push(q, (
void*) rrset, context, &tries);
58 while (status == ODS_STATUS_UNCHANGED) {
60 if (context->
worker->need_to_exit) {
61 pthread_mutex_unlock(&q->q_lock);
70 ods_thread_wait(&q->q_nonfull, &q->q_lock, 5);
71 status = fifoq_push(q, (
void*) rrset, context, &tries);
73 pthread_mutex_unlock(&q->q_lock);
75 ods_log_assert(status == ODS_STATUS_OK);
89 ods_log_assert(context);
91 ods_log_assert(domain);
94 worker_queue_rrset(context, q, rrset, nsubtasks);
98 if (denial && denial->
rrset) {
99 worker_queue_rrset(context, q, denial->
rrset, nsubtasks);
111 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
113 ods_log_assert(context);
115 ods_log_assert(zone);
119 if (zone->
db->
domains->root != LDNS_RBTREE_NULL) {
120 node = ldns_rbtree_first(zone->
db->
domains);
122 while (node && node != LDNS_RBTREE_NULL) {
124 worker_queue_domain(context, q, domain, nsubtasks);
125 node = ldns_rbtree_next(node);
135worker_check_jobs(worker_type* worker, task_type* task,
int ntasks,
long ntasksfailed)
137 ods_log_assert(worker);
138 ods_log_assert(task);
140 ods_log_error(
"[%s] sign zone %s failed: %ld RRsets failed",
141 worker->name, task->owner, ntasksfailed);
142 return ODS_STATUS_ERR;
143 }
else if (worker->need_to_exit) {
144 ods_log_error(
"[%s] sign zone %s failed: worker needs to exit",
145 worker->name, task->owner);
146 return ODS_STATUS_ERR;
148 return ODS_STATUS_OK;
157 hsm_ctx_t* ctx = NULL;
161 while (
worker->need_to_exit == 0) {
162 ods_log_deeebug(
"[%s] report for duty",
worker->name);
163 pthread_mutex_lock(&
signq->q_lock);
167 ods_log_deeebug(
"[%s] nothing to do, wait",
worker->name);
174 pthread_cond_wait(&
signq->q_threshold, &
signq->q_lock);
175 if(
worker->need_to_exit == 0)
178 pthread_mutex_unlock(&
signq->q_lock);
181 ods_log_assert(superior);
183 ods_log_debug(
"[%s] create hsm context",
worker->name);
184 ctx = hsm_create_context();
188 ods_log_crit(
"[%s] error creating libhsm context",
worker->name);
193 ods_log_error(
"signer instructed to reload due to hsm reset while signing");
194 status = ODS_STATUS_HSM_ERR;
204 hsm_destroy_context(ctx);
209do_readsignconf(task_type* task,
const char* zonename,
void* zonearg,
void *contextarg)
217 ods_log_debug(
"No signconf.xml for zone %s yet", task->owner);
218 status = ODS_STATUS_ERR;
221 if (status == ODS_STATUS_OK || status == ODS_STATUS_UNCHANGED) {
226 return schedule_SUCCESS;
230 ods_log_warning(
"WARNING: unable to sign zone %s, signconf is not ready", task->owner);
232 ods_log_crit(
"CRITICAL: failed to sign zone %s: %s", task->owner, ods_status2str(status));
234 return schedule_DEFER;
247 if (status == ODS_STATUS_UNCHANGED) {
254 return schedule_SUCCESS;
255 }
else if (status == ODS_STATUS_OK) {
261 return schedule_SUCCESS;
263 return schedule_SUCCESS;
268do_signzone(task_type* task,
const char* zonename,
void* zonearg,
void *contextarg)
278 long nsubtasksfailed = 0;
281 if (status != ODS_STATUS_OK) {
282 ods_log_error(
"[%s] unable to sign zone %s: failed to increment serial",
worker->name, task->owner);
283 ods_log_crit(
"[%s] CRITICAL: failed to sign zone %s: %s",
284 worker->name, task->owner, ods_status2str(status));
285 return schedule_DEFER;
301 if (hsm_check_context()) {
302 ods_log_error(
"signer instructed to reload due to hsm reset in sign task");
307 ods_log_crit(
"[%s] CRITICAL: failed to sign zone %s: %s",
308 worker->name, task->owner, ods_status2str(status));
309 return schedule_DEFER;
313 if (status == ODS_STATUS_OK) {
315 worker_queue_zone(context,
worker->taskq->signq, zone, &nsubtasks);
316 ods_log_deeebug(
"[%s] wait until drudgers are finished "
317 "signing zone %s",
worker->name, task->owner);
319 fifoq_waitfor(context->
signq,
worker, nsubtasks, &nsubtasksfailed);
324 if (status == ODS_STATUS_OK) {
325 status = worker_check_jobs(
worker, task, nsubtasks, nsubtasksfailed);
327 if (status == ODS_STATUS_OK && zone->
stats) {
332 if (status != ODS_STATUS_OK) {
333 ods_log_crit(
"[%s] CRITICAL: failed to sign zone %s: %s",
334 worker->name, task->owner, ods_status2str(status));
335 return schedule_DEFER;
339 return schedule_SUCCESS;
343do_readzone(task_type* task,
const char* zonename,
void* zonearg,
void *contextarg)
345 ods_status status = ODS_STATUS_OK;
351 ods_log_debug(
"no signconf.xml for zone %s yet", task->owner);
352 status = ODS_STATUS_ERR;
354 if (status == ODS_STATUS_OK) {
356 if (status == ODS_STATUS_UNCHANGED) {
357 ods_log_verbose(
"zone %s unsigned data not changed, continue", task->owner);
358 status = ODS_STATUS_OK;
361 if (status != ODS_STATUS_OK) {
363 ods_log_warning(
"WARNING: unable to sign zone %s, signconf is not ready", task->owner);
364 }
else if (status != ODS_STATUS_XFR_NOT_READY) {
366 ods_log_crit(
"CRITICAL: failed to sign zone %s: %s", task->owner, ods_status2str(status));
368 return schedule_DEFER;
383 return schedule_SUCCESS;
390 ods_status status = ODS_STATUS_OK;
396 ods_log_debug(
"no signconf.xml for zone %s yet", task->owner);
397 status = ODS_STATUS_ERR;
399 if (status == ODS_STATUS_OK) {
401 if (status == ODS_STATUS_UNCHANGED) {
402 ods_log_verbose(
"zone %s unsigned data not changed, continue", task->owner);
403 status = ODS_STATUS_OK;
406 if (status != ODS_STATUS_OK) {
408 ods_log_warning(
"WARNING: unable to sign zone %s, signconf is not ready", task->owner);
409 }
else if (status != ODS_STATUS_XFR_NOT_READY) {
411 ods_log_crit(
"CRITICAL: failed to sign zone %s: %s", task->owner, ods_status2str(status));
413 return schedule_SUCCESS;
421 return schedule_SUCCESS;
426do_writezone(task_type* task,
const char* zonename,
void* zonearg,
void *contextarg)
437 if (status != ODS_STATUS_OK) {
438 ods_log_crit(
"[%s] CRITICAL: failed to sign zone %s: %s",
439 worker->name, task->owner, ods_status2str(status));
440 return schedule_DEFER;
447 ods_log_error(
"[%s] unable to retrieve resign interval "
448 "for zone %s: duration2time() failed",
449 worker->name, task->owner);
450 ods_log_info(
"[%s] defaulting to 1H resign interval for "
451 "zone %s",
worker->name, task->owner);
456 if (status != ODS_STATUS_OK) {
457 ods_log_warning(
"[%s] unable to backup zone %s: %s",
458 worker->name, task->owner, ods_status2str(status));
460 status = ODS_STATUS_OK;
463 return schedule_SUCCESS;
ods_status rrset_sign(hsm_ctx_t *ctx, rrset_type *rrset, time_t signtime)
time_t do_forcereadzone(task_type *task, const char *zonename, void *zonearg, void *contextarg)
time_t do_readzone(task_type *task, const char *zonename, void *zonearg, void *contextarg)
void drudge(worker_type *worker)
time_t do_forcereadsignconf(task_type *task, const char *zonename, void *zonearg, void *contextarg)
time_t do_readsignconf(task_type *task, const char *zonename, void *zonearg, void *contextarg)
time_t do_signzone(task_type *task, const char *zonename, void *zonearg, void *contextarg)
time_t do_writezone(task_type *task, const char *zonename, void *zonearg, void *contextarg)
pthread_mutex_t signal_lock
pthread_cond_t signal_cond
duration_type * sig_resign_interval
pthread_mutex_t stats_lock
pthread_mutex_t zone_lock
ods_status zone_backup2(zone_type *zone, time_t nextResign)
ods_status zone_update_serial(zone_type *zone)
ods_status zone_prepare_keys(zone_type *zone)