pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/39369?usp=email )
Change subject: stream: Add osmo_stream_srv_link_set_msgb_alloc_info() ......................................................................
stream: Add osmo_stream_srv_link_set_msgb_alloc_info()
This is needed so that user can set desired headroom+size info on rx-allocated msgbs, so that osmo_stream_srv can inherit them upon osmo_stream_srv_create2().
Manually obtaining the iofd through osmo_stream_srv_get_iofd() and changing the params directly in the iofd produces undesired effects, since the first msgbs are alredy allocated during osmo_stream_srv_create2 (which calls osmo_iofd_register()) before the object is available to the user. As a result, first rx messages may come with unexpected size/headroom.
Ideally we'd had written the osmo_stream_srv APIs to have a 2 step setup, eg _alloc() + _run()/_start(), but too late to do so now. This approach is already follwed by existing osmo_stream_srv_link_set_tx_queue_max_length() API.
Change-Id: I80a1c4b227629e3ca0c8c587a103db6057322cb4 --- M TODO-RELEASE M include/osmocom/netif/stream.h M src/stream_srv.c 3 files changed, 34 insertions(+), 0 deletions(-)
Approvals: laforge: Looks good to me, but someone else must approve pespin: Looks good to me, approved osmith: Looks good to me, but someone else must approve Jenkins Builder: Verified
diff --git a/TODO-RELEASE b/TODO-RELEASE index e66b421..dfdbd89 100644 --- a/TODO-RELEASE +++ b/TODO-RELEASE @@ -11,3 +11,4 @@ libosmo-netif add API osmo-stream_cli_set_tx_queue_max_length(), osmo_stream_srv_link_set_tx_queue_max_length() libosmo-netif add API struct osmo_ipa_ka_fsm_inst libosmo-netif add API osmo_stream_{cli,srv}_set_segmentation_cb2() +libosmo-netif add API osmo_stream_srv_link_set_msgb_alloc_info() diff --git a/include/osmocom/netif/stream.h b/include/osmocom/netif/stream.h index e793a26..83f17d7 100644 --- a/include/osmocom/netif/stream.h +++ b/include/osmocom/netif/stream.h @@ -88,6 +88,7 @@ char *osmo_stream_srv_link_get_sockname(const struct osmo_stream_srv_link *link); struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link); int osmo_stream_srv_link_get_fd(const struct osmo_stream_srv_link *link); +int osmo_stream_srv_link_set_msgb_alloc_info(struct osmo_stream_srv_link *link, unsigned int size, unsigned int headroom); bool osmo_stream_srv_link_is_opened(const struct osmo_stream_srv_link *link); int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link); void osmo_stream_srv_link_close(struct osmo_stream_srv_link *link); diff --git a/src/stream_srv.c b/src/stream_srv.c index c2b187a..261539b 100644 --- a/src/stream_srv.c +++ b/src/stream_srv.c @@ -69,6 +69,15 @@ * Server side. */
+struct msgb_alloc_info { + /*! Whether it was set by user or we use iofd defaults */ + bool set_by_user; + /*! size of msgb to allocate (excluding headroom) */ + unsigned int size; + /*! headroom to allocate when allocating msgb's */ + unsigned int headroom; +}; + #define OSMO_STREAM_SRV_F_RECONF (1 << 0) #define OSMO_STREAM_SRV_F_NODELAY (1 << 1)
@@ -88,6 +97,7 @@ void *data; int flags; unsigned int tx_queue_max_length; /* Max amount of msgbs which can be enqueued */ + struct msgb_alloc_info msgb_alloc; struct osmo_sock_init2_multiaddr_pars ma_pars; };
@@ -506,6 +516,26 @@ link->accept_cb = accept_cb; }
+/*! Set the msgb allocation parameters on child osmo_stream_srv objects + * \param[in] link Stream Server Link + * \param[in] size Size of msgb to allocate (excluding headroom) + * \param[in] headroom Headroom to allocate when allocating msgb's + * + * The parameters are applied to osmo_stream_srv objects upon creation. + * Setting both to 0 leaves it as implementation default. + **/ +int osmo_stream_srv_link_set_msgb_alloc_info(struct osmo_stream_srv_link *link, unsigned int size, unsigned int headroom) +{ + if (size == 0 && headroom == 0) { + link->msgb_alloc.set_by_user = false; + } else { + link->msgb_alloc.set_by_user = true; + link->msgb_alloc.headroom = headroom; + link->msgb_alloc.size = size; + } + return 0; +} + /*! Destroy the stream server link. Closes + Releases Memory. * \param[in] link Stream Server Link */ void osmo_stream_srv_link_destroy(struct osmo_stream_srv_link *link) @@ -962,6 +992,8 @@ }
osmo_iofd_set_txqueue_max_length(conn->iofd, conn->srv->tx_queue_max_length); + if (conn->srv->msgb_alloc.set_by_user) + osmo_iofd_set_alloc_info(conn->iofd, conn->srv->msgb_alloc.size, conn->srv->msgb_alloc.headroom);
if (osmo_iofd_register(conn->iofd, fd) < 0) { LOGSSRV(conn, LOGL_ERROR, "could not register FD %d\n", fd);