Change in osmo-hlr[master]: osmo-hlr: allow configuring db path from cfg file

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Wed May 8 04:12:38 UTC 2019


Neels Hofmeyr has submitted this change and it was merged. ( https://gerrit.osmocom.org/13586 )

Change subject: osmo-hlr: allow configuring db path from cfg file
......................................................................

osmo-hlr: allow configuring db path from cfg file

So far, the cmdline argument was the only way to set a database config file.
Add a similar config to VTY as 'hlr' / 'database'. The cmdline arg is stronger
than the 'database' cfg item. DB is not reloaded from VTY command.

Change-Id: I87b8673324e1e6225afb758fb4963ff3279ea3d8
---
M src/hlr.c
M src/hlr.h
M src/hlr_vty.c
M tests/test_nodes.vty
4 files changed, 25 insertions(+), 3 deletions(-)

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



diff --git a/src/hlr.c b/src/hlr.c
index d9ebaf7..0bea590 100644
--- a/src/hlr.c
+++ b/src/hlr.c
@@ -626,7 +626,7 @@
 	bool db_upgrade;
 } cmdline_opts = {
 	.config_file = "osmo-hlr.cfg",
-	.db_file = "hlr.db",
+	.db_file = NULL,
 	.daemonize = false,
 	.db_upgrade = false,
 };
@@ -741,6 +741,7 @@
 	INIT_LLIST_HEAD(&g_hlr->iuse_list);
 	INIT_LLIST_HEAD(&g_hlr->ss_sessions);
 	INIT_LLIST_HEAD(&g_hlr->ussd_routes);
+	g_hlr->db_file_path = talloc_strdup(g_hlr, HLR_DEFAULT_DB_FILE_PATH);
 
 	/* Init default (call independent) SS session guard timeout value */
 	g_hlr->ncss_guard_timeout = NCSS_GUARD_TIMEOUT_DEFAULT;
@@ -779,9 +780,12 @@
 		exit(1);
 	}
 
-	g_hlr->dbc = db_open(hlr_ctx, cmdline_opts.db_file, true, cmdline_opts.db_upgrade);
+	if (cmdline_opts.db_file)
+		osmo_talloc_replace_string(g_hlr, &g_hlr->db_file_path, cmdline_opts.db_file);
+
+	g_hlr->dbc = db_open(hlr_ctx, g_hlr->db_file_path, true, cmdline_opts.db_upgrade);
 	if (!g_hlr->dbc) {
-		LOGP(DMAIN, LOGL_FATAL, "Error opening database\n");
+		LOGP(DMAIN, LOGL_FATAL, "Error opening database %s\n", osmo_quote_str(g_hlr->db_file_path, -1));
 		exit(1);
 	}
 
diff --git a/src/hlr.h b/src/hlr.h
index 00fa43c..e2e96a4 100644
--- a/src/hlr.h
+++ b/src/hlr.h
@@ -25,6 +25,8 @@
 #include <stdbool.h>
 #include <osmocom/core/linuxlist.h>
 
+#define HLR_DEFAULT_DB_FILE_PATH "hlr.db"
+
 struct hlr_euse;
 
 struct hlr {
@@ -32,6 +34,7 @@
 	struct osmo_gsup_server *gs;
 
 	/* DB context */
+	char *db_file_path;
 	struct db_context *dbc;
 
 	/* Control Interface */
diff --git a/src/hlr_vty.c b/src/hlr_vty.c
index d0a623a..e4cc4be 100644
--- a/src/hlr_vty.c
+++ b/src/hlr_vty.c
@@ -74,6 +74,8 @@
 	vty_out(vty, "hlr%s", VTY_NEWLINE);
 	if (g_hlr->store_imei)
 		vty_out(vty, " store-imei%s", VTY_NEWLINE);
+	if (g_hlr->db_file_path && strcmp(g_hlr->db_file_path, HLR_DEFAULT_DB_FILE_PATH))
+		vty_out(vty, " database %s%s", g_hlr->db_file_path, VTY_NEWLINE);
 	return CMD_SUCCESS;
 }
 
@@ -224,6 +226,15 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(cfg_database, cfg_database_cmd,
+	"database PATH",
+	"Set the path to the HLR database file\n"
+	"Relative or absolute file system path to the database file (default is '" HLR_DEFAULT_DB_FILE_PATH "')\n")
+{
+	osmo_talloc_replace_string(g_hlr, &g_hlr->db_file_path, argv[0]);
+	return CMD_SUCCESS;
+}
+
 struct cmd_node euse_node = {
 	EUSE_NODE,
 	"%s(config-hlr-euse)# ",
@@ -380,6 +391,8 @@
 
 	install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd);
 
+	install_element(HLR_NODE, &cfg_database_cmd);
+
 	install_element(HLR_NODE, &cfg_euse_cmd);
 	install_element(HLR_NODE, &cfg_no_euse_cmd);
 	install_node(&euse_node, config_write_euse);
diff --git a/tests/test_nodes.vty b/tests/test_nodes.vty
index d90fa70..a4e53db 100644
--- a/tests/test_nodes.vty
+++ b/tests/test_nodes.vty
@@ -75,6 +75,7 @@
   exit
   end
   gsup
+  database PATH
   euse NAME
   no euse NAME
   ussd route prefix PREFIX internal (own-msisdn|own-imsi)
@@ -124,6 +125,7 @@
 ...
 hlr
  store-imei
+ database hlr_vty_test.db
  gsup
   bind ip 127.0.0.1
  ussd route prefix *#100# internal own-msisdn

-- 
To view, visit https://gerrit.osmocom.org/13586
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I87b8673324e1e6225afb758fb4963ff3279ea3d8
Gerrit-Change-Number: 13586
Gerrit-PatchSet: 5
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-CC: Vadim Yanitskiy <axilirator at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190508/0c9a1488/attachment.html>


More information about the gerrit-log mailing list