From d3246d74ccbf0539fda6a739c265678e2004d5b8 Mon Sep 17 00:00:00 2001 From: Dumitru Ceara Date: Tue, 10 Oct 2023 13:06:50 +0200 Subject: [PATCH] TODO --- controller/ovn-controller.c | 4 +-- lib/extend-table.c | 51 +++++++++++++++++++++---------------- lib/extend-table.h | 8 ++++-- tests/test-ovn.c | 4 +-- 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index 6ff4548c9f..1349bdb011 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -3949,8 +3949,8 @@ en_lflow_output_init(struct engine_node *node OVS_UNUSED, { struct ed_type_lflow_output *data = xzalloc(sizeof *data); ovn_desired_flow_table_init(&data->flow_table); - ovn_extend_table_init(&data->group_table, OFPG_MAX); - ovn_extend_table_init(&data->meter_table, OFPM13_MAX); + ovn_extend_table_init(&data->group_table, "group-table", OFPG_MAX); + ovn_extend_table_init(&data->meter_table, "meter-table", OFPM13_MAX); objdep_mgr_init(&data->lflow_deps_mgr); lflow_conj_ids_init(&data->conj_ids); uuidset_init(&data->objs_processed); diff --git a/lib/extend-table.c b/lib/extend-table.c index 90a1cf92b2..ebcb79247b 100644 --- a/lib/extend-table.c +++ b/lib/extend-table.c @@ -19,6 +19,7 @@ #include "extend-table.h" #include "hash.h" +#include "id-pool.h" #include "lib/uuid.h" #include "openvswitch/vlog.h" @@ -29,13 +30,17 @@ ovn_extend_table_delete_desired(struct ovn_extend_table *table, struct ovn_extend_table_lflow_to_desired *l); void -ovn_extend_table_init(struct ovn_extend_table *table, uint32_t max_id) +ovn_extend_table_init(struct ovn_extend_table *table, const char *table_name, + uint32_t max_id) { - /* Table id 0 is invalid, set id-pool base to 1. */ - table->table_ids = id_pool_create(1, max_id); - hmap_init(&table->desired); - hmap_init(&table->lflow_to_desired); - hmap_init(&table->existing); + *table = (struct ovn_extend_table) { + .name = table_name, + /* Table id 0 is invalid, set id-pool base to 1. */ + .table_ids = id_pool_create(1, max_id), + .desired = HMAP_INITIALIZER(&table->desired), + .lflow_to_desired = HMAP_INITIALIZER(&table->lflow_to_desired), + .existing = HMAP_INITIALIZER(&table->existing), + }; } static struct ovn_extend_table_info * @@ -116,13 +121,13 @@ ovn_extend_table_add_desired_to_lflow(struct ovn_extend_table *table, ovs_list_init(&l->desired); hmap_insert(&table->lflow_to_desired, &l->hmap_node, uuid_hash(lflow_uuid)); - VLOG_DBG("%s: add new lflow_to_desired entry "UUID_FMT, - __func__, UUID_ARGS(lflow_uuid)); + VLOG_DBG("%s: table %s: add new lflow_to_desired entry "UUID_FMT, + __func__, table->name, UUID_ARGS(lflow_uuid)); } ovs_list_insert(&l->desired, &r->list_node); - VLOG_DBG("%s: lflow "UUID_FMT" use new item %s, id %"PRIu32, - __func__, UUID_ARGS(lflow_uuid), r->desired->name, + VLOG_DBG("%s: table %s: lflow "UUID_FMT" use new item %s, id %"PRIu32, + __func__, table->name, UUID_ARGS(lflow_uuid), r->desired->name, r->desired->table_id); } @@ -159,10 +164,11 @@ ovn_extend_info_add_lflow_ref(struct ovn_extend_table *table, } static void -ovn_extend_info_del_lflow_ref(struct ovn_extend_table_lflow_ref *r) +ovn_extend_info_del_lflow_ref(struct ovn_extend_table *table, + struct ovn_extend_table_lflow_ref *r) { - VLOG_DBG("%s: name %s, lflow "UUID_FMT" n %"PRIuSIZE, __func__, - r->desired->name, UUID_ARGS(&r->lflow_uuid), + VLOG_DBG("%s: table %s: name %s, lflow "UUID_FMT" n %"PRIuSIZE, __func__, + table->name, r->desired->name, UUID_ARGS(&r->lflow_uuid), hmap_count(&r->desired->references)); hmap_remove(&r->desired->references, &r->hmap_node); ovs_list_remove(&r->list_node); @@ -190,7 +196,7 @@ ovn_extend_table_clear(struct ovn_extend_table *table, bool existing) if (g->peer) { g->peer->peer = NULL; } else { - /* Unset the bitmap because the peer is deleted already. */ + /* Unset the id because the peer is deleted already. */ id_pool_free_id(table->table_ids, g->table_id); } ovn_extend_table_info_destroy(g); @@ -233,10 +239,10 @@ ovn_extend_table_delete_desired(struct ovn_extend_table *table, struct ovn_extend_table_lflow_ref *r; LIST_FOR_EACH_SAFE (r, list_node, &l->desired) { struct ovn_extend_table_info *e = r->desired; - ovn_extend_info_del_lflow_ref(r); + ovn_extend_info_del_lflow_ref(table, r); if (hmap_is_empty(&e->references)) { - VLOG_DBG("%s: %s, "UUID_FMT, __func__, - e->name, UUID_ARGS(&l->lflow_uuid)); + VLOG_DBG("%s: table %s: %s, "UUID_FMT, __func__, + table->name, e->name, UUID_ARGS(&l->lflow_uuid)); hmap_remove(&table->desired, &e->hmap_node); if (e->peer) { e->peer->peer = NULL; @@ -283,7 +289,7 @@ ovn_extend_table_sync(struct ovn_extend_table *table) } } -/* Assign a new table ID for the table information from the bitmap. +/* Assign a new table ID for the table information from the ID pool. * If it already exists, return the old ID. */ uint32_t ovn_extend_table_assign_id(struct ovn_extend_table *table, const char *name, @@ -297,9 +303,9 @@ ovn_extend_table_assign_id(struct ovn_extend_table *table, const char *name, /* Check whether we have non installed but allocated group_id. */ HMAP_FOR_EACH_WITH_HASH (table_info, hmap_node, hash, &table->desired) { if (!strcmp(table_info->name, name)) { - VLOG_DBG("ovn_externd_table_assign_id: reuse old id %"PRIu32 - " for %s, used by lflow "UUID_FMT, - table_info->table_id, table_info->name, + VLOG_DBG("ovn_extend_table_assign_id: table %s: " + "reuse old id %"PRIu32" for %s, used by lflow "UUID_FMT, + table->name, table_info->table_id, table_info->name, UUID_ARGS(&lflow_uuid)); ovn_extend_info_add_lflow_ref(table, table_info, &lflow_uuid); return table_info->table_id; @@ -321,7 +327,8 @@ ovn_extend_table_assign_id(struct ovn_extend_table *table, const char *name, /* Reserve a new id. */ if (!id_pool_alloc_id(table->table_ids, &table_id)) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); - VLOG_ERR_RL(&rl, "%"PRIu32" out of table ids.", table_id); + + VLOG_ERR_RL(&rl, "table %s: out of table ids.", table->name); return EXT_TABLE_ID_INVALID; } } diff --git a/lib/extend-table.h b/lib/extend-table.h index 56d54afe93..9ca80e0f31 100644 --- a/lib/extend-table.h +++ b/lib/extend-table.h @@ -22,11 +22,14 @@ #include "openvswitch/hmap.h" #include "openvswitch/list.h" #include "openvswitch/uuid.h" -#include "id-pool.h" + +struct id_pool; /* Used to manage expansion tables associated with Flow table, * such as the Group Table or Meter Table. */ struct ovn_extend_table { + const char *name; /* Used to identify this table in a user friendly way, + * e.g., for logging. */ struct id_pool *table_ids; /* Used to allocated ids in either desired or * existing (or both). If the same "name" * exists in both desired and existing tables, @@ -80,7 +83,8 @@ struct ovn_extend_table_lflow_ref { struct ovn_extend_table_info *desired; }; -void ovn_extend_table_init(struct ovn_extend_table *, uint32_t max_id); +void ovn_extend_table_init(struct ovn_extend_table *, const char *table_name, + uint32_t max_id); void ovn_extend_table_destroy(struct ovn_extend_table *); diff --git a/tests/test-ovn.c b/tests/test-ovn.c index e4f03806a3..aaf2825edc 100644 --- a/tests/test-ovn.c +++ b/tests/test-ovn.c @@ -1300,11 +1300,11 @@ test_parse_actions(struct ovs_cmdl_context *ctx OVS_UNUSED) /* Initialize group ids. */ struct ovn_extend_table group_table; - ovn_extend_table_init(&group_table, OFPG_MAX); + ovn_extend_table_init(&group_table, "group-table", OFPG_MAX); /* Initialize meter ids for QoS. */ struct ovn_extend_table meter_table; - ovn_extend_table_init(&meter_table, OFPM13_MAX); + ovn_extend_table_init(&meter_table, "meter-table", OFPM13_MAX); /* Initialize collector sets. */ struct flow_collector_ids collector_ids;