]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: add an api to process/clean the pending dplane queue
authorMark Stapp <mjs@voltanet.io>
Mon, 30 Nov 2020 21:42:18 +0000 (16:42 -0500)
committerMark Stapp <mjs@voltanet.io>
Mon, 30 Nov 2020 21:42:18 +0000 (16:42 -0500)
Add an api that allows a caller in the zebra main pthread to
process the queue of pending dplane updates. The caller supplies
a function to call to test each pending context. Selected
contexts are dequeued, and freed without being processed.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
zebra/zebra_dplane.c
zebra/zebra_dplane.h

index 22cc234b2f6da517f3680922dff304b3ac274b60..8cfe259932a54a57e8a94821a9eca2ab932a37a2 100644 (file)
@@ -4327,6 +4327,49 @@ static void dplane_provider_init(void)
 #endif /* DPLANE_TEST_PROVIDER */
 }
 
+/*
+ * Allow zebra code to walk the queue of pending contexts, evaluate each one
+ * using a callback function. If the function returns 'true', the context
+ * will be dequeued and freed without being processed.
+ */
+int dplane_clean_ctx_queue(bool (*context_cb)(struct zebra_dplane_ctx *ctx,
+                                             void *arg), void *val)
+{
+       struct zebra_dplane_ctx *ctx, *temp;
+       struct dplane_ctx_q work_list;
+
+       TAILQ_INIT(&work_list);
+
+       if (context_cb == NULL)
+               goto done;
+
+       /* Walk the pending context queue under the dplane lock. */
+       DPLANE_LOCK();
+
+       TAILQ_FOREACH_SAFE(ctx, &zdplane_info.dg_update_ctx_q, zd_q_entries,
+                          temp) {
+               if (context_cb(ctx, val)) {
+                       TAILQ_REMOVE(&zdplane_info.dg_update_ctx_q, ctx,
+                                    zd_q_entries);
+                       TAILQ_INSERT_TAIL(&work_list, ctx, zd_q_entries);
+               }
+       }
+
+       DPLANE_UNLOCK();
+
+       /* Now free any contexts selected by the caller, without holding
+        * the lock.
+        */
+       TAILQ_FOREACH_SAFE(ctx, &work_list, zd_q_entries, temp) {
+               TAILQ_REMOVE(&work_list, ctx, zd_q_entries);
+               dplane_ctx_fini(&ctx);
+       }
+
+done:
+
+       return 0;
+}
+
 /* Indicates zebra shutdown/exit is in progress. Some operations may be
  * simplified or skipped during shutdown processing.
  */
index 1b2ea9d96bca2f77a42e3c128c845c5979187e14..3b4f0490686d0b4335f396f5a19ba4f8da04e43a 100644 (file)
@@ -216,6 +216,15 @@ struct zebra_dplane_ctx *dplane_ctx_alloc(void);
  */
 void dplane_ctx_reset(struct zebra_dplane_ctx *ctx);
 
+/*
+ * Allow zebra code to walk the queue of pending contexts, evaluate each one
+ * using a callback function. The caller can supply an optional void* arg also.
+ * If the function returns 'true', the context will be dequeued and freed
+ * without being processed.
+ */
+int dplane_clean_ctx_queue(bool (*context_cb)(struct zebra_dplane_ctx *ctx,
+                                             void *arg), void *val);
+
 /* Return a dataplane results context block after use; the caller's pointer will
  * be cleared.
  */