pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-pcap/+/39774?usp=email )
Change subject: pcap-server: Introduce VTY cmd file-write-queue-max-length ......................................................................
pcap-server: Introduce VTY cmd file-write-queue-max-length
This allows dimensioning the write queue used to write msgbs to disk.
Related: SYS#7374 Change-Id: I137f13481c03f82d11a2d38ba4fd5691a55535ce --- M include/osmo-pcap/osmo_pcap_server.h M src/osmo_pcap_wr_file.c M src/osmo_server_core.c M src/osmo_server_vty.c 4 files changed, 49 insertions(+), 0 deletions(-)
Approvals: Jenkins Builder: Verified osmith: Looks good to me, approved
diff --git a/include/osmo-pcap/osmo_pcap_server.h b/include/osmo-pcap/osmo_pcap_server.h index f97e4ae..12a2cb3 100644 --- a/include/osmo-pcap/osmo_pcap_server.h +++ b/include/osmo-pcap/osmo_pcap_server.h @@ -45,6 +45,7 @@
struct osmo_pcap_server;
+#define PCAP_SERVER_FILE_WRQUEUE_MAX_LEN 1024
#define STATE_INITIAL 0 #define STATE_DATA 1 @@ -83,6 +84,8 @@ char *filename; /* file descriptor of the file we write to */ struct osmo_io_fd *local_iofd; + /* Maximum size of write queue of pcap files being stored on disk: */ + size_t wr_queue_max_length; /* Current write offset of the file we write to (local_fd) */ off_t wr_offset; /* Number of bytes confirmed to be written, <=wr_offset */ @@ -90,6 +93,7 @@ osmo_pcap_wr_file_flush_completed_cb_t flush_completed_cb; }; struct osmo_pcap_wr_file *osmo_pcap_wr_file_alloc(void *ctx, void *data); +void osmo_pcap_wr_file_set_write_queue_max_length(struct osmo_pcap_wr_file *wrf, size_t max_len); void osmo_pcap_wr_file_free(struct osmo_pcap_wr_file *wrf); void osmo_pcap_wr_file_set_flush_completed_cb(struct osmo_pcap_wr_file *wrf, osmo_pcap_wr_file_flush_completed_cb_t flush_completed_cb); int osmo_pcap_wr_file_open(struct osmo_pcap_wr_file *wrf, const char *filename, mode_t mode); @@ -184,6 +188,8 @@ off_t max_size; bool max_size_enabled; int max_snaplen; + /* Maximum size of write queue of pcap files being stored on disk: */ + size_t file_wr_queue_max_length;
struct { bool enabled; diff --git a/src/osmo_pcap_wr_file.c b/src/osmo_pcap_wr_file.c index 582caa8..d60c5a7 100644 --- a/src/osmo_pcap_wr_file.c +++ b/src/osmo_pcap_wr_file.c @@ -75,6 +75,7 @@ * list in osmo_pcap_wr_file_is_flushing(): */ INIT_LLIST_HEAD(&wrf->entry); wrf->data = data; + wrf->wr_queue_max_length = PCAP_SERVER_FILE_WRQUEUE_MAX_LEN; wrf->wr_offset = 0; wrf->wr_completed = 0;
@@ -96,6 +97,13 @@ wrf->flush_completed_cb = flush_completed_cb; }
+void osmo_pcap_wr_file_set_write_queue_max_length(struct osmo_pcap_wr_file *wrf, size_t max_len) +{ + wrf->wr_queue_max_length = max_len; + if (wrf->local_iofd) + osmo_iofd_set_txqueue_max_length(wrf->local_iofd, wrf->wr_queue_max_length); +} + int osmo_pcap_wr_file_open(struct osmo_pcap_wr_file *wrf, const char *filename, mode_t mode) { struct osmo_io_ops ioops = { @@ -117,6 +125,7 @@ &ioops, wrf); if (!wrf->local_iofd) return -EBADFD; + osmo_iofd_set_txqueue_max_length(wrf->local_iofd, wrf->wr_queue_max_length); if (osmo_iofd_register(wrf->local_iofd, -1) < 0) { osmo_iofd_free(wrf->local_iofd); wrf->local_iofd = NULL; diff --git a/src/osmo_server_core.c b/src/osmo_server_core.c index 77d916a..4dc4178 100644 --- a/src/osmo_server_core.c +++ b/src/osmo_server_core.c @@ -349,6 +349,7 @@
conn->wrf = osmo_pcap_wr_file_alloc(conn, conn); osmo_pcap_wr_file_set_flush_completed_cb(conn->wrf, osmo_pcap_wr_file_flush_completed_cb); + osmo_pcap_wr_file_set_write_queue_max_length(conn->wrf, conn->server->file_wr_queue_max_length); rc = osmo_pcap_wr_file_open(conn->wrf, curr_filename, conn->server->permission_mask); talloc_free(curr_filename); if (rc < 0) @@ -578,6 +579,7 @@ psrv->max_size = 1073741824; /* 1024^3, 1GB **/ psrv->max_size_enabled = true; psrv->max_snaplen = DEFAULT_SNAPLEN; + psrv->file_wr_queue_max_length = PCAP_SERVER_FILE_WRQUEUE_MAX_LEN; /* By default rotate daily: */ psrv->rotate_localtime.enabled = true; psrv->rotate_localtime.intv = TIME_INTERVAL_DAY; diff --git a/src/osmo_server_vty.c b/src/osmo_server_vty.c index 51448ff..0a86633 100644 --- a/src/osmo_server_vty.c +++ b/src/osmo_server_vty.c @@ -100,6 +100,7 @@ if (pcap_server->completed_path) vty_out(vty, " completed-path %s%s", pcap_server->completed_path, VTY_NEWLINE); vty_out(vty, " file-permission-mask 0%o%s", pcap_server->permission_mask, VTY_NEWLINE); + vty_out(vty, " file-write-queue-max-length %zu%s", pcap_server->file_wr_queue_max_length, VTY_NEWLINE); if (pcap_server->addr) vty_out(vty, " server ip %s%s", pcap_server->addr, VTY_NEWLINE); if (pcap_server->port > 0) @@ -226,6 +227,36 @@ return CMD_WARNING; }
+DEFUN(cfg_server_file_write_queue_max_length, + cfg_server_file_write_queue_max_length_cmd, + "file-write-queue-max-length <0-4294967295>", + "Configure the write-queue used for storing received pcap data to disk\n" + "Maximum amount of packets before dropping starts (default " + OSMO_STRINGIFY_VAL(PCAP_SERVER_FILE_WRQUEUE_MAX_LEN) ")\n") +{ + struct osmo_pcap_conn *conn; + int64_t val; + + + if (osmo_str_to_int64(&val, argv[0], 10, 0, INT64_MAX)) { + vty_out(vty, "%% Error parsing value %s%s", argv[0], VTY_NEWLINE); + return CMD_WARNING; + } + + pcap_server->file_wr_queue_max_length = (size_t)val; + + llist_for_each_entry(conn, &pcap_server->conn, entry) { + if (!conn->wrf) + continue; + osmo_pcap_wr_file_set_write_queue_max_length(conn->wrf, + pcap_server->file_wr_queue_max_length); + /* wrfs in conn->wrf_flushing_list don't need queue size increase + * since anyway they won't get more data enqueued in it. */ + } + + return CMD_SUCCESS; +} + DEFUN(cfg_server_ip, cfg_server_ip_cmd, "server ip A.B.C.D", @@ -696,6 +727,7 @@ install_element(SERVER_NODE, &cfg_server_no_completed_path_cmd); install_element(SERVER_NODE, &cfg_server_completed_path_cmd); install_element(SERVER_NODE, &cfg_server_file_permission_mask_cmd); + install_element(SERVER_NODE, &cfg_server_file_write_queue_max_length_cmd); install_element(SERVER_NODE, &cfg_server_ip_cmd); install_element(SERVER_NODE, &cfg_server_port_cmd); install_element(SERVER_NODE, &cfg_server_no_rotate_localtime_cmd);