[MERGED] osmo-msc[master]: dissolve libcommon: move talloc ctx into msc_main.c, drop ta...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu Mar 22 17:27:44 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: dissolve libcommon: move talloc ctx into msc_main.c, drop talloc_ctx.c
......................................................................


dissolve libcommon: move talloc ctx into msc_main.c, drop talloc_ctx.c

Drop tall_bsc_ctx; in mncc_sock_init(), talloc the mncc_sock_state from
gsm_network.

In tests or utils, move from using an extern tall_bsc_ctx to a local root
context pointer.

Change-Id: I92c252be1d1e7634f1653de47d37c99d77d9501c
---
M include/osmocom/msc/gsm_data.h
M include/osmocom/msc/gsup_client.h
M src/libcommon/Makefile.am
M src/libcommon/gsup_client.c
M src/libcommon/gsup_test_client.c
D src/libcommon/talloc_ctx.c
M src/libmsc/mncc_sock.c
M src/libvlr/vlr.c
M src/osmo-msc/msc_main.c
M tests/msc_vlr/msc_vlr_tests.c
10 files changed, 31 insertions(+), 64 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/msc/gsm_data.h b/include/osmocom/msc/gsm_data.h
index 2d1d20c..9b6e4e4 100644
--- a/include/osmocom/msc/gsm_data.h
+++ b/include/osmocom/msc/gsm_data.h
@@ -359,8 +359,6 @@
 	char text[SMS_TEXT_SIZE];
 };
 
-extern void talloc_ctx_init(void *ctx_root);
-
 extern void *tall_bsc_ctx;
 extern int ipacc_rtp_direct;
 
diff --git a/include/osmocom/msc/gsup_client.h b/include/osmocom/msc/gsup_client.h
index ce065a6..59e650f 100644
--- a/include/osmocom/msc/gsup_client.h
+++ b/include/osmocom/msc/gsup_client.h
@@ -54,7 +54,8 @@
 	int got_ipa_pong;
 };
 
