*: 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 <sharpd@nvidia.com>
This commit is contained in:
Donald Sharp 2020-10-14 12:44:23 -04:00
parent 0894afd4cf
commit c10e14e96d
15 changed files with 53 additions and 33 deletions

View File

@ -2481,11 +2481,10 @@ static int install_evpn_route_entry_in_vrf(struct bgp *bgp_vrf,
bgp_dest_unlock_node(dest); bgp_dest_unlock_node(dest);
if (bgp_debug_zebra(NULL)) if (bgp_debug_zebra(NULL))
zlog_debug( zlog_debug("... %s pi dest %p (l %d) pi %p (l %d, f 0x%x)",
"... %s pi dest %p (l %d) pi %p (l %d, f 0x%x)", new_pi ? "new" : "update", dest,
new_pi ? "new" : "update", bgp_dest_get_lock_count(dest), pi, pi->lock,
dest, bgp_dest_to_rnode(dest)->lock, pi->flags);
pi, pi->lock, pi->flags);
return ret; return ret;
} }
@ -2620,10 +2619,9 @@ static int uninstall_evpn_route_entry_in_vrf(struct bgp *bgp_vrf,
return 0; return 0;
if (bgp_debug_zebra(NULL)) if (bgp_debug_zebra(NULL))
zlog_debug( zlog_debug("... delete dest %p (l %d) pi %p (l %d, f 0x%x)",
"... delete dest %p (l %d) pi %p (l %d, f 0x%x)", dest, bgp_dest_get_lock_count(dest), pi, pi->lock,
dest, bgp_dest_to_rnode(dest)->lock, pi->flags);
pi, pi->lock, pi->flags);
/* Process for route leaking. */ /* Process for route leaking. */
vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp_vrf, pi); vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp_vrf, pi);

View File

@ -216,7 +216,7 @@ void bgp_path_info_extra_free(struct bgp_path_info_extra **extra)
unsigned refcount; unsigned refcount;
bpi = bgp_path_info_lock(bpi); 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); bgp_dest_unlock_node((struct bgp_dest *)bpi->net);
if (!refcount) if (!refcount)
bpi->net = NULL; bpi->net = NULL;

View File

@ -469,6 +469,11 @@ static inline const struct prefix *bgp_dest_get_prefix(const struct bgp_dest *de
return &dest->p; return &dest->p;
} }
static inline unsigned int bgp_dest_get_lock_count(const struct bgp_dest *dest)
{
return dest->lock;
}
#ifdef _FRR_ATTRIBUTE_PRINTFRR #ifdef _FRR_ATTRIBUTE_PRINTFRR
#pragma FRR printfrr_ext "%pRN" (struct bgp_node *) #pragma FRR printfrr_ext "%pRN" (struct bgp_node *)
#pragma FRR printfrr_ext "%pBD" (struct bgp_dest *) #pragma FRR printfrr_ext "%pBD" (struct bgp_dest *)

View File

@ -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( vnc_zlog_debug_verbose(
"%s: count_bpi=%d, count_monitor=%d, lockoffset=%d, rn->lock=%d", "%s: count_bpi=%d, count_monitor=%d, lockoffset=%d, rn->lock=%d",
__func__, count_bpi, count_monitor, lockoffset, __func__, count_bpi, count_monitor, lockoffset,
rn->lock); agg_node_get_lock_count(rn));
assert(0); assert(0);
} }
} }
@ -3665,7 +3666,8 @@ void rfapiBgpInfoFilteredImportVPN(
} }
vnc_zlog_debug_verbose("%s: inserting bpi %p at prefix %pRN #%d", 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); rfapiBgpInfoAttachSorted(rn, info_new, afi, SAFI_MPLS_VPN);
rfapiItBiIndexAdd(rn, info_new); rfapiItBiIndexAdd(rn, info_new);

View File

