Browse Source

switch from libdbi to lbsqlite3

The choice of libdbi was one of the biggest early mistakes in (back
then) OpenBSC development.  A database abstraction library that
prevents you from using proper prepared statements.  Let's finally
abandon it and use sqlite3 directly, just like we do in osmo-hlr.

I decided to remove the database migration code as it would be relatively
cumbersome to port all of it to direct sqlite3 with prepared statements,
and it is prone to introduction of all kinds of errors.  Since we don't
have a body of older database files and comprehensive migration tests,
it is safer to not offer migration code of uncertain quality.  The last
schema revision (5) was introduced 5 years ago in 2017 (osmo-msc
v1.1.0), so it is considered an exceptionally rare case.  People can
install osmo-msc 1.1.0 through 1.8.0 to upgrade to v5 before using
this new 'direct sqlite3' version of osmo-msc.

Change-Id: Ia334904289f92d014e7bd16b02b3b5817c12c790
Related: OS#5559, OS#5563, OS#5564
changes/14/28114/10
Harald Welte 3 months ago
parent
commit
d43c22ef65
  1. 4
      configure.ac
  2. 7
      contrib/osmo-msc.spec.in
  3. 4
      debian/control
  4. 9
      include/osmocom/msc/db.h
  5. 1227
      src/libmsc/db.c
  6. 4
      src/libmsc/sms_queue.c
  7. 1
      src/osmo-msc/Makefile.am
  8. 3
      src/osmo-msc/msc_main.c
  9. 1
      tests/db_sms/Makefile.am
  10. 2
      tests/db_sms/db_sms_test.c
  11. 1
      tests/sms_queue/Makefile.am

4
configure.ac

@ -110,10 +110,6 @@ fi
AM_CONDITIONAL(BUILD_IU, test "x$osmo_ac_iu" = "xyes")
AC_SUBST(osmo_ac_iu)
dnl checks for header files
AC_HEADER_STDC
AC_CHECK_HEADERS(dbi/dbd.h,,AC_MSG_ERROR(DBI library is not installed))
# Coverage build taken from WebKit's configure.in
AC_MSG_CHECKING([whether to enable code coverage support])
AC_ARG_ENABLE(coverage,

7
contrib/osmo-msc.spec.in

@ -27,13 +27,11 @@ URL: https://osmocom.org/projects/osmomsc
Source: %{name}-%{version}.tar.xz
BuildRequires: autoconf
BuildRequires: automake
BuildRequires: libdbi-drivers-dbd-sqlite3
BuildRequires: libtool
%if 0%{?suse_version}
BuildRequires: systemd-rpm-macros
%endif
BuildRequires: pkgconfig >= 0.20
BuildRequires: pkgconfig(dbi)
BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(libcrypto) >= 0.9.5
BuildRequires: pkgconfig(libosmo-gsup-client) >= 1.4.0
@ -55,11 +53,6 @@ BuildRequires: lksctp-tools-devel
BuildRequires: pkgconfig(libasn1c) >= 0.9.30
BuildRequires: pkgconfig(libosmo-ranap) >= 0.8.0
%endif
%if 0%{?suse_version}
Requires: libdbi-drivers-dbd-sqlite3
%else
Requires: libdbi-dbd-sqlite
%endif
%description
The Mobile Switching Center (MSC) is the heart of 2G/3G

4
debian/control vendored

@ -9,8 +9,6 @@ Build-Depends: debhelper (>=9),
automake,
libtool,
pkg-config,
libdbi-dev,
libdbd-sqlite3,
libsqlite3-dev,
libsctp-dev,
libtalloc-dev,
@ -33,7 +31,7 @@ Homepage: https://osmocom.org/projects/osmomsc
Package: osmo-msc
Architecture: any
Multi-Arch: foreign
Depends: ${misc:Depends}, ${shlibs:Depends}, libdbd-sqlite3
Depends: ${misc:Depends}, ${shlibs:Depends}
Recommends: osmo-mgw
Description: OsmoMSC: Osmocom's Mobile Switching Center for 2G and 3G circuit-switched mobile networks
The Mobile Switching Center (MSC) is the heart of 2G/3G

9
include/osmocom/msc/db.h

@ -1,5 +1,6 @@
/* (C) 2008 by Jan Luebbe <jluebbe@debian.org>
* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2022 by Harald Welte <laforge@osmocom.org>
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
@ -30,7 +31,7 @@ struct gsm_network;
struct gsm_sms;
/* one time initialisation */
int db_init(const char *name);
int db_init(void *ctx, const char *fname, bool enable_sqlite_logging);
int db_prepare(void);
int db_fini(void);
@ -39,12 +40,12 @@ int db_sms_store(struct gsm_sms *sms);
struct gsm_sms *db_sms_get(struct gsm_network *net, unsigned long long id);
struct gsm_sms *db_sms_get_next_unsent(struct gsm_network *net,
unsigned long long min_sms_id,
unsigned int max_failed);
int max_failed);
struct gsm_sms *db_sms_get_next_unsent_rr_msisdn(struct gsm_network *net,
const char *last_msisdn,
unsigned int max_failed);
int max_failed);
struct gsm_sms *db_sms_get_unsent_for_subscr(struct vlr_subscr *vsub,
unsigned int max_failed);
int max_failed);
int db_sms_mark_delivered(struct gsm_sms *sms);
int db_sms_inc_deliver_attempts(struct gsm_sms *sms);
int db_sms_delete_by_msisdn(const char *msisdn);