-struct gsup_client *gsup_client_create(const char *unit_name,
+struct gsup_client *gsup_client_create(void *talloc_ctx,
+				       const char *unit_name,
 				       const char *ip_addr,
 				       unsigned int tcp_port,
 				       gsup_client_read_cb_t read_cb,
diff --git a/src/libcommon/Makefile.am b/src/libcommon/Makefile.am
index 5bd1c2f..dff0be3 100644
--- a/src/libcommon/Makefile.am
+++ b/src/libcommon/Makefile.am
@@ -23,7 +23,6 @@
 	gsm_data.c \
 	gsup_client.c \
 	oap_client.c \
-	talloc_ctx.c \
 	gsm_subscriber_base.c \
 	$(NULL)
 
diff --git a/src/libcommon/gsup_client.c b/src/libcommon/gsup_client.c
index 0335e21..9051b31 100644
--- a/src/libcommon/gsup_client.c
+++ b/src/libcommon/gsup_client.c
@@ -265,7 +265,8 @@
 	gsup_client_send_ping(gsupc);
 }
 
-struct gsup_client *gsup_client_create(const char *unit_name,
+struct gsup_client *gsup_client_create(void *talloc_ctx,
+				       const char *unit_name,
 				       const char *ip_addr,
 				       unsigned int tcp_port,
 				       gsup_client_read_cb_t read_cb,
@@ -274,7 +275,7 @@
 	struct gsup_client *gsupc;
 	int rc;
 
-	gsupc = talloc_zero(tall_bsc_ctx, struct gsup_client);
+	gsupc = talloc_zero(talloc_ctx, struct gsup_client);
 	OSMO_ASSERT(gsupc);
 
 	/* struct ipaccess_unit has a non-const unit_name, so let's copy to be
diff --git a/src/libcommon/gsup_test_client.c b/src/libcommon/gsup_test_client.c
index 3e88689..add98e4 100644
--- a/src/libcommon/gsup_test_client.c
+++ b/src/libcommon/gsup_test_client.c
@@ -275,8 +275,6 @@
 	}
 }
 
-void *tall_bsc_ctx = NULL;
-
 /* default categories */
 static struct log_info_cat default_categories[] = {
 };
@@ -294,7 +292,7 @@
 
 	osmo_init_logging(&gsup_test_client_log_info);
 
-	g_gc = gsup_client_create("GSUPTEST", server_host, server_port,
+	g_gc = gsup_client_create(NULL, "GSUPTEST", server_host, server_port,
 				  gsupc_read_cb, NULL);
 
 
diff --git a/src/libcommon/talloc_ctx.c b/src/libcommon/talloc_ctx.c
deleted file mode 100644
index ccda0d0..0000000
--- a/src/libcommon/talloc_ctx.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/* OpenBSC allocation contexts initialization code */
-/* (C) 2011-2016 by sysmocom s.f.m.c. GmbH <info at sysmocom.de>
- * All Rights Reserved
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include <osmocom/core/talloc.h>
-#include <osmocom/core/msgb.h>
-
-extern void *tall_bsc_ctx;
-extern void *tall_gsms_ctx;
-extern void *tall_subscr_ctx;
-extern void *tall_call_ctx;
-extern void *tall_sigh_ctx;
-extern void *tall_trans_ctx;
-
-void talloc_ctx_init(void *ctx_root)
-{
-	msgb_talloc_ctx_init(ctx_root, 0);
-	tall_gsms_ctx = talloc_named_const(ctx_root, 0, "sms");
-	tall_subscr_ctx = talloc_named_const(ctx_root, 0, "subscriber");
-	tall_call_ctx = talloc_named_const(ctx_root, 0, "gsm_call");
-	tall_sigh_ctx = talloc_named_const(ctx_root, 0, "signal_handler");
-	tall_trans_ctx = talloc_named_const(ctx_root, 0, "transaction");
-}
diff --git a/src/libmsc/mncc_sock.c b/src/libmsc/mncc_sock.c
index 14613ca..74ea9d2 100644
--- a/src/libmsc/mncc_sock.c
+++ b/src/libmsc/mncc_sock.c
@@ -284,7 +284,7 @@
 	struct osmo_fd *bfd;
 	int rc;
 
-	state = talloc_zero(tall_bsc_ctx, struct mncc_sock_state);
+	state = talloc_zero(net, struct mncc_sock_state);
 	if (!state)
 		return -ENOMEM;
 
diff --git a/src/libvlr/vlr.c b/src/libvlr/vlr.c
index f73eeb4..01e7ee1 100644
--- a/src/libvlr/vlr.c
+++ b/src/libvlr/vlr.c
@@ -1040,7 +1040,7 @@
 {
 	OSMO_ASSERT(vlr);
 
-	vlr->gsup_client = gsup_client_create(gsup_unit_name,
+	vlr->gsup_client = gsup_client_create(vlr, gsup_unit_name,
 					      gsup_server_addr_str,
 					      gsup_server_port,
 					      &vlr_gsupc_read_cb, NULL);
diff --git a/src/osmo-msc/msc_main.c b/src/osmo-msc/msc_main.c
index 1cf2642..2b1a8c7 100644
--- a/src/osmo-msc/msc_main.c
+++ b/src/osmo-msc/msc_main.c
@@ -513,6 +513,10 @@
 	.num_cat = ARRAY_SIZE(msc_default_categories),
 };
 
+extern void *tall_gsms_ctx;
+extern void *tall_call_ctx;
+extern void *tall_trans_ctx;
+
 int main(int argc, char **argv)
 {
 	int rc;
@@ -520,9 +524,13 @@
 	msc_vty_info.copyright	= osmomsc_copyright;
 
 	tall_msc_ctx = talloc_named_const(NULL, 1, "osmo_msc");
-	talloc_ctx_init(tall_msc_ctx);
 	msc_vty_info.tall_ctx = tall_msc_ctx;
 
+	msgb_talloc_ctx_init(tall_msc_ctx, 0);
+	tall_gsms_ctx = talloc_named_const(tall_msc_ctx, 0, "sms");
+	tall_call_ctx = talloc_named_const(tall_msc_ctx, 0, "gsm_call");
+	tall_trans_ctx = talloc_named_const(tall_msc_ctx, 0, "transaction");
+
 	osmo_init_logging(&log_info);
 	osmo_stats_init(tall_msc_ctx);
 
diff --git a/tests/msc_vlr/msc_vlr_tests.c b/tests/msc_vlr/msc_vlr_tests.c
index 4c51790..709355c 100644
--- a/tests/msc_vlr/msc_vlr_tests.c
+++ b/tests/msc_vlr/msc_vlr_tests.c
@@ -45,6 +45,8 @@
 
 #include "msc_vlr_tests.h"
 
+void *msc_vlr_tests_ctx = NULL;
+
 bool _log_lines = false;
 
 struct gsm_network *net = NULL;
@@ -472,8 +474,6 @@
 	.num_cat = ARRAY_SIZE(test_categories),
 };
 
-extern void *tall_bsc_ctx;
-
 int mncc_recv(struct gsm_network *net, struct msgb *msg)
 {
 	struct gsm_mncc *mncc = (void*)msg->data;
@@ -513,7 +513,7 @@
 			  struct oap_client_config *oap_config)
 {
 	struct gsup_client *gsupc;
-	gsupc = talloc_zero(tall_bsc_ctx, struct gsup_client);
+	gsupc = talloc_zero(msc_vlr_tests_ctx, struct gsup_client);
 	OSMO_ASSERT(gsupc);
 	return gsupc;
 }
@@ -805,12 +805,12 @@
 	fake_time_passes(0, 0);
 }
 
-static void check_talloc(void *msgb_ctx, void *tall_bsc_ctx, int expected_blocks)
+static void check_talloc(void *msgb_ctx, void *msc_vlr_tests_ctx, int expected_blocks)
 {
 	talloc_report_full(msgb_ctx, stderr);
-	/* Expecting these to stick around in tall_bsc_ctx:
+	/* Expecting these to stick around in msc_vlr_tests_ctx:
 full talloc report on 'msgb' (total      0 bytes in   1 blocks)
-talloc_total_blocks(tall_bsc_ctx) == 7
+talloc_total_blocks(msc_vlr_tests_ctx) == 7
 full talloc report on 'subscr_conn_test_ctx' (total   2642 bytes in   8 blocks)
     struct gsup_client             contains    248 bytes in   1 blocks (ref 0) 0x61300000dee0
     struct gsm_network             contains   2023 bytes in   6 blocks (ref 0) 0x61700000fce0
@@ -820,9 +820,9 @@
     msgb                           contains      0 bytes in   1 blocks (ref 0) 0x60800000bf80
 	*/
 	fprintf(stderr, "talloc_total_blocks(tall_bsc_ctx) == %zu\n",
-		talloc_total_blocks(tall_bsc_ctx));
-	if (talloc_total_blocks(tall_bsc_ctx) != expected_blocks)
-		talloc_report_full(tall_bsc_ctx, stderr);
+		talloc_total_blocks(msc_vlr_tests_ctx));
+	if (talloc_total_blocks(msc_vlr_tests_ctx) != expected_blocks)
+		talloc_report_full(msc_vlr_tests_ctx, stderr);
 	fprintf(stderr, "\n");
 }
 
@@ -895,7 +895,7 @@
 		if (cmdline_opts.verbose)
 			fprintf(stderr, "(test nr %d)\n", test_nr + 1);
 
-		check_talloc(msgb_ctx, tall_bsc_ctx, 7);
+		check_talloc(msgb_ctx, msc_vlr_tests_ctx, 7);
 	}
 }
 
