From patchwork Wed Feb 9 06:37:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1590204 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JtqvK1t76z9sCD for ; Wed, 9 Feb 2022 17:38:05 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id EB14C60FBC; Wed, 9 Feb 2022 06:38:01 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Xh-Fpqp3_RkN; Wed, 9 Feb 2022 06:38:00 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 5A9EB60F84; Wed, 9 Feb 2022 06:37:58 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id EC14DC0039; Wed, 9 Feb 2022 06:37:57 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1EC58C0070 for ; Wed, 9 Feb 2022 06:37:57 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id C205983298 for ; Wed, 9 Feb 2022 06:37:52 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bzVRXXutiDr9 for ; Wed, 9 Feb 2022 06:37:51 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by smtp1.osuosl.org (Postfix) with ESMTPS id 62DF783260 for ; Wed, 9 Feb 2022 06:37:51 +0000 (UTC) Received: (Authenticated sender: hzhou@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id 111E3FF806; Wed, 9 Feb 2022 06:37:48 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Tue, 8 Feb 2022 22:37:24 -0800 Message-Id: <20220209063726.1134827-10-hzhou@ovn.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220209063726.1134827-1-hzhou@ovn.org> References: <20220209063726.1134827-1-hzhou@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn 09/11] lflow: Track reference count of address sets when parsing lflows. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Not only track the address set references but also track how many times each address set is referenced when parsing an lflow. This count will be needed by address set incremental processing. Signed-off-by: Han Zhou --- controller/lflow.c | 32 ++++++++++++++++++-------------- controller/lflow.h | 3 +++ include/ovn/expr.h | 4 ++-- lib/expr.c | 16 ++++++++++++---- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/controller/lflow.c b/controller/lflow.c index d0b335893..66c31db9e 100644 --- a/controller/lflow.c +++ b/controller/lflow.c @@ -90,7 +90,8 @@ static void lflows_processed_add(struct hmap *lflows_processed, static void lflows_processed_remove(struct hmap *lflows_processed, struct lflow_processed_node *node); static void lflow_resource_add(struct lflow_resource_ref *, enum ref_type, - const char *ref_name, const struct uuid *); + const char *ref_name, const struct uuid *, + size_t ref_count); static struct ref_lflow_node *ref_lflow_lookup(struct hmap *ref_lflow_table, enum ref_type, const char *ref_name); @@ -115,7 +116,7 @@ lookup_port_cb(const void *aux_, const char *port_name, unsigned int *portp) * in the future when the lport's port binding changes, the logical flow * that references this lport can be reprocessed. */ lflow_resource_add(aux->lfrr, REF_TYPE_PORTBINDING, port_name, - &aux->lflow->header_.uuid); + &aux->lflow->header_.uuid, 0); const struct sbrec_port_binding *pb = lport_lookup_by_name(aux->sbrec_port_binding_by_name, port_name); @@ -131,7 +132,7 @@ lookup_port_cb(const void *aux_, const char *port_name, unsigned int *portp) struct ds mg_key = DS_EMPTY_INITIALIZER; get_mc_group_key(port_name, aux->dp->tunnel_key, &mg_key); lflow_resource_add(aux->lfrr, REF_TYPE_MC_GROUP, ds_cstr(&mg_key), - &aux->lflow->header_.uuid); + &aux->lflow->header_.uuid, 0); ds_destroy(&mg_key); const struct sbrec_multicast_group *mg = mcgroup_lookup_by_dp_name( @@ -173,7 +174,7 @@ is_chassis_resident_cb(const void *c_aux_, const char *port_name) * that in the future when the lport's port-binding changes the logical * flow that references this lport can be reprocessed. */ lflow_resource_add(c_aux->lfrr, REF_TYPE_PORTBINDING, port_name, - &c_aux->lflow->header_.uuid); + &c_aux->lflow->header_.uuid, 0); const struct sbrec_port_binding *pb = lport_lookup_by_name(c_aux->sbrec_port_binding_by_name, port_name); @@ -266,7 +267,8 @@ lflow_ref_lookup(struct hmap *lflow_ref_table, static void lflow_resource_add(struct lflow_resource_ref *lfrr, enum ref_type type, - const char *ref_name, const struct uuid *lflow_uuid) + const char *ref_name, const struct uuid *lflow_uuid, + size_t ref_count) { struct ref_lflow_node *rlfn = ref_lflow_lookup(&lfrr->ref_lflow_table, type, ref_name); @@ -302,6 +304,7 @@ lflow_resource_add(struct lflow_resource_ref *lfrr, enum ref_type type, struct lflow_ref_list_node *lrln = xzalloc(sizeof *lrln); lrln->lflow_uuid = *lflow_uuid; + lrln->ref_count = ref_count; lrln->rlfn = rlfn; hmap_insert(&rlfn->lflow_uuids, &lrln->hmap_node, uuid_hash(lflow_uuid)); ovs_list_push_back(&lfrn->lflow_ref_head, &lrln->list_node); @@ -750,7 +753,7 @@ convert_match_to_expr(const struct sbrec_logical_flow *lflow, struct lflow_resource_ref *lfrr, bool *pg_addr_set_ref) { - struct sset addr_sets_ref = SSET_INITIALIZER(&addr_sets_ref); + struct shash addr_sets_ref = SHASH_INITIALIZER(&addr_sets_ref); struct sset port_groups_ref = SSET_INITIALIZER(&port_groups_ref); char *error = NULL; @@ -758,22 +761,23 @@ convert_match_to_expr(const struct sbrec_logical_flow *lflow, port_groups, &addr_sets_ref, &port_groups_ref, dp->tunnel_key, &error); - const char *addr_set_name; - SSET_FOR_EACH (addr_set_name, &addr_sets_ref) { - lflow_resource_add(lfrr, REF_TYPE_ADDRSET, addr_set_name, - &lflow->header_.uuid); + struct shash_node *addr_sets_ref_node; + SHASH_FOR_EACH (addr_sets_ref_node, &addr_sets_ref) { + lflow_resource_add(lfrr, REF_TYPE_ADDRSET, addr_sets_ref_node->name, + &lflow->header_.uuid, + *(size_t *)addr_sets_ref_node->data); } const char *port_group_name; SSET_FOR_EACH (port_group_name, &port_groups_ref) { lflow_resource_add(lfrr, REF_TYPE_PORTGROUP, port_group_name, - &lflow->header_.uuid); + &lflow->header_.uuid, 0); } if (pg_addr_set_ref) { *pg_addr_set_ref = (!sset_is_empty(&port_groups_ref) || - !sset_is_empty(&addr_sets_ref)); + !shash_is_empty(&addr_sets_ref)); } - sset_destroy(&addr_sets_ref); + shash_destroy(&addr_sets_ref); sset_destroy(&port_groups_ref); if (!error) { @@ -812,7 +816,7 @@ consider_logical_flow__(const struct sbrec_logical_flow *lflow, const char *io_port = smap_get(&lflow->tags, "in_out_port"); if (io_port) { lflow_resource_add(l_ctx_out->lfrr, REF_TYPE_PORTBINDING, io_port, - &lflow->header_.uuid); + &lflow->header_.uuid, 0); const struct sbrec_port_binding *pb = lport_lookup_by_name(l_ctx_in->sbrec_port_binding_by_name, io_port); diff --git a/controller/lflow.h b/controller/lflow.h index d6dad17ec..b131b6cb6 100644 --- a/controller/lflow.h +++ b/controller/lflow.h @@ -105,6 +105,9 @@ struct lflow_ref_list_node { struct ovs_list list_node; /* node in lflow_ref_node.lflow_ref_head. */ struct hmap_node hmap_node; /* node in ref_lflow_node.lflow_uuids. */ struct uuid lflow_uuid; + size_t ref_count; /* Reference count of the resource by this lflow. + Currently used for the resource type REF_TYPE_ADDRSET + only, and for other types it is always 0. */ struct ref_lflow_node *rlfn; }; diff --git a/include/ovn/expr.h b/include/ovn/expr.h index 5b232c246..cb3baf001 100644 --- a/include/ovn/expr.h +++ b/include/ovn/expr.h @@ -419,13 +419,13 @@ size_t expr_size(const struct expr *); struct expr *expr_parse(struct lexer *, const struct shash *symtab, const struct shash *addr_sets, const struct shash *port_groups, - struct sset *addr_sets_ref, + struct shash *addr_sets_ref, struct sset *port_groups_ref, int64_t dp_id); struct expr *expr_parse_string(const char *, const struct shash *symtab, const struct shash *addr_sets, const struct shash *port_groups, - struct sset *addr_sets_ref, + struct shash *addr_sets_ref, struct sset *port_groups_ref, int64_t dp_id, char **errorp); diff --git a/lib/expr.c b/lib/expr.c index 2fdb7e3bb..2c178d87f 100644 --- a/lib/expr.c +++ b/lib/expr.c @@ -519,7 +519,7 @@ struct expr_context { const struct shash *symtab; /* Symbol table. */ const struct shash *addr_sets; /* Address set table. */ const struct shash *port_groups; /* Port group table. */ - struct sset *addr_sets_ref; /* The set of address set referenced. */ + struct shash *addr_sets_ref; /* The set of address set referenced. */ struct sset *port_groups_ref; /* The set of port groups referenced. */ int64_t dp_id; /* The tunnel_key of the datapath for which we're parsing the current @@ -798,7 +798,15 @@ parse_addr_sets(struct expr_context *ctx, struct expr_constant_set *cs, size_t *allocated_values) { if (ctx->addr_sets_ref) { - sset_add(ctx->addr_sets_ref, ctx->lexer->token.s); + size_t *ref_count = shash_find_data(ctx->addr_sets_ref, + ctx->lexer->token.s); + if (!ref_count) { + ref_count = xmalloc(sizeof *ref_count); + *ref_count = 1; + shash_add(ctx->addr_sets_ref, ctx->lexer->token.s, ref_count); + } else { + (*ref_count)++; + } } struct expr_constant_set *addr_sets @@ -1513,7 +1521,7 @@ struct expr * expr_parse(struct lexer *lexer, const struct shash *symtab, const struct shash *addr_sets, const struct shash *port_groups, - struct sset *addr_sets_ref, + struct shash *addr_sets_ref, struct sset *port_groups_ref, int64_t dp_id) { @@ -1537,7 +1545,7 @@ struct expr * expr_parse_string(const char *s, const struct shash *symtab, const struct shash *addr_sets, const struct shash *port_groups, - struct sset *addr_sets_ref, + struct shash *addr_sets_ref, struct sset *port_groups_ref, int64_t dp_id, char **errorp)