git: 45645b05b887 - stable/13 - Fib algo: extend KPI by allowing algo to set datapath pointers.

Alexander V. Chernikov melifaro at FreeBSD.org
Mon Apr 26 09:11:59 UTC 2021


The branch stable/13 has been updated by melifaro:

URL: https://cgit.FreeBSD.org/src/commit/?id=45645b05b887f9bc38b2350ae5334a4e8f47ebbb

commit 45645b05b887f9bc38b2350ae5334a4e8f47ebbb
Author:     Alexander V. Chernikov <melifaro at FreeBSD.org>
AuthorDate: 2021-04-15 17:44:11 +0000
Commit:     Alexander V. Chernikov <melifaro at FreeBSD.org>
CommitDate: 2021-04-26 08:48:14 +0000

    Fib algo: extend KPI by allowing algo to set datapath pointers.
    
    Some algorithms may require updating datapath and control plane
     algo pointers after the (batched) updates.
    
    Export fib_set_datapath_ptr() to allow setting the new datapath
     function or data pointer from the algo.
    Add fib_set_algo_ptr() to allow updating algo control plane
     pointer from the algo.
    Add fib_epoch_call() epoch(9) wrapper to simplify freeing old
     datapath state.
    
    Reviewed by:            zec
    Differential Revision: https://reviews.freebsd.org/D29799
    MFC after:              1 week
    
    (cherry picked from commit e2f79d9e518f885bf875f6613e70af39b7c397de)
---
 sys/net/route/fib_algo.c | 59 ++++++++++++++++++++++++++++++++----------------
 sys/net/route/fib_algo.h |  4 +++-
 2 files changed, 42 insertions(+), 21 deletions(-)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index 03c265d28d09..e2b94e645db3 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -163,7 +163,6 @@ struct fib_data {
 static bool rebuild_fd(struct fib_data *fd);
 static void rebuild_fd_callout(void *_data);
 static void destroy_fd_instance_epoch(epoch_context_t ctx);
-static enum flm_op_result attach_datapath(struct fib_data *fd);
 static bool is_idx_free(struct fib_data *fd, uint32_t index);
 static void set_algo_fixed(struct rib_head *rh);
 static bool is_algo_fixed(struct rib_head *rh);
@@ -763,8 +762,7 @@ schedule_destroy_fd_instance(struct fib_data *fd, bool in_callout)
 	 */
 	callout_stop(&fd->fd_callout);
 
-	epoch_call(net_epoch_preempt, destroy_fd_instance_epoch,
-	    &fd->fd_epoch_ctx);
+	fib_epoch_call(destroy_fd_instance_epoch, &fd->fd_epoch_ctx);
 
 	return (0);
 }