@@ -926,8 +926,8 @@
 {
 	handle_options(argc, argv);
 
-	tall_bsc_ctx = talloc_named_const(NULL, 0, "subscr_conn_test_ctx");
-	msgb_ctx = msgb_talloc_ctx_init(tall_bsc_ctx, 0);
+	msc_vlr_tests_ctx = talloc_named_const(NULL, 0, "msc_vlr_tests_ctx");
+	msgb_ctx = msgb_talloc_ctx_init(msc_vlr_tests_ctx, 0);
 	osmo_init_logging(&info);
 
 	_log_lines = cmdline_opts.verbose;
@@ -941,7 +941,7 @@
 	if (cmdline_opts.verbose)
 		log_set_category_filter(osmo_stderr_target, DLSMS, 1, LOGL_DEBUG);
 
-	net = test_net(tall_bsc_ctx);
+	net = test_net(msc_vlr_tests_ctx);
 
 	osmo_fsm_log_addr(false);
 
@@ -969,6 +969,6 @@
 
 	printf("Done\n");
 
-	check_talloc(msgb_ctx, tall_bsc_ctx, 7);
+	check_talloc(msgb_ctx, msc_vlr_tests_ctx, 7);
 	return 0;
 }

-- 
To view, visit https://gerrit.osmocom.org/7450
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I92c252be1d1e7634f1653de47d37c99d77d9501c
Gerrit-PatchSet: 1
Gerrit-Project: osmo-msc
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list