]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Rename task states, to match documentation
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 6 Mar 2025 22:15:32 +0000 (16:15 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 6 Mar 2025 22:15:32 +0000 (16:15 -0600)
src/cache.c
src/object/tal.c
src/task.c
src/task.h
test/cache_test.c
test/task_test.c

index e0b6b4a3ee8834200372a5e35196b67f0d80a05f..cabd0269f27af3d54cd7461f2dc7d01eae207408 100644 (file)
@@ -900,7 +900,7 @@ do_refresh(struct cache_table *tbl, char const *uri, struct cache_node **result)
        /* node->state is guaranteed to be DLS_FRESH at this point. */
 
        if (downloaded) /* Kickstart tasks that fell into DLS_ONGOING */
-               task_wakeup_busy();
+               task_wakeup_dormants();
 
        if (node->dlerr != 0) {
                pr_val_debug("Refresh failed.");
index f8d01321ae9313faeb742f320eae5a85cc3d938d..cb199627a9f475e0ac1c4b02b9352664447f2552 100644 (file)
@@ -169,6 +169,7 @@ traverse_tal(char const *tal_path, void *arg)
        /* Online attempts */
        ARRAYLIST_FOREACH(&tal.urls, url) {
                map.url = *url;
+               // XXX if this is rsync, it seems this will queue and fail
                map.path = cache_refresh_by_url(*url);
                if (!map.path)
                        continue;
@@ -205,7 +206,7 @@ pick_up_work(void *arg)
 
        while ((task = task_dequeue(task)) != NULL) {
                if (certificate_traverse(task->ca) == EBUSY) {
-                       task_requeue_busy(task);
+                       task_requeue_dormant(task);
                        task = NULL;
                }
        }
index 6fab1945d9c56f0da00fc65b2604b9a8773476ff..a4a2b758c308efe823e80f449499380aab660447 100644 (file)
@@ -9,11 +9,14 @@
 STAILQ_HEAD(validation_tasks, validation_task);
 
 /* Queued, not yet claimed tasks */
-static struct validation_tasks tasks;
+static struct validation_tasks waiting;
 /* Queued, but not yet available for claiming */
-static struct validation_tasks busy;
-/* Active tasks (length(@tasks) + length(@busy) + number of running tasks) */
-static int active;
+static struct validation_tasks dormant;
+/*
+ * Total currently existing tasks
+ * (length(@waiting) + length(@dormant) + total active tasks)
+ */
+static int ntasks;
 
 static bool enabled = true;
 
@@ -30,9 +33,9 @@ task_free(struct validation_task *task)
 void
 task_setup(void)
 {
-       STAILQ_INIT(&tasks);
-       STAILQ_INIT(&busy);
-       active = 0;
+       STAILQ_INIT(&waiting);
+       STAILQ_INIT(&dormant);
+       ntasks = 0;
        enabled = true;
        panic_on_fail(pthread_mutex_init(&lock, NULL), "pthread_mutex_init");
        panic_on_fail(pthread_cond_init(&awakener, NULL), "pthread_cond_init");
@@ -54,9 +57,9 @@ static void
 cleanup(void)
 {
        enabled = false;
-       active = 0;
-       cleanup_tasks(&tasks);
-       cleanup_tasks(&busy);
+       ntasks = 0;
+       cleanup_tasks(&waiting);
+       cleanup_tasks(&dormant);
 }
 
 void
@@ -84,6 +87,7 @@ task_teardown(void)
 /*
  * Defers a task for later.
  * Call task_wakeup() once you've queued all your tasks.
+ * Returns number of deferred tasks.
  */
 unsigned int
 task_enqueue(struct cache_mapping *map, struct rpki_certificate *parent)
@@ -104,9 +108,9 @@ task_enqueue(struct cache_mapping *map, struct rpki_certificate *parent)
 
        mutex_lock(&lock);
        if (enabled) {
-               STAILQ_INSERT_TAIL(&tasks, task, lh);
+               STAILQ_INSERT_TAIL(&waiting, task, lh);
                task = NULL;
-               active++;
+               ntasks++;
        }
        mutex_unlock(&lock);
 
@@ -118,12 +122,13 @@ task_enqueue(struct cache_mapping *map, struct rpki_certificate *parent)
        return 1;
 }
 
+/* Steals ownership of @task. */
 void
-task_requeue_busy(struct validation_task *task)
+task_requeue_dormant(struct validation_task *task)
 {
        mutex_lock(&lock);
        if (enabled) {
-               STAILQ_INSERT_TAIL(&busy, task, lh);
+               STAILQ_INSERT_TAIL(&dormant, task, lh);
                task = NULL;
        }
        mutex_unlock(&lock);
@@ -132,7 +137,7 @@ task_requeue_busy(struct validation_task *task)
                task_free(task); /* Couldn't queue */
 }
 
-/* Wakes up threads currently waiting for tasks. */
+/* Wakes up all sleeping task threads. */
 void
 task_wakeup(void)
 {
@@ -142,11 +147,12 @@ task_wakeup(void)
        mutex_unlock(&lock);
 }
 
+/* Upgrades all dormant tasks, and wakes up all sleeping task threads. */
 void
-task_wakeup_busy(void)
+task_wakeup_dormants(void)
 {
        mutex_lock(&lock);
-       STAILQ_CONCAT(&tasks, &busy);
+       STAILQ_CONCAT(&waiting, &dormant);
        panic_on_fail(pthread_cond_broadcast(&awakener),
            "pthread_cond_broadcast");
        mutex_unlock(&lock);
@@ -156,9 +162,10 @@ task_wakeup_busy(void)
  * Frees the @prev previous task, and returns the next one.
  *
  * If no task is available yet, will sleep until someone calls task_wakeup() or
- * task_wakeup_busy().
+ * task_wakeup_dormants().
  * If all the tasks are done, returns NULL.
  *
+ * Steals ownership of @prev.
  * Assumes at least one task has been queued before the first dequeue.
  */
 struct validation_task *
@@ -178,17 +185,17 @@ task_dequeue(struct validation_task *prev)
                goto end;
 
        if (prev) {
-               active--;
-               if (active < 0)
-                       pr_crit("active < 0: %d", active);
+               ntasks--;
+               if (ntasks < 0)
+                       pr_crit("active < 0: %d", ntasks);
        }
 
-       while (active > 0) {
-               pr_op_debug("task_dequeue(): %u tasks active.", active);
+       while (ntasks > 0) {
+               pr_op_debug("task_dequeue(): %u existing tasks.", ntasks);
 
-               task = STAILQ_FIRST(&tasks);
+               task = STAILQ_FIRST(&waiting);
                if (task != NULL) {
-                       STAILQ_REMOVE_HEAD(&tasks, lh);
+                       STAILQ_REMOVE_HEAD(&waiting, lh);
                        mutex_unlock(&lock);
                        pr_op_debug("task_dequeue(): Claimed task '%s'.",
                            task->ca->map.url);
index 356cf53f63e338f9063a301cb1f32c8169717c92..b31251cc34ace11e016d01c3650ef1d696160b28 100644 (file)
@@ -17,9 +17,9 @@ void task_stop(void);
 void task_teardown(void);
 
 unsigned int task_enqueue(struct cache_mapping *, struct rpki_certificate *);
-void task_requeue_busy(struct validation_task *);
+void task_requeue_dormant(struct validation_task *);
 void task_wakeup(void);
-void task_wakeup_busy(void);
+void task_wakeup_dormants(void);
 struct validation_task *task_dequeue(struct validation_task *);
 
 #endif /* SRC_TASK_H_ */
index d63b5980d04b2ec212a933656201b47428b557d6..cbaec3acfe91c227feefccf78bd59666790c97c0 100644 (file)
@@ -53,7 +53,7 @@ rsync_download(char const *url, char const *path)
 }
 
 MOCK_VOID(__delete_node_cb, struct cache_node const *node)
-MOCK_VOID(task_wakeup_busy, void)
+MOCK_VOID(task_wakeup_dormants, void)
 static asn_dec_rval_t dummy = { 0 };
 __MOCK_ABORT(ber_check_tags, asn_dec_rval_t, dummy, const asn_codec_ctx_t *ctx,
     const asn_TYPE_descriptor_t *td, asn_struct_ctx_t *opt_ctx,
index 5df2f53bcdac7f8c436c5df987ed7a52caa0950e..bdd0d839c4b4e28e43494027ec02ae9150d65b36 100644 (file)
@@ -139,7 +139,7 @@ struct test_task {
 
 static STAILQ_HEAD(test_task_list, test_task) test_tasks;
 static pthread_mutex_t test_tasks_lock = PTHREAD_MUTEX_INITIALIZER;
-static bool return_busy;
+static bool return_dormant;
 
 static void
 populate_test_tasks(void)
@@ -188,7 +188,7 @@ certificate_traverse_mock(struct rpki_certificate *ca, int thid)
        if (n != 0)
                task_wakeup();
 
-       if (return_busy && (rand() & 3) == 0)
+       if (return_dormant && (rand() & 3) == 0)
                return EBUSY; /* Return "busy" 25% of the time */
 
        return 0;
@@ -210,7 +210,7 @@ user_thread(void *arg)
                if (certificate_traverse_mock(task->ca, thid) == EBUSY) {
                        printf("+ th%d: Requeuing '%s'\n",
                            thid, task->ca->map.url);
-                       task_requeue_busy(task);
+                       task_requeue_dormant(task);
                        task = NULL;
                }
        }
@@ -241,7 +241,7 @@ run_threads(void)
 
 START_TEST(test_queue_multiuser)
 {
-       return_busy = false;
+       return_dormant = false;
 
        task_setup();
        task_start();
@@ -255,20 +255,20 @@ START_TEST(test_queue_multiuser)
 END_TEST
 
 static void *
-release_busies(void *arg)
+upgrade_dormants(void *arg)
 {
        unsigned int i;
 
        for (i = 0; i < 2; i++) {
                sleep(1);
-               printf("Waking up busy tasks!\n");
-               task_wakeup_busy();
+               printf("Upgrading dormant tasks!\n");
+               task_wakeup_dormants();
        }
 
        sleep(1);
-       return_busy = false;
-       printf("Waking up busy tasks for the last time!\n");
-       task_wakeup_busy();
+       return_dormant = false;
+       printf("Upgrading dormant tasks for the last time!\n");
+       task_wakeup_dormants();
 
        return NULL;
 }
@@ -277,12 +277,12 @@ START_TEST(test_queue_multiuser_busy)
 {
        pthread_t thr;
 
-       return_busy = true;
+       return_dormant = true;
 
        task_setup();
        task_start();
 
-       ck_assert_int_eq(0, pthread_create(&thr, NULL, release_busies, NULL));
+       ck_assert_int_eq(0, pthread_create(&thr, NULL, upgrade_dormants, NULL));
 
        populate_test_tasks();
        run_threads();