From patchwork Wed Mar 10 00:24:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 1450253 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.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (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 ozlabs.org (Postfix) with ESMTPS id 4DwCWw4Bknz9sVt for ; Wed, 10 Mar 2021 11:25:00 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 6D68B43137; Wed, 10 Mar 2021 00:24:57 +0000 (UTC) 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 hu____33BvB7; Wed, 10 Mar 2021 00:24:56 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTP id 7A202430EE; Wed, 10 Mar 2021 00:24:55 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id B2BDEC0015; Wed, 10 Mar 2021 00:24:53 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id C6813C000A for ; Wed, 10 Mar 2021 00:24:50 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id A590A4EBBF for ; Wed, 10 Mar 2021 00:24:50 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cRvWtX6Xv1r2 for ; Wed, 10 Mar 2021 00:24:49 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by smtp4.osuosl.org (Postfix) with ESMTPS id 7C3594C642 for ; Wed, 10 Mar 2021 00:24:49 +0000 (UTC) X-Originating-IP: 75.54.222.30 Received: from sigfpe.attlocal.net (75-54-222-30.lightspeed.rdcyca.sbcglobal.net [75.54.222.30]) (Authenticated sender: blp@ovn.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 8C3F220002; Wed, 10 Mar 2021 00:24:45 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Tue, 9 Mar 2021 16:24:38 -0800 Message-Id: <20210310002440.3449903-1-blp@ovn.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Cc: Ben Pfaff Subject: [ovs-dev] [PATCH ovn 1/3] ovn-northd-ddlog: Fix memory leaks. 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" ddlog_delta_get_table() returns data that must be freed, but the code in northd_update_probe_interval() did not do that. This fixes it. In addition, the accumulated deltas weren't freed when the daemon exits. This doesn't really matter but it's cleaner to do so, so this commit also does that. Signed-off-by: Ben Pfaff Reported-by: Numan Siddique Acked-by: Numan Siddique --- northd/ovn-northd-ddlog.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/northd/ovn-northd-ddlog.c b/northd/ovn-northd-ddlog.c index 238987410239..be3de5cee29e 100644 --- a/northd/ovn-northd-ddlog.c +++ b/northd/ovn-northd-ddlog.c @@ -577,6 +577,7 @@ northd_update_probe_interval(struct northd_ctx *nb, struct northd_ctx *sb) table_id tid = ddlog_get_table_id("Northd_Probe_Interval"); ddlog_delta *probe_delta = ddlog_delta_get_table(delta, tid); ddlog_delta_enumerate(probe_delta, northd_update_probe_interval_cb, (uintptr_t) &probe_interval); + ddlog_free_delta(probe_delta); ovsdb_cs_set_probe_interval(nb->cs, probe_interval); ovsdb_cs_set_probe_interval(sb->cs, probe_interval); @@ -1230,6 +1231,7 @@ main(int argc, char *argv[]) northd_ctx_destroy(nb_ctx); northd_ctx_destroy(sb_ctx); + ddlog_free_delta(delta); ddlog_stop(ddlog); if (replay_fd >= 0) { From patchwork Wed Mar 10 00:24:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 1450252 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.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (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 ozlabs.org (Postfix) with ESMTPS id 4DwCWr728Gz9sVt for ; Wed, 10 Mar 2021 11:24:56 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id DAFF3430B5; Wed, 10 Mar 2021 00:24:54 +0000 (UTC) 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 TKg-UTODqVTY; Wed, 10 Mar 2021 00:24:54 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTP id 2560142F3A; Wed, 10 Mar 2021 00:24:53 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id DCF2EC000A; Wed, 10 Mar 2021 00:24:52 +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 B658AC0001 for ; Wed, 10 Mar 2021 00:24:50 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 90C0442FBF for ; Wed, 10 Mar 2021 00:24:50 +0000 (UTC) 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 g3pGy4ZhNn6o for ; Wed, 10 Mar 2021 00:24:49 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by smtp2.osuosl.org (Postfix) with ESMTPS id 8AF0842F3A for ; Wed, 10 Mar 2021 00:24:49 +0000 (UTC) X-Originating-IP: 75.54.222.30 Received: from sigfpe.attlocal.net (75-54-222-30.lightspeed.rdcyca.sbcglobal.net [75.54.222.30]) (Authenticated sender: blp@ovn.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 3434320004; Wed, 10 Mar 2021 00:24:46 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Tue, 9 Mar 2021 16:24:39 -0800 Message-Id: <20210310002440.3449903-2-blp@ovn.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210310002440.3449903-1-blp@ovn.org> References: <20210310002440.3449903-1-blp@ovn.org> MIME-Version: 1.0 Cc: Ben Pfaff Subject: [ovs-dev] [PATCH ovn 2/3] ovn-northd-ddlog: Remove deltas from output tables when we use them. 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" Otherwise we will see these deltas every time we go through the main loop, which is harmless but unnecessary. Signed-off-by: Ben Pfaff --- northd/ovn-northd-ddlog.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/northd/ovn-northd-ddlog.c b/northd/ovn-northd-ddlog.c index be3de5cee29e..80d3aa8d8aeb 100644 --- a/northd/ovn-northd-ddlog.c +++ b/northd/ovn-northd-ddlog.c @@ -575,7 +575,7 @@ northd_update_probe_interval(struct northd_ctx *nb, struct northd_ctx *sb) * database. */ int probe_interval = 0; table_id tid = ddlog_get_table_id("Northd_Probe_Interval"); - ddlog_delta *probe_delta = ddlog_delta_get_table(delta, tid); + ddlog_delta *probe_delta = ddlog_delta_remove_table(delta, tid); ddlog_delta_enumerate(probe_delta, northd_update_probe_interval_cb, (uintptr_t) &probe_interval); ddlog_free_delta(probe_delta); @@ -961,7 +961,7 @@ get_database_ops(struct northd_ctx *ctx) int64_t new_sb_cfg = old_sb_cfg; if (ctx->has_timestamp_columns) { table_id sb_cfg_tid = ddlog_get_table_id("SbCfg"); - ddlog_delta *sb_cfg_delta = ddlog_delta_get_table(delta, sb_cfg_tid); + ddlog_delta *sb_cfg_delta = ddlog_delta_remove_table(delta, sb_cfg_tid); ddlog_delta_enumerate(sb_cfg_delta, northd_update_sb_cfg_cb, (uintptr_t) &new_sb_cfg); ddlog_free_delta(sb_cfg_delta); From patchwork Wed Mar 10 00:24:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 1450254 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.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (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 ozlabs.org (Postfix) with ESMTPS id 4DwCWz45wpz9sVt for ; Wed, 10 Mar 2021 11:25:03 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 4CE3C4314F; Wed, 10 Mar 2021 00:24:59 +0000 (UTC) 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 NayXqcTxb8bI; Wed, 10 Mar 2021 00:24:57 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTP id A3BF643123; Wed, 10 Mar 2021 00:24:56 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7FA2FC0019; Wed, 10 Mar 2021 00:24:54 +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 7ACBFC0001 for ; Wed, 10 Mar 2021 00:24:52 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 5C84C6F602 for ; Wed, 10 Mar 2021 00:24:52 +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 BU4XUREGb_Et for ; Wed, 10 Mar 2021 00:24:51 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by smtp3.osuosl.org (Postfix) with ESMTPS id 20440605BD for ; Wed, 10 Mar 2021 00:24:50 +0000 (UTC) X-Originating-IP: 75.54.222.30 Received: from sigfpe.attlocal.net (75-54-222-30.lightspeed.rdcyca.sbcglobal.net [75.54.222.30]) (Authenticated sender: blp@ovn.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 886DB20005; Wed, 10 Mar 2021 00:24:48 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Tue, 9 Mar 2021 16:24:40 -0800 Message-Id: <20210310002440.3449903-3-blp@ovn.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210310002440.3449903-1-blp@ovn.org> References: <20210310002440.3449903-1-blp@ovn.org> MIME-Version: 1.0 Cc: Ben Pfaff Subject: [ovs-dev] [PATCH ovn 3/3] ovn-northd-ddlog: Move 'delta' global variable into northd_ctx. 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" Seems overall like a cleanup. Signed-off-by: Ben Pfaff --- northd/ovn-northd-ddlog.c | 58 ++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/northd/ovn-northd-ddlog.c b/northd/ovn-northd-ddlog.c index 80d3aa8d8aeb..4efdfa38749a 100644 --- a/northd/ovn-northd-ddlog.c +++ b/northd/ovn-northd-ddlog.c @@ -85,27 +85,29 @@ static void init_table_ids(void) NB_CFG_TIMESTAMP_ID = ddlog_get_table_id("NbCfgTimestamp"); } -/* - * Accumulates DDlog delta to be sent to OVSDB. - * - * FIXME: There is currently no global northd state descriptor shared by NB and - * SB connections. We should probably introduce it and move this variable there - * instead of declaring it as a global variable. - */ -static ddlog_delta *delta; - - struct northd_ctx { + /* Shared between NB and SB database contexts. */ ddlog_prog ddlog; - char *prefix; + ddlog_delta *delta; /* Accumulated delta to send to OVSDB. */ + + /* Database info. + * + * The '*_relations' vectors are arrays of strings that contain DDlog + * relation names, terminated by a null pointer. 'prefix' is the prefix + * for the DDlog module that contains the relations. */ + char *prefix; /* e.g. "OVN_Northbound::" */ const char **input_relations; const char **output_relations; const char **output_only_relations; + /* Whether this is the database that has the 'nb_cfg_timestamp' and + * 'sb_cfg_timestamp' columns in NB_Global. True for the northbound + * database, false for the southbound database. */ bool has_timestamp_columns; + /* OVSDB connection. */ struct ovsdb_cs *cs; - struct json *request_id; + struct json *request_id; /* JSON request ID for outstanding txn if any. */ enum { /* Initial state, before the output-only data (if any) has been * requested. */ @@ -120,7 +122,7 @@ struct northd_ctx { } state; /* Database info. */ - const char *db_name; + const char *db_name; /* e.g. "OVN_Northbound". */ struct json *output_only_data; const char *lock_name; /* Name of lock we need, NULL if none. */ bool paused; @@ -154,7 +156,7 @@ static struct northd_ctx * northd_ctx_create(const char *server, const char *database, const char *unixctl_command_prefix, const char *lock_name, - ddlog_prog ddlog, + ddlog_prog ddlog, ddlog_delta *delta, const char **input_relations, const char **output_relations, const char **output_only_relations) @@ -162,6 +164,7 @@ northd_ctx_create(const char *server, const char *database, struct northd_ctx *ctx = xmalloc(sizeof *ctx); *ctx = (struct northd_ctx) { .ddlog = ddlog, + .delta = delta, .prefix = xasprintf("%s::", database), .input_relations = input_relations, .output_relations = output_relations, @@ -317,7 +320,7 @@ warning_cb(uintptr_t arg OVS_UNUSED, } static int -ddlog_commit(ddlog_prog ddlog) +ddlog_commit(ddlog_prog ddlog, ddlog_delta *delta) { ddlog_delta *new_delta = ddlog_transaction_commit_dump_changes(ddlog); if (!delta) { @@ -432,7 +435,7 @@ northd_parse_update(struct northd_ctx *ctx, } /* Commit changes to DDlog. */ - if (ddlog_commit(ctx->ddlog)) { + if (ddlog_commit(ctx->ddlog, ctx->delta)) { goto error; } old_nb_cfg = new_nb_cfg; @@ -575,7 +578,7 @@ northd_update_probe_interval(struct northd_ctx *nb, struct northd_ctx *sb) * database. */ int probe_interval = 0; table_id tid = ddlog_get_table_id("Northd_Probe_Interval"); - ddlog_delta *probe_delta = ddlog_delta_remove_table(delta, tid); + ddlog_delta *probe_delta = ddlog_delta_remove_table(nb->delta, tid); ddlog_delta_enumerate(probe_delta, northd_update_probe_interval_cb, (uintptr_t) &probe_interval); ddlog_free_delta(probe_delta); @@ -596,7 +599,7 @@ northd_wait(struct northd_ctx *ctx) /* Generate OVSDB update command for delta-plus, delta-minus, and delta-update * tables. */ static void -ddlog_table_update_deltas(struct ds *ds, ddlog_prog ddlog, +ddlog_table_update_deltas(struct ds *ds, ddlog_prog ddlog, ddlog_delta *delta, const char *db, const char *table) { int error; @@ -620,7 +623,7 @@ ddlog_table_update_deltas(struct ds *ds, ddlog_prog ddlog, /* Generate OVSDB update command for a output-only table. */ static void -ddlog_table_update_output(struct ds *ds, ddlog_prog ddlog, +ddlog_table_update_output(struct ds *ds, ddlog_prog ddlog, ddlog_delta *delta, const char *db, const char *table) { int error; @@ -858,7 +861,8 @@ get_database_ops(struct northd_ctx *ctx) size_t start_len = ops_s.length; for (const char **p = ctx->output_relations; *p; p++) { - ddlog_table_update_deltas(&ops_s, ctx->ddlog, ctx->db_name, *p); + ddlog_table_update_deltas(&ops_s, ctx->ddlog, ctx->delta, + ctx->db_name, *p); } if (ctx->output_only_data) { @@ -937,7 +941,8 @@ get_database_ops(struct northd_ctx *ctx) /* Discard any queued output to this table, since we just * did a full sync to it. */ struct ds tmp = DS_EMPTY_INITIALIZER; - ddlog_table_update_output(&tmp, ctx->ddlog, ctx->db_name, table); + ddlog_table_update_output(&tmp, ctx->ddlog, ctx->delta, + ctx->db_name, table); ds_destroy(&tmp); } @@ -945,7 +950,8 @@ get_database_ops(struct northd_ctx *ctx) ctx->output_only_data = NULL; } else { for (const char **p = ctx->output_only_relations; *p; p++) { - ddlog_table_update_output(&ops_s, ctx->ddlog, ctx->db_name, *p); + ddlog_table_update_output(&ops_s, ctx->ddlog, ctx->delta, + ctx->db_name, *p); } } @@ -961,7 +967,8 @@ get_database_ops(struct northd_ctx *ctx) int64_t new_sb_cfg = old_sb_cfg; if (ctx->has_timestamp_columns) { table_id sb_cfg_tid = ddlog_get_table_id("SbCfg"); - ddlog_delta *sb_cfg_delta = ddlog_delta_remove_table(delta, sb_cfg_tid); + ddlog_delta *sb_cfg_delta = ddlog_delta_remove_table(ctx->delta, + sb_cfg_tid); ddlog_delta_enumerate(sb_cfg_delta, northd_update_sb_cfg_cb, (uintptr_t) &new_sb_cfg); ddlog_free_delta(sb_cfg_delta); @@ -1135,6 +1142,7 @@ main(int argc, char *argv[]) ddlog_prog ddlog; + ddlog_delta *delta; ddlog = ddlog_run(1, false, ddlog_print_error, &delta); if (!ddlog) { ovs_fatal(0, "DDlog instance could not be created"); @@ -1160,10 +1168,10 @@ main(int argc, char *argv[]) } struct northd_ctx *nb_ctx = northd_ctx_create( - ovnnb_db, "OVN_Northbound", "nb", NULL, ddlog, + ovnnb_db, "OVN_Northbound", "nb", NULL, ddlog, delta, nb_input_relations, nb_output_relations, nb_output_only_relations); struct northd_ctx *sb_ctx = northd_ctx_create( - ovnsb_db, "OVN_Southbound", "sb", "ovn_northd", ddlog, + ovnsb_db, "OVN_Southbound", "sb", "ovn_northd", ddlog, delta, sb_input_relations, sb_output_relations, sb_output_only_relations); unixctl_command_register("pause", "", 0, 0, ovn_northd_pause, sb_ctx);