1227
src/libmsc/db.c

File diff suppressed because it is too large Load Diff

4
src/libmsc/sms_queue.c

@ -431,7 +431,7 @@ static void sms_send_next(struct vlr_subscr *vsub)
OSMO_ASSERT(!sms_subscriber_is_pending(smsq, vsub));
/* check for more messages for this subscriber */
sms = db_sms_get_unsent_for_subscr(vsub, UINT_MAX);
sms = db_sms_get_unsent_for_subscr(vsub, INT_MAX);
if (!sms)
goto no_pending_sms;
@ -537,7 +537,7 @@ static int sub_ready_for_sm(struct gsm_network *net, struct vlr_subscr *vsub)
}
/* Now try to deliver any pending SMS to this sub */
sms = db_sms_get_unsent_for_subscr(vsub, UINT_MAX);
sms = db_sms_get_unsent_for_subscr(vsub, INT_MAX);
if (!sms)
return -1;

1
src/osmo-msc/Makefile.am

@ -50,6 +50,5 @@ osmo_msc_LDADD = \
$(LIBOSMOMGCPCLIENT_LIBS) \
$(LIBOSMOGSUPCLIENT_LIBS) \
$(LIBSQLITE3_LIBS) \
-ldbi \
-lsctp \
$(NULL)

3
src/osmo-msc/msc_main.c

@ -685,7 +685,7 @@ TODO: we probably want some of the _net_ ctrl commands from bsc_base_ctrl_cmds_i
if (msc_cmdline_config.database_name)
osmo_talloc_replace_string(msc_network, &msc_network->sms_db_file_path, msc_cmdline_config.database_name);
if (db_init(msc_network->sms_db_file_path)) {
if (db_init(tall_msc_ctx, msc_network->sms_db_file_path, true)) {
fprintf(stderr, "DB: Failed to init database: %s\n",
osmo_quote_str((char*)msc_network->sms_db_file_path, -1));
return 4;
@ -799,6 +799,7 @@ TODO: we probably want some of the _net_ ctrl commands from bsc_base_ctrl_cmds_i
}
} while (!osmo_select_shutdown_done());
db_fini();
log_fini();
/**

1
tests/db_sms/Makefile.am

@ -49,5 +49,4 @@ db_sms_test_LDADD = \
$(LIBOSMOGSUPCLIENT_LIBS) \
$(LIBSQLITE3_LIBS) \
$(LIBRARY_GSM) \
-ldbi \
$(NULL)

2
tests/db_sms/db_sms_test.c

@ -538,7 +538,7 @@ int main(int argc, char **argv)
* the test output is not deterministic. Let's suppress this
* message by increasing the log level to LOGL_ERROR. */
log_parse_category_mask(osmo_stderr_target, "DDB,7");
rc = db_init(":memory:");
rc = db_init(talloc_ctx, ":memory:", true);
OSMO_ASSERT(rc == 0);
/* HACK: relax log level back to LOGL_DEBUG (see note above) */

1
tests/sms_queue/Makefile.am

@ -46,7 +46,6 @@ sms_queue_test_LDADD = \
$(LIBOSMOGSUPCLIENT_LIBS) \
$(LIBSQLITE3_LIBS) \
$(LIBRARY_GSM) \
-ldbi \
$(NULL)
sms_queue_test_LDFLAGS = \

Loading…
Cancel
Save