From patchwork Mon Sep 21 16:25:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 1368498 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=140.211.166.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NCkYDs/7; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bw8vX73Frz9sVT for ; Tue, 22 Sep 2020 02:26:16 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 1F06920C45; Mon, 21 Sep 2020 16:26:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Lnn0q7HU+QBb; Mon, 21 Sep 2020 16:26:01 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id A767A2107A; Mon, 21 Sep 2020 16:26:00 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7BA02C0890; Mon, 21 Sep 2020 16:26:00 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id D76C7C0051 for ; Mon, 21 Sep 2020 16:25:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id C31898728A for ; Mon, 21 Sep 2020 16:25:58 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KdEhuW4gO7YL for ; Mon, 21 Sep 2020 16:25:56 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by hemlock.osuosl.org (Postfix) with ESMTPS id B40F6871DB for ; Mon, 21 Sep 2020 16:25:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600705555; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P7eKeYdCjlAI29Yq4TUvVLYUpKpkJIkAeRpvvFf7JUY=; b=NCkYDs/77a1i2/KTCs3LlajRwSPUrjVlKQLRle15/LWbiU8iizvlrvQMiSej7+yE2lJOfp NZXXERoy+IywhTr8nHxMssK0Wmg42XUa/vFekKMs28orJET1K6NJA284fQ2f+C6j1elPpA izMH0n/liV0qFqqidaymgtO0tcRkpFY= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-142-sxqt_mEQM-Ox7Ad68Mq24w-1; Mon, 21 Sep 2020 12:25:50 -0400 X-MC-Unique: sxqt_mEQM-Ox7Ad68Mq24w-1 Received: by mail-wr1-f69.google.com with SMTP id a12so6089542wrg.13 for ; Mon, 21 Sep 2020 09:25:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=P7eKeYdCjlAI29Yq4TUvVLYUpKpkJIkAeRpvvFf7JUY=; b=nRO8wZ5bA9PSoZ8j7wX4f+97IM5RUH5+SJHDgykEiSaXXFtrTLcxQt2o4l+tOfWkGl 9B7Hmf0gNUDYBFdPsHA0ApBMBHv6FyPWj+nMJG5uHh8A8XSnHHUJ4NbzEddT+ZD5APhy EvVmsXunEouz0KcvPoY4AR/hxdo1kMRCJnhmRPib6EZGJ3Q1A3HpLzrL9ygni/UJGtfr GY6S9Ia3ADnTVKCHF3MT2y8MCodTBz3seTrpm8cY8Xsl4zJoXPwVs4iPjI97D8Bippm9 ihBR99Xutv1B/SM5axadFWpSaICKxIJx7Cx9Tdfwo825JnSVQc8dCemvOw7yPfhHA8Kc BYig== X-Gm-Message-State: AOAM530WYqe2uc2ymsWR7kAoa+dAYjxDdR9Tv/vzkOaBaO/Pb4+ZACVm u9b9VuoekxRxmZNQXkxT/kC4j3xWL49bdDrmgAJX4oljavoS4ZFZ4XUC0jfsJ01CIIY9LqJeA2/ IXUPMhu1OPJDn6tXzag== X-Received: by 2002:a1c:4054:: with SMTP id n81mr160180wma.81.1600705547789; Mon, 21 Sep 2020 09:25:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3KxJUlcJBJqnWAEsyteYqdoYntCJZGlOkyhJcnSLfEkMvVA1/9nZvwPskeSEtAgkBRBwvAQ== X-Received: by 2002:a1c:4054:: with SMTP id n81mr160157wma.81.1600705547499; Mon, 21 Sep 2020 09:25:47 -0700 (PDT) Received: from lore-desk.redhat.com ([151.66.80.226]) by smtp.gmail.com with ESMTPSA id s11sm21019205wrt.43.2020.09.21.09.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 09:25:47 -0700 (PDT) From: Lorenzo Bianconi To: ovs-dev@openvswitch.org Date: Mon, 21 Sep 2020 18:25:35 +0200 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lorenzo.bianconi@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: hzhou@ovn.org Subject: [ovs-dev] [PATCH v2 ovn 1/3] controller: binding: rely on shash for local_iface_ids 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" Rely on shash for local_iface_ids instead of smap for local_iface_ids. This is a preliminary patch to properly manage ovn-egress-iface in binding I-P engine Signed-off-by: Lorenzo Bianconi --- controller/binding.c | 40 +++++++++++++++++++++++++++++-------- controller/binding.h | 6 +++++- controller/ovn-controller.c | 39 +++++++++++++++++++++++++++++------- 3 files changed, 69 insertions(+), 16 deletions(-) diff --git a/controller/binding.c b/controller/binding.c index 3c102dc7f..0397e145a 100644 --- a/controller/binding.c +++ b/controller/binding.c @@ -1349,8 +1349,16 @@ build_local_bindings(struct binding_ctx_in *b_ctx_in, } update_local_lports(iface_id, b_ctx_out); - smap_replace(b_ctx_out->local_iface_ids, iface_rec->name, - iface_id); + + struct local_iface_node *iface_node = + xmalloc(sizeof *iface_node); + iface_node->iface_id = xstrdup(iface_id); + iface_node = shash_replace(b_ctx_out->local_ifaces, + iface_rec->name, iface_node); + if (iface_node) { + free(iface_node->iface_id); + free(iface_node); + } } /* Check if this is a tunnel interface. */ @@ -1689,7 +1697,15 @@ consider_iface_claim(const struct ovsrec_interface *iface_rec, struct hmap *qos_map) { update_local_lports(iface_id, b_ctx_out); - smap_replace(b_ctx_out->local_iface_ids, iface_rec->name, iface_id); + + struct local_iface_node *iface_node = xmalloc(sizeof *iface_node); + iface_node->iface_id = xstrdup(iface_id); + iface_node = shash_replace(b_ctx_out->local_ifaces, + iface_rec->name, iface_node); + if (iface_node) { + free(iface_node->iface_id); + free(iface_node); + } struct local_binding *lbinding = local_binding_find(b_ctx_out->local_bindings, iface_id); @@ -1783,7 +1799,13 @@ consider_iface_release(const struct ovsrec_interface *iface_rec, } remove_local_lports(iface_id, b_ctx_out); - smap_remove(b_ctx_out->local_iface_ids, iface_rec->name); + struct local_iface_node *iface_node = shash_find_and_delete( + b_ctx_out->local_ifaces, + iface_rec->name); + if (iface_node) { + free(iface_node->iface_id); + free(iface_node); + } return true; } @@ -1822,11 +1844,11 @@ binding_handle_ovs_interface_changes(struct binding_ctx_in *b_ctx_in, * 2. external_ids:iface-id is cleared in which case we need to * release the port binding corresponding to the previously set * 'old-iface-id' (which is stored in the smap - * 'b_ctx_out->local_iface_ids'). + * 'b_ctx_out->local_ifaces'). * 3. external_ids:iface-id is updated with a different value * in which case we need to release the port binding corresponding * to the previously set 'old-iface-id' (which is stored in the smap - * 'b_ctx_out->local_iface_ids'). + * 'b_ctx_out->local_ifaces'). * 4. ofport of the OVS interface is 0. * */ @@ -1842,8 +1864,10 @@ binding_handle_ovs_interface_changes(struct binding_ctx_in *b_ctx_in, } const char *iface_id = smap_get(&iface_rec->external_ids, "iface-id"); - const char *old_iface_id = smap_get(b_ctx_out->local_iface_ids, - iface_rec->name); + + struct local_iface_node *iface_node = shash_find_data( + b_ctx_out->local_ifaces, iface_rec->name); + const char *old_iface_id = iface_node ? iface_node->iface_id : NULL; const char *cleared_iface_id = NULL; if (!ovsrec_interface_is_deleted(iface_rec)) { int64_t ofport = iface_rec->n_ofport ? *iface_rec->ofport : 0; diff --git a/controller/binding.h b/controller/binding.h index c9740560f..a1e0f1ccf 100644 --- a/controller/binding.h +++ b/controller/binding.h @@ -54,6 +54,10 @@ struct binding_ctx_in { const struct ovsrec_interface_table *iface_table; }; +struct local_iface_node { + char *iface_id; +}; + struct binding_ctx_out { struct hmap *local_datapaths; struct shash *local_bindings; @@ -77,7 +81,7 @@ struct binding_ctx_out { struct sset *egress_ifaces; /* smap of OVS interface name as key and * OVS interface external_ids:iface-id as value. */ - struct smap *local_iface_ids; + struct shash *local_ifaces; /* hmap of 'struct tracked_binding_datapath' which the * callee (binding_handle_ovs_interface_changes and diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index 8d8c678e5..0a6f171be 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -35,6 +35,7 @@ #include "fatal-signal.h" #include "ip-mcast.h" #include "openvswitch/hmap.h" +#include "openvswitch/shash.h" #include "lflow.h" #include "lib/vswitch-idl.h" #include "lport.h" @@ -1033,7 +1034,7 @@ struct ed_type_runtime_data { /* runtime data engine private data. */ struct sset egress_ifaces; - struct smap local_iface_ids; + struct shash local_ifaces; /* Tracked data. See below for more details and comments. */ bool tracked; @@ -1085,7 +1086,7 @@ struct ed_type_runtime_data { * | local_bindings | the @tracked_dp_bindings indirectly and hence it | * | local_lport_ids | is not tracked explicitly. | * --------------------------------------------------------------------- - * | local_iface_ids | This is used internally within the runtime data | + * | local_ifaces | This is used internally within the runtime data | * | egress_ifaces | engine (used only in binding.c) and hence there | * | | there is no need to track. | * --------------------------------------------------------------------- @@ -1124,7 +1125,7 @@ en_runtime_data_init(struct engine_node *node OVS_UNUSED, sset_init(&data->local_lport_ids); sset_init(&data->active_tunnels); sset_init(&data->egress_ifaces); - smap_init(&data->local_iface_ids); + shash_init(&data->local_ifaces); local_bindings_init(&data->local_bindings); /* Init the tracked data. */ @@ -1142,7 +1143,19 @@ en_runtime_data_cleanup(void *data) sset_destroy(&rt_data->local_lport_ids); sset_destroy(&rt_data->active_tunnels); sset_destroy(&rt_data->egress_ifaces); - smap_destroy(&rt_data->local_iface_ids); + + struct shash_node *sh_node, *sh_node_next; + SHASH_FOR_EACH_SAFE (sh_node, sh_node_next, + &rt_data->local_ifaces) { + struct local_iface_node *iface_node = sh_node->data; + hmap_remove(&rt_data->local_ifaces.map, &sh_node->node); + free(iface_node->iface_id); + free(sh_node->data); + free(sh_node->name); + free(sh_node); + } + hmap_destroy(&rt_data->local_ifaces.map); + struct local_datapath *cur_node, *next_node; HMAP_FOR_EACH_SAFE (cur_node, next_node, hmap_node, &rt_data->local_datapaths) { @@ -1234,7 +1247,7 @@ init_binding_ctx(struct engine_node *node, b_ctx_out->non_vif_ports_changed = false; b_ctx_out->egress_ifaces = &rt_data->egress_ifaces; b_ctx_out->local_bindings = &rt_data->local_bindings; - b_ctx_out->local_iface_ids = &rt_data->local_iface_ids; + b_ctx_out->local_ifaces = &rt_data->local_ifaces; b_ctx_out->tracked_dp_bindings = NULL; b_ctx_out->local_lports_changed = NULL; } @@ -1282,12 +1295,24 @@ en_runtime_data_run(struct engine_node *node, void *data) sset_destroy(local_lport_ids); sset_destroy(active_tunnels); sset_destroy(&rt_data->egress_ifaces); - smap_destroy(&rt_data->local_iface_ids); + + struct shash_node *sh_node, *sh_node_next; + SHASH_FOR_EACH_SAFE (sh_node, sh_node_next, + &rt_data->local_ifaces) { + struct local_iface_node *iface_node = sh_node->data; + hmap_remove(&rt_data->local_ifaces.map, &sh_node->node); + free(iface_node->iface_id); + free(sh_node->data); + free(sh_node->name); + free(sh_node); + } + hmap_destroy(&rt_data->local_ifaces.map); + sset_init(local_lports); sset_init(local_lport_ids); sset_init(active_tunnels); sset_init(&rt_data->egress_ifaces); - smap_init(&rt_data->local_iface_ids); + shash_init(&rt_data->local_ifaces); local_bindings_init(&rt_data->local_bindings); }