[ovs-dev] [PATCH v4 2/3] ovn-controller: Move ovnsb cursors to idl context.
Han Zhou
zhouhan at gmail.com
Mon Aug 28 04:14:41 UTC 2017
Cursors need to be bound with idl so that different idl for same
DB can work properly without stepping onto each other. This will
be needed for a future patch that requires separate ovnsb idl for
different thread.
Signed-off-by: Han Zhou <zhouhan at gmail.com>
---
v3->v4: this change was not in v3. It is needed because of the recent
change that replaced lport and ldatapath index by ovsdb index.
ovn/controller/binding.c | 4 +--
ovn/controller/lflow.c | 16 ++++++------
ovn/controller/lport.c | 55 +++++++++++++++++++++--------------------
ovn/controller/lport.h | 22 ++++++++++++-----
ovn/controller/ovn-controller.c | 4 ++-
ovn/controller/ovn-controller.h | 1 +
ovn/controller/physical.c | 6 ++---
ovn/controller/pinctrl.c | 12 ++++-----
8 files changed, 67 insertions(+), 53 deletions(-)
diff --git a/ovn/controller/binding.c b/ovn/controller/binding.c
index bb1728f..396a504 100644
--- a/ovn/controller/binding.c
+++ b/ovn/controller/binding.c
@@ -153,7 +153,7 @@ add_local_datapath__(struct controller_ctx *ctx,
if (peer_name) {
const struct sbrec_port_binding *peer;
- peer = lport_lookup_by_name( ctx->ovnsb_idl, peer_name);
+ peer = lport_lookup_by_name( ctx->ovnsb_cursors, peer_name);
if (peer && peer->datapath) {
add_local_datapath__(ctx, peer->datapath,
@@ -163,7 +163,7 @@ add_local_datapath__(struct controller_ctx *ctx,
ld->peer_dps,
ld->n_peer_dps * sizeof *ld->peer_dps);
ld->peer_dps[ld->n_peer_dps - 1] = datapath_lookup_by_key(
- ctx->ovnsb_idl, peer->datapath->tunnel_key);
+ ctx->ovnsb_cursors, peer->datapath->tunnel_key);
}
}
}
diff --git a/ovn/controller/lflow.c b/ovn/controller/lflow.c
index 6d9f02c..0359667 100644
--- a/ovn/controller/lflow.c
+++ b/ovn/controller/lflow.c
@@ -46,12 +46,12 @@ lflow_init(void)
}
struct lookup_port_aux {
- struct ovsdb_idl *ovnsb_idl;
+ struct ovnsb_cursors *ovnsb_cursors;
const struct sbrec_datapath_binding *dp;
};
struct condition_aux {
- struct ovsdb_idl *ovnsb_idl;
+ struct ovnsb_cursors *ovnsb_cursors;
const struct sbrec_chassis *chassis;
const struct sset *active_tunnels;
const struct chassis_index *chassis_index;
@@ -76,14 +76,14 @@ lookup_port_cb(const void *aux_, const char *port_name, unsigned int *portp)
const struct lookup_port_aux *aux = aux_;
const struct sbrec_port_binding *pb
- = lport_lookup_by_name(aux->ovnsb_idl, port_name);
+ = lport_lookup_by_name(aux->ovnsb_cursors, port_name);
if (pb && pb->datapath == aux->dp) {
*portp = pb->tunnel_key;
return true;
}
const struct sbrec_multicast_group *mg
- = mcgroup_lookup_by_dp_name(aux->ovnsb_idl, aux->dp, port_name);
+ = mcgroup_lookup_by_dp_name(aux->ovnsb_cursors, aux->dp, port_name);
if (mg) {
*portp = mg->tunnel_key;
return true;
@@ -98,7 +98,7 @@ is_chassis_resident_cb(const void *c_aux_, const char *port_name)
const struct condition_aux *c_aux = c_aux_;
const struct sbrec_port_binding *pb
- = lport_lookup_by_name(c_aux->ovnsb_idl, port_name);
+ = lport_lookup_by_name(c_aux->ovnsb_cursors, port_name);
if (!pb) {
return false;
}
@@ -243,7 +243,7 @@ consider_logical_flow(struct controller_ctx *ctx,
uint64_t ofpacts_stub[1024 / 8];
struct ofpbuf ofpacts = OFPBUF_STUB_INITIALIZER(ofpacts_stub);
struct lookup_port_aux aux = {
- .ovnsb_idl = ctx->ovnsb_idl,
+ .ovnsb_cursors = ctx->ovnsb_cursors,
.dp = lflow->logical_datapath
};
struct ovnact_encode_params ep = {
@@ -285,7 +285,7 @@ consider_logical_flow(struct controller_ctx *ctx,
return;
}
- struct condition_aux cond_aux = { ctx->ovnsb_idl, chassis, active_tunnels,
+ struct condition_aux cond_aux = { ctx->ovnsb_cursors, chassis, active_tunnels,
chassis_index};
expr = expr_simplify(expr, is_chassis_resident_cb, &cond_aux);
expr = expr_normalize(expr);
@@ -348,7 +348,7 @@ consider_neighbor_flow(struct controller_ctx *ctx,
struct hmap *flow_table)
{
const struct sbrec_port_binding *pb
- = lport_lookup_by_name(ctx->ovnsb_idl, b->logical_port);
+ = lport_lookup_by_name(ctx->ovnsb_cursors, b->logical_port);
if (!pb) {
return;
}
diff --git a/ovn/controller/lport.c b/ovn/controller/lport.c
index e5305d0..6be6b31 100644
--- a/ovn/controller/lport.c
+++ b/ovn/controller/lport.c
@@ -22,29 +22,25 @@
#include "ovn/lib/ovn-sb-idl.h"
VLOG_DEFINE_THIS_MODULE(lport);
-static struct ovsdb_idl_index_cursor lport_by_name_cursor;
-static struct ovsdb_idl_index_cursor lport_by_key_cursor;
-static struct ovsdb_idl_index_cursor dpath_by_key_cursor;
-static struct ovsdb_idl_index_cursor mc_grp_by_dp_name_cursor;
-
/* Finds and returns the port binding record with the given 'name',
* or NULL if no such port binding exists. */
const struct sbrec_port_binding *
-lport_lookup_by_name(struct ovsdb_idl *idl, const char *name)
+lport_lookup_by_name(struct ovnsb_cursors *cursors, const char *name)
{
struct sbrec_port_binding *value;
const struct sbrec_port_binding *pb, *retval = NULL;
/* Build key for an indexed lookup. */
- value = sbrec_port_binding_index_init_row(idl, &sbrec_table_port_binding);
+ value = sbrec_port_binding_index_init_row(cursors->idl, &sbrec_table_port_binding);
sbrec_port_binding_index_set_logical_port(value, name);
/* Find an entry with matching logical port name. Since this column is
* declared to be an index in the OVN_Southbound schema, the first match
* (if any) will be the only match. */
- SBREC_PORT_BINDING_FOR_EACH_EQUAL (pb, &lport_by_name_cursor, value) {
+ SBREC_PORT_BINDING_FOR_EACH_EQUAL (pb, &cursors->lport_by_name_cursor,
+ value) {
retval = pb;
break;
}
@@ -57,20 +53,21 @@ lport_lookup_by_name(struct ovsdb_idl *idl, const char *name)
/* Finds and returns the datapath binding record with tunnel_key equal to the
* given 'dp_key', or NULL if no such datapath binding exists. */
const struct sbrec_datapath_binding *
-datapath_lookup_by_key(struct ovsdb_idl *idl, uint64_t dp_key)
+datapath_lookup_by_key(struct ovnsb_cursors *cursors, uint64_t dp_key)
{
struct sbrec_datapath_binding *dbval;
const struct sbrec_datapath_binding *db, *retval = NULL;
/* Build key for an indexed lookup. */
- dbval = sbrec_datapath_binding_index_init_row(idl,
- &sbrec_table_datapath_binding);
+ dbval = sbrec_datapath_binding_index_init_row(
+ cursors->idl, &sbrec_table_datapath_binding);
sbrec_datapath_binding_index_set_tunnel_key(dbval, dp_key);
/* Find an entry with matching tunnel_key. Since this column is declared
* to be an index in the OVN_Southbound schema, the first match (if any)
* will be the only match. */
- SBREC_DATAPATH_BINDING_FOR_EACH_EQUAL (db, &dpath_by_key_cursor, dbval) {
+ SBREC_DATAPATH_BINDING_FOR_EACH_EQUAL (db, &cursors->dpath_by_key_cursor,
+ dbval) {
retval = db;
break;
}
@@ -83,27 +80,30 @@ datapath_lookup_by_key(struct ovsdb_idl *idl, uint64_t dp_key)
* given 'port_key' and datapath binding matching 'dp_key', or NULL if no
* such port binding exists. */
const struct sbrec_port_binding *
-lport_lookup_by_key(struct ovsdb_idl *idl, uint64_t dp_key, uint64_t port_key)
+lport_lookup_by_key(struct ovnsb_cursors *cursors, uint64_t dp_key,
+ uint64_t port_key)
{
struct sbrec_port_binding *pbval;
const struct sbrec_port_binding *pb, *retval = NULL;
const struct sbrec_datapath_binding *db;
/* Lookup datapath corresponding to dp_key. */
- db = datapath_lookup_by_key(idl, dp_key);
+ db = datapath_lookup_by_key(cursors, dp_key);
if (!db) {
return NULL;
}
/* Build key for an indexed lookup. */
- pbval = sbrec_port_binding_index_init_row(idl, &sbrec_table_port_binding);
+ pbval = sbrec_port_binding_index_init_row(cursors->idl,
+ &sbrec_table_port_binding);
sbrec_port_binding_index_set_datapath(pbval, db);
sbrec_port_binding_index_set_tunnel_key(pbval, port_key);
/* Find an entry with matching tunnel_key and datapath UUID. Since this
* column pair is declared to be an index in the OVN_Southbound schema,
* the first match (if any) will be the only match. */
- SBREC_PORT_BINDING_FOR_EACH_EQUAL (pb, &lport_by_key_cursor, pbval) {
+ SBREC_PORT_BINDING_FOR_EACH_EQUAL (pb, &cursors->lport_by_key_cursor,
+ pbval) {
retval = pb;
break;
}
@@ -115,15 +115,15 @@ lport_lookup_by_key(struct ovsdb_idl *idl, uint64_t dp_key, uint64_t port_key)
/* Finds and returns the logical multicast group with the given 'name' and
* datapath binding, or NULL if no such logical multicast group exists. */
const struct sbrec_multicast_group *
-mcgroup_lookup_by_dp_name(struct ovsdb_idl *idl,
- const struct sbrec_datapath_binding *dp,
- const char *name)
+mcgroup_lookup_by_dp_name(struct ovnsb_cursors *cursors,
+ const struct sbrec_datapath_binding *dp,
+ const char *name)
{
struct sbrec_multicast_group *mcval;
const struct sbrec_multicast_group *mc, *retval = NULL;
/* Build key for an indexed lookup. */
- mcval = sbrec_multicast_group_index_init_row(idl,
+ mcval = sbrec_multicast_group_index_init_row(cursors->idl,
&sbrec_table_multicast_group);
sbrec_multicast_group_index_set_name(mcval, name);
sbrec_multicast_group_index_set_datapath(mcval, dp);
@@ -131,8 +131,8 @@ mcgroup_lookup_by_dp_name(struct ovsdb_idl *idl,
/* Find an entry with matching logical multicast group name and datapath.
* Since this column pair is declared to be an index in the OVN_Southbound
* schema, the first match (if any) will be the only match. */
- SBREC_MULTICAST_GROUP_FOR_EACH_EQUAL (mc, &mc_grp_by_dp_name_cursor,
- mcval) {
+ SBREC_MULTICAST_GROUP_FOR_EACH_EQUAL (mc,
+ &cursors->mc_grp_by_dp_name_cursor, mcval) {
retval = mc;
break;
}
@@ -143,25 +143,26 @@ mcgroup_lookup_by_dp_name(struct ovsdb_idl *idl,
}
void
-lport_init(struct ovsdb_idl *idl)
+lport_init(struct ovnsb_cursors *cursors, struct ovsdb_idl *idl)
{
+ cursors->idl = idl;
/* Create a cursor for searching multicast group table by datapath
* and group name. */
ovsdb_idl_initialize_cursor(idl, &sbrec_table_multicast_group,
"multicast-group-by-dp-name",
- &mc_grp_by_dp_name_cursor);
+ &cursors->mc_grp_by_dp_name_cursor);
/* Create cursor to search port binding table by logical port name. */
ovsdb_idl_initialize_cursor(idl, &sbrec_table_port_binding,
"lport-by-name",
- &lport_by_name_cursor);
+ &cursors->lport_by_name_cursor);
/* Create cursor to search port binding table by logical port tunnel key
* and datapath uuid. */
ovsdb_idl_initialize_cursor(idl, &sbrec_table_port_binding, "lport-by-key",
- &lport_by_key_cursor);
+ &cursors->lport_by_key_cursor);
/* Create cursor to search datapath binding table by tunnel key. */
ovsdb_idl_initialize_cursor(idl, &sbrec_table_datapath_binding,
- "dpath-by-key", &dpath_by_key_cursor);
+ "dpath-by-key", &cursors->dpath_by_key_cursor);
}
diff --git a/ovn/controller/lport.h b/ovn/controller/lport.h
index 38c7344..4421c02 100644
--- a/ovn/controller/lport.h
+++ b/ovn/controller/lport.h
@@ -20,6 +20,7 @@
#include "lib/uuid.h"
#include "openvswitch/hmap.h"
#include "openvswitch/list.h"
+#include "ovn/lib/ovn-sb-idl.h"
struct ovsdb_idl;
struct sbrec_chassis;
@@ -34,22 +35,31 @@ struct sbrec_port_binding;
* look up data based on values of its fields. It's not that smart (yet), so
* instead we define our own indexes.
*/
+
+struct ovnsb_cursors {
+ struct ovsdb_idl *idl;
+ struct ovsdb_idl_index_cursor lport_by_name_cursor;
+ struct ovsdb_idl_index_cursor lport_by_key_cursor;
+ struct ovsdb_idl_index_cursor dpath_by_key_cursor;
+ struct ovsdb_idl_index_cursor mc_grp_by_dp_name_cursor;
+};
+
-const struct sbrec_datapath_binding *datapath_lookup_by_key(struct ovsdb_idl *,
- uint64_t dp_key);
+const struct sbrec_datapath_binding *datapath_lookup_by_key(
+ struct ovnsb_cursors *, uint64_t dp_key);
const struct sbrec_port_binding *lport_lookup_by_name(
- struct ovsdb_idl *, const char *name);
+ struct ovnsb_cursors *, const char *name);
const struct sbrec_port_binding *lport_lookup_by_key(
- struct ovsdb_idl *, uint64_t dp_key, uint64_t port_key);
+ struct ovnsb_cursors *, uint64_t dp_key, uint64_t port_key);
const struct sbrec_multicast_group *mcgroup_lookup_by_dp_name(
- struct ovsdb_idl *idl,
+ struct ovnsb_cursors *,
const struct sbrec_datapath_binding *,
const char *name);
-void lport_init(struct ovsdb_idl *idl);
+void lport_init(struct ovnsb_cursors *cursors, struct ovsdb_idl *idl);
#endif /* ovn/lport.h */
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index 2dacba1..414443f 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -620,7 +620,8 @@ main(int argc, char *argv[])
ovsdb_idl_create(ovnsb_remote, &sbrec_idl_class, true, true));
create_ovnsb_indexes(ovnsb_idl_loop.idl);
- lport_init(ovnsb_idl_loop.idl);
+ struct ovnsb_cursors ovnsb_cursors;
+ lport_init(ovnsb_cursors, ovnsb_idl_loop.idl);
ovsdb_idl_omit_alert(ovnsb_idl_loop.idl, &sbrec_chassis_col_nb_cfg);
update_sb_monitors(ovnsb_idl_loop.idl, NULL, NULL, NULL);
@@ -658,6 +659,7 @@ main(int argc, char *argv[])
.ovs_idl_txn = ovsdb_idl_loop_run(&ovs_idl_loop),
.ovnsb_idl = ovnsb_idl_loop.idl,
.ovnsb_idl_txn = ovsdb_idl_loop_run(&ovnsb_idl_loop),
+ .ovnsb_cursors = &ovnsb_cursors,
};
update_probe_interval(&ctx, ovnsb_remote);
diff --git a/ovn/controller/ovn-controller.h b/ovn/controller/ovn-controller.h
index 6617b0c..f57c557 100644
--- a/ovn/controller/ovn-controller.h
+++ b/ovn/controller/ovn-controller.h
@@ -29,6 +29,7 @@ struct controller_ctx {
struct ovsdb_idl *ovs_idl;
struct ovsdb_idl_txn *ovs_idl_txn;
+ struct ovnsb_cursors *ovnsb_cursors;
};
/* States to move through when a new conntrack zone has been allocated. */
diff --git a/ovn/controller/physical.c b/ovn/controller/physical.c
index df71979..3d06623 100644
--- a/ovn/controller/physical.c
+++ b/ovn/controller/physical.c
@@ -318,7 +318,7 @@ consider_port_binding(struct controller_ctx *ctx,
}
const struct sbrec_port_binding *peer = lport_lookup_by_name(
- ctx->ovnsb_idl, peer_name);
+ ctx->ovnsb_cursors, peer_name);
if (!peer || strcmp(peer->type, binding->type)) {
return;
}
@@ -385,7 +385,7 @@ consider_port_binding(struct controller_ctx *ctx,
const char *distributed_port = smap_get_def(&binding->options,
"distributed-port", "");
const struct sbrec_port_binding *distributed_binding
- = lport_lookup_by_name(ctx->ovnsb_idl, distributed_port);
+ = lport_lookup_by_name(ctx->ovnsb_cursors, distributed_port);
if (!distributed_binding) {
/* Packet will be dropped. */
@@ -1109,7 +1109,7 @@ physical_run(struct controller_ctx *ctx, enum mf_field_id mff_ovn_geneve,
* rule with higher priority for every localport in this
* datapath. */
const struct sbrec_port_binding *pb = lport_lookup_by_name(
- ctx->ovnsb_idl, localport);
+ ctx->ovnsb_cursors, localport);
if (pb && !strcmp(pb->type, "localport")) {
match_set_reg(&match, MFF_LOG_INPORT - MFF_REG0, pb->tunnel_key);
match_set_metadata(&match, htonll(pb->datapath->tunnel_key));
diff --git a/ovn/controller/pinctrl.c b/ovn/controller/pinctrl.c
index 469a355..9412b48 100644
--- a/ovn/controller/pinctrl.c
+++ b/ovn/controller/pinctrl.c
@@ -1182,7 +1182,7 @@ run_put_mac_binding(struct controller_ctx *ctx,
/* Convert logical datapath and logical port key into lport. */
const struct sbrec_port_binding *pb
- = lport_lookup_by_key(ctx->ovnsb_idl, pmb->dp_key, pmb->port_key);
+ = lport_lookup_by_key(ctx->ovnsb_cursors, pmb->dp_key, pmb->port_key);
if (!pb) {
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
@@ -1462,7 +1462,7 @@ get_localnet_vifs_l3gwports(struct controller_ctx *ctx,
continue;
}
const struct sbrec_port_binding *pb
- = lport_lookup_by_name(ctx->ovnsb_idl, iface_id);
+ = lport_lookup_by_name(ctx->ovnsb_cursors, iface_id);
if (!pb) {
continue;
}
@@ -1514,7 +1514,7 @@ pinctrl_is_chassis_resident(struct controller_ctx *ctx,
const char *port_name)
{
const struct sbrec_port_binding *pb
- = lport_lookup_by_name(ctx->ovnsb_idl, port_name);
+ = lport_lookup_by_name(ctx->ovnsb_cursors, port_name);
if (!pb || !pb->chassis) {
return false;
}
@@ -1643,7 +1643,7 @@ get_nat_addresses_and_keys(struct controller_ctx *ctx,
SSET_FOR_EACH(gw_port, local_l3gw_ports) {
const struct sbrec_port_binding *pb;
- pb = lport_lookup_by_name(ctx->ovnsb_idl, gw_port);
+ pb = lport_lookup_by_name(ctx->ovnsb_cursors, gw_port);
if (!pb) {
continue;
}
@@ -1712,7 +1712,7 @@ send_garp_run(struct controller_ctx *ctx,
SSET_FOR_EACH (iface_id, &localnet_vifs) {
const struct sbrec_port_binding *pb;
- pb = lport_lookup_by_name(ctx->ovnsb_idl, iface_id);
+ pb = lport_lookup_by_name(ctx->ovnsb_cursors, iface_id);
if (pb) {
send_garp_update(pb, &localnet_ofports, local_datapaths,
&nat_addresses);
@@ -1724,7 +1724,7 @@ send_garp_run(struct controller_ctx *ctx,
SSET_FOR_EACH (gw_port, &local_l3gw_ports) {
const struct sbrec_port_binding *pb;
- pb = lport_lookup_by_name(ctx->ovnsb_idl, gw_port);
+ pb = lport_lookup_by_name(ctx->ovnsb_cursors, gw_port);
if (pb) {
send_garp_update(pb, &localnet_ofports, local_datapaths,
&nat_addresses);
--
2.1.0
More information about the dev
mailing list