diff options
author | Adrian Moreno <amorenoz@redhat.com> | 2022-03-23 12:56:14 +0100 |
---|---|---|
committer | Ilya Maximets <i.maximets@ovn.org> | 2022-03-30 16:59:02 +0200 |
commit | e9bf5bffb020e3dca4104118e15c69242bc12e33 (patch) | |
tree | 01e35216faf311d3313c6f20464dc884c2dc1f81 /ovsdb | |
parent | d4566085edf50033087652f35f92b9b77cbec70f (diff) | |
download | openvswitch-e9bf5bffb020e3dca4104118e15c69242bc12e33.tar.gz |
list: use short version of safe loops if possible.
Using the 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.
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/jsonrpc-server.c | 16 | ||||
-rw-r--r-- | ovsdb/monitor.c | 24 | ||||
-rw-r--r-- | ovsdb/ovsdb.c | 4 | ||||
-rw-r--r-- | ovsdb/raft.c | 15 | ||||
-rw-r--r-- | ovsdb/transaction-forward.c | 6 | ||||
-rw-r--r-- | ovsdb/transaction.c | 28 | ||||
-rw-r--r-- | ovsdb/trigger.c | 4 |
7 files changed, 48 insertions, 49 deletions
diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c index 351c39d8a..d091602d5 100644 --- a/ovsdb/jsonrpc-server.c +++ b/ovsdb/jsonrpc-server.c @@ -585,9 +585,9 @@ ovsdb_jsonrpc_session_set_options(struct ovsdb_jsonrpc_session *session, static void ovsdb_jsonrpc_session_run_all(struct ovsdb_jsonrpc_remote *remote) { - struct ovsdb_jsonrpc_session *s, *next; + struct ovsdb_jsonrpc_session *s; - LIST_FOR_EACH_SAFE (s, next, node, &remote->sessions) { + LIST_FOR_EACH_SAFE (s, node, &remote->sessions) { int error = ovsdb_jsonrpc_session_run(s); if (error) { ovsdb_jsonrpc_session_close(s); @@ -642,9 +642,9 @@ ovsdb_jsonrpc_session_get_memory_usage_all( static void ovsdb_jsonrpc_session_close_all(struct ovsdb_jsonrpc_remote *remote) { - struct ovsdb_jsonrpc_session *s, *next; + struct ovsdb_jsonrpc_session *s; - LIST_FOR_EACH_SAFE (s, next, node, &remote->sessions) { + LIST_FOR_EACH_SAFE (s, node, &remote->sessions) { ovsdb_jsonrpc_session_close(s); } } @@ -660,9 +660,9 @@ static void ovsdb_jsonrpc_session_reconnect_all(struct ovsdb_jsonrpc_remote *remote, bool force, const char *comment) { - struct ovsdb_jsonrpc_session *s, *next; + struct ovsdb_jsonrpc_session *s; - LIST_FOR_EACH_SAFE (s, next, node, &remote->sessions) { + LIST_FOR_EACH_SAFE (s, node, &remote->sessions) { if (force || !s->db_change_aware) { jsonrpc_session_force_reconnect(s->js); if (comment && jsonrpc_session_is_connected(s->js)) { @@ -1226,8 +1226,8 @@ ovsdb_jsonrpc_trigger_complete_all(struct ovsdb_jsonrpc_session *s) static void ovsdb_jsonrpc_trigger_complete_done(struct ovsdb_jsonrpc_session *s) { - struct ovsdb_jsonrpc_trigger *trigger, *next; - LIST_FOR_EACH_SAFE (trigger, next, trigger.node, &s->up.completions) { + struct ovsdb_jsonrpc_trigger *trigger; + LIST_FOR_EACH_SAFE (trigger, trigger.node, &s->up.completions) { ovsdb_jsonrpc_trigger_complete(trigger); } } diff --git a/ovsdb/monitor.c b/ovsdb/monitor.c index 0f222cc99..513f37b1b 100644 --- a/ovsdb/monitor.c +++ b/ovsdb/monitor.c @@ -638,8 +638,8 @@ ovsdb_monitor_change_set_destroy(struct ovsdb_monitor_change_set *mcs) { ovs_list_remove(&mcs->list_node); - struct ovsdb_monitor_change_set_for_table *mcst, *next_mcst; - LIST_FOR_EACH_SAFE (mcst, next_mcst, list_in_change_set, + struct ovsdb_monitor_change_set_for_table *mcst; + LIST_FOR_EACH_SAFE (mcst, list_in_change_set, &mcs->change_set_for_tables) { ovs_list_remove(&mcst->list_in_change_set); ovs_list_remove(&mcst->list_in_mt); @@ -1711,8 +1711,8 @@ ovsdb_monitor_destroy(struct ovsdb_monitor *dbmon) ovsdb_monitor_json_cache_flush(dbmon); hmap_destroy(&dbmon->json_cache); - struct ovsdb_monitor_change_set *cs, *cs_next; - LIST_FOR_EACH_SAFE (cs, cs_next, list_node, &dbmon->change_sets) { + struct ovsdb_monitor_change_set *cs; + LIST_FOR_EACH_SAFE (cs, list_node, &dbmon->change_sets) { ovsdb_monitor_change_set_destroy(cs); } @@ -1760,14 +1760,14 @@ ovsdb_monitors_commit(struct ovsdb *db, const struct ovsdb_txn *txn) void ovsdb_monitors_remove(struct ovsdb *db) { - struct ovsdb_monitor *m, *next_m; + struct ovsdb_monitor *m; - LIST_FOR_EACH_SAFE (m, next_m, list_node, &db->monitors) { - struct jsonrpc_monitor_node *jm, *next_jm; + LIST_FOR_EACH_SAFE (m, list_node, &db->monitors) { + struct jsonrpc_monitor_node *jm; /* Delete all front-end monitors. Removing the last front-end monitor * will also destroy the corresponding ovsdb_monitor. */ - LIST_FOR_EACH_SAFE (jm, next_jm, node, &m->jsonrpc_monitors) { + LIST_FOR_EACH_SAFE (jm, node, &m->jsonrpc_monitors) { ovsdb_jsonrpc_monitor_destroy(jm->jsonrpc_monitor, false); } } @@ -1789,14 +1789,14 @@ ovsdb_monitor_get_memory_usage(struct simap *usage) void ovsdb_monitor_prereplace_db(struct ovsdb *db) { - struct ovsdb_monitor *m, *next_m; + struct ovsdb_monitor *m; - LIST_FOR_EACH_SAFE (m, next_m, list_node, &db->monitors) { - struct jsonrpc_monitor_node *jm, *next_jm; + LIST_FOR_EACH_SAFE (m, list_node, &db->monitors) { + struct jsonrpc_monitor_node *jm; /* Delete all front-end monitors. Removing the last front-end monitor * will also destroy the corresponding ovsdb_monitor. */ - LIST_FOR_EACH_SAFE (jm, next_jm, node, &m->jsonrpc_monitors) { + LIST_FOR_EACH_SAFE (jm, node, &m->jsonrpc_monitors) { ovsdb_jsonrpc_monitor_destroy(jm->jsonrpc_monitor, true); } } diff --git a/ovsdb/ovsdb.c b/ovsdb/ovsdb.c index e6d866182..91b4a01af 100644 --- a/ovsdb/ovsdb.c +++ b/ovsdb/ovsdb.c @@ -571,8 +571,8 @@ ovsdb_replace(struct ovsdb *dst, struct ovsdb *src) ovsdb_monitor_prereplace_db(dst); /* Cancel triggers. */ - struct ovsdb_trigger *trigger, *next; - LIST_FOR_EACH_SAFE (trigger, next, node, &dst->triggers) { + struct ovsdb_trigger *trigger; + LIST_FOR_EACH_SAFE (trigger, node, &dst->triggers) { ovsdb_trigger_prereplace_db(trigger); } diff --git a/ovsdb/raft.c b/ovsdb/raft.c index 855404808..23a2728f3 100644 --- a/ovsdb/raft.c +++ b/ovsdb/raft.c @@ -1384,8 +1384,8 @@ raft_close__(struct raft *raft) raft->remove_server = NULL; } - struct raft_conn *conn, *next; - LIST_FOR_EACH_SAFE (conn, next, list_node, &raft->conns) { + struct raft_conn *conn; + LIST_FOR_EACH_SAFE (conn, list_node, &raft->conns) { raft_conn_close(conn); } } @@ -1721,8 +1721,8 @@ raft_waiters_run(struct raft *raft) } uint64_t cur = ovsdb_log_commit_progress(raft->log); - struct raft_waiter *w, *next; - LIST_FOR_EACH_SAFE (w, next, list_node, &raft->waiters) { + struct raft_waiter *w; + LIST_FOR_EACH_SAFE (w, list_node, &raft->waiters) { if (cur < w->commit_ticket) { break; } @@ -1744,8 +1744,8 @@ raft_waiters_wait(struct raft *raft) static void raft_waiters_destroy(struct raft *raft) { - struct raft_waiter *w, *next; - LIST_FOR_EACH_SAFE (w, next, list_node, &raft->waiters) { + struct raft_waiter *w; + LIST_FOR_EACH_SAFE (w, list_node, &raft->waiters) { raft_waiter_destroy(w); } } @@ -1968,8 +1968,7 @@ raft_run(struct raft *raft) /* Close unneeded sessions. */ struct raft_server *server; - struct raft_conn *next; - LIST_FOR_EACH_SAFE (conn, next, list_node, &raft->conns) { + LIST_FOR_EACH_SAFE (conn, list_node, &raft->conns) { if (!raft_conn_should_stay_open(raft, conn)) { server = raft_find_new_server(raft, &conn->sid); if (server) { diff --git a/ovsdb/transaction-forward.c b/ovsdb/transaction-forward.c index d15f2f1d6..4549e3427 100644 --- a/ovsdb/transaction-forward.c +++ b/ovsdb/transaction-forward.c @@ -126,10 +126,10 @@ ovsdb_txn_forward_steal_reply(struct ovsdb_txn_forward *txn_fwd) void ovsdb_txn_forward_run(struct ovsdb *db, struct ovsdb_cs *cs) { - struct ovsdb_txn_forward *t, *next; + struct ovsdb_txn_forward *t; /* Send all transactions that needs to be forwarded. */ - LIST_FOR_EACH_SAFE (t, next, new_node, &db->txn_forward_new) { + LIST_FOR_EACH_SAFE (t, new_node, &db->txn_forward_new) { if (!ovsdb_cs_may_send_transaction(cs)) { break; } @@ -177,7 +177,7 @@ ovsdb_txn_forward_cancel_all(struct ovsdb *db, bool sent_only) return; } - LIST_FOR_EACH_SAFE (t, next, new_node, &db->txn_forward_new) { + LIST_FOR_EACH_SAFE (t, new_node, &db->txn_forward_new) { ovsdb_txn_forward_cancel(db, t); } } diff --git a/ovsdb/transaction.c b/ovsdb/transaction.c index 090068603..3b96a3a14 100644 --- a/ovsdb/transaction.c +++ b/ovsdb/transaction.c @@ -159,15 +159,15 @@ ovsdb_txn_row_abort(struct ovsdb_txn *txn OVS_UNUSED, hmap_replace(&new->table->rows, &new->hmap_node, &old->hmap_node); } - struct ovsdb_weak_ref *weak, *next; - LIST_FOR_EACH_SAFE (weak, next, src_node, &txn_row->deleted_refs) { + struct ovsdb_weak_ref *weak; + LIST_FOR_EACH_SAFE (weak, src_node, &txn_row->deleted_refs) { ovs_list_remove(&weak->src_node); ovs_list_init(&weak->src_node); if (hmap_node_is_null(&weak->dst_node)) { ovsdb_weak_ref_destroy(weak); } } - LIST_FOR_EACH_SAFE (weak, next, src_node, &txn_row->added_refs) { + LIST_FOR_EACH_SAFE (weak, src_node, &txn_row->added_refs) { ovs_list_remove(&weak->src_node); ovs_list_init(&weak->src_node); if (hmap_node_is_null(&weak->dst_node)) { @@ -508,11 +508,11 @@ static struct ovsdb_error * ovsdb_txn_update_weak_refs(struct ovsdb_txn *txn OVS_UNUSED, struct ovsdb_txn_row *txn_row) { - struct ovsdb_weak_ref *weak, *next, *dst_weak; + struct ovsdb_weak_ref *weak, *dst_weak; struct ovsdb_row *dst_row; /* Find and clean up deleted references from destination rows. */ - LIST_FOR_EACH_SAFE (weak, next, src_node, &txn_row->deleted_refs) { + LIST_FOR_EACH_SAFE (weak, src_node, &txn_row->deleted_refs) { dst_row = CONST_CAST(struct ovsdb_row *, ovsdb_table_get_row(weak->dst_table, &weak->dst)); if (dst_row) { @@ -529,7 +529,7 @@ ovsdb_txn_update_weak_refs(struct ovsdb_txn *txn OVS_UNUSED, } /* Insert the weak references added in the new version of the row. */ - LIST_FOR_EACH_SAFE (weak, next, src_node, &txn_row->added_refs) { + LIST_FOR_EACH_SAFE (weak, src_node, &txn_row->added_refs) { dst_row = CONST_CAST(struct ovsdb_row *, ovsdb_table_get_row(weak->dst_table, &weak->dst)); @@ -597,7 +597,7 @@ find_and_add_weak_ref(struct ovsdb_txn_row *txn_row, static struct ovsdb_error * OVS_WARN_UNUSED_RESULT assess_weak_refs(struct ovsdb_txn *txn, struct ovsdb_txn_row *txn_row) { - struct ovsdb_weak_ref *weak, *next; + struct ovsdb_weak_ref *weak; struct ovsdb_table *table; struct shash_node *node; @@ -642,7 +642,7 @@ assess_weak_refs(struct ovsdb_txn *txn, struct ovsdb_txn_row *txn_row) /* Collecting all key-value pairs that references deleted rows. */ ovsdb_datum_init_empty(&deleted_refs); - LIST_FOR_EACH_SAFE (weak, next, src_node, &txn_row->deleted_refs) { + LIST_FOR_EACH_SAFE (weak, src_node, &txn_row->deleted_refs) { if (column->index == weak->column_idx) { ovsdb_datum_add_unsafe(&deleted_refs, &weak->key, &weak->value, &column->type, NULL); @@ -1094,8 +1094,8 @@ static void ovsdb_txn_destroy_cloned(struct ovsdb_txn *txn) { ovs_assert(!txn->db); - struct ovsdb_txn_table *t, *next_txn_table; - LIST_FOR_EACH_SAFE (t, next_txn_table, node, &txn->txn_tables) { + 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) { if (r->old) { @@ -1550,10 +1550,10 @@ for_each_txn_row(struct ovsdb_txn *txn, serial++; do { - struct ovsdb_txn_table *t, *next_txn_table; + struct ovsdb_txn_table *t; any_work = false; - LIST_FOR_EACH_SAFE (t, next_txn_table, node, &txn->txn_tables) { + LIST_FOR_EACH_SAFE (t, node, &txn->txn_tables) { if (t->serial != serial) { t->serial = serial; t->n_processed = 0; @@ -1630,8 +1630,8 @@ ovsdb_txn_history_destroy(struct ovsdb *db) return; } - struct ovsdb_txn_history_node *txn_h_node, *next; - LIST_FOR_EACH_SAFE (txn_h_node, next, node, &db->txn_history) { + struct ovsdb_txn_history_node *txn_h_node; + LIST_FOR_EACH_SAFE (txn_h_node, node, &db->txn_history) { ovs_list_remove(&txn_h_node->node); ovsdb_txn_destroy_cloned(txn_h_node->txn); free(txn_h_node); diff --git a/ovsdb/trigger.c b/ovsdb/trigger.c index 726c138bf..7d3003bca 100644 --- a/ovsdb/trigger.c +++ b/ovsdb/trigger.c @@ -146,14 +146,14 @@ ovsdb_trigger_prereplace_db(struct ovsdb_trigger *trigger) bool ovsdb_trigger_run(struct ovsdb *db, long long int now) { - struct ovsdb_trigger *t, *next; + struct ovsdb_trigger *t; bool run_triggers = db->run_triggers; db->run_triggers_now = db->run_triggers = false; bool disconnect_all = false; - LIST_FOR_EACH_SAFE (t, next, node, &db->triggers) { + LIST_FOR_EACH_SAFE (t, node, &db->triggers) { if (run_triggers || now - t->created >= t->timeout_msec || t->progress || t->txn_forward) { |