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 if(!strcmp(zone->
signconf->
soa_serial,
"keep") && (status == ODS_STATUS_FOPEN_ERR || status == ODS_STATUS_CONFLICT_ERR)) {
283 if(task->backoff > 0) {
284 ods_log_error(
"[%s] unable to sign zone %s: failed to increment serial",
worker->name, task->owner);
285 ods_log_crit(
"[%s] CRITICAL: repeatedly failed to sign zone %s: %s",
worker->name, task->owner, ods_status2str(status));
287 ods_log_warning(
"[%s] unable to sign zone %s: failed to increment serial",
worker->name, task->owner);
288 ods_log_warning(
"[%s] CRITICAL: failed to sign zone %s: %s",
worker->name, task->owner, ods_status2str(status));
293 ods_log_error(
"[%s] unable to sign zone %s: failed to increment serial",
worker->name, task->owner);
294 ods_log_crit(
"[%s] CRITICAL: failed to sign zone %s: %s",
worker->name, task->owner, ods_status2str(status));
295 return schedule_DEFER;
312 if (hsm_check_context()) {
313 ods_log_error(
"signer instructed to reload due to hsm reset in sign task");
318 ods_log_crit(
"[%s] CRITICAL: failed to sign zone %s: %s",
worker->name, task->owner, ods_status2str(status));
319 return schedule_DEFER;
323 if (status == ODS_STATUS_OK) {
325 worker_queue_zone(context,
worker->taskq->signq, zone, &nsubtasks);
326 ods_log_deeebug(
"[%s] wait until drudgers are finished "
327 "signing zone %s",
worker->name, task->owner);
329 fifoq_waitfor(context->
signq,
worker, nsubtasks, &nsubtasksfailed);
334 if (status == ODS_STATUS_OK) {
335 status = worker_check_jobs(
worker, task, nsubtasks, nsubtasksfailed);
337 if (status == ODS_STATUS_OK && zone->
stats) {
342 if (status != ODS_STATUS_OK) {
343 ods_log_crit(
"[%s] CRITICAL: failed to sign zone %s: %s",
worker->name, task->owner, ods_status2str(status));
344 return schedule_DEFER;
348 return schedule_SUCCESS;
352do_readzone(task_type* task,
const char* zonename,
void* zonearg,
void *contextarg)
354 ods_status status = ODS_STATUS_OK;
360 ods_log_debug(
"no signconf.xml for zone %s yet", task->owner);
361 status = ODS_STATUS_ERR;
363 if (status == ODS_STATUS_OK) {
365 if (status == ODS_STATUS_UNCHANGED) {
366 ods_log_verbose(
"zone %s unsigned data not changed, continue", task->owner);
367 status = ODS_STATUS_OK;
370 if (status != ODS_STATUS_OK) {
372 ods_log_warning(
"WARNING: unable to sign zone %s, signconf is not ready", task->owner);
373 return schedule_DEFER;
374 }
else if (status != ODS_STATUS_XFR_NOT_READY) {
376 if(!strcmp(zone->
signconf->
soa_serial,
"keep") && (status == ODS_STATUS_FOPEN_ERR || status == ODS_STATUS_CONFLICT_ERR)) {
377 if(task->backoff > 0) {
378 ods_log_crit(
"CRITICAL: repeatedly failed to sign zone %s: %s", task->owner, ods_status2str(status));
380 ods_log_warning(
"Warning: failed to sign zone %s: %s", task->owner, ods_status2str(status));
385 ods_log_crit(
"CRITICAL: failed to sign zone %s: %s", task->owner, ods_status2str(status));
386 return schedule_DEFER;
403 return schedule_SUCCESS;
410 ods_status status = ODS_STATUS_OK;
416 ods_log_debug(
"no signconf.xml for zone %s yet", task->owner);
417 status = ODS_STATUS_ERR;
419 if (status == ODS_STATUS_OK) {
421 if (status == ODS_STATUS_UNCHANGED) {
422 ods_log_verbose(
"zone %s unsigned data not changed, continue", task->owner);
423 status = ODS_STATUS_OK;
426 if (status != ODS_STATUS_OK) {
428 ods_log_warning(
"WARNING: unable to sign zone %s, signconf is not ready", task->owner);
429 }
else if (status != ODS_STATUS_XFR_NOT_READY) {
431 if(!strcmp(zone->
signconf->
soa_serial,
"keep") && (status == ODS_STATUS_FOPEN_ERR || status == ODS_STATUS_CONFLICT_ERR)) {
432 if(task->backoff > 0) {
433 ods_log_crit(
"CRITICAL: repeatedly failed to sign zone %s: %s", task->owner, ods_status2str(status));
435 ods_log_warning(
"Warning: failed to sign zone %s: %s", task->owner, ods_status2str(status));
440 ods_log_crit(
"CRITICAL: failed to sign zone %s: %s", task->owner, ods_status2str(status));
441 return schedule_DEFER;
444 return schedule_SUCCESS;
452 return schedule_SUCCESS;
457do_writezone(task_type* task,
const char* zonename,
void* zonearg,
void *contextarg)
468 if (status != ODS_STATUS_OK) {
469 ods_log_crit(
"[%s] CRITICAL: failed to sign zone %s: %s",
470 worker->name, task->owner, ods_status2str(status));
471 return schedule_DEFER;
478 ods_log_error(
"[%s] unable to retrieve resign interval "
479 "for zone %s: duration2time() failed",
480 worker->name, task->owner);
481 ods_log_info(
"[%s] defaulting to 1H resign interval for "
482 "zone %s",
worker->name, task->owner);
487 if (status != ODS_STATUS_OK) {
488 ods_log_warning(
"[%s] unable to backup zone %s: %s",
489 worker->name, task->owner, ods_status2str(status));
491 status = ODS_STATUS_OK;
494 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)