laforge has uploaded this change for review.

View Change

WIP: migrate gsmtap logging over to osmo_io

This is working in principle; The problem is just that osmo_io itself
contains LOGP calls from within osmo_iofd_write_msgb() and downstream
code, so we might easily get up in an infinite recursion bug.

This needs further study; possibly we need a "safe" logging function
which will never use osmo_io. Or something like a per-thread global
boolean variable which the code can check to know if it's re-entering?

Change-Id: I69d7eca7d50666b4fcfe73a1dc03f8e8491b32fc
---
M include/osmocom/core/gsmtap_util.h
M src/core/gsmtap_util.c
M src/core/libosmocore.map
M src/vty/logging_vty.c
4 files changed, 41 insertions(+), 5 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/62/36362/1
diff --git a/include/osmocom/core/gsmtap_util.h b/include/osmocom/core/gsmtap_util.h
index d24ee95..e755931 100644
--- a/include/osmocom/core/gsmtap_util.h
+++ b/include/osmocom/core/gsmtap_util.h
@@ -1,5 +1,6 @@
#pragma once

+#include <stdbool.h>
#include <stdint.h>
#include <osmocom/core/write_queue.h>
#include <osmocom/core/select.h>
@@ -31,6 +32,8 @@

int gsmtap_inst_fd2(const struct gsmtap_inst *gti);

+bool gsmtap_inst_get_osmo_io_mode(const struct gsmtap_inst *gti);
+
int gsmtap_source_init_fd(const char *host, uint16_t port);
int gsmtap_source_init_fd2(const char *local_host, uint16_t local_port, const char *rem_host, uint16_t rem_port);

diff --git a/src/core/gsmtap_util.c b/src/core/gsmtap_util.c
index b64c7b0..6c36b28 100644
--- a/src/core/gsmtap_util.c
+++ b/src/core/gsmtap_util.c
@@ -38,6 +38,7 @@
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
+#include <stdbool.h>
#include <string.h>
#include <errno.h>

@@ -85,6 +86,12 @@
return gti->wq.bfd.fd;
}

+/*! determine whether the gsmtap_inst is in osmo_io mode or not. */
+bool gsmtap_inst_get_osmo_io_mode(const struct gsmtap_inst *gti)
+{
+ return gti->osmo_io_mode;
+}
+
/*! convert RSL channel number to GSMTAP channel type
* \param[in] rsl_chantype RSL channel type
* \param[in] link_id RSL link identifier
diff --git a/src/core/libosmocore.map b/src/core/libosmocore.map
index 072efee..bdbfe07 100644
--- a/src/core/libosmocore.map
+++ b/src/core/libosmocore.map
@@ -41,6 +41,7 @@
gsmtap_gsm_channel_names;
gsmtap_inst_fd;
gsmtap_inst_fd2;
+gsmtap_inst_get_osmo_io_mode;
gsmtap_makemsg;
gsmtap_makemsg_ex;
gsmtap_send;
diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c
index 2a07422..bfe73bb 100644
--- a/src/vty/logging_vty.c
+++ b/src/vty/logging_vty.c
@@ -29,6 +29,7 @@
#include <osmocom/core/strrb.h>
#include <osmocom/core/loggingrb.h>
#include <osmocom/core/gsmtap.h>
+#include <osmocom/core/gsmtap_util.h>
#include <osmocom/core/application.h>

#include <osmocom/vty/command.h>
@@ -803,18 +804,24 @@
}

DEFUN(cfg_log_gsmtap, cfg_log_gsmtap_cmd,
- "log gsmtap [HOSTNAME]",
+ "log gsmtap [HOSTNAME] [sync-io]",
LOG_STR "Logging via GSMTAP\n"
"Host name to send the GSMTAP logging to (UDP port 4729)\n")
{
- const char *hostname = argc ? argv[0] : "127.0.0.1";
+ const char *hostname = "127.0.0.1";
+ bool async_io = true;
struct log_target *tgt;

+ if (argc >= 1)
+ hostname = argv[0];
+ if (argc >= 2 && !strcmp(argv[1], "sync-io"))
+ async_io = false;
+
log_tgt_mutex_lock();
tgt = log_target_find(LOG_TGT_TYPE_GSMTAP, hostname);
if (!tgt) {
tgt = log_target_create_gsmtap(hostname, GSMTAP_UDP_PORT,
- host.app_info->name, false,
+ host.app_info->name, async_io,
true);
if (!tgt) {
vty_out(vty, "%% Unable to create GSMTAP log for %s%s",
@@ -1032,8 +1039,9 @@
log_target_rb_avail_size(tgt), VTY_NEWLINE);
break;
case LOG_TGT_TYPE_GSMTAP:
- vty_out(vty, "log gsmtap %s%s",
- tgt->tgt_gsmtap.hostname, VTY_NEWLINE);
+ vty_out(vty, "log gsmtap %s%s%s", tgt->tgt_gsmtap.hostname,
+ gsmtap_inst_get_osmo_io_mode(tgt->tgt_gsmtap.gsmtap_inst) ? "" : " sync-io",
+ VTY_NEWLINE);
break;
case LOG_TGT_TYPE_SYSTEMD:
vty_out(vty, "log systemd-journal%s%s",

To view, visit change 36362. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I69d7eca7d50666b4fcfe73a1dc03f8e8491b32fc
Gerrit-Change-Number: 36362
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge@osmocom.org>
Gerrit-MessageType: newchange