From patchwork Wed Dec 14 20:11:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frode Nordahl X-Patchwork-Id: 1715924 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=Q+1WK3RE; dkim-atps=neutral Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NXRMn3jSlz23yr for ; Thu, 15 Dec 2022 07:11:32 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id E9D3281F9C; Wed, 14 Dec 2022 20:11:29 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org E9D3281F9C Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=Q+1WK3RE 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 BzTAw_tCBtLR; Wed, 14 Dec 2022 20:11:28 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id D504F81F96; Wed, 14 Dec 2022 20:11:27 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org D504F81F96 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A959EC0033; Wed, 14 Dec 2022 20:11:27 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 626DAC002D for ; Wed, 14 Dec 2022 20:11:26 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 37A6B81F96 for ; Wed, 14 Dec 2022 20:11:26 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 37A6B81F96 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 QlTxk4unGy2J for ; Wed, 14 Dec 2022 20:11:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 6B8DB81F90 Received: from smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) by smtp1.osuosl.org (Postfix) with ESMTPS id 6B8DB81F90 for ; Wed, 14 Dec 2022 20:11:24 +0000 (UTC) Received: from frode-threadripper.. (ti0189a330-0102.bb.online.no [88.91.31.103]) (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 smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id E5B73435A5 for ; Wed, 14 Dec 2022 20:11:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1671048682; bh=5GXwIGBVd5tipPaR75hHniEaoZOTt2fY1Jo83dKYG2w=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q+1WK3REo1rVI1E2x+KKVxSLLBrNo9Gvq25cYhZITVJS8jhvwGdeGfZa5XgJZnUk/ EygZpyLLgwhAA3aZ3OE6dnAtceiCR3iKY+g14ZwuK4jD/lOpvgskuDieFUBd0wmkkG oSfGj4oHybqilYzxmw3wem3C87lzBmPDqnxjISkh3/B7lhNX6U+G9T6B4yytRjqrsD pwF5MnoSoxNbg+RYmfFz/TQp/GrDNcLdPCkEWm4+4EMZzN4kFvZvrTPg5kfx1zYVzp xcBmV1k5W7eJLuZdDnTM+hqYsZYzVljQYO10C4PtPTDvVwk6pgtrY9o0AJhiyvhib/ T2e13W+OwZY2g== From: Frode Nordahl To: dev@openvswitch.org Date: Wed, 14 Dec 2022 21:11:20 +0100 Message-Id: <20221214201120.1496319-1-frode.nordahl@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221214190205.126684-1-frode.nordahl@canonical.com> References: <20221214190205.126684-1-frode.nordahl@canonical.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn v2] ovn-sbctl: Fix removal of Chassis_Private record on chassis-del. 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" After commit 4adc10f58127e, the ovn-controller will populate both Chassis and Chassis_Private tables on registration. The `ovn-sbctl chassis-del` command exists so that an administrator can manually remove a chassis record when needed. Before this patch any existing Chassis_Private record would be left behind, and this may cause problems for other automation or CMS software. Fixes: 4adc10f58127 ("Avoid nb_cfg update notification flooding") Signed-off-by: Frode Nordahl --- tests/ovn-sbctl.at | 22 ++++++++++++++++ utilities/ovn-sbctl.c | 58 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/tests/ovn-sbctl.at b/tests/ovn-sbctl.at index 1d1eee23e..19ac55c80 100644 --- a/tests/ovn-sbctl.at +++ b/tests/ovn-sbctl.at @@ -93,6 +93,28 @@ AT_CHECK([ovn-sbctl -f csv -d bare --no-headings --columns ip,type list encap | 1.2.3.5,vxlan ]) +AT_CHECK([ovn-sbctl chassis-add ch2 geneve 2.3.4.5]) +ch2_uuid=$(ovn-sbctl -d bare --no-headings --columns _uuid find chassis name=ch2) +ovn-sbctl create Chassis_Private name=ch2 chassis=$ch2_uuid +check_row_count Chassis_Private 1 + +AT_CHECK([ovn-sbctl -f csv -d bare --no-headings --columns ip,type list encap | sort], + [0], [dnl +1.2.3.5,geneve +1.2.3.5,stt +1.2.3.5,vxlan +2.3.4.5,geneve +]) + +AT_CHECK([ovn-sbctl chassis-del ch2]) +AT_CHECK([ovn-sbctl -f csv -d bare --no-headings --columns ip,type list encap | sort], + [0], [dnl +1.2.3.5,geneve +1.2.3.5,stt +1.2.3.5,vxlan +]) +check_row_count Chassis_Private 0 + as ovn-sb OVS_APP_EXIT_AND_WAIT([ovsdb-server]) as diff --git a/utilities/ovn-sbctl.c b/utilities/ovn-sbctl.c index 4d7e7d670..37760805d 100644 --- a/utilities/ovn-sbctl.c +++ b/utilities/ovn-sbctl.c @@ -164,6 +164,8 @@ struct sbctl_context { bool cache_valid; /* Maps from chassis name to struct sbctl_chassis. */ struct shash chassis; + /* Maps from chassis name to struct sbctl_chassis_private. */ + struct shash chassis_private; /* Maps from lport name to struct sbctl_port_binding. */ struct shash port_bindings; }; @@ -179,6 +181,10 @@ struct sbctl_chassis { const struct sbrec_chassis *ch_cfg; }; +struct sbctl_chassis_private { + const struct sbrec_chassis_private *ch_priv; +}; + struct sbctl_port_binding { const struct sbrec_port_binding *bd_cfg; }; @@ -193,6 +199,7 @@ sbctl_context_invalidate_cache(struct ctl_context *ctx) } sbctl_ctx->cache_valid = false; shash_destroy_free_data(&sbctl_ctx->chassis); + shash_destroy_free_data(&sbctl_ctx->chassis_private); shash_destroy_free_data(&sbctl_ctx->port_bindings); } @@ -207,11 +214,13 @@ sbctl_context_get(struct ctl_context *ctx) } const struct sbrec_chassis *chassis_rec; + const struct sbrec_chassis_private *chassis_private_rec; const struct sbrec_port_binding *port_binding_rec; struct sset chassis, port_bindings; sbctl_ctx->cache_valid = true; shash_init(&sbctl_ctx->chassis); + shash_init(&sbctl_ctx->chassis_private); shash_init(&sbctl_ctx->port_bindings); sset_init(&chassis); SBREC_CHASSIS_FOR_EACH(chassis_rec, ctx->idl) { @@ -229,6 +238,25 @@ sbctl_context_get(struct ctl_context *ctx) } sset_destroy(&chassis); + sset_init(&chassis); + SBREC_CHASSIS_PRIVATE_FOR_EACH (chassis_private_rec, ctx->idl) { + struct sbctl_chassis_private *ch_priv; + + if (!sset_add(&chassis, chassis_private_rec->name)) { + VLOG_WARN("database contains duplicate private record for " + "chassis named (%s)", + chassis_rec->name); + continue; + } + + ch_priv = xmalloc(sizeof *ch_priv); + ch_priv->ch_priv = chassis_private_rec; + shash_add(&sbctl_ctx->chassis_private, + chassis_private_rec->name, + ch_priv); + } + sset_destroy(&chassis); + sset_init(&port_bindings); SBREC_PORT_BINDING_FOR_EACH(port_binding_rec, ctx->idl) { struct sbctl_port_binding *bd; @@ -280,6 +308,22 @@ find_chassis(struct ctl_context *ctx, const char *name, bool must_exist) return sbctl_ch; } +static struct sbctl_chassis_private * +find_chassis_private(struct ctl_context *ctx, + const char *name, + bool must_exist) +{ + struct sbctl_context *sbctl_ctx = sbctl_context_get(ctx); + struct sbctl_chassis_private *sbctl_ch_priv = shash_find_data( + &sbctl_ctx->chassis_private, name); + + if (must_exist && !sbctl_ch_priv) { + ctl_error(ctx, "no private record for chassis named %s", name); + } + + return sbctl_ch_priv; +} + static struct sbctl_port_binding * find_port_binding(struct ctl_context *ctx, const char *name, bool must_exist) { @@ -299,6 +343,8 @@ pre_get_info(struct ctl_context *ctx) ovsdb_idl_add_column(ctx->idl, &sbrec_chassis_col_name); ovsdb_idl_add_column(ctx->idl, &sbrec_chassis_col_encaps); + ovsdb_idl_add_column(ctx->idl, &sbrec_chassis_private_col_name); + ovsdb_idl_add_column(ctx->idl, &sbrec_encap_col_type); ovsdb_idl_add_column(ctx->idl, &sbrec_encap_col_ip); @@ -432,6 +478,18 @@ cmd_chassis_del(struct ctl_context *ctx) for (i = 0; i < sbctl_ch->ch_cfg->n_encaps; i++) { sbrec_encap_delete(sbctl_ch->ch_cfg->encaps[i]); } + + struct sbctl_chassis_private *sbctl_ch_priv; + sbctl_ch_priv = find_chassis_private(ctx, ctx->argv[1], false); + if (sbctl_ch_priv) { + if (sbctl_ch_priv->ch_priv) { + sbrec_chassis_private_delete(sbctl_ch_priv->ch_priv); + } + shash_find_and_delete(&sbctl_ctx->chassis_private, + ctx->argv[1]); + free(sbctl_ch_priv); + } + sbrec_chassis_delete(sbctl_ch->ch_cfg); } shash_find_and_delete(&sbctl_ctx->chassis, ctx->argv[1]);