From: Donald Sharp Date: Wed, 14 Oct 2020 16:44:23 +0000 (-0400) Subject: *: Create/Use accessor functions for lock count X-Git-Tag: base_7.6~391^2~5 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=c10e14e96dae32a3b52bc97ab197e58577cff709;p=matthieu%2Ffrr.git *: Create/Use accessor functions for lock count Create appropriate accessor functions for the rn->lock data. We should be accessing this data through accessor functions since it is private data to the data structure. Signed-off-by: Donald Sharp --- diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index 7f9ef0c9cd..8f65b3afba 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -2481,11 +2481,10 @@ static int install_evpn_route_entry_in_vrf(struct bgp *bgp_vrf, bgp_dest_unlock_node(dest); if (bgp_debug_zebra(NULL)) - zlog_debug( - "... %s pi dest %p (l %d) pi %p (l %d, f 0x%x)", - new_pi ? "new" : "update", - dest, bgp_dest_to_rnode(dest)->lock, - pi, pi->lock, pi->flags); + zlog_debug("... %s pi dest %p (l %d) pi %p (l %d, f 0x%x)", + new_pi ? "new" : "update", dest, + bgp_dest_get_lock_count(dest), pi, pi->lock, + pi->flags); return ret; } @@ -2620,10 +2619,9 @@ static int uninstall_evpn_route_entry_in_vrf(struct bgp *bgp_vrf, return 0; if (bgp_debug_zebra(NULL)) - zlog_debug( - "... delete dest %p (l %d) pi %p (l %d, f 0x%x)", - dest, bgp_dest_to_rnode(dest)->lock, - pi, pi->lock, pi->flags); + zlog_debug("... delete dest %p (l %d) pi %p (l %d, f 0x%x)", + dest, bgp_dest_get_lock_count(dest), pi, pi->lock, + pi->flags); /* Process for route leaking. */ vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp_vrf, pi); diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 73f5526fe2..f998a4d350 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -216,7 +216,7 @@ void bgp_path_info_extra_free(struct bgp_path_info_extra **extra) unsigned refcount; bpi = bgp_path_info_lock(bpi); - refcount = bpi->net->lock - 1; + refcount = bgp_dest_get_lock_count(bpi->net) - 1; bgp_dest_unlock_node((struct bgp_dest *)bpi->net); if (!refcount) bpi->net = NULL; diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h index 31ea5554d5..9dd27628ce 100644 --- a/bgpd/bgp_table.h +++ b/bgpd/bgp_table.h @@ -469,6 +469,11 @@ static inline const struct prefix *bgp_dest_get_prefix(const struct bgp_dest *de return &dest->p; } +static inline unsigned int bgp_dest_get_lock_count(const struct bgp_dest *dest) +{ + return dest->lock; +} + #ifdef _FRR_ATTRIBUTE_PRINTFRR #pragma FRR printfrr_ext "%pRN" (struct bgp_node *) #pragma FRR printfrr_ext "%pBD" (struct bgp_dest *) diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index c3ad95ff28..1e8a381e2d 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -265,11 +265,12 @@ void rfapiCheckRefcount(struct agg_node *rn, safi_t safi, int lockoffset) } } - if (count_bpi + count_monitor + lockoffset != rn->lock) { + if (count_bpi + count_monitor + lockoffset + != agg_node_get_lock_count(rn)) { vnc_zlog_debug_verbose( "%s: count_bpi=%d, count_monitor=%d, lockoffset=%d, rn->lock=%d", __func__, count_bpi, count_monitor, lockoffset, - rn->lock); + agg_node_get_lock_count(rn)); assert(0); } } @@ -3665,7 +3666,8 @@ void rfapiBgpInfoFilteredImportVPN( } vnc_zlog_debug_verbose("%s: inserting bpi %p at prefix %pRN #%d", - __func__, info_new, rn, rn->lock); + __func__, info_new, rn, + agg_node_get_lock_count(rn)); rfapiBgpInfoAttachSorted(rn, info_new, afi, SAFI_MPLS_VPN); rfapiItBiIndexAdd(rn, info_new); diff --git a/bgpd/rfapi/rfapi_rib.c b/bgpd/rfapi/rfapi_rib.c index e068eb7af6..8109e7e3d7 100644 --- a/bgpd/rfapi/rfapi_rib.c +++ b/bgpd/rfapi/rfapi_rib.c @@ -802,7 +802,7 @@ int rfapiRibPreloadBi( */ trn = agg_node_get(rfd->rsp_times[afi], p); /* locks trn */ trn->info = (void *)(uintptr_t)bgp_clock(); - if (trn->lock > 1) + if (agg_node_get_lock_count(trn) > 1) agg_unlock_node(trn); return 0; @@ -1242,7 +1242,7 @@ callback: trn = agg_node_get(rfd->rsp_times[afi], p); /* locks trn */ trn->info = (void *)(uintptr_t)bgp_clock(); - if (trn->lock > 1) + if (agg_node_get_lock_count(trn) > 1) agg_unlock_node(trn); rfapiRfapiIpAddr2Str(&new->vn_address, buf, BUFSIZ); @@ -1833,7 +1833,7 @@ int rfapiRibFTDFilterRecentPrefix( */ trn = agg_node_get(rfd->rsp_times[afi], p); /* locks trn */ prefix_time = (time_t)trn->info; - if (trn->lock > 1) + if (agg_node_get_lock_count(trn) > 1) agg_unlock_node(trn); #ifdef DEBUG_FTD_FILTER_RECENT @@ -2069,7 +2069,7 @@ rfapiRibPreload(struct bgp *bgp, struct rfapi_descriptor *rfd, */ trn = agg_node_get(rfd->rsp_times[afi], &pfx); /* locks trn */ trn->info = (void *)(uintptr_t)bgp_clock(); - if (trn->lock > 1) + if (agg_node_get_lock_count(trn) > 1) agg_unlock_node(trn); { diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c index d74404ea56..850e8325c9 100644 --- a/bgpd/rfapi/rfapi_vty.c +++ b/bgpd/rfapi/rfapi_vty.c @@ -751,7 +751,7 @@ void rfapiShowItNode(void *stream, struct agg_node *rn) if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) return; - fp(out, "%pRN @%p #%d%s", rn, rn, rn->lock, HVTYNL); + fp(out, "%pRN @%p #%d%s", rn, rn, agg_node_get_lock_count(rn), HVTYNL); for (bpi = rn->info; bpi; bpi = bpi->next) { rfapiPrintBi(stream, bpi); @@ -787,7 +787,8 @@ void rfapiShowImportTable(void *stream, const char *label, struct agg_table *rt, } fp(out, "%s/%d @%p #%d%s", buf, p->prefixlen, rn, - rn->lock - 1, /* account for loop iterator locking */ + agg_node_get_lock_count(rn) + - 1, /* account for loop iterator locking */ HVTYNL); for (bpi = rn->info; bpi; bpi = bpi->next) { diff --git a/lib/agg_table.h b/lib/agg_table.h index e98476f1b7..e0c06449ee 100644 --- a/lib/agg_table.h +++ b/lib/agg_table.h @@ -161,6 +161,11 @@ agg_node_get_prefix(const struct agg_node *node) return &node->p; } +static inline unsigned int agg_node_get_lock_count(const struct agg_node *node) +{ + return node->lock; +} + #ifdef _FRR_ATTRIBUTE_PRINTFRR #pragma FRR printfrr_ext "%pRN" (struct agg_node *) #endif diff --git a/lib/routemap.c b/lib/routemap.c index fb70860024..3bac243cee 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -3176,7 +3176,8 @@ DEFUN_HIDDEN(show_route_map_pfx_tbl, show_route_map_pfx_tbl_cmd, vty_out(vty, " %s/%d (%d)\n", inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), - p->prefixlen, rn->lock); + p->prefixlen, + route_node_get_lock_count(rn)); vty_out(vty, "(P) "); prn = rn->parent; @@ -3220,7 +3221,8 @@ DEFUN_HIDDEN(show_route_map_pfx_tbl, show_route_map_pfx_tbl_cmd, vty_out(vty, " %s/%d (%d)\n", inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), - p->prefixlen, rn->lock); + p->prefixlen, + route_node_get_lock_count(rn)); vty_out(vty, "(P) "); prn = rn->parent; diff --git a/lib/table.c b/lib/table.c index 86347cbacd..b315637f19 100644 --- a/lib/table.c +++ b/lib/table.c @@ -119,7 +119,8 @@ static void route_table_free(struct route_table *rt) node = node->parent; tmp_node->table->count--; - tmp_node->lock = 0; /* to cause assert if unlocked after this */ + tmp_node->lock = + 0; /* to cause assert if unlocked after this */ rn_hash_node_del(&rt->hash, tmp_node); route_node_free(rt, tmp_node); diff --git a/lib/table.h b/lib/table.h index 9cd9503376..5d620d332b 100644 --- a/lib/table.h +++ b/lib/table.h @@ -262,6 +262,11 @@ static inline void route_unlock_node(struct route_node *node) route_node_delete(node); } +static inline unsigned int route_node_get_lock_count(struct route_node *node) +{ + return node->lock; +} + /* * route_table_iter_next * diff --git a/ospf6d/ospf6_route.c b/ospf6d/ospf6_route.c index a443e4c3ba..4044cdc549 100644 --- a/ospf6d/ospf6_route.c +++ b/ospf6d/ospf6_route.c @@ -714,7 +714,7 @@ struct ospf6_route *ospf6_route_add(struct ospf6_route *route, "%s %p: route add %p cost %u: another path: prev %p, next %p node ref %u", ospf6_route_table_name(table), (void *)table, (void *)route, route->path.cost, (void *)prev, - (void *)next, node->lock); + (void *)next, route_node_get_lock_count(node)); else if (IS_OSPF6_DEBUG_ROUTE(TABLE)) zlog_debug("%s: route add cost %u: another path found", ospf6_route_table_name(table), diff --git a/ospfd/ospf_neighbor.c b/ospfd/ospf_neighbor.c index b0ff40afe5..52ee21473d 100644 --- a/ospfd/ospf_neighbor.c +++ b/ospfd/ospf_neighbor.c @@ -285,7 +285,8 @@ void ospf_nbr_add_self(struct ospf_interface *oi, struct in_addr router_id) if (IS_DEBUG_OSPF_EVENT) zlog_debug( "router_id %s already present in neighbor table. node refcount %u", - inet_ntoa(router_id), rn->lock); + inet_ntoa(router_id), + route_node_get_lock_count(rn)); route_unlock_node(rn); } else rn->info = oi->nbr_self; diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index 93fe787a93..11e6d47fc9 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -134,7 +134,7 @@ void pim_rp_init(struct pim_instance *pim) if (PIM_DEBUG_PIM_TRACE) zlog_debug( "Allocated: %p for rp_info: %p(224.0.0.0/4) Lock: %d", - rn, rp_info, rn->lock); + rn, rp_info, route_node_get_lock_count(rn)); } void pim_rp_free(struct pim_instance *pim) @@ -254,7 +254,7 @@ struct rp_info *pim_rp_find_match_group(struct pim_instance *pim, zlog_debug("Lookedup: %p for rp_info: %p(%s) Lock: %d", rn, rp_info, prefix2str(&rp_info->group, buf, sizeof(buf)), - rn->lock); + route_node_get_lock_count(rn)); } route_unlock_node(rn); @@ -649,7 +649,7 @@ int pim_rp_new(struct pim_instance *pim, struct in_addr rp_addr, zlog_debug("Allocated: %p for rp_info: %p(%s) Lock: %d", rn, rp_info, prefix2str(&rp_info->group, buf, sizeof(buf)), - rn->lock); + route_node_get_lock_count(rn)); } frr_each (rb_pim_upstream, &pim->upstream_head, up) { @@ -845,7 +845,7 @@ int pim_rp_del(struct pim_instance *pim, struct in_addr rp_addr, __func__, rn, rp_info, prefix2str(&rp_info->group, buf, sizeof(buf)), - rn->lock); + route_node_get_lock_count(rn)); } rn->info = NULL; route_unlock_node(rn); diff --git a/tests/lib/test_srcdest_table.c b/tests/lib/test_srcdest_table.c index dbfe853365..097da113ab 100644 --- a/tests/lib/test_srcdest_table.c +++ b/tests/lib/test_srcdest_table.c @@ -271,7 +271,7 @@ static void test_state_verify(struct test_state *test) associated with rn */ expected_lock++; - if (rn->lock != expected_lock) + if (route_node_get_lock_count(rn) != expected_lock) test_failed( test, "Dest rnode lock count doesn't match expected count!", @@ -283,7 +283,7 @@ static void test_state_verify(struct test_state *test) != NULL) /* The route node is not internal */ expected_lock++; - if (rn->lock != expected_lock) { + if (route_node_get_lock_count(rn) != expected_lock) { srcdest_rnode_prefixes( rn, (const struct prefix **)&dst_p, (const struct prefix **)&src_p); diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 8b375e44b6..0503748a69 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -2294,7 +2294,7 @@ static void process_subq_route(struct listnode *lnode, uint8_t qindex) else { zlog_debug ("%s: called for route_node (%p, %d) with no ribs", - __func__, rnode, rnode->lock); + __func__, rnode, route_node_get_lock_count(rnode)); zlog_backtrace(LOG_DEBUG); } #endif @@ -2469,8 +2469,8 @@ int rib_queue_add(struct route_node *rn) /* Pointless to queue a route_node with no RIB entries to add or remove */ if (!rnode_to_ribs(rn)) { - zlog_debug("%s: called for route_node (%p, %d) with no ribs", - __func__, (void *)rn, rn->lock); + zlog_debug("%s: called for route_node (%p, %u) with no ribs", + __func__, (void *)rn, route_node_get_lock_count(rn)); zlog_backtrace(LOG_DEBUG); return -1; }