[ovs-dev] [PATCH v2 2/5] chassis-index: Use OVSDB index mechanism.

Han Zhou zhouhan at gmail.com
Tue Jun 12 02:29:54 UTC 2018


On Mon, Jun 11, 2018 at 3:14 PM, Ben Pfaff <blp at ovn.org> wrote:
>
> It seems like a good idea to use the built-in indexing instead of doing it
> by hand.
>
> Signed-off-by: Ben Pfaff <blp at ovn.org>
> ---
>  ovn/controller/bfd.c            | 23 +++++++-------
>  ovn/controller/bfd.h            |  6 ++--
>  ovn/controller/binding.c        | 13 ++++----
>  ovn/controller/binding.h        |  3 +-
>  ovn/controller/gchassis.c       |  6 ++--
>  ovn/controller/gchassis.h       |  6 ++--
>  ovn/controller/lflow.c          | 28 +++++++++--------
>  ovn/controller/lflow.h          |  5 ++--
>  ovn/controller/ovn-controller.c | 30 +++++++++----------
>  ovn/controller/physical.c       | 15 +++++-----
>  ovn/controller/physical.h       |  7 ++---
>  ovn/controller/pinctrl.c        | 43 ++++++++++++++-------------
>  ovn/controller/pinctrl.h        |  3 +-
>  ovn/lib/chassis-index.c         | 66
++++++++++-------------------------------
>  ovn/lib/chassis-index.h         | 22 +++-----------
>  ovn/northd/ovn-northd.c         | 58 ++++++++++++++++++------------------
>  16 files changed, 143 insertions(+), 191 deletions(-)
>
> diff --git a/ovn/controller/bfd.c b/ovn/controller/bfd.c
> index 1b78b6114658..051781f38ba8 100644
> --- a/ovn/controller/bfd.c
> +++ b/ovn/controller/bfd.c
> @@ -186,8 +186,8 @@ bfd_travel_gw_related_chassis(
>
>  static struct ovs_list *
>  bfd_find_ha_gateway_chassis(
> +    struct ovsdb_idl_index *sbrec_chassis_by_name,
>      struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
> -    const struct chassis_index *chassis_index,
>      const struct sbrec_datapath_binding *datapath)
>  {
>      struct sbrec_port_binding *target =
sbrec_port_binding_index_init_row(
> @@ -203,7 +203,7 @@ bfd_find_ha_gateway_chassis(
>          }
>
>          struct ovs_list *gateway_chassis = gateway_chassis_get_ordered(
> -            pb, chassis_index);
> +            sbrec_chassis_by_name, pb);
>          if (!gateway_chassis || ovs_list_is_short(gateway_chassis)) {
>              /* We don't need BFD for non-HA chassisredirect. */
>              gateway_chassis_destroy(gateway_chassis);
> @@ -219,10 +219,10 @@ bfd_find_ha_gateway_chassis(
>
>  static void
>  bfd_calculate_chassis(
> +    struct ovsdb_idl_index *sbrec_chassis_by_name,
>      struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
>      const struct sbrec_chassis *our_chassis,
>      const struct hmap *local_datapaths,
> -    const struct chassis_index *chassis_index,
>      struct sset *bfd_chassis)
>  {
>      /* Identify all chassis nodes to which we need to enable bfd.
> @@ -239,8 +239,9 @@ bfd_calculate_chassis(
>          bool our_chassis_is_gw_for_dp = false;
>          if (is_router) {
>              struct ovs_list *ha_gateway_chassis
> -                =
bfd_find_ha_gateway_chassis(sbrec_port_binding_by_datapath,
> -                                              chassis_index,
dp->datapath);
> +                = bfd_find_ha_gateway_chassis(sbrec_chassis_by_name,
> +
 sbrec_port_binding_by_datapath,
> +                                              dp->datapath);
>              if (ha_gateway_chassis) {
>                  our_chassis_is_gw_for_dp = gateway_chassis_contains(
>                      ha_gateway_chassis, our_chassis);
> @@ -261,21 +262,21 @@ bfd_calculate_chassis(
>  }
>
>  void
> -bfd_run(struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
> +bfd_run(struct ovsdb_idl_index *sbrec_chassis_by_name,
> +        struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
>          const struct ovsrec_interface_table *interface_table,
>          const struct ovsrec_bridge *br_int,
>          const struct sbrec_chassis *chassis_rec,
> -        const struct hmap *local_datapaths,
> -        const struct chassis_index *chassis_index)
> +        const struct hmap *local_datapaths)
>  {
>
>      if (!chassis_rec) {
>          return;
>      }
>      struct sset bfd_chassis = SSET_INITIALIZER(&bfd_chassis);
> -    bfd_calculate_chassis(sbrec_port_binding_by_datapath,
> -                          chassis_rec, local_datapaths, chassis_index,
> -                          &bfd_chassis);
> +    bfd_calculate_chassis(sbrec_chassis_by_name,
> +                          sbrec_port_binding_by_datapath,
> +                          chassis_rec, local_datapaths, &bfd_chassis);
>      /* Identify tunnels ports(connected to remote chassis id) to enable
bfd */
>      struct sset tunnels = SSET_INITIALIZER(&tunnels);
>      struct sset bfd_ifaces = SSET_INITIALIZER(&bfd_ifaces);
> diff --git a/ovn/controller/bfd.h b/ovn/controller/bfd.h
> index a453976d50d4..bc7615d28ca7 100644
> --- a/ovn/controller/bfd.h
> +++ b/ovn/controller/bfd.h
> @@ -16,7 +16,6 @@
>  #ifndef OVN_BFD_H
>  #define OVN_BFD_H 1
>
> -struct chassis_index;
>  struct controller_ctx;
>  struct hmap;
>  struct ovsdb_idl;
> @@ -27,11 +26,12 @@ struct sbrec_chassis;
>  struct sset;
>
>  void bfd_register_ovs_idl(struct ovsdb_idl *);
> -void bfd_run(struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
> +void bfd_run(struct ovsdb_idl_index *sbrec_chassis_by_name,
> +             struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
>               const struct ovsrec_interface_table *interface_table,
>               const struct ovsrec_bridge *br_int,
>               const struct sbrec_chassis *chassis_rec,
> -             const struct hmap *local_datapaths, const struct
chassis_index *);
> +             const struct hmap *local_datapaths);
>  void  bfd_calculate_active_tunnels(const struct ovsrec_bridge *br_int,
>                                     struct sset *active_tunnels);
>
> diff --git a/ovn/controller/binding.c b/ovn/controller/binding.c
> index b5e8c8ed4db4..5a3896c1d39f 100644
> --- a/ovn/controller/binding.c
> +++ b/ovn/controller/binding.c
> @@ -393,10 +393,10 @@ update_local_lport_ids(struct sset *local_lport_ids,
>
>  static void
>  consider_local_datapath(struct controller_ctx *ctx,
> +                        struct ovsdb_idl_index *sbrec_chassis_by_name,
>                          struct ovsdb_idl_index
*sbrec_datapath_binding_by_key,
>                          struct ovsdb_idl_index
*sbrec_port_binding_by_datapath,
>                          struct ovsdb_idl_index
*sbrec_port_binding_by_name,
> -                        const struct chassis_index *chassis_index,
>                          const struct sset *active_tunnels,
>                          const struct sbrec_chassis *chassis_rec,
>                          const struct sbrec_port_binding *binding_rec,
> @@ -441,8 +441,8 @@ consider_local_datapath(struct controller_ctx *ctx,
>                                 binding_rec->datapath, false,
local_datapaths);
>          }
>      } else if (!strcmp(binding_rec->type, "chassisredirect")) {
> -        gateway_chassis = gateway_chassis_get_ordered(binding_rec,
> -                                                       chassis_index);
> +        gateway_chassis =
gateway_chassis_get_ordered(sbrec_chassis_by_name,
> +                                                      binding_rec);
>          if (gateway_chassis &&
>              gateway_chassis_contains(gateway_chassis, chassis_rec)) {
>
> @@ -546,6 +546,7 @@ consider_localnet_port(const struct
sbrec_port_binding *binding_rec,
>
>  void
>  binding_run(struct controller_ctx *ctx,
> +            struct ovsdb_idl_index *sbrec_chassis_by_name,
>              struct ovsdb_idl_index *sbrec_datapath_binding_by_key,
>              struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
>              struct ovsdb_idl_index *sbrec_port_binding_by_name,
> @@ -554,7 +555,6 @@ binding_run(struct controller_ctx *ctx,
>              const struct sbrec_port_binding_table *port_binding_table,
>              const struct ovsrec_bridge *br_int,
>              const struct sbrec_chassis *chassis_rec,
> -            const struct chassis_index *chassis_index,
>              const struct sset *active_tunnels,
>              struct hmap *local_datapaths, struct sset *local_lports,
>              struct sset *local_lport_ids)
> @@ -578,9 +578,10 @@ binding_run(struct controller_ctx *ctx,
>       * chassis and update the binding accordingly.  This includes both
>       * directly connected logical ports and children of those ports. */
>      SBREC_PORT_BINDING_TABLE_FOR_EACH (binding_rec, port_binding_table) {
> -        consider_local_datapath(ctx, sbrec_datapath_binding_by_key,
> +        consider_local_datapath(ctx, sbrec_chassis_by_name,
> +                                sbrec_datapath_binding_by_key,
>                                  sbrec_port_binding_by_datapath,
> -                                sbrec_port_binding_by_name,
chassis_index,
> +                                sbrec_port_binding_by_name,
>                                  active_tunnels, chassis_rec, binding_rec,
>                                  sset_is_empty(&egress_ifaces) ? NULL :
>                                  &qos_map, local_datapaths,
&lport_to_iface,
> diff --git a/ovn/controller/binding.h b/ovn/controller/binding.h
> index 1759b70de2e3..21d63f577671 100644
> --- a/ovn/controller/binding.h
> +++ b/ovn/controller/binding.h
> @@ -20,7 +20,6 @@
>  #include <stdbool.h>
>
>  struct controller_ctx;
> -struct chassis_index;
>  struct hmap;
>  struct ovsdb_idl;
>  struct ovsdb_idl_index;
> @@ -33,6 +32,7 @@ struct sset;
>
>  void binding_register_ovs_idl(struct ovsdb_idl *);
>  void binding_run(struct controller_ctx *,
> +                 struct ovsdb_idl_index *sbrec_chassis_by_name,
>                   struct ovsdb_idl_index *sbrec_datapath_binding_by_key,
>                   struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
>                   struct ovsdb_idl_index *sbrec_port_binding_by_name,
> @@ -41,7 +41,6 @@ void binding_run(struct controller_ctx *,
>                   const struct sbrec_port_binding_table *,
>                   const struct ovsrec_bridge *br_int,
>                   const struct sbrec_chassis *,
> -                 const struct chassis_index *,
>                   const struct sset *active_tunnels,
>                   struct hmap *local_datapaths,
>                   struct sset *local_lports, struct sset
*local_lport_ids);
> diff --git a/ovn/controller/gchassis.c b/ovn/controller/gchassis.c
> index fedb4329cd5f..34b78bcc0cdd 100644
> --- a/ovn/controller/gchassis.c
> +++ b/ovn/controller/gchassis.c
> @@ -39,8 +39,8 @@ compare_chassis_prio_(const void *a_, const void *b_)
>  }
>
>  struct ovs_list*
> -gateway_chassis_get_ordered(const struct sbrec_port_binding *binding,
> -                            const struct chassis_index *chassis_index)
> +gateway_chassis_get_ordered(struct ovsdb_idl_index
*sbrec_chassis_by_name,
> +                            const struct sbrec_port_binding *binding)
>  {
>      const char *redir_chassis_str;
>      const struct sbrec_chassis *redirect_chassis = NULL;
> @@ -52,7 +52,7 @@ gateway_chassis_get_ordered(const struct
sbrec_port_binding *binding,
>      redir_chassis_str = smap_get(&binding->options, "redirect-chassis");
>
>      if (redir_chassis_str) {
> -        redirect_chassis = chassis_lookup_by_name(chassis_index,
> +        redirect_chassis = chassis_lookup_by_name(sbrec_chassis_by_name,
>                                                    redir_chassis_str);
>          if (!redirect_chassis) {
>              static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1,
1);
> diff --git a/ovn/controller/gchassis.h b/ovn/controller/gchassis.h
> index c16529e74041..901be449195f 100644
> --- a/ovn/controller/gchassis.h
> +++ b/ovn/controller/gchassis.h
> @@ -21,8 +21,8 @@
>  #include "openvswitch/hmap.h"
>  #include "openvswitch/list.h"
>
> -struct chassis_index;
>  struct ovsdb_idl;
> +struct ovsdb_idl_index;
>  struct sbrec_chassis;
>  struct sbrec_gateway_chassis;
>  struct sbrec_port_binding;
> @@ -44,8 +44,8 @@ struct gateway_chassis {
>
>  /* Gets, and orders by priority/name the list of Gateway_Chassis */
>  struct ovs_list *gateway_chassis_get_ordered(
> -        const struct sbrec_port_binding *binding,
> -        const struct chassis_index *chassis_index);
> +    struct ovsdb_idl_index *sbrec_chassis_by_name,
> +    const struct sbrec_port_binding *binding);
>
>  /* Checks if an specific chassis is contained in the gateway_chassis
>   * list */
> diff --git a/ovn/controller/lflow.c b/ovn/controller/lflow.c
> index e3aed0420d1c..8db81927e2c4 100644
> --- a/ovn/controller/lflow.c
> +++ b/ovn/controller/lflow.c
> @@ -56,16 +56,16 @@ struct lookup_port_aux {
>  };
>
>  struct condition_aux {
> +    struct ovsdb_idl_index *sbrec_chassis_by_name;
>      struct ovsdb_idl_index *sbrec_port_binding_by_name;
>      const struct sbrec_chassis *chassis;
>      const struct sset *active_tunnels;
> -    const struct chassis_index *chassis_index;
>  };
>
>  static void consider_logical_flow(
> +    struct ovsdb_idl_index *sbrec_chassis_by_name,
>      struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath,
>      struct ovsdb_idl_index *sbrec_port_binding_by_name,
> -    const struct chassis_index *,
>      const struct sbrec_logical_flow *,
>      const struct hmap *local_datapaths,
>      const struct sbrec_chassis *,
> @@ -118,8 +118,8 @@ is_chassis_resident_cb(const void *c_aux_, const char
*port_name)
>          return pb->chassis && pb->chassis == c_aux->chassis;
>      } else {
>          struct ovs_list *gateway_chassis;
> -        gateway_chassis = gateway_chassis_get_ordered(pb,
> -
 c_aux->chassis_index);
> +        gateway_chassis = gateway_chassis_get_ordered(
> +            c_aux->sbrec_chassis_by_name, pb);
>          if (gateway_chassis) {
>              bool active = gateway_chassis_is_active(gateway_chassis,
>                                                      c_aux->chassis,
> @@ -141,12 +141,12 @@ is_switch(const struct sbrec_datapath_binding *ldp)
>  /* Adds the logical flows from the Logical_Flow table to flow tables. */
>  static void
>  add_logical_flows(
> +    struct ovsdb_idl_index *sbrec_chassis_by_name,
>      struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath,
>      struct ovsdb_idl_index *sbrec_port_binding_by_name,
>      const struct sbrec_dhcp_options_table *dhcp_options_table,
>      const struct sbrec_dhcpv6_options_table *dhcpv6_options_table,
>      const struct sbrec_logical_flow_table *logical_flow_table,
> -    const struct chassis_index *chassis_index,
>      const struct hmap *local_datapaths,
>      const struct sbrec_chassis *chassis,
>      const struct shash *addr_sets,
> @@ -180,9 +180,10 @@ add_logical_flows(
>      nd_ra_opts_init(&nd_ra_opts);
>
>      SBREC_LOGICAL_FLOW_TABLE_FOR_EACH (lflow, logical_flow_table) {
> -        consider_logical_flow(sbrec_multicast_group_by_name_datapath,
> +        consider_logical_flow(sbrec_chassis_by_name,
> +                              sbrec_multicast_group_by_name_datapath,
>                                sbrec_port_binding_by_name,
> -                              chassis_index, lflow, local_datapaths,
> +                              lflow, local_datapaths,
>                                chassis, &dhcp_opts, &dhcpv6_opts,
&nd_ra_opts,
>                                addr_sets, port_groups, active_tunnels,
>                                local_lport_ids, &conj_id_ofs,
> @@ -196,9 +197,9 @@ add_logical_flows(
>
>  static void
>  consider_logical_flow(
> +    struct ovsdb_idl_index *sbrec_chassis_by_name,
>      struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath,
>      struct ovsdb_idl_index *sbrec_port_binding_by_name,
> -    const struct chassis_index *chassis_index,
>      const struct sbrec_logical_flow *lflow,
>      const struct hmap *local_datapaths,
>      const struct sbrec_chassis *chassis,
> @@ -294,10 +295,10 @@ consider_logical_flow(
>          .dp = lflow->logical_datapath
>      };
>      struct condition_aux cond_aux = {
> +        .sbrec_chassis_by_name = sbrec_chassis_by_name,
>          .sbrec_port_binding_by_name = sbrec_port_binding_by_name,
>          .chassis = chassis,
>          .active_tunnels = active_tunnels,
> -        .chassis_index = chassis_index
>      };
>      expr = expr_simplify(expr, is_chassis_resident_cb, &cond_aux);
>      expr = expr_normalize(expr);
> @@ -459,14 +460,14 @@ add_neighbor_flows(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>  /* Translates logical flows in the Logical_Flow table in the OVN_SB
database
>   * into OpenFlow flows.  See ovn-architecture(7) for more information. */
>  void
> -lflow_run(struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath,
> +lflow_run(struct ovsdb_idl_index *sbrec_chassis_by_name,
> +          struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath,
>            struct ovsdb_idl_index *sbrec_port_binding_by_name,
>            const struct sbrec_dhcp_options_table *dhcp_options_table,
>            const struct sbrec_dhcpv6_options_table *dhcpv6_options_table,
>            const struct sbrec_logical_flow_table *logical_flow_table,
>            const struct sbrec_mac_binding_table *mac_binding_table,
>            const struct sbrec_chassis *chassis,
> -          const struct chassis_index *chassis_index,
>            const struct hmap *local_datapaths,
>            const struct shash *addr_sets,
>            const struct shash *port_groups,
> @@ -478,9 +479,10 @@ lflow_run(struct ovsdb_idl_index
*sbrec_multicast_group_by_name_datapath,
>  {
>      COVERAGE_INC(lflow_run);
>
> -    add_logical_flows(sbrec_multicast_group_by_name_datapath,
> +    add_logical_flows(sbrec_chassis_by_name,
> +                      sbrec_multicast_group_by_name_datapath,
>                        sbrec_port_binding_by_name, dhcp_options_table,
> -                      dhcpv6_options_table, logical_flow_table,
chassis_index,
> +                      dhcpv6_options_table, logical_flow_table,
>                        local_datapaths, chassis, addr_sets, port_groups,
>                        active_tunnels, local_lport_ids, flow_table,
group_table,
>                        meter_table);
> diff --git a/ovn/controller/lflow.h b/ovn/controller/lflow.h
> index feb59ee09d08..d193381404e5 100644
> --- a/ovn/controller/lflow.h
> +++ b/ovn/controller/lflow.h
> @@ -35,7 +35,6 @@
>
>  #include <stdint.h>
>
> -struct chassis_index;
>  struct ovn_extend_table;
>  struct ovsdb_idl_index;
>  struct hmap;
> @@ -66,14 +65,14 @@ struct uuid;
>  #define LOG_PIPELINE_LEN 24
>
>  void lflow_init(void);
> -void lflow_run(struct ovsdb_idl_index
*sbrec_multicast_group_by_name_datapath,
> +void lflow_run(struct ovsdb_idl_index *sbrec_chassis_by_name,
> +               struct ovsdb_idl_index
*sbrec_multicast_group_by_name_datapath,
>                 struct ovsdb_idl_index *sbrec_port_binding_by_name,
>                 const struct sbrec_dhcp_options_table *,
>                 const struct sbrec_dhcpv6_options_table *,
>                 const struct sbrec_logical_flow_table *,
>                 const struct sbrec_mac_binding_table *,
>                 const struct sbrec_chassis *chassis,
> -               const struct chassis_index *,
>                 const struct hmap *local_datapaths,
>                 const struct shash *addr_sets,
>                 const struct shash *port_groups,
> diff --git a/ovn/controller/ovn-controller.c
b/ovn/controller/ovn-controller.c
> index 6bf94718016f..cd4208556de7 100644
> --- a/ovn/controller/ovn-controller.c
> +++ b/ovn/controller/ovn-controller.c
> @@ -603,6 +603,8 @@ main(int argc, char *argv[])
>          ovsdb_idl_create(ovnsb_remote, &sbrec_idl_class, true, true));
>      ovsdb_idl_set_leader_only(ovnsb_idl_loop.idl, false);
>
> +    struct ovsdb_idl_index *sbrec_chassis_by_name
> +        = chassis_index_create(ovnsb_idl_loop.idl);
>      struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath
>          = ovsdb_idl_index_create2(ovnsb_idl_loop.idl,
>                                    &sbrec_multicast_group_col_name,
> @@ -687,10 +689,6 @@ main(int argc, char *argv[])
>          const char *chassis_id
>              = get_chassis_id(ovsrec_open_vswitch_table_get(ctx.ovs_idl));
>
> -        struct chassis_index chassis_index;
> -        chassis_index_init(sbrec_chassis_table_get(ctx.ovnsb_idl),
> -                           &chassis_index);
> -
>          const struct sbrec_chassis *chassis = NULL;
>          if (chassis_id) {
>              chassis = chassis_run(&ctx,
> @@ -701,7 +699,7 @@ main(int argc, char *argv[])
>                         ovsrec_bridge_table_get(ctx.ovs_idl), br_int,
>                         sbrec_chassis_table_get(ctx.ovnsb_idl),
chassis_id);
>              bfd_calculate_active_tunnels(br_int, &active_tunnels);
> -            binding_run(&ctx,
> +            binding_run(&ctx, sbrec_chassis_by_name,
>                          sbrec_datapath_binding_by_key,
>                          sbrec_port_binding_by_datapath,
>                          sbrec_port_binding_by_name,
> @@ -709,7 +707,7 @@ main(int argc, char *argv[])
>                          ovsrec_qos_table_get(ctx.ovs_idl),
>                          sbrec_port_binding_table_get(ctx.ovnsb_idl),
>                          br_int, chassis,
> -                        &chassis_index, &active_tunnels,
&local_datapaths,
> +                        &active_tunnels, &local_datapaths,
>                          &local_lports, &local_lport_ids);
>          }
>          if (br_int && chassis) {
> @@ -730,14 +728,14 @@ main(int argc, char *argv[])
>              enum mf_field_id mff_ovn_geneve = ofctrl_run(br_int,
>
&pending_ct_zones);
>
> -            pinctrl_run(&ctx,
> +            pinctrl_run(&ctx, sbrec_chassis_by_name,
>                          sbrec_datapath_binding_by_key,
>                          sbrec_port_binding_by_datapath,
>                          sbrec_port_binding_by_key,
>                          sbrec_port_binding_by_name,
>                          sbrec_dns_table_get(ctx.ovnsb_idl),
>                          sbrec_mac_binding_table_get(ctx.ovnsb_idl),
> -                        br_int, chassis, &chassis_index,
> +                        br_int, chassis,
>                          &local_datapaths, &active_tunnels);
>              update_ct_zones(&local_lports, &local_datapaths, &ct_zones,
>                              ct_zone_bitmap, &pending_ct_zones);
> @@ -749,31 +747,33 @@ main(int argc, char *argv[])
>                      commit_ct_zones(br_int, &pending_ct_zones);
>
>                      struct hmap flow_table =
HMAP_INITIALIZER(&flow_table);
> -                    lflow_run(sbrec_multicast_group_by_name_datapath,
> +                    lflow_run(sbrec_chassis_by_name,
> +                              sbrec_multicast_group_by_name_datapath,
>                                sbrec_port_binding_by_name,
>
 sbrec_dhcp_options_table_get(ctx.ovnsb_idl),
>
 sbrec_dhcpv6_options_table_get(ctx.ovnsb_idl),
>
 sbrec_logical_flow_table_get(ctx.ovnsb_idl),
>                                sbrec_mac_binding_table_get(ctx.ovnsb_idl),
>                                chassis,
> -                              &chassis_index, &local_datapaths,
&addr_sets,
> +                              &local_datapaths, &addr_sets,
>                                &port_groups, &active_tunnels,
&local_lport_ids,
>                                &flow_table, &group_table, &meter_table);
>
>                      if (chassis_id) {
> -                        bfd_run(sbrec_port_binding_by_datapath,
> +                        bfd_run(sbrec_chassis_by_name,
> +                                sbrec_port_binding_by_datapath,
>                                  ovsrec_interface_table_get(ctx.ovs_idl),
> -                                br_int, chassis, &local_datapaths,
> -                                &chassis_index);
> +                                br_int, chassis, &local_datapaths);
>                      }
>                      physical_run(
> +                        sbrec_chassis_by_name,
>                          sbrec_port_binding_by_name,
>                          sbrec_multicast_group_table_get(ctx.ovnsb_idl),
>                          sbrec_port_binding_table_get(ctx.ovnsb_idl),
>                          mff_ovn_geneve,
>                          br_int, chassis, &ct_zones,
>                          &local_datapaths, &local_lports,
> -                        &chassis_index, &active_tunnels,
> +                        &active_tunnels,
>                          &flow_table);
>
>                      stopwatch_stop(CONTROLLER_LOOP_STOPWATCH_NAME,
> @@ -824,8 +824,6 @@ main(int argc, char *argv[])
>              free(pending_pkt.flow_s);
>          }
>
> -        chassis_index_destroy(&chassis_index);
> -
>          sset_destroy(&local_lports);
>          sset_destroy(&local_lport_ids);
>          sset_destroy(&active_tunnels);
> diff --git a/ovn/controller/physical.c b/ovn/controller/physical.c
> index eb2e35dafa6e..dcf218342632 100644
> --- a/ovn/controller/physical.c
> +++ b/ovn/controller/physical.c
> @@ -291,10 +291,10 @@ load_logical_ingress_metadata(const struct
sbrec_port_binding *binding,
>  }
>
>  static void
> -consider_port_binding(struct ovsdb_idl_index *sbrec_port_binding_by_name,
> +consider_port_binding(struct ovsdb_idl_index *sbrec_chassis_by_name,
> +                      struct ovsdb_idl_index *sbrec_port_binding_by_name,
>                        enum mf_field_id mff_ovn_geneve,
>                        const struct simap *ct_zones,
> -                      const struct chassis_index *chassis_index,
>                        const struct sset *active_tunnels,
>                        const struct hmap *local_datapaths,
>                        const struct sbrec_port_binding *binding,
> @@ -361,7 +361,7 @@ consider_port_binding(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>      }
>
>      struct ovs_list *gateway_chassis
> -        = gateway_chassis_get_ordered(binding, chassis_index);
> +        = gateway_chassis_get_ordered(sbrec_chassis_by_name, binding);
>
>      if (!strcmp(binding->type, "chassisredirect")
>          && (binding->chassis == chassis
> @@ -868,7 +868,8 @@ update_ofports(struct simap *old, struct simap *new)
>  }
>
>  void
> -physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
> +physical_run(struct ovsdb_idl_index *sbrec_chassis_by_name,
> +             struct ovsdb_idl_index *sbrec_port_binding_by_name,
>               const struct sbrec_multicast_group_table
*multicast_group_table,
>               const struct sbrec_port_binding_table *port_binding_table,
>               enum mf_field_id mff_ovn_geneve,
> @@ -877,7 +878,6 @@ physical_run(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>               const struct simap *ct_zones,
>               const struct hmap *local_datapaths,
>               const struct sset *local_lports,
> -             const struct chassis_index *chassis_index,
>               const struct sset *active_tunnels,
>               struct hmap *flow_table)
>  {
> @@ -999,9 +999,10 @@ physical_run(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>       * 64 for logical-to-physical translation. */
>      const struct sbrec_port_binding *binding;
>      SBREC_PORT_BINDING_TABLE_FOR_EACH (binding, port_binding_table) {
> -        consider_port_binding(sbrec_port_binding_by_name,
> +        consider_port_binding(sbrec_chassis_by_name,
> +                              sbrec_port_binding_by_name,
>                                mff_ovn_geneve, ct_zones,
> -                              chassis_index, active_tunnels,
> +                              active_tunnels,
>                                local_datapaths, binding, chassis,
>                                &ofpacts, flow_table);
>      }
> diff --git a/ovn/controller/physical.h b/ovn/controller/physical.h
> index 4a070a7d0128..8b737d1712d1 100644
> --- a/ovn/controller/physical.h
> +++ b/ovn/controller/physical.h
> @@ -27,10 +27,9 @@
>
>  #include "openvswitch/meta-flow.h"
>
> -struct chassis_index;
>  struct controller_ctx;
>  struct hmap;
> -struct ovsdb_idl;
> +struct ovsdb_idl_index;
>  struct ovsrec_bridge;
>  struct simap;
>  struct sbrec_multicast_group_table;
> @@ -45,7 +44,8 @@ struct sset;
>  #define OVN_GENEVE_LEN 4
>
>  void physical_register_ovs_idl(struct ovsdb_idl *);
> -void physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name,
> +void physical_run(struct ovsdb_idl_index *sbrec_chassis_by_name,
> +                  struct ovsdb_idl_index *sbrec_port_binding_by_name,
>                    const struct sbrec_multicast_group_table *,
>                    const struct sbrec_port_binding_table *,
>                    enum mf_field_id mff_ovn_geneve,
> @@ -54,7 +54,6 @@ void physical_run(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>                    const struct simap *ct_zones,
>                    const struct hmap *local_datapaths,
>                    const struct sset *local_lports,
> -                  const struct chassis_index *chassis_index,
>                    const struct sset *active_tunnels,
>                    struct hmap *flow_table);
>
> diff --git a/ovn/controller/pinctrl.c b/ovn/controller/pinctrl.c
> index dcb90a39c6bf..fbb90252a705 100644
> --- a/ovn/controller/pinctrl.c
> +++ b/ovn/controller/pinctrl.c
> @@ -78,11 +78,11 @@ static void init_send_garps(void);
>  static void destroy_send_garps(void);
>  static void send_garp_wait(void);
>  static void send_garp_run(
> +    struct ovsdb_idl_index *sbrec_chassis_by_name,
>      struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
>      struct ovsdb_idl_index *sbrec_port_binding_by_name,
>      const struct ovsrec_bridge *,
>      const struct sbrec_chassis *,
> -    const struct chassis_index *chassis_index,
>      const struct hmap *local_datapaths,
>      const struct sset *active_tunnels);
>  static void pinctrl_handle_nd_na(const struct flow *ip_flow,
> @@ -1246,6 +1246,7 @@ pinctrl_recv(const struct sbrec_dns_table
*dns_table,
>
>  void
>  pinctrl_run(struct controller_ctx *ctx,
> +            struct ovsdb_idl_index *sbrec_chassis_by_name,
>              struct ovsdb_idl_index *sbrec_datapath_binding_by_key,
>              struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
>              struct ovsdb_idl_index *sbrec_port_binding_by_key,
> @@ -1254,7 +1255,6 @@ pinctrl_run(struct controller_ctx *ctx,
>              const struct sbrec_mac_binding_table *mac_binding_table,
>              const struct ovsrec_bridge *br_int,
>              const struct sbrec_chassis *chassis,
> -            const struct chassis_index *chassis_index,
>              const struct hmap *local_datapaths,
>              const struct sset *active_tunnels)
>  {
> @@ -1294,8 +1294,8 @@ pinctrl_run(struct controller_ctx *ctx,
>
>      run_put_mac_bindings(ctx, sbrec_datapath_binding_by_key,
>                           sbrec_port_binding_by_key, mac_binding_table);
> -    send_garp_run(sbrec_port_binding_by_datapath,
> -                  sbrec_port_binding_by_name, br_int, chassis,
chassis_index,
> +    send_garp_run(sbrec_chassis_by_name, sbrec_port_binding_by_datapath,
> +                  sbrec_port_binding_by_name, br_int, chassis,
>                    local_datapaths, active_tunnels);
>      send_ipv6_ras(sbrec_port_binding_by_datapath,
>                    sbrec_port_binding_by_name, local_datapaths);
> @@ -2054,9 +2054,9 @@ get_localnet_vifs_l3gwports(
>  }
>
>  static bool
> -pinctrl_is_chassis_resident(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
> +pinctrl_is_chassis_resident(struct ovsdb_idl_index
*sbrec_chassis_by_name,
> +                            struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>                              const struct sbrec_chassis *chassis,
> -                            const struct chassis_index *chassis_index,
>                              const struct sset *active_tunnels,
>                              const char *port_name)
>  {
> @@ -2069,7 +2069,7 @@ pinctrl_is_chassis_resident(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>          return pb->chassis == chassis;
>      } else {
>          struct ovs_list *gateway_chassis =
> -            gateway_chassis_get_ordered(pb, chassis_index);
> +            gateway_chassis_get_ordered(sbrec_chassis_by_name, pb);
>          bool active = gateway_chassis_is_active(gateway_chassis,
>                                                  chassis,
>                                                  active_tunnels);
> @@ -2145,12 +2145,12 @@ extract_addresses_with_port(const char *addresses,
>  }
>
>  static void
> -consider_nat_address(struct ovsdb_idl_index *sbrec_port_binding_by_name,
> +consider_nat_address(struct ovsdb_idl_index *sbrec_chassis_by_name,
> +                     struct ovsdb_idl_index *sbrec_port_binding_by_name,
>                       const char *nat_address,
>                       const struct sbrec_port_binding *pb,
>                       struct sset *nat_address_keys,
>                       const struct sbrec_chassis *chassis,
> -                     const struct chassis_index *chassis_index,
>                       const struct sset *active_tunnels,
>                       struct shash *nat_addresses)
>  {
> @@ -2159,7 +2159,7 @@ consider_nat_address(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>      if (!extract_addresses_with_port(nat_address, laddrs, &lport)
>          || (!lport && !strcmp(pb->type, "patch"))
>          || (lport && !pinctrl_is_chassis_resident(
> -                sbrec_port_binding_by_name, chassis, chassis_index,
> +                sbrec_chassis_by_name, sbrec_port_binding_by_name,
chassis,
>                  active_tunnels, lport))) {
>          destroy_lport_addresses(laddrs);
>          free(laddrs);
> @@ -2179,11 +2179,11 @@ consider_nat_address(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>  }
>
>  static void
> -get_nat_addresses_and_keys(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
> +get_nat_addresses_and_keys(struct ovsdb_idl_index *sbrec_chassis_by_name,
> +                           struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>                             struct sset *nat_address_keys,
>                             struct sset *local_l3gw_ports,
>                             const struct sbrec_chassis *chassis,
> -                           const struct chassis_index *chassis_index,
>                             const struct sset *active_tunnels,
>                             struct shash *nat_addresses)
>  {
> @@ -2198,10 +2198,11 @@ get_nat_addresses_and_keys(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>
>          if (pb->n_nat_addresses) {
>              for (int i = 0; i < pb->n_nat_addresses; i++) {
> -                consider_nat_address(sbrec_port_binding_by_name,
> +                consider_nat_address(sbrec_chassis_by_name,
> +                                     sbrec_port_binding_by_name,
>                                       pb->nat_addresses[i], pb,
>                                       nat_address_keys, chassis,
> -                                     chassis_index, active_tunnels,
> +                                     active_tunnels,
>                                       nat_addresses);
>              }
>          } else {
> @@ -2210,10 +2211,11 @@ get_nat_addresses_and_keys(struct ovsdb_idl_index
*sbrec_port_binding_by_name,
>              const char *nat_addresses_options = smap_get(&pb->options,
>
"nat-addresses");
>              if (nat_addresses_options) {
> -                consider_nat_address(sbrec_port_binding_by_name,
> +                consider_nat_address(sbrec_chassis_by_name,
> +                                     sbrec_port_binding_by_name,
>                                       nat_addresses_options, pb,
>                                       nat_address_keys, chassis,
> -                                     chassis_index, active_tunnels,
> +                                     active_tunnels,
>                                       nat_addresses);
>              }
>          }
> @@ -2227,11 +2229,11 @@ send_garp_wait(void)
>  }
>
>  static void
> -send_garp_run(struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
> +send_garp_run(struct ovsdb_idl_index *sbrec_chassis_by_name,
> +              struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
>                struct ovsdb_idl_index *sbrec_port_binding_by_name,
>                const struct ovsrec_bridge *br_int,
>                const struct sbrec_chassis *chassis,
> -              const struct chassis_index *chassis_index,
>                const struct hmap *local_datapaths,
>                const struct sset *active_tunnels)
>  {
> @@ -2249,9 +2251,10 @@ send_garp_run(struct ovsdb_idl_index
*sbrec_port_binding_by_datapath,
>                                  &localnet_vifs, &localnet_ofports,
>                                  &local_l3gw_ports);
>
> -    get_nat_addresses_and_keys(sbrec_port_binding_by_name,
> +    get_nat_addresses_and_keys(sbrec_chassis_by_name,
> +                               sbrec_port_binding_by_name,
>                                 &nat_ip_keys, &local_l3gw_ports,
> -                               chassis, chassis_index, active_tunnels,
> +                               chassis, active_tunnels,
>                                 &nat_addresses);
>      /* For deleted ports and deleted nat ips, remove from
send_garp_data. */
>      struct shash_node *iter, *next;
> diff --git a/ovn/controller/pinctrl.h b/ovn/controller/pinctrl.h
> index 27f51d7de65c..19bfa88c8c8a 100644
> --- a/ovn/controller/pinctrl.h
> +++ b/ovn/controller/pinctrl.h
> @@ -22,7 +22,6 @@
>  #include "lib/sset.h"
>  #include "openvswitch/meta-flow.h"
>
> -struct chassis_index;
>  struct controller_ctx;
>  struct hmap;
>  struct lport_index;
> @@ -34,6 +33,7 @@ struct sbrec_mac_binding_table;
>
>  void pinctrl_init(void);
>  void pinctrl_run(struct controller_ctx *,
> +                 struct ovsdb_idl_index *sbrec_chassis_by_name,
>                   struct ovsdb_idl_index *sbrec_datapath_binding_by_key,
>                   struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
>                   struct ovsdb_idl_index *sbrec_port_binding_by_key,
> @@ -41,7 +41,6 @@ void pinctrl_run(struct controller_ctx *,
>                   const struct sbrec_dns_table *,
>                   const struct sbrec_mac_binding_table *,
>                   const struct ovsrec_bridge *, const struct
sbrec_chassis *,
> -                 const struct chassis_index *,
>                   const struct hmap *local_datapaths,
>                   const struct sset *active_tunnels);
>  void pinctrl_wait(struct controller_ctx *);
> diff --git a/ovn/lib/chassis-index.c b/ovn/lib/chassis-index.c
> index 5ead32a4b118..a5dbf4ace5da 100644
> --- a/ovn/lib/chassis-index.c
> +++ b/ovn/lib/chassis-index.c
> @@ -13,65 +13,29 @@
>   */
>
>  #include <config.h>
> -
> -#include "openvswitch/hmap.h"
> -#include "openvswitch/vlog.h"
> -#include "ovn/actions.h"
>  #include "ovn/lib/chassis-index.h"
>  #include "ovn/lib/ovn-sb-idl.h"
>
> -VLOG_DEFINE_THIS_MODULE(chassis_index);
> -
> -struct chassis {
> -    struct hmap_node name_node;
> -    const struct sbrec_chassis *db;
> -};
> -
> -const struct sbrec_chassis *
> -chassis_lookup_by_name(const struct chassis_index *chassis_index,
> -                       const char *name)
> +struct ovsdb_idl_index *
> +chassis_index_create(struct ovsdb_idl *idl)
>  {
> -    const struct chassis *chassis;
> -    HMAP_FOR_EACH_WITH_HASH (chassis, name_node, hash_string(name, 0),
> -                             &chassis_index->by_name) {
> -        if (!strcmp(chassis->db->name, name)) {
> -            return chassis->db;
> -        }
> -    }
> -    return NULL;
> +    return ovsdb_idl_index_create1(idl, &sbrec_chassis_col_name);
>  }
>
> -void
> -chassis_index_init(const struct sbrec_chassis_table *chassis_table,
> -                   struct chassis_index *chassis_index)
> +/* Finds and returns the chassis with the given 'name', or NULL if no
such
> + * chassis exists. */
> +const struct sbrec_chassis *
> +chassis_lookup_by_name(struct ovsdb_idl_index *sbrec_chassis_by_name,
> +                       const char *name)
>  {
> -    hmap_init(&chassis_index->by_name);
> +    struct sbrec_chassis *target = sbrec_chassis_index_init_row(
> +        sbrec_chassis_by_name);
> +    sbrec_chassis_set_name(target, name);
>
> -    const struct sbrec_chassis *chassis;
> -    SBREC_CHASSIS_TABLE_FOR_EACH (chassis, chassis_table) {
> -        if (!chassis->name) {
> -            continue;
> -        }
> -        struct chassis *c = xmalloc(sizeof *c);
> -        hmap_insert(&chassis_index->by_name, &c->name_node,
> -                    hash_string(chassis->name, 0));
> -        c->db = chassis;
> -    }
> -}
> -
> -void
> -chassis_index_destroy(struct chassis_index *chassis_index)
> -{
> -    if (!chassis_index) {
> -        return;
> -    }
> +    struct sbrec_chassis *retval = sbrec_chassis_index_find(
> +        sbrec_chassis_by_name, target);
>
> -    /* Destroy all of the "struct chassis"s. */
> -    struct chassis *chassis, *next;
> -    HMAP_FOR_EACH_SAFE (chassis, next, name_node,
&chassis_index->by_name) {
> -        hmap_remove(&chassis_index->by_name, &chassis->name_node);
> -        free(chassis);
> -    }
> +    sbrec_chassis_index_destroy_row(target);
>
> -    hmap_destroy(&chassis_index->by_name);
> +    return retval;
>  }
> diff --git a/ovn/lib/chassis-index.h b/ovn/lib/chassis-index.h
> index 59b3de7d4532..d5e5df926723 100644
> --- a/ovn/lib/chassis-index.h
> +++ b/ovn/lib/chassis-index.h
> @@ -16,25 +16,11 @@
>  #ifndef OVN_CHASSIS_INDEX_H
>  #define OVN_CHASSIS_INDEX_H 1
>
> -#include "openvswitch/hmap.h"
> +struct ovsdb_idl;
>
> -struct chassis_index {
> -    struct hmap by_name;
> -};
> +struct ovsdb_idl_index *chassis_index_create(struct ovsdb_idl *);
>
> -struct sbrec_chassis_table;
> -
> -/* Finds and returns the chassis with the given 'name', or NULL if no
such
> - * chassis exists. */
> -const struct sbrec_chassis *
> -chassis_lookup_by_name(const struct chassis_index *chassis_index,
> -                       const char *name);
> -
> -/* Initializes the chassis index out of the ovsdb_idl to SBDB */
> -void chassis_index_init(const struct sbrec_chassis_table *,
> -                        struct chassis_index *chassis_index);
> -
> -/* Free a chassis index from memory */
> -void chassis_index_destroy(struct chassis_index *chassis_index);
> +const struct sbrec_chassis *chassis_lookup_by_name(
> +    struct ovsdb_idl_index *sbrec_chassis_by_name, const char *name);
>
>  #endif /* ovn/lib/chassis-index.h */
> diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c
> index 151e64873aab..aa6a18f160df 100644
> --- a/ovn/northd/ovn-northd.c
> +++ b/ovn/northd/ovn-northd.c
> @@ -1731,9 +1731,9 @@ gateway_chassis_equal(const struct
nbrec_gateway_chassis *nb_gwc,
>
>  static bool
>  sbpb_gw_chassis_needs_update(
> -        const struct sbrec_port_binding *port_binding,
> -        const struct nbrec_logical_router_port *lrp,
> -        const struct chassis_index *chassis_index)
> +    struct ovsdb_idl_index *sbrec_chassis_by_name,
> +    const struct sbrec_port_binding *port_binding,
> +    const struct nbrec_logical_router_port *lrp)
>  {
>      if (!lrp || !port_binding) {
>          return false;
> @@ -1758,7 +1758,7 @@ sbpb_gw_chassis_needs_update(
>          }
>
>          const struct sbrec_chassis *chassis =
> -            chassis_lookup_by_name(chassis_index,
> +            chassis_lookup_by_name(sbrec_chassis_by_name,
>
lrp->gateway_chassis[n]->chassis_name);
>
>          lrp_gwc_c[lrp_n_gateway_chassis] = chassis;
> @@ -1815,8 +1815,8 @@ sbpb_gw_chassis_needs_update(
>  static void
>  copy_gw_chassis_from_nbrp_to_sbpb(
>          struct northd_context *ctx,
> +        struct ovsdb_idl_index *sbrec_chassis_by_name,
>          const struct nbrec_logical_router_port *lrp,
> -        const struct chassis_index *chassis_index,
>          const struct sbrec_port_binding *port_binding) {
>
>      if (!lrp || !port_binding || !lrp->n_gateway_chassis) {
> @@ -1840,7 +1840,8 @@ copy_gw_chassis_from_nbrp_to_sbpb(
>          }
>
>          const struct sbrec_chassis *chassis =
> -            chassis_lookup_by_name(chassis_index, lrp_gwc->chassis_name);
> +            chassis_lookup_by_name(sbrec_chassis_by_name,
> +                                   lrp_gwc->chassis_name);
>
>          gw_chassis = xrealloc(gw_chassis, (n_gwc + 1) * sizeof
*gw_chassis);
>
> @@ -1861,8 +1862,8 @@ copy_gw_chassis_from_nbrp_to_sbpb(
>
>  static void
>  ovn_port_update_sbrec(struct northd_context *ctx,
> +                      struct ovsdb_idl_index *sbrec_chassis_by_name,
>                        const struct ovn_port *op,
> -                      const struct chassis_index *chassis_index,
>                        struct hmap *chassis_qdisc_queues)
>  {
>      sbrec_port_binding_set_datapath(op->sb, op->od->sb);
> @@ -1893,10 +1894,11 @@ ovn_port_update_sbrec(struct northd_context *ctx,
>              }
>
>              if (op->nbrp->n_gateway_chassis) {
> -                if (sbpb_gw_chassis_needs_update(op->sb, op->nbrp,
> -                                                   chassis_index)) {
> -                    copy_gw_chassis_from_nbrp_to_sbpb(ctx, op->nbrp,
> -                                                        chassis_index,
op->sb);
> +                if (sbpb_gw_chassis_needs_update(sbrec_chassis_by_name,
> +                                                 op->sb, op->nbrp)) {
> +                    copy_gw_chassis_from_nbrp_to_sbpb(ctx,
> +
 sbrec_chassis_by_name,
> +                                                      op->nbrp, op->sb);
>                  }
>
>              } else if (redirect_chassis) {
> @@ -1904,7 +1906,8 @@ ovn_port_update_sbrec(struct northd_context *ctx,
>                   * to them, and for backwards compatibility convert them
>                   * to a single Gateway_Chassis entry */
>                  const struct sbrec_chassis *chassis =
> -                    chassis_lookup_by_name(chassis_index,
redirect_chassis);
> +                    chassis_lookup_by_name(sbrec_chassis_by_name,
> +                                           redirect_chassis);
>                  if (chassis) {
>                      /* If we found the chassis, and the gw chassis on
record
>                       * differs from what we expect go ahead and update */
> @@ -2105,8 +2108,9 @@ cleanup_mac_bindings(struct northd_context *ctx,
struct hmap *ports)
>   * using the "struct ovn_datapath"s in 'datapaths' to look up logical
>   * datapaths. */
>  static void
> -build_ports(struct northd_context *ctx, struct hmap *datapaths,
> -            const struct chassis_index *chassis_index, struct hmap
*ports)
> +build_ports(struct northd_context *ctx,
> +            struct ovsdb_idl_index *sbrec_chassis_by_name,
> +            struct hmap *datapaths, struct hmap *ports)
>  {
>      struct ovs_list sb_only, nb_only, both;
>      struct hmap tag_alloc_table = HMAP_INITIALIZER(&tag_alloc_table);
> @@ -2124,7 +2128,8 @@ build_ports(struct northd_context *ctx, struct hmap
*datapaths,
>          if (op->nbsp) {
>              tag_alloc_create_new_tag(&tag_alloc_table, op->nbsp);
>          }
> -        ovn_port_update_sbrec(ctx, op, chassis_index,
&chassis_qdisc_queues);
> +        ovn_port_update_sbrec(ctx, sbrec_chassis_by_name,
> +                              op, &chassis_qdisc_queues);
>
>          add_tnlid(&op->od->port_tnlids, op->sb->tunnel_key);
>          if (op->sb->tunnel_key > op->od->port_key_hint) {
> @@ -2140,7 +2145,8 @@ build_ports(struct northd_context *ctx, struct hmap
*datapaths,
>          }
>
>          op->sb = sbrec_port_binding_insert(ctx->ovnsb_txn);
> -        ovn_port_update_sbrec(ctx, op, chassis_index,
&chassis_qdisc_queues);
> +        ovn_port_update_sbrec(ctx, sbrec_chassis_by_name, op,
> +                              &chassis_qdisc_queues);
>
>          sbrec_port_binding_set_logical_port(op->sb, op->key);
>          sbrec_port_binding_set_tunnel_key(op->sb, tunnel_key);
> @@ -6544,7 +6550,8 @@ sync_dns_entries(struct northd_context *ctx, struct
hmap *datapaths)
>
>
>  static void
> -ovnnb_db_run(struct northd_context *ctx, struct chassis_index
*chassis_index,
> +ovnnb_db_run(struct northd_context *ctx,
> +             struct ovsdb_idl_index *sbrec_chassis_by_name,
>               struct ovsdb_idl_loop *sb_loop)
>  {
>      if (!ctx->ovnsb_txn || !ctx->ovnnb_txn) {
> @@ -6552,7 +6559,7 @@ ovnnb_db_run(struct northd_context *ctx, struct
chassis_index *chassis_index,
>      }
>      struct hmap datapaths, ports, port_groups;
>      build_datapaths(ctx, &datapaths);
> -    build_ports(ctx, &datapaths, chassis_index, &ports);
> +    build_ports(ctx, sbrec_chassis_by_name, &datapaths, &ports);
>      build_ipam(&datapaths, &ports);
>      build_port_group_lswitches(ctx, &port_groups, &ports);
>      build_lflows(ctx, &datapaths, &ports, &port_groups);
> @@ -7188,6 +7195,9 @@ main(int argc, char *argv[])
>      ovsdb_idl_add_column(ovnsb_idl_loop.idl, &sbrec_chassis_col_nb_cfg);
>      ovsdb_idl_add_column(ovnsb_idl_loop.idl, &sbrec_chassis_col_name);
>
> +    struct ovsdb_idl_index *sbrec_chassis_by_name
> +        = chassis_index_create(ovnsb_idl_loop.idl);
> +
>      /* Ensure that only a single ovn-northd is active in the deployment
by
>       * acquiring a lock called "ovn_northd" on the southbound database
>       * and then only performing DB transactions if the lock is held. */
> @@ -7214,14 +7224,8 @@ main(int argc, char *argv[])
>              had_lock = false;
>          }
>
> -        struct chassis_index chassis_index;
> -        bool destroy_chassis_index = false;
>          if (ovsdb_idl_has_lock(ovnsb_idl_loop.idl)) {
> -
 chassis_index_init(sbrec_chassis_table_get(ovnsb_idl_loop.idl),
> -                               &chassis_index);
> -            destroy_chassis_index = true;
> -
> -            ovnnb_db_run(&ctx, &chassis_index, &ovnsb_idl_loop);
> +            ovnnb_db_run(&ctx, sbrec_chassis_by_name, &ovnsb_idl_loop);
>              ovnsb_db_run(&ctx, &ovnsb_idl_loop);
>              if (ctx.ovnsb_txn) {
>                  check_and_add_supported_dhcp_opts_to_sb_db(&ctx);
> @@ -7242,10 +7246,6 @@ main(int argc, char *argv[])
>          if (should_service_stop()) {
>              exiting = true;
>          }
> -
> -        if (destroy_chassis_index) {
> -            chassis_index_destroy(&chassis_index);
> -        }
>      }
>
>      unixctl_server_destroy(unixctl);
> --
> 2.16.1
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev


Acked-by: Han Zhou <hzhou8 at ebay.com>


More information about the dev mailing list