@ -802,7 +802,7 @@ int rfapiRibPreloadBi(
*/ */
trn = agg_node_get(rfd->rsp_times[afi], p); /* locks trn */ trn = agg_node_get(rfd->rsp_times[afi], p); /* locks trn */
trn->info = (void *)(uintptr_t)bgp_clock(); trn->info = (void *)(uintptr_t)bgp_clock();
if (trn->lock > 1) if (agg_node_get_lock_count(trn) > 1)
agg_unlock_node(trn); agg_unlock_node(trn);
return 0; return 0;
@ -1242,7 +1242,7 @@ callback:
trn = agg_node_get(rfd->rsp_times[afi], trn = agg_node_get(rfd->rsp_times[afi],
p); /* locks trn */ p); /* locks trn */
trn->info = (void *)(uintptr_t)bgp_clock(); trn->info = (void *)(uintptr_t)bgp_clock();
if (trn->lock > 1) if (agg_node_get_lock_count(trn) > 1)
agg_unlock_node(trn); agg_unlock_node(trn);
rfapiRfapiIpAddr2Str(&new->vn_address, buf, BUFSIZ); rfapiRfapiIpAddr2Str(&new->vn_address, buf, BUFSIZ);
@ -1833,7 +1833,7 @@ int rfapiRibFTDFilterRecentPrefix(
*/ */
trn = agg_node_get(rfd->rsp_times[afi], p); /* locks trn */ trn = agg_node_get(rfd->rsp_times[afi], p); /* locks trn */
prefix_time = (time_t)trn->info; prefix_time = (time_t)trn->info;
if (trn->lock > 1) if (agg_node_get_lock_count(trn) > 1)
agg_unlock_node(trn); agg_unlock_node(trn);
#ifdef DEBUG_FTD_FILTER_RECENT #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 = agg_node_get(rfd->rsp_times[afi], &pfx); /* locks trn */
trn->info = (void *)(uintptr_t)bgp_clock(); trn->info = (void *)(uintptr_t)bgp_clock();
if (trn->lock > 1) if (agg_node_get_lock_count(trn) > 1)
agg_unlock_node(trn); agg_unlock_node(trn);
{ {

View File

@ -751,7 +751,7 @@ void rfapiShowItNode(void *stream, struct agg_node *rn)
if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0)
return; 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) { for (bpi = rn->info; bpi; bpi = bpi->next) {
rfapiPrintBi(stream, bpi); 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, 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); HVTYNL);
for (bpi = rn->info; bpi; bpi = bpi->next) { for (bpi = rn->info; bpi; bpi = bpi->next) {

View File

@ -161,6 +161,11 @@ agg_node_get_prefix(const struct agg_node *node)
return &node->p; return &node->p;
} }
static inline unsigned int agg_node_get_lock_count(const struct agg_node *node)
{
return node->lock;
}
#ifdef _FRR_ATTRIBUTE_PRINTFRR #ifdef _FRR_ATTRIBUTE_PRINTFRR
#pragma FRR printfrr_ext "%pRN" (struct agg_node *) #pragma FRR printfrr_ext "%pRN" (struct agg_node *)
#endif #endif

View File

@ -3176,7 +3176,8 @@ DEFUN_HIDDEN(show_route_map_pfx_tbl, show_route_map_pfx_tbl_cmd,
vty_out(vty, " %s/%d (%d)\n", vty_out(vty, " %s/%d (%d)\n",
inet_ntop(p->family, &p->u.prefix, buf, inet_ntop(p->family, &p->u.prefix, buf,
SU_ADDRSTRLEN), SU_ADDRSTRLEN),
p->prefixlen, rn->lock); p->prefixlen,
route_node_get_lock_count(rn));
vty_out(vty, "(P) "); vty_out(vty, "(P) ");
prn = rn->parent; 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", vty_out(vty, " %s/%d (%d)\n",
inet_ntop(p->family, &p->u.prefix, buf, inet_ntop(p->family, &p->u.prefix, buf,
SU_ADDRSTRLEN), SU_ADDRSTRLEN),
p->prefixlen, rn->lock); p->prefixlen,
route_node_get_lock_count(rn));
vty_out(vty, "(P) "); vty_out(vty, "(P) ");
prn = rn->parent; prn = rn->parent;

View File

@ -119,7 +119,8 @@ static void route_table_free(struct route_table *rt)
node = node->parent; node = node->parent;
tmp_node->table->count--; 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); rn_hash_node_del(&rt->hash, tmp_node);
route_node_free(rt, tmp_node); route_node_free(rt, tmp_node);

