From patchwork Wed Dec 14 19:02:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frode Nordahl X-Patchwork-Id: 1715910 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::133; helo=smtp2.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=cR6JbgvT; dkim-atps=neutral Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (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 4NXPqv6SzFz23yy for ; Thu, 15 Dec 2022 06:02:19 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id D269E40127; Wed, 14 Dec 2022 19:02:17 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org D269E40127 Authentication-Results: smtp2.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=cR6JbgvT X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aJbqe4z5x3bq; Wed, 14 Dec 2022 19:02:16 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id 7B05840144; Wed, 14 Dec 2022 19:02:15 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 7B05840144 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2CA5CC0033; Wed, 14 Dec 2022 19:02:15 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 01F0EC002D for ; Wed, 14 Dec 2022 19:02:10 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id D7B2B40144 for ; Wed, 14 Dec 2022 19:02:10 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org D7B2B40144 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JZJ_dFQmPmPF for ; Wed, 14 Dec 2022 19:02:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 5DF5F40127 Received: from smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) by smtp2.osuosl.org (Postfix) with ESMTPS id 5DF5F40127 for ; Wed, 14 Dec 2022 19:02:09 +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 D953B435A4 for ; Wed, 14 Dec 2022 19:02:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1671044526; bh=EPyrKOfUt0rP6hsBihMMprYEso0V0UlrvzDEH9iSXzA=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=cR6JbgvTTjSwR5DgN09CKMS8UOevPGWhKbwVxlNfXLr8pZ2ka+mCBQzmPM+ivPqJY ekVTGZ+J8wEXSNM35B9N/tUhcypccpkDnGC3jqjUcmgVHsctMpj3XgnMsKRbIrrctP BuSHUAMPxDknKAqw2piqBqy7we/KlkokA7YoQRuiBOHHiD27HwS3+JqazpYWnuZBFj Jcx2tSu/zDFGF3FabCkrgjlsB65IXQs7Ol163JzY2BL7izUDakVNviHm9Teeh3Erw8 DspFeGGzULSA5N4x2IUSFLwQEh9ThInvhqPmqYf7HYVtF7qroihFtUQWfpUnzl3ne9 HKQEPtK4Ftymg== From: Frode Nordahl To: dev@openvswitch.org Date: Wed, 14 Dec 2022 20:02:05 +0100 Message-Id: <20221214190205.126684-1-frode.nordahl@canonical.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Subject: [ovs-dev] [PATCH ovn] 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: 4adc10f58127e ("Avoid nb_cfg update notification flooding") Signed-off-by: Frode Nordahl --- tests/ovn-sbctl.at | 22 +++++++++++++++++ utilities/ovn-sbctl.c | 57 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 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..761377cdf 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; }; @@ -207,11 +213,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 +237,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 +307,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 +342,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 +477,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]);