Skip to content

Commit

Permalink
mgmtd: add bit walking FOREACH macro
Browse files Browse the repository at this point in the history
Walk the client IDs whose bits are set in a mask.

Signed-off-by: Christian Hopps <[email protected]>
  • Loading branch information
choppsv1 committed Oct 9, 2023
1 parent 341d263 commit 530fa95
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ ForEachMacros:
- 'FOREACH_AFI_SAFI'
- 'FOREACH_AFI_SAFI_NSF'
- 'FOREACH_BE_APPLY_BATCH_IN_LIST'
- 'FOREACH_BE_CLIENT_BITS'
- 'FOREACH_BE_TXN_BATCH_IN_LIST'
- 'FOREACH_BE_TXN_IN_LIST'
- 'FOREACH_CMT_REC'
Expand Down
6 changes: 6 additions & 0 deletions lib/mgmt_be_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ enum mgmt_be_client_id {
for ((id) = MGMTD_BE_CLIENT_ID_MIN; \
(id) < MGMTD_BE_CLIENT_ID_MAX; (id)++)

#define FOREACH_BE_CLIENT_BITS(id, bits) \
FOREACH_MGMTD_BE_CLIENT_ID (id) \
if (IS_IDBIT_UNSET((bits), (id))) \
continue; \
else

#define IS_IDBIT_UNSET(v, id) (!((v) & (1ull << (id))))
#define IS_IDBIT_SET(v, id) (!IS_IDBIT_UNSET(v, id))

Expand Down
16 changes: 5 additions & 11 deletions mgmtd/mgmt_be_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,11 +708,9 @@ uint64_t mgmt_be_interested_clients(const char *xpath, bool config)
clients |= map->clients;

if (DEBUG_MODE_CHECK(&mgmt_debug_be, DEBUG_MODE_ALL)) {
FOREACH_MGMTD_BE_CLIENT_ID (id) {
if (IS_IDBIT_SET(clients, id))
MGMTD_BE_ADAPTER_DBG("Cient: %s: subscribed",
mgmt_be_client_id2name(id));
}
FOREACH_BE_CLIENT_BITS (id, clients)
MGMTD_BE_ADAPTER_DBG("Cient: %s: subscribed",
mgmt_be_client_id2name(id));
}
return clients;
}
Expand Down Expand Up @@ -786,9 +784,7 @@ static void be_show_xpath_register(struct vty *vty,
const char *astr;

vty_out(vty, " - xpath: '%s'\n", map->xpath_regexp);
FOREACH_MGMTD_BE_CLIENT_ID (id) {
if (IS_IDBIT_UNSET(map->clients, id))
continue;
FOREACH_BE_CLIENT_BITS (id, map->clients) {
astr = mgmt_be_get_adapter_by_id(id) ? "active" : "inactive";
vty_out(vty, " -- %s-client: '%s'\n", astr,
mgmt_be_client_id2name(id));
Expand Down Expand Up @@ -820,9 +816,7 @@ void mgmt_be_show_xpath_registries(struct vty *vty, const char *xpath)
combined = cclients | oclients;

vty_out(vty, "XPath: '%s'\n", xpath);
FOREACH_MGMTD_BE_CLIENT_ID (id) {
if (IS_IDBIT_UNSET(combined, id))
continue;
FOREACH_BE_CLIENT_BITS (id, combined) {
vty_out(vty, " -- Client: '%s'\tconfig:%d oper:%d\n",
mgmt_be_client_id2name(id), IS_IDBIT_SET(cclients, id),
IS_IDBIT_SET(oclients, id));
Expand Down
5 changes: 1 addition & 4 deletions mgmtd/mgmt_txn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1042,10 +1042,7 @@ static int mgmt_txn_create_config_batches(struct mgmt_txn_req *txn_req,

xpath_len = strlen(xpath) + 1;
value_len = strlen(value) + 1;
FOREACH_MGMTD_BE_CLIENT_ID (id) {
if (IS_IDBIT_UNSET(clients, id))
continue;

FOREACH_BE_CLIENT_BITS (id, clients) {
adapter = mgmt_be_get_adapter_by_id(id);
if (!adapter)
continue;
Expand Down
1 change: 1 addition & 0 deletions tools/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ sub hash_show_words {
SUBGRP_FOREACH_PEER|SUBGRP_FOREACH_PEER_SAFE|
SUBGRP_FOREACH_ADJ|SUBGRP_FOREACH_ADJ_SAFE|
AF_FOREACH|FOREACH_AFI_SAFI|FOREACH_SAFI|
FOREACH_BE_CLIENT_BITS|FOREACH_MGMTD_BE_CLIENT_ID|
LSDB_LOOP
}x;

Expand Down

0 comments on commit 530fa95

Please sign in to comment.