View File

@ -262,6 +262,11 @@ static inline void route_unlock_node(struct route_node *node)
route_node_delete(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 * route_table_iter_next
* *

View File

@ -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", "%s %p: route add %p cost %u: another path: prev %p, next %p node ref %u",
ospf6_route_table_name(table), (void *)table, ospf6_route_table_name(table), (void *)table,
(void *)route, route->path.cost, (void *)prev, (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)) else if (IS_OSPF6_DEBUG_ROUTE(TABLE))
zlog_debug("%s: route add cost %u: another path found", zlog_debug("%s: route add cost %u: another path found",
ospf6_route_table_name(table), ospf6_route_table_name(table),

View File

@ -285,7 +285,8 @@ void ospf_nbr_add_self(struct ospf_interface *oi, struct in_addr router_id)
if (IS_DEBUG_OSPF_EVENT) if (IS_DEBUG_OSPF_EVENT)
zlog_debug( zlog_debug(
"router_id %s already present in neighbor table. node refcount %u", "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); route_unlock_node(rn);
} else } else
rn->info = oi->nbr_self; rn->info = oi->nbr_self;

View File

@ -134,7 +134,7 @@ void pim_rp_init(struct pim_instance *pim)
if (PIM_DEBUG_PIM_TRACE) if (PIM_DEBUG_PIM_TRACE)
zlog_debug( zlog_debug(
"Allocated: %p for rp_info: %p(224.0.0.0/4) Lock: %d", "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) 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, zlog_debug("Lookedup: %p for rp_info: %p(%s) Lock: %d", rn,
rp_info, rp_info,
prefix2str(&rp_info->group, buf, sizeof(buf)), prefix2str(&rp_info->group, buf, sizeof(buf)),
rn->lock); route_node_get_lock_count(rn));
} }
route_unlock_node(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, zlog_debug("Allocated: %p for rp_info: %p(%s) Lock: %d", rn,
rp_info, rp_info,
prefix2str(&rp_info->group, buf, sizeof(buf)), prefix2str(&rp_info->group, buf, sizeof(buf)),
rn->lock); route_node_get_lock_count(rn));
} }
frr_each (rb_pim_upstream, &pim->upstream_head, up) { 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, __func__, rn, rp_info,
prefix2str(&rp_info->group, buf, prefix2str(&rp_info->group, buf,
sizeof(buf)), sizeof(buf)),
rn->lock); route_node_get_lock_count(rn));
} }
rn->info = NULL; rn->info = NULL;
route_unlock_node(rn); route_unlock_node(rn);

View File

@ -271,7 +271,7 @@ static void test_state_verify(struct test_state *test)
associated with rn */ associated with rn */
expected_lock++; expected_lock++;
if (rn->lock != expected_lock) if (route_node_get_lock_count(rn) != expected_lock)
test_failed( test_failed(
test, test,
"Dest rnode lock count doesn't match expected count!", "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 */ != NULL) /* The route node is not internal */
expected_lock++; expected_lock++;
if (rn->lock != expected_lock) { if (route_node_get_lock_count(rn) != expected_lock) {
srcdest_rnode_prefixes( srcdest_rnode_prefixes(
rn, (const struct prefix **)&dst_p, rn, (const struct prefix **)&dst_p,
(const struct prefix **)&src_p); (const struct prefix **)&src_p);

View File

@ -2294,7 +2294,7 @@ static void process_subq_route(struct listnode *lnode, uint8_t qindex)
else else
{ {
zlog_debug ("%s: called for route_node (%p, %d) with no ribs", 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); zlog_backtrace(LOG_DEBUG);
} }
#endif #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 /* Pointless to queue a route_node with no RIB entries to add or remove
*/ */
if (!rnode_to_ribs(rn)) { if (!rnode_to_ribs(rn)) {
zlog_debug("%s: called for route_node (%p, %d) with no ribs", zlog_debug("%s: called for route_node (%p, %u) with no ribs",
__func__, (void *)rn, rn->lock); __func__, (void *)rn, route_node_get_lock_count(rn));
zlog_backtrace(LOG_DEBUG); zlog_backtrace(LOG_DEBUG);
return -1; return -1;
} }