@@ -983,8 +981,10 @@ setup_fd_instance(struct fib_lookup_module *flm, struct rib_head *rh,
 	for (int i = 0; i < FIB_MAX_TRIES; i++) {
 		result = try_setup_fd_instance(flm, rh, prev_fd, &new_fd);
 
-		if ((result == FLM_SUCCESS) && attach)
-			result = attach_datapath(new_fd);
+		if ((result == FLM_SUCCESS) && attach) {
+			if (!fib_set_datapath_ptr(new_fd, &new_fd->fd_dp))
+				result = FLM_REBUILD;
+		}
 
 		if ((prev_fd != NULL) && (prev_fd != orig_fd)) {
 			schedule_destroy_fd_instance(prev_fd, false);
@@ -1254,32 +1254,33 @@ get_fib_dp_header(struct fib_dp *dp)
 /*
  * Replace per-family index pool @pdp with a new one which
  * contains updated callback/algo data from @fd.
- * Returns 0 on success.
+ * Returns true on success.
  */
-static enum flm_op_result
-replace_rtables_family(struct fib_dp **pdp, struct fib_data *fd)
+static bool
+replace_rtables_family(struct fib_dp **pdp, struct fib_data *fd, struct fib_dp *dp)
 {
 	struct fib_dp_header *new_fdh, *old_fdh;
 
 	NET_EPOCH_ASSERT();
 
 	FD_PRINTF(LOG_DEBUG, fd, "[vnet %p] replace with f:%p arg:%p",
-	    curvnet, fd->fd_dp.f, fd->fd_dp.arg);
+	    curvnet, dp->f, dp->arg);
 
 	FIB_MOD_LOCK();
 	old_fdh = get_fib_dp_header(*pdp);
+
 	new_fdh = alloc_fib_dp_array(old_fdh->fdh_num_tables, false);
 	FD_PRINTF(LOG_DEBUG, fd, "OLD FDH: %p NEW FDH: %p", old_fdh, new_fdh);
 	if (new_fdh == NULL) {
 		FIB_MOD_UNLOCK();
 		FD_PRINTF(LOG_WARNING, fd, "error attaching datapath");
-		return (FLM_REBUILD);
+		return (false);
 	}
 
 	memcpy(&new_fdh->fdh_idx[0], &old_fdh->fdh_idx[0],
 	    old_fdh->fdh_num_tables * sizeof(struct fib_dp));
 	/* Update relevant data structure for @fd */
-	new_fdh->fdh_idx[fd->fd_fibnum] = fd->fd_dp;
+	new_fdh->fdh_idx[fd->fd_fibnum] = *dp;
 
 	/* Ensure memcpy() writes have completed */
 	atomic_thread_fence_rel();
@@ -1288,10 +1289,9 @@ replace_rtables_family(struct fib_dp **pdp, struct fib_data *fd)
 	FIB_MOD_UNLOCK();
 	FD_PRINTF(LOG_DEBUG, fd, "update %p -> %p", old_fdh, new_fdh);
 
-	epoch_call(net_epoch_preempt, destroy_fdh_epoch,
-	    &old_fdh->fdh_epoch_ctx);
+	fib_epoch_call(destroy_fdh_epoch, &old_fdh->fdh_epoch_ctx);
 
-	return (FLM_SUCCESS);
+	return (true);
 }
 
 static struct fib_dp **
@@ -1309,13 +1309,13 @@ get_family_dp_ptr(int family)
 /*
  * Make datapath use fib instance @fd
  */
-static enum flm_op_result
-attach_datapath(struct fib_data *fd)
+bool
+fib_set_datapath_ptr(struct fib_data *fd, struct fib_dp *dp)
 {
 	struct fib_dp **pdp;
 
 	pdp = get_family_dp_ptr(fd->fd_family);
-	return (replace_rtables_family(pdp, fd));
+	return (replace_rtables_family(pdp, fd, dp));
 }
 
 /*
@@ -1343,8 +1343,7 @@ grow_rtables_family(struct fib_dp **pdp, uint32_t new_num_tables)
 	FIB_MOD_UNLOCK();
 
 	if (old_fdh != NULL)
-		epoch_call(net_epoch_preempt, destroy_fdh_epoch,
-		    &old_fdh->fdh_epoch_ctx);
+		fib_epoch_call(destroy_fdh_epoch, &old_fdh->fdh_epoch_ctx);
 }
 
 /*
@@ -1375,6 +1374,26 @@ fib_get_rtable_info(struct rib_head *rh, struct rib_rtable_info *rinfo)
 #endif
 }
 
+/*
+ * Updates pointer to the algo data for the @fd.
+ */
+void
+fib_set_algo_ptr(struct fib_data *fd, void *algo_data)
+{
+	RIB_WLOCK_ASSERT(fd->fd_rh);
+
+	fd->fd_algo_data = algo_data;
+}
+
+/*
+ * Calls @callback with @ctx after the end of a current epoch.
+ */
+void
+fib_epoch_call(epoch_callback_t callback, epoch_context_t ctx)
+{
+	epoch_call(net_epoch_preempt, callback, ctx);
+}
+
 /*
  * Accessor to get rib instance @fd is attached to.
  */
@@ -1473,7 +1492,7 @@ fib_schedule_release_nhop(struct fib_data *fd, struct nhop_object *nh)
 	nrd = malloc(sizeof(struct nhop_release_data), M_TEMP, M_NOWAIT | M_ZERO);
 	if (nrd != NULL) {
 		nrd->nh = nh;
-		epoch_call(net_epoch_preempt, release_nhop_epoch, &nrd->ctx);
+		fib_epoch_call(release_nhop_epoch, &nrd->ctx);
 	} else {
 		/*
 		 * Unable to allocate memory. Leak nexthop to maintain guarantee
diff --git a/sys/net/route/fib_algo.h b/sys/net/route/fib_algo.h
index fe66c7ce53d4..0e9994245ca4 100644
--- a/sys/net/route/fib_algo.h
+++ b/sys/net/route/fib_algo.h
@@ -105,5 +105,7 @@ uint32_t fib_get_nhop_idx(struct fib_data *fd, struct nhop_object *nh);
 struct nhop_object **fib_get_nhop_array(struct fib_data *fd);
 void fib_get_rtable_info(struct rib_head *rh, struct rib_rtable_info *rinfo);
 struct rib_head *fib_get_rh(struct fib_data *fd);
-
+bool fib_set_datapath_ptr(struct fib_data *fd, struct fib_dp *dp);
+void fib_set_algo_ptr(struct fib_data *fd, void *algo_data);
+void fib_epoch_call(epoch_callback_t callback, epoch_context_t ctx);
 


More information about the dev-commits-src-all mailing list