summaryrefslogtreecommitdiff
path: root/ovsdb
diff options
context:
space:
mode:
authorAdrian Moreno <amorenoz@redhat.com>2022-03-23 12:56:17 +0100
committerIlya Maximets <i.maximets@ovn.org>2022-03-30 16:59:02 +0200
commit9e56549c2bba79e644de2d3876b363553175210c (patch)
treebf0bf39f86c3e63eda7171f727a6ca3dcc69922b /ovsdb
parent860e69a8c3d6994dc000b37d682bd16cd2925bef (diff)
downloadopenvswitch-9e56549c2bba79e644de2d3876b363553175210c.tar.gz
hmap: use short version of safe loops if possible.
Using SHORT version of the *_SAFE loops makes the code cleaner and less error prone. So, use the SHORT version and remove the extra variable when possible for hmap and all its derived types. In order to be able to use both long and short versions without changing the name of the macro for all the clients, overload the existing name and select the appropriate version depending on the number of arguments. Acked-by: Dumitru Ceara <dceara@redhat.com> Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Diffstat (limited to 'ovsdb')
-rw-r--r--ovsdb/condition.c8
-rw-r--r--ovsdb/jsonrpc-server.c24
-rw-r--r--ovsdb/monitor.c12
-rw-r--r--ovsdb/ovsdb-server.c11
-rw-r--r--ovsdb/ovsdb-tool.c7
-rw-r--r--ovsdb/query.c4
-rw-r--r--ovsdb/raft-private.c4
-rw-r--r--ovsdb/raft.c18
-rw-r--r--ovsdb/relay.c4
-rw-r--r--ovsdb/replication.c8
-rw-r--r--ovsdb/table.c4
-rw-r--r--ovsdb/transaction-forward.c4
-rw-r--r--ovsdb/transaction.c8
13 files changed, 57 insertions, 59 deletions
diff --git a/ovsdb/condition.c b/ovsdb/condition.c
index 388dd54a1..9aa3788db 100644
--- a/ovsdb/condition.c
+++ b/ovsdb/condition.c
@@ -220,13 +220,13 @@ ovsdb_condition_optimize(struct ovsdb_condition *cnd)
static void
ovsdb_condition_optimize_destroy(struct ovsdb_condition *cnd)
{
- struct shash_node *node, *next;
+ struct shash_node *node;
- SHASH_FOR_EACH_SAFE (node, next, &cnd->o_columns) {
+ SHASH_FOR_EACH_SAFE (node, &cnd->o_columns) {
struct ovsdb_o_column *o_column = node->data;
- struct ovsdb_o_clause *c, *c_next;
+ struct ovsdb_o_clause *c;
- HMAP_FOR_EACH_SAFE(c, c_next, hmap_node, &o_column->o_clauses) {
+ HMAP_FOR_EACH_SAFE (c, hmap_node, &o_column->o_clauses) {
hmap_remove(&o_column->o_clauses, &c->hmap_node);
free(c);
}
diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c
index d091602d5..916a1f414 100644
--- a/ovsdb/jsonrpc-server.c
+++ b/ovsdb/jsonrpc-server.c
@@ -197,9 +197,9 @@ ovsdb_jsonrpc_server_remove_db(struct ovsdb_jsonrpc_server *svr,
void
ovsdb_jsonrpc_server_destroy(struct ovsdb_jsonrpc_server *svr)
{
- struct shash_node *node, *next;
+ struct shash_node *node;
- SHASH_FOR_EACH_SAFE (node, next, &svr->remotes) {
+ SHASH_FOR_EACH_SAFE (node, &svr->remotes) {
ovsdb_jsonrpc_server_del_remote(node);
}
shash_destroy(&svr->remotes);
@@ -227,9 +227,9 @@ void
ovsdb_jsonrpc_server_set_remotes(struct ovsdb_jsonrpc_server *svr,
const struct shash *new_remotes)
{
- struct shash_node *node, *next;
+ struct shash_node *node;
- SHASH_FOR_EACH_SAFE (node, next, &svr->remotes) {
+ SHASH_FOR_EACH_SAFE (node, &svr->remotes) {
struct ovsdb_jsonrpc_remote *remote = node->data;
struct ovsdb_jsonrpc_options *options
= shash_find_data(new_remotes, node->name);
@@ -909,9 +909,9 @@ error:
static void
ovsdb_jsonrpc_session_unlock_all(struct ovsdb_jsonrpc_session *s)
{
- struct ovsdb_lock_waiter *waiter, *next;
+ struct ovsdb_lock_waiter *waiter;
- HMAP_FOR_EACH_SAFE (waiter, next, session_node, &s->up.waiters) {
+ HMAP_FOR_EACH_SAFE (waiter, session_node, &s->up.waiters) {
ovsdb_jsonrpc_session_unlock__(waiter);
}
}
@@ -1198,8 +1198,8 @@ static void
ovsdb_jsonrpc_trigger_remove__(struct ovsdb_jsonrpc_session *s,
struct ovsdb *db)
{
- struct ovsdb_jsonrpc_trigger *t, *next;
- HMAP_FOR_EACH_SAFE (t, next, hmap_node, &s->triggers) {
+ struct ovsdb_jsonrpc_trigger *t;
+ HMAP_FOR_EACH_SAFE (t, hmap_node, &s->triggers) {
if (!db || t->trigger.db == db) {
ovsdb_jsonrpc_trigger_complete(t);
}
@@ -1688,8 +1688,8 @@ ovsdb_jsonrpc_monitor_preremove_db(struct ovsdb_jsonrpc_session *s,
{
ovs_assert(db);
- struct ovsdb_jsonrpc_monitor *m, *next;
- HMAP_FOR_EACH_SAFE (m, next, node, &s->monitors) {
+ struct ovsdb_jsonrpc_monitor *m;
+ HMAP_FOR_EACH_SAFE (m, node, &s->monitors) {
if (m->db == db) {
ovsdb_jsonrpc_monitor_destroy(m, true);
}
@@ -1700,9 +1700,9 @@ ovsdb_jsonrpc_monitor_preremove_db(struct ovsdb_jsonrpc_session *s,
static void
ovsdb_jsonrpc_monitor_remove_all(struct ovsdb_jsonrpc_session *s)
{
- struct ovsdb_jsonrpc_monitor *m, *next;
+ struct ovsdb_jsonrpc_monitor *m;
- HMAP_FOR_EACH_SAFE (m, next, node, &s->monitors) {
+ HMAP_FOR_EACH_SAFE (m, node, &s->monitors) {
ovsdb_jsonrpc_monitor_destroy(m, false);
}
}
diff --git a/ovsdb/monitor.c b/ovsdb/monitor.c
index 513f37b1b..952fa902e 100644
--- a/ovsdb/monitor.c
+++ b/ovsdb/monitor.c
@@ -644,8 +644,8 @@ ovsdb_monitor_change_set_destroy(struct ovsdb_monitor_change_set *mcs)
ovs_list_remove(&mcst->list_in_change_set);
ovs_list_remove(&mcst->list_in_mt);
- struct ovsdb_monitor_row *row, *next;
- HMAP_FOR_EACH_SAFE (row, next, hmap_node, &mcst->rows) {
+ struct ovsdb_monitor_row *row;
+ HMAP_FOR_EACH_SAFE (row, hmap_node, &mcst->rows) {
hmap_remove(&mcst->rows, &row->hmap_node);
ovsdb_monitor_row_destroy(mcst->mt, row, mcst->n_columns);
}
@@ -700,13 +700,13 @@ void
ovsdb_monitor_session_condition_destroy(
struct ovsdb_monitor_session_condition *condition)
{
- struct shash_node *node, *next;
+ struct shash_node *node;
if (!condition) {
return;
}
- SHASH_FOR_EACH_SAFE (node, next, &condition->tables) {
+ SHASH_FOR_EACH_SAFE (node, &condition->tables) {
struct ovsdb_monitor_table_condition *mtc = node->data;
ovsdb_condition_destroy(&mtc->new_condition);
@@ -1122,11 +1122,11 @@ ovsdb_monitor_compose_update(
json = NULL;
struct ovsdb_monitor_change_set_for_table *mcst;
LIST_FOR_EACH (mcst, list_in_change_set, &mcs->change_set_for_tables) {
- struct ovsdb_monitor_row *row, *next;
+ struct ovsdb_monitor_row *row;
struct json *table_json = NULL;
struct ovsdb_monitor_table *mt = mcst->mt;
- HMAP_FOR_EACH_SAFE (row, next, hmap_node, &mcst->rows) {
+ HMAP_FOR_EACH_SAFE (row, hmap_node, &mcst->rows) {
struct json *row_json;
row_json = (*row_update)(mt, condition, OVSDB_MONITOR_ROW, row,
initial, changed, mcst->n_columns);
diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
index a4f6bca73..8fa937903 100644
--- a/ovsdb/ovsdb-server.c
+++ b/ovsdb/ovsdb-server.c
@@ -229,8 +229,7 @@ main_loop(struct server_config *config,
ovsdb_relay_run();
- struct shash_node *next;
- SHASH_FOR_EACH_SAFE (node, next, all_dbs) {
+ SHASH_FOR_EACH_SAFE (node, all_dbs) {
struct db *db = node->data;
ovsdb_txn_history_run(db->db);
ovsdb_storage_run(db->db->storage);
@@ -322,7 +321,7 @@ main(int argc, char *argv[])
FILE *config_tmpfile;
struct server_config server_config;
struct shash all_dbs;
- struct shash_node *node, *next;
+ struct shash_node *node;
int replication_probe_interval = REPLICATION_DEFAULT_PROBE_INTERVAL;
ovs_cmdl_proctitle_init(argc, argv);
@@ -492,7 +491,7 @@ main(int argc, char *argv[])
main_loop(&server_config, jsonrpc, &all_dbs, unixctl, &remotes,
run_process, &exiting, &is_backup);
- SHASH_FOR_EACH_SAFE(node, next, &all_dbs) {
+ SHASH_FOR_EACH_SAFE (node, &all_dbs) {
struct db *db = node->data;
close_db(&server_config, db, NULL);
shash_delete(&all_dbs, node);
@@ -1245,8 +1244,8 @@ update_server_status(struct shash *all_dbs)
/* Update rows for databases that still exist.
* Delete rows for databases that no longer exist. */
- const struct ovsdb_row *row, *next_row;
- HMAP_FOR_EACH_SAFE (row, next_row, hmap_node, &database_table->rows) {
+ const struct ovsdb_row *row;
+ HMAP_FOR_EACH_SAFE (row, hmap_node, &database_table->rows) {
const char *name;
ovsdb_util_read_string_column(row, "name", &name);
struct db *db = shash_find_data(all_dbs, name);
diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c
index d4a9e34cc..df2e373c3 100644
--- a/ovsdb/ovsdb-tool.c
+++ b/ovsdb/ovsdb-tool.c
@@ -1579,15 +1579,14 @@ do_check_cluster(struct ovs_cmdl_context *ctx)
}
free(c.servers);
- struct commit *next_commit;
- HMAP_FOR_EACH_SAFE (commit, next_commit, hmap_node, &c.commits) {
+ HMAP_FOR_EACH_SAFE (commit, hmap_node, &c.commits) {
hmap_remove(&c.commits, &commit->hmap_node);
free(commit);
}
hmap_destroy(&c.commits);
- struct leader *leader, *next_leader;
- HMAP_FOR_EACH_SAFE (leader, next_leader, hmap_node, &c.leaders) {
+ struct leader *leader;
+ HMAP_FOR_EACH_SAFE (leader, hmap_node, &c.leaders) {
hmap_remove(&c.leaders, &leader->hmap_node);
free(leader);
}
diff --git a/ovsdb/query.c b/ovsdb/query.c
index de7451998..eebe56412 100644
--- a/ovsdb/query.c
+++ b/ovsdb/query.c
@@ -40,9 +40,9 @@ ovsdb_query(struct ovsdb_table *table, const struct ovsdb_condition *cnd,
}
} else {
/* Linear scan. */
- const struct ovsdb_row *row, *next;
+ const struct ovsdb_row *row;
- HMAP_FOR_EACH_SAFE (row, next, hmap_node, &table->rows) {
+ HMAP_FOR_EACH_SAFE (row, hmap_node, &table->rows) {
if (ovsdb_condition_match_every_clause(row, cnd) &&
!output_row(row, aux)) {
break;
diff --git a/ovsdb/raft-private.c b/ovsdb/raft-private.c
index 4145c8729..e685c8103 100644
--- a/ovsdb/raft-private.c
+++ b/ovsdb/raft-private.c
@@ -150,8 +150,8 @@ raft_server_destroy(struct raft_server *s)
void
raft_servers_destroy(struct hmap *servers)
{
- struct raft_server *s, *next;
- HMAP_FOR_EACH_SAFE (s, next, hmap_node, servers) {
+ struct raft_server *s;
+ HMAP_FOR_EACH_SAFE (s, hmap_node, servers) {
hmap_remove(servers, &s->hmap_node);
raft_server_destroy(s);
}
diff --git a/ovsdb/raft.c b/ovsdb/raft.c
index 23a2728f3..530c5e5a3 100644
--- a/ovsdb/raft.c
+++ b/ovsdb/raft.c
@@ -700,8 +700,8 @@ static void
raft_set_servers(struct raft *raft, const struct hmap *new_servers,
enum vlog_level level)
{
- struct raft_server *s, *next;
- HMAP_FOR_EACH_SAFE (s, next, hmap_node, &raft->servers) {
+ struct raft_server *s;
+ HMAP_FOR_EACH_SAFE (s, hmap_node, &raft->servers) {
if (!raft_server_find(new_servers, &s->sid)) {
ovs_assert(s != raft->remove_server);
@@ -711,7 +711,7 @@ raft_set_servers(struct raft *raft, const struct hmap *new_servers,
}
}
- HMAP_FOR_EACH_SAFE (s, next, hmap_node, new_servers) {
+ HMAP_FOR_EACH_SAFE (s, hmap_node, new_servers) {
if (!raft_find_server(raft, &s->sid)) {
VLOG(level, "server %s added to configuration", s->nickname);
@@ -2062,8 +2062,8 @@ raft_run(struct raft *raft)
* commands becomes new leader: the pending commands can still complete
* if the crashed leader has replicated the transactions to majority of
* followers before it crashed. */
- struct raft_command *cmd, *next_cmd;
- HMAP_FOR_EACH_SAFE (cmd, next_cmd, hmap_node, &raft->commands) {
+ struct raft_command *cmd;
+ HMAP_FOR_EACH_SAFE (cmd, hmap_node, &raft->commands) {
if (cmd->timestamp
&& now - cmd->timestamp > raft->election_timer * 2) {
raft_command_complete(raft, cmd, RAFT_CMD_TIMEOUT);
@@ -2266,8 +2266,8 @@ raft_command_initiate(struct raft *raft,
static void
log_all_commands(struct raft *raft)
{
- struct raft_command *cmd, *next;
- HMAP_FOR_EACH_SAFE (cmd, next, hmap_node, &raft->commands) {
+ struct raft_command *cmd;
+ HMAP_FOR_EACH_SAFE (cmd, hmap_node, &raft->commands) {
VLOG_DBG("raft command eid: "UUID_FMT, UUID_ARGS(&cmd->eid));
}
}
@@ -2421,8 +2421,8 @@ raft_command_complete(struct raft *raft,
static void
raft_complete_all_commands(struct raft *raft, enum raft_command_status status)
{
- struct raft_command *cmd, *next;
- HMAP_FOR_EACH_SAFE (cmd, next, hmap_node, &raft->commands) {
+ struct raft_command *cmd;
+ HMAP_FOR_EACH_SAFE (cmd, hmap_node, &raft->commands) {
raft_command_complete(raft, cmd, status);
}
}
diff --git a/ovsdb/relay.c b/ovsdb/relay.c
index 2df393403..9ff6ed8f3 100644
--- a/ovsdb/relay.c
+++ b/ovsdb/relay.c
@@ -280,9 +280,9 @@ ovsdb_relay_clear(struct ovsdb *db)
SHASH_FOR_EACH (table_node, &db->tables) {
struct ovsdb_table *table = table_node->data;
- struct ovsdb_row *row, *next;
+ struct ovsdb_row *row;
- HMAP_FOR_EACH_SAFE (row, next, hmap_node, &table->rows) {
+ HMAP_FOR_EACH_SAFE (row, hmap_node, &table->rows) {
ovsdb_txn_row_delete(txn, row);
}
}
diff --git a/ovsdb/replication.c b/ovsdb/replication.c
index d8b56d813..477c69d70 100644
--- a/ovsdb/replication.c
+++ b/ovsdb/replication.c
@@ -549,8 +549,8 @@ reset_database(struct ovsdb *db)
/* Delete all rows if the table is not excluded. */
if (!excluded_tables_find(db->schema->name, table_node->name)) {
struct ovsdb_table *table = table_node->data;
- struct ovsdb_row *row, *next;
- HMAP_FOR_EACH_SAFE (row, next, hmap_node, &table->rows) {
+ struct ovsdb_row *row;
+ HMAP_FOR_EACH_SAFE (row, hmap_node, &table->rows) {
ovsdb_txn_row_delete(txn, row);
}
}
@@ -769,9 +769,9 @@ replication_dbs_destroy(void)
return;
}
- struct shash_node *node, *next;
+ struct shash_node *node;
- SHASH_FOR_EACH_SAFE (node, next, replication_dbs) {
+ SHASH_FOR_EACH_SAFE (node, replication_dbs) {
hmap_remove(&replication_dbs->map, &node->node);
struct replication_db *rdb = node->data;
if (rdb->active_db_schema) {
diff --git a/ovsdb/table.c b/ovsdb/table.c
index 455a3663f..2184701ec 100644
--- a/ovsdb/table.c
+++ b/ovsdb/table.c
@@ -309,10 +309,10 @@ void
ovsdb_table_destroy(struct ovsdb_table *table)
{
if (table) {
- struct ovsdb_row *row, *next;
+ struct ovsdb_row *row;
size_t i;
- HMAP_FOR_EACH_SAFE (row, next, hmap_node, &table->rows) {
+ HMAP_FOR_EACH_SAFE (row, hmap_node, &table->rows) {
ovsdb_row_destroy(row);
}
hmap_destroy(&table->rows);
diff --git a/ovsdb/transaction-forward.c b/ovsdb/transaction-forward.c
index 4549e3427..963e93795 100644
--- a/ovsdb/transaction-forward.c
+++ b/ovsdb/transaction-forward.c
@@ -167,9 +167,9 @@ ovsdb_txn_forward_cancel(struct ovsdb *db, struct ovsdb_txn_forward *txn_fwd)
void
ovsdb_txn_forward_cancel_all(struct ovsdb *db, bool sent_only)
{
- struct ovsdb_txn_forward *t, *next;
+ struct ovsdb_txn_forward *t;
- HMAP_FOR_EACH_SAFE (t, next, sent_node, &db->txn_forward_sent) {
+ HMAP_FOR_EACH_SAFE (t, sent_node, &db->txn_forward_sent) {
ovsdb_txn_forward_cancel(db, t);
}
diff --git a/ovsdb/transaction.c b/ovsdb/transaction.c
index 3b96a3a14..437a75494 100644
--- a/ovsdb/transaction.c
+++ b/ovsdb/transaction.c
@@ -1096,8 +1096,8 @@ ovsdb_txn_destroy_cloned(struct ovsdb_txn *txn)
ovs_assert(!txn->db);
struct ovsdb_txn_table *t;
LIST_FOR_EACH_SAFE (t, node, &txn->txn_tables) {
- struct ovsdb_txn_row *r, *next_txn_row;
- HMAP_FOR_EACH_SAFE (r, next_txn_row, hmap_node, &t->txn_rows) {
+ struct ovsdb_txn_row *r;
+ HMAP_FOR_EACH_SAFE (r, hmap_node, &t->txn_rows) {
if (r->old) {
ovsdb_row_destroy(r->old);
}
@@ -1560,9 +1560,9 @@ for_each_txn_row(struct ovsdb_txn *txn,
}
while (t->n_processed < hmap_count(&t->txn_rows)) {
- struct ovsdb_txn_row *r, *next_txn_row;
+ struct ovsdb_txn_row *r;
- HMAP_FOR_EACH_SAFE (r, next_txn_row, hmap_node, &t->txn_rows) {
+ HMAP_FOR_EACH_SAFE (r, hmap_node, &t->txn_rows) {
if (r->serial != serial) {
struct ovsdb_error *error;