From patchwork Tue Sep 3 12:01:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Simonart X-Patchwork-Id: 1980003 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=WbSIDwcV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wykk540Qcz1yZ9 for ; Tue, 3 Sep 2024 22:01:31 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 7E5DB4030B; Tue, 3 Sep 2024 12:01:29 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id mKVrF-FSpzf4; Tue, 3 Sep 2024 12:01:28 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 3411640301 Authentication-Results: smtp4.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WbSIDwcV Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 3411640301; Tue, 3 Sep 2024 12:01:28 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0898AC0012; Tue, 3 Sep 2024 12:01:28 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id D7E53C0011 for ; Tue, 3 Sep 2024 12:01:26 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id D3F716061B for ; Tue, 3 Sep 2024 12:01:26 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id awPogCDChU8F for ; Tue, 3 Sep 2024 12:01:26 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=xsimonar@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 2EAD560608 Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 2EAD560608 Authentication-Results: smtp3.osuosl.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WbSIDwcV Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 2EAD560608 for ; Tue, 3 Sep 2024 12:01:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725364885; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EDFziP0C1Mt0QPB1D2UTtOVUF1vFCPyQ5PtGO5aOCeE=; b=WbSIDwcVcx9aXBl7Bq53rOfJRCUSrrKBpcHMB2mxT2iLPMbMx15TU1a0Xhmw71TSbizoCD oVLl3gv6kV6o94mQxx2QpjfPITq8MD7IyPpcI732uvBbBp81fhkECp3HQ8bn7NFm9/Bv+K V8kzJobeOhT2zEu9imiBlVsPtovbFao= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-458-IVoqdGfWNm-zh52JWCAoYA-1; Tue, 03 Sep 2024 08:01:23 -0400 X-MC-Unique: IVoqdGfWNm-zh52JWCAoYA-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 174961955BF6 for ; Tue, 3 Sep 2024 12:01:23 +0000 (UTC) Received: from wsfd-netdev90.ntdv.lab.eng.bos.redhat.com (wsfd-netdev90.anl.eng.rdu2.dc.redhat.com [10.6.38.135]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8A1B219560AE; Tue, 3 Sep 2024 12:01:22 +0000 (UTC) From: Xavier Simonart To: xsimonar@redhat.com, dev@openvswitch.org Date: Tue, 3 Sep 2024 14:01:19 +0200 Message-Id: <20240903120120.1864392-2-xsimonar@redhat.com> In-Reply-To: <20240903120120.1864392-1-xsimonar@redhat.com> References: <20240903120120.1864392-1-xsimonar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH ovn 1/2] vif-plug: Fix small memory leak when exiting. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" A small memory leak was possible when exiting ovn-controller while an ovsdb transaction was pending. Signed-off-by: Xavier Simonart Acked-by: Ales Musil --- controller/ovn-controller.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index c48667887..9101dfa8d 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -5908,7 +5908,22 @@ loop_done: } ovsdb_idl_loop_commit_and_wait(&ovnsb_idl_loop); - ovsdb_idl_loop_commit_and_wait(&ovs_idl_loop); + int ovs_txn_status = ovsdb_idl_loop_commit_and_wait(&ovs_idl_loop); + if (!ovs_txn_status) { + /* The transaction failed. */ + vif_plug_clear_deleted( + &vif_plug_deleted_iface_ids); + vif_plug_clear_changed( + &vif_plug_changed_iface_ids); + } else if (ovs_txn_status == 1) { + /* The transaction committed successfully + * (or it did not change anything in the database). */ + vif_plug_finish_deleted( + &vif_plug_deleted_iface_ids); + vif_plug_finish_changed( + &vif_plug_changed_iface_ids); + } + poll_block(); } } From patchwork Tue Sep 3 12:01:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Simonart X-Patchwork-Id: 1980005 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=RJEi7dxF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wykk83KJvz1yZ9 for ; Tue, 3 Sep 2024 22:01:36 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 876806083E; Tue, 3 Sep 2024 12:01:32 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id jtNDA1RVxV6K; Tue, 3 Sep 2024 12:01:31 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org B6A21607E2 Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RJEi7dxF Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id B6A21607E2; Tue, 3 Sep 2024 12:01:30 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7D6DCC0014; Tue, 3 Sep 2024 12:01:30 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 00CDFC0012 for ; Tue, 3 Sep 2024 12:01:28 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id DA28240993 for ; Tue, 3 Sep 2024 12:01:28 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id HUB_0mJLqQkO for ; Tue, 3 Sep 2024 12:01:27 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=xsimonar@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp2.osuosl.org 19032402EB Authentication-Results: smtp2.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 19032402EB Authentication-Results: smtp2.osuosl.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RJEi7dxF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp2.osuosl.org (Postfix) with ESMTPS id 19032402EB for ; Tue, 3 Sep 2024 12:01:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725364885; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FGRNG7KwfupbGkzWNsSMQSIqnpzok2IMhByn1SSIT80=; b=RJEi7dxF/JZWtWH6Aff85tjn2GvVcZYlC2eZxBegLUeYy+ZpSmu7M6nynrIwsArGoH0jYm FT4WMDwg3z3+MXEK0/emI+D6y0Q9vFPU9Yah3K09E06CUbr1SgDL7Z2nv4aQTDDBPAx3t9 wu9/4+pemzWx3mS8h4QWtjLKshHubVk= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-161-hrsWx0EAMPyiCTkzb9bZQw-1; Tue, 03 Sep 2024 08:01:24 -0400 X-MC-Unique: hrsWx0EAMPyiCTkzb9bZQw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C80811954B1D for ; Tue, 3 Sep 2024 12:01:23 +0000 (UTC) Received: from wsfd-netdev90.ntdv.lab.eng.bos.redhat.com (wsfd-netdev90.anl.eng.rdu2.dc.redhat.com [10.6.38.135]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4C0F219560A3; Tue, 3 Sep 2024 12:01:23 +0000 (UTC) From: Xavier Simonart To: xsimonar@redhat.com, dev@openvswitch.org Date: Tue, 3 Sep 2024 14:01:20 +0200 Message-Id: <20240903120120.1864392-3-xsimonar@redhat.com> In-Reply-To: <20240903120120.1864392-1-xsimonar@redhat.com> References: <20240903120120.1864392-1-xsimonar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH ovn 2/2] vif-plug: Avoid Transaction failures in ovsdb. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Transaction failures could occur as trying to plug multiple times the same interface in ovsdb i.e. "Transaction causes multiple rows in \"Interface\" table to have identical values". This could for instance occur between the time the VIF is plug first and an ofport is created. Signed-off-by: Xavier Simonart Reviewed-by: Ales Musil --- controller/binding.c | 2 +- controller/binding.h | 3 + controller/ovn-controller.c | 7 +++ controller/vif-plug.c | 117 ++++++++++++++++++++++-------------- controller/vif-plug.h | 1 + tests/ovn.at | 53 ++++++++++++++++ 6 files changed, 137 insertions(+), 46 deletions(-) diff --git a/controller/binding.c b/controller/binding.c index bfdeb99b9..31d73d6a9 100644 --- a/controller/binding.c +++ b/controller/binding.c @@ -2529,7 +2529,7 @@ is_iface_vif(const struct ovsrec_interface *iface_rec) return true; } -static bool +bool is_iface_in_int_bridge(const struct ovsrec_interface *iface, const struct ovsrec_bridge *br_int) { diff --git a/controller/binding.h b/controller/binding.h index f44f95833..d13ae36c7 100644 --- a/controller/binding.h +++ b/controller/binding.h @@ -284,4 +284,7 @@ void claimed_lport_set_up(const struct sbrec_port_binding *pb, bool port_binding_is_up(const struct sbrec_chassis *chassis_rec, const struct sbrec_port_binding_table *, const struct uuid *pb_uuid); +bool is_iface_in_int_bridge(const struct ovsrec_interface *iface, + const struct ovsrec_bridge *br_int); + #endif /* controller/binding.h */ diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index 9101dfa8d..48ecadb64 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -4872,6 +4872,9 @@ main(int argc, char *argv[]) struct ovsdb_idl_index *ovsrec_port_by_qos = ovsdb_idl_index_create1(ovs_idl_loop.idl, &ovsrec_port_col_qos); + struct ovsdb_idl_index *ovsrec_interface_by_name + = ovsdb_idl_index_create1(ovs_idl_loop.idl, + &ovsrec_interface_col_name); struct ovsdb_idl_index *ovsrec_queue_by_external_ids = ovsdb_idl_index_create1(ovs_idl_loop.idl, &ovsrec_queue_col_external_ids); @@ -5254,6 +5257,8 @@ main(int argc, char *argv[]) engine_ovsdb_node_add_index(&en_ovs_flow_sample_collector_set, "id", ovsrec_flow_sample_collector_set_by_id); engine_ovsdb_node_add_index(&en_ovs_port, "qos", ovsrec_port_by_qos); + engine_ovsdb_node_add_index(&en_ovs_interface, "name", + ovsrec_interface_by_name); engine_ovsdb_node_add_index(&en_ovs_queue, "external_ids", ovsrec_queue_by_external_ids); @@ -5608,6 +5613,8 @@ main(int argc, char *argv[]) sbrec_port_binding_by_requested_chassis, .ovsrec_port_by_interfaces = ovsrec_port_by_interfaces, + .ovsrec_interface_by_name = + ovsrec_interface_by_name, .ovs_table = ovs_table, .br_int = br_int, .iface_table = diff --git a/controller/vif-plug.c b/controller/vif-plug.c index d4c7552ea..662ae52c4 100644 --- a/controller/vif-plug.c +++ b/controller/vif-plug.c @@ -208,6 +208,22 @@ transact_update_port(const struct ovsrec_interface *iface_rec, mtu_request); } +static const struct ovsrec_interface * +iface_lookup_by_name(struct ovsdb_idl_index *ovsrec_interface_by_name, + char *name) +{ + struct ovsrec_interface *iface = ovsrec_interface_index_init_row( + ovsrec_interface_by_name); + ovsrec_interface_set_name(iface, name); + + const struct ovsrec_interface *retval + = ovsrec_interface_index_find(ovsrec_interface_by_name, + iface); + + ovsrec_interface_index_destroy_row(iface); + + return retval; +} static bool consider_unplug_iface(const struct ovsrec_interface *iface, @@ -287,11 +303,10 @@ get_plug_mtu_request(const struct smap *lport_options) } static bool -consider_plug_lport_create__(const struct vif_plug_class *vif_plug, - const struct smap *iface_external_ids, - const struct sbrec_port_binding *pb, - struct vif_plug_ctx_in *vif_plug_ctx_in, - struct vif_plug_ctx_out *vif_plug_ctx_out) +consider_plug_lport__(const struct vif_plug_class *vif_plug, + const struct sbrec_port_binding *pb, + struct vif_plug_port_ctx **vif_plug_port_ctx_ptr, + struct vif_plug_ctx_in *vif_plug_ctx_in) { if (!vif_plug_ctx_in->chassis_rec || !vif_plug_ctx_in->br_int || !vif_plug_ctx_in->ovs_idl_txn) { @@ -317,13 +332,22 @@ consider_plug_lport_create__(const struct vif_plug_class *vif_plug, &vif_plug_port_ctx->vif_plug_port_ctx_out)) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); VLOG_INFO_RL(&rl, - "Not plugging lport %s on direction from VIF plug " - "provider.", + "Not plugging/updating lport %s on direction from VIF " + "plug provider.", pb->logical_port); destroy_port_ctx(vif_plug_port_ctx); return true; } - + *vif_plug_port_ctx_ptr = vif_plug_port_ctx; + return true; +} +static bool +consider_plug_lport_create__(const struct smap *iface_external_ids, + const struct sbrec_port_binding *pb, + const struct vif_plug_port_ctx *vif_plug_port_ctx, + struct vif_plug_ctx_in *vif_plug_ctx_in, + struct vif_plug_ctx_out *vif_plug_ctx_out) +{ VLOG_INFO("Plugging port %s into %s for lport %s on this " "chassis.", vif_plug_port_ctx->vif_plug_port_ctx_out.name, @@ -340,41 +364,12 @@ static bool consider_plug_lport_update__(const struct vif_plug_class *vif_plug, const struct smap *iface_external_ids, const struct sbrec_port_binding *pb, - struct local_binding *lbinding, + const struct ovsrec_interface *iface_rec, + struct vif_plug_port_ctx *vif_plug_port_ctx, struct vif_plug_ctx_in *vif_plug_ctx_in, struct vif_plug_ctx_out *vif_plug_ctx_out) { - if (!vif_plug_ctx_in->chassis_rec || !vif_plug_ctx_in->br_int - || !vif_plug_ctx_in->ovs_idl_txn) { - /* Some of our prerequisites are not available, ask for a recompute. */ - return false; - } - /* Our contract with the VIF plug provider is that vif_plug_port_finish - * will be called with vif_plug_port_ctx_in and vif_plug_port_ctx_out - * objects once the transaction commits. - * - * Since this happens asynchronously we need to allocate memory for - * and duplicate any database references so that they stay valid. - * - * The data is freed with a call to destroy_port_ctx after the - * transaction completes at the end of the ovn-controller main - * loop. */ - struct vif_plug_port_ctx *vif_plug_port_ctx = build_port_ctx( - vif_plug, PLUG_OP_CREATE, vif_plug_ctx_in, pb, NULL, NULL); - - if (!vif_plug_port_prepare(vif_plug, - &vif_plug_port_ctx->vif_plug_port_ctx_in, - &vif_plug_port_ctx->vif_plug_port_ctx_out)) { - static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); - VLOG_INFO_RL(&rl, - "Not updating lport %s on direction from VIF plug " - "provider.", - pb->logical_port); - destroy_port_ctx(vif_plug_port_ctx); - return true; - } - - if (strcmp(lbinding->iface->name, + if (strcmp(iface_rec->name, vif_plug_port_ctx->vif_plug_port_ctx_out.name)) { VLOG_WARN("Attempt of incompatible change to existing " "port detected, please recreate port: %s", @@ -386,7 +381,7 @@ consider_plug_lport_update__(const struct vif_plug_class *vif_plug, return false; } VLOG_DBG("updating iface for: %s", pb->logical_port); - transact_update_port(lbinding->iface, vif_plug_ctx_in, vif_plug_ctx_out, + transact_update_port(iface_rec, vif_plug_ctx_in, vif_plug_ctx_out, vif_plug_port_ctx, iface_external_ids, get_plug_mtu_request(&pb->options)); @@ -438,13 +433,45 @@ consider_plug_lport(const struct sbrec_port_binding *pb, UUID_ARGS(&lbinding->iface->header_.uuid)); return false; } + struct vif_plug_port_ctx *vif_plug_port_ctx = NULL; + if (!consider_plug_lport__(vif_plug, pb, &vif_plug_port_ctx, + vif_plug_ctx_in)) { + return false; + } + ret = consider_plug_lport_update__(vif_plug, &iface_external_ids, - pb, lbinding, vif_plug_ctx_in, + pb, lbinding->iface, + vif_plug_port_ctx, + vif_plug_ctx_in, vif_plug_ctx_out); } else { - ret = consider_plug_lport_create__(vif_plug, &iface_external_ids, - pb, vif_plug_ctx_in, - vif_plug_ctx_out); + struct vif_plug_port_ctx *vif_plug_port_ctx = NULL; + if (!consider_plug_lport__(vif_plug, pb, &vif_plug_port_ctx, + vif_plug_ctx_in)) { + return false; + } + + const struct ovsrec_interface *iface_rec = + iface_lookup_by_name(vif_plug_ctx_in->ovsrec_interface_by_name, + vif_plug_port_ctx->vif_plug_port_ctx_out.name); + if (iface_rec && + smap_get(&iface_rec->external_ids, "iface-id") && + smap_get(&iface_rec->external_ids, + OVN_PLUGGED_EXT_ID) && + is_iface_in_int_bridge(iface_rec, vif_plug_ctx_in->br_int)) { + + ret = consider_plug_lport_update__(vif_plug, + &iface_external_ids, + pb, iface_rec, + vif_plug_port_ctx, + vif_plug_ctx_in, + vif_plug_ctx_out); + } else { + ret = consider_plug_lport_create__(&iface_external_ids, pb, + vif_plug_port_ctx, + vif_plug_ctx_in, + vif_plug_ctx_out); + } } } diff --git a/controller/vif-plug.h b/controller/vif-plug.h index 7a1978e38..0fc7219c4 100644 --- a/controller/vif-plug.h +++ b/controller/vif-plug.h @@ -34,6 +34,7 @@ struct vif_plug_ctx_in { struct ovsdb_idl_index *sbrec_port_binding_by_name; struct ovsdb_idl_index *sbrec_port_binding_by_requested_chassis; struct ovsdb_idl_index *ovsrec_port_by_interfaces; + struct ovsdb_idl_index *ovsrec_interface_by_name; const struct ovsrec_open_vswitch_table *ovs_table; const struct ovsrec_bridge *br_int; const struct ovsrec_interface_table *iface_table; diff --git a/tests/ovn.at b/tests/ovn.at index acf18c4e0..01064a37f 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -38924,3 +38924,56 @@ OVN_CHECK_PACKETS([hv/vif1-tx.pcap], [expected-vif1]) AT_CLEANUP ]) + +OVN_FOR_EACH_NORTHD([ +AT_SETUP([ovn-controller - vif-plug transaction failures]) +AT_KEYWORDS([vif-plug]) + +ovn_start + +net_add n1 +sim_add hv1 +ovs-vsctl add-br br-phys +ovn_attach n1 br-phys 192.168.0.1 +ovn-appctl vlog/set dbg + +sim_add hv2 +ovs-vsctl add-br br-phys +ovn_attach n1 br-phys 192.168.0.2 +ovn-appctl vlog/set dbg + +check ovn-nbctl ls-add lsw0 + +check ovn-nbctl lsp-add lsw0 lsp1 +check ovn-nbctl lsp-set-addresses lsp1 "f0:00:00:00:00:01 172.16.0.101" + +sleep_ovs hv1 + +# This used to cause Transaction failures in ovsdb until ofport is created. +check ovn-nbctl lsp-set-options lsp1 \ + requested-chassis=hv1 \ + vif-plug-type=dummy \ + vif-plug-mtu-request=420 + +check ovn-nbctl lsp-add lsw0 lsp2 +check ovn-nbctl lsp-set-addresses lsp2 "f0:00:00:00:00:02 172.16.0.102" + +sleep_ovs hv2 + +check ovn-nbctl lsp-set-options lsp2 \ + requested-chassis=hv2 \ + vif-plug-type=dummy \ + vif-plug-mtu-request=420 + +wake_up_ovs hv1 +wait_for_ports_up lsp1 + +# Exit ovn-controller while last transaction to ovsdb is not completed +as hv2 +OVS_APP_EXIT_AND_WAIT([ovn-controller]) +wake_up_ovs hv2 +OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) + +OVN_CLEANUP([hv1]) +AT_CLEANUP +])