pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/39067?usp=email )
Change subject: osmo_io: Use early return to simplify code
......................................................................
osmo_io: Use early return to simplify code
Change-Id: Idd4c4f2da7f15b86ddd4765c60680130af08b22d
---
M src/core/osmo_io_uring.c
1 file changed, 19 insertions(+), 17 deletions(-)
Approvals:
Jenkins Builder: Verified
fixeria: Looks good to me, but someone else must approve
osmith: Looks good to me, approved
diff --git a/src/core/osmo_io_uring.c b/src/core/osmo_io_uring.c
index 569f150..1b1f997 100644
--- a/src/core/osmo_io_uring.c
+++ b/src/core/osmo_io_uring.c
@@ -498,24 +498,26 @@
static void iofd_uring_notify_connected(struct osmo_io_fd *iofd)
{
- if (iofd->mode == OSMO_IO_FD_MODE_RECVMSG_SENDMSG) {
- /* Don't call this function after enabling read or write. */
- OSMO_ASSERT(!iofd->u.uring.write_enabled && !iofd->u.uring.read_enabled);
-
- /* Use a temporary osmo_fd which we can use to notify us once the connection is established
- * or failed (indicated by FD becoming writable).
- * This is needed as (at least for SCTP sockets) one cannot submit a zero-length writev/sendmsg
- * in order to get notification when the socekt is writable.*/
- if (!IOFD_FLAG_ISSET(iofd, IOFD_FLAG_NOTIFY_CONNECTED)) {
- osmo_fd_setup(&iofd->u.uring.connect_ofd, iofd->fd, OSMO_FD_WRITE,
- iofd_uring_connected_cb, iofd, 0);
- if (osmo_fd_register(&iofd->u.uring.connect_ofd) < 0)
- LOGPIO(iofd, LOGL_ERROR, "Failed to register FD for connect event.\n");
- else
- IOFD_FLAG_SET(iofd, IOFD_FLAG_NOTIFY_CONNECTED);
- }
- } else
+ if (iofd->mode != OSMO_IO_FD_MODE_RECVMSG_SENDMSG) {
iofd_uring_write_enable(iofd);
+ return;
+ }
+
+ /* OSMO_IO_FD_MODE_RECVMSG_SENDMSG: Don't call this function after enabling read or write. */
+ OSMO_ASSERT(!iofd->u.uring.write_enabled && !iofd->u.uring.read_enabled);
+
+ /* Use a temporary osmo_fd which we can use to notify us once the connection is established
+ * or failed (indicated by FD becoming writable).
+ * This is needed as (at least for SCTP sockets) one cannot submit a zero-length writev/sendmsg
+ * in order to get notification when the socekt is writable.*/
+ if (!IOFD_FLAG_ISSET(iofd, IOFD_FLAG_NOTIFY_CONNECTED)) {
+ osmo_fd_setup(&iofd->u.uring.connect_ofd, iofd->fd, OSMO_FD_WRITE,
+ iofd_uring_connected_cb, iofd, 0);
+ if (osmo_fd_register(&iofd->u.uring.connect_ofd) < 0)
+ LOGPIO(iofd, LOGL_ERROR, "Failed to register FD for connect event.\n");
+ else
+ IOFD_FLAG_SET(iofd, IOFD_FLAG_NOTIFY_CONNECTED);
+ }
}
const struct iofd_backend_ops iofd_uring_ops = {
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/39067?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Idd4c4f2da7f15b86ddd4765c60680130af08b22d
Gerrit-Change-Number: 39067
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/39068?usp=email )
Change subject: osmo_io: uring: Setup connect_notify internal ofd during register() op
......................................................................
osmo_io: uring: Setup connect_notify internal ofd during register() op
osmo_fd used internally should only be registered during
osmo_iofd_register() time, not before.
Unregistering was already placed at the proper place.
Change-Id: Ifac374170736a9fe922362e95059a18c2a3ccaac
---
M src/core/osmo_io_uring.c
1 file changed, 59 insertions(+), 52 deletions(-)
Approvals:
osmith: Looks good to me, but someone else must approve
fixeria: Looks good to me, but someone else must approve
Jenkins Builder: Verified
pespin: Looks good to me, approved
diff --git a/src/core/osmo_io_uring.c b/src/core/osmo_io_uring.c
index 1b1f997..be7e1d8 100644
--- a/src/core/osmo_io_uring.c
+++ b/src/core/osmo_io_uring.c
@@ -324,8 +324,65 @@
static void iofd_uring_write_enable(struct osmo_io_fd *iofd);
static void iofd_uring_read_enable(struct osmo_io_fd *iofd);
+
+/* called via osmocom poll/select main handling once outbound non-blocking connect() completes */
+static int iofd_uring_connected_cb(struct osmo_fd *ofd, unsigned int what)
+{
+ struct osmo_io_fd *iofd = ofd->data;
+
+ LOGPIO(iofd, LOGL_DEBUG, "Socket connected or failed.\n");
+
+ if (!(what & OSMO_FD_WRITE))
+ return 0;
+
+ /* Unregister from poll/select handling. */
+ osmo_fd_unregister(ofd);
+ IOFD_FLAG_UNSET(iofd, IOFD_FLAG_NOTIFY_CONNECTED);
+
+ /* Notify the application about this via a zero-length write completion call-back. */
+ IOFD_FLAG_SET(iofd, IOFD_FLAG_IN_CALLBACK);
+ switch (iofd->mode) {
+ case OSMO_IO_FD_MODE_READ_WRITE:
+ iofd->io_ops.write_cb(iofd, 0, NULL);
+ break;
+ case OSMO_IO_FD_MODE_RECVFROM_SENDTO:
+ iofd->io_ops.sendto_cb(iofd, 0, NULL, NULL);
+ break;
+ case OSMO_IO_FD_MODE_RECVMSG_SENDMSG:
+ iofd->io_ops.sendmsg_cb(iofd, 0, NULL);
+ break;
+ }
+ IOFD_FLAG_UNSET(iofd, IOFD_FLAG_IN_CALLBACK);
+
+ /* If write/read notifications are pending, enable it now. */
+ if (iofd->u.uring.write_enabled && !IOFD_FLAG_ISSET(iofd, IOFD_FLAG_CLOSED))
+ iofd_uring_write_enable(iofd);
+ if (iofd->u.uring.read_enabled && !IOFD_FLAG_ISSET(iofd, IOFD_FLAG_CLOSED))
+ iofd_uring_read_enable(iofd);
+
+ if (IOFD_FLAG_ISSET(iofd, IOFD_FLAG_TO_FREE) && !iofd->u.uring.read_msghdr && !iofd->u.uring.write_msghdr)
+ talloc_free(iofd);
+ return 0;
+}
+
static int iofd_uring_register(struct osmo_io_fd *iofd)
{
+ if (iofd->mode != OSMO_IO_FD_MODE_RECVMSG_SENDMSG)
+ return 0; /* Nothing to be done */
+
+ /* OSMO_IO_FD_MODE_RECVMSG_SENDMSG:
+ * Use a temporary osmo_fd which we can use to notify us once the connection is established
+ * or failed (indicated by FD becoming writable). This is needed as (at least for SCTP sockets)
+ * one cannot submit a zero-length writev/sendmsg in order to get notification when the socekt
+ * is writable.*/
+ if (IOFD_FLAG_ISSET(iofd, IOFD_FLAG_NOTIFY_CONNECTED)) {
+ osmo_fd_setup(&iofd->u.uring.connect_ofd, iofd->fd, OSMO_FD_WRITE,
+ iofd_uring_connected_cb, iofd, 0);
+ if (osmo_fd_register(&iofd->u.uring.connect_ofd) < 0) {
+ LOGPIO(iofd, LOGL_ERROR, "Failed to register FD for connect event.\n");
+ return -EBADFD;
+ }
+ }
return 0;
}
@@ -456,46 +513,6 @@
return close(iofd->fd);
}
-/* called via osmocom poll/select main handling once outbound non-blocking connect() completes */
-static int iofd_uring_connected_cb(struct osmo_fd *ofd, unsigned int what)
-{
- struct osmo_io_fd *iofd = ofd->data;
-
- LOGPIO(iofd, LOGL_DEBUG, "Socket connected or failed.\n");
-
- if (!(what & OSMO_FD_WRITE))
- return 0;
-
- /* Unregister from poll/select handling. */
- osmo_fd_unregister(ofd);
- IOFD_FLAG_UNSET(iofd, IOFD_FLAG_NOTIFY_CONNECTED);
-
- /* Notify the application about this via a zero-length write completion call-back. */
- IOFD_FLAG_SET(iofd, IOFD_FLAG_IN_CALLBACK);
- switch (iofd->mode) {
- case OSMO_IO_FD_MODE_READ_WRITE:
- iofd->io_ops.write_cb(iofd, 0, NULL);
- break;
- case OSMO_IO_FD_MODE_RECVFROM_SENDTO:
- iofd->io_ops.sendto_cb(iofd, 0, NULL, NULL);
- break;
- case OSMO_IO_FD_MODE_RECVMSG_SENDMSG:
- iofd->io_ops.sendmsg_cb(iofd, 0, NULL);
- break;
- }
- IOFD_FLAG_UNSET(iofd, IOFD_FLAG_IN_CALLBACK);
-
- /* If write/read notifications are pending, enable it now. */
- if (iofd->u.uring.write_enabled && !IOFD_FLAG_ISSET(iofd, IOFD_FLAG_CLOSED))
- iofd_uring_write_enable(iofd);
- if (iofd->u.uring.read_enabled && !IOFD_FLAG_ISSET(iofd, IOFD_FLAG_CLOSED))
- iofd_uring_read_enable(iofd);
-
- if (IOFD_FLAG_ISSET(iofd, IOFD_FLAG_TO_FREE) && !iofd->u.uring.read_msghdr && !iofd->u.uring.write_msghdr)
- talloc_free(iofd);
- return 0;
-}
-
static void iofd_uring_notify_connected(struct osmo_io_fd *iofd)
{
if (iofd->mode != OSMO_IO_FD_MODE_RECVMSG_SENDMSG) {
@@ -506,18 +523,8 @@
/* OSMO_IO_FD_MODE_RECVMSG_SENDMSG: Don't call this function after enabling read or write. */
OSMO_ASSERT(!iofd->u.uring.write_enabled && !iofd->u.uring.read_enabled);
- /* Use a temporary osmo_fd which we can use to notify us once the connection is established
- * or failed (indicated by FD becoming writable).
- * This is needed as (at least for SCTP sockets) one cannot submit a zero-length writev/sendmsg
- * in order to get notification when the socekt is writable.*/
- if (!IOFD_FLAG_ISSET(iofd, IOFD_FLAG_NOTIFY_CONNECTED)) {
- osmo_fd_setup(&iofd->u.uring.connect_ofd, iofd->fd, OSMO_FD_WRITE,
- iofd_uring_connected_cb, iofd, 0);
- if (osmo_fd_register(&iofd->u.uring.connect_ofd) < 0)
- LOGPIO(iofd, LOGL_ERROR, "Failed to register FD for connect event.\n");
- else
- IOFD_FLAG_SET(iofd, IOFD_FLAG_NOTIFY_CONNECTED);
- }
+ /* Set flag to enable temporary osmo_fd during register() time: */
+ IOFD_FLAG_SET(iofd, IOFD_FLAG_NOTIFY_CONNECTED);
}
const struct iofd_backend_ops iofd_uring_ops = {
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/39068?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ifac374170736a9fe922362e95059a18c2a3ccaac
Gerrit-Change-Number: 39068
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/39070?usp=email )
Change subject: osmo_io: close() op in backend only takes care of closing
......................................................................
osmo_io: close() op in backend only takes care of closing
Move dependent steps such as unregister to be done at the common path,
and leave the close() op on each backend to implement only the specific
close operations.
Change-Id: I0150afcc0b83ea8b2d00d108658ed688ce487f7f
---
M src/core/osmo_io.c
M src/core/osmo_io_poll.c
M src/core/osmo_io_uring.c
3 files changed, 4 insertions(+), 5 deletions(-)
Approvals:
Jenkins Builder: Verified
fixeria: Looks good to me, but someone else must approve
osmith: Looks good to me, but someone else must approve
pespin: Looks good to me, approved
diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c
index cef9bec..387cefb 100644
--- a/src/core/osmo_io.c
+++ b/src/core/osmo_io.c
@@ -845,6 +845,10 @@
iofd->pending = NULL;
+ osmo_iofd_ops.read_disable(iofd);
+ osmo_iofd_ops.write_disable(iofd);
+ osmo_iofd_unregister(iofd);
+
rc = osmo_iofd_ops.close(iofd);
iofd->fd = -1;
return rc;
diff --git a/src/core/osmo_io_poll.c b/src/core/osmo_io_poll.c
index 89ff466..92f03f8 100644
--- a/src/core/osmo_io_poll.c
+++ b/src/core/osmo_io_poll.c
@@ -156,9 +156,7 @@
static int iofd_poll_close(struct osmo_io_fd *iofd)
{
- iofd_poll_unregister(iofd);
osmo_fd_close(&iofd->u.poll.ofd);
-
return 0;
}
diff --git a/src/core/osmo_io_uring.c b/src/core/osmo_io_uring.c
index be7e1d8..72a465e 100644
--- a/src/core/osmo_io_uring.c
+++ b/src/core/osmo_io_uring.c
@@ -507,9 +507,6 @@
static int iofd_uring_close(struct osmo_io_fd *iofd)
{
- iofd_uring_read_disable(iofd);
- iofd_uring_write_disable(iofd);
- iofd_uring_unregister(iofd);
return close(iofd->fd);
}
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/39070?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I0150afcc0b83ea8b2d00d108658ed688ce487f7f
Gerrit-Change-Number: 39070
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/39071?usp=email )
Change subject: osmo_io: Track IOFD_FLAG_FD_REGISTERED in all backends
......................................................................
osmo_io: Track IOFD_FLAG_FD_REGISTERED in all backends
This will be used in common segmentation handling code to figure out
whether the iofd is still registered or was unregistered by the user
during the read cb, in order to know whether to continue submitting read
events upwards or to discard the handling.
Change-Id: Id5e92aa22ce1c5d76028c539784118be227b9d5a
---
M src/core/osmo_io.c
M src/core/osmo_io_poll.c
2 files changed, 21 insertions(+), 15 deletions(-)
Approvals:
Jenkins Builder: Verified
osmith: Looks good to me, but someone else must approve
pespin: Looks good to me, approved
fixeria: Looks good to me, but someone else must approve
diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c
index 387cefb..c61c8e9 100644
--- a/src/core/osmo_io.c
+++ b/src/core/osmo_io.c
@@ -737,19 +737,29 @@
{
int rc = 0;
- if (fd >= 0)
- iofd->fd = fd;
- else if (iofd->fd < 0) {
+ if (fd < 0 && iofd->fd < 0) {
/* this might happen if both osmo_iofd_setup() and osmo_iofd_register() are called with -1 */
LOGPIO(iofd, LOGL_ERROR, "Cannot register io_fd using invalid fd == %d\n", iofd->fd);
return -EBADF;
}
+ if (fd < 0)
+ fd = iofd->fd;
+ else if (iofd->fd < 0)
+ iofd->fd = fd;
+
+ if (IOFD_FLAG_ISSET(iofd, IOFD_FLAG_FD_REGISTERED)) {
+ /* If re-registering same fd, handle as NO-OP.
+ * New FD should go through unregister() first. */
+ return iofd->fd == fd ? 0 : -ENOTSUP;
+ }
rc = osmo_iofd_ops.register_fd(iofd);
if (rc)
return rc;
IOFD_FLAG_UNSET(iofd, IOFD_FLAG_CLOSED);
+ IOFD_FLAG_SET(iofd, IOFD_FLAG_FD_REGISTERED);
+
if ((iofd->mode == OSMO_IO_FD_MODE_READ_WRITE && iofd->io_ops.read_cb) ||
(iofd->mode == OSMO_IO_FD_MODE_RECVFROM_SENDTO && iofd->io_ops.recvfrom_cb) ||
(iofd->mode == OSMO_IO_FD_MODE_RECVMSG_SENDMSG && iofd->io_ops.recvmsg_cb)) {
@@ -772,7 +782,14 @@
*/
int osmo_iofd_unregister(struct osmo_io_fd *iofd)
{
- return osmo_iofd_ops.unregister_fd(iofd);
+ int rc;
+
+ if (!IOFD_FLAG_ISSET(iofd, IOFD_FLAG_FD_REGISTERED))
+ return 0;
+
+ rc = osmo_iofd_ops.unregister_fd(iofd);
+ IOFD_FLAG_UNSET(iofd, IOFD_FLAG_FD_REGISTERED);
+ return rc;
}
/*! Retrieve the number of messages pending in the transmit queue.
diff --git a/src/core/osmo_io_poll.c b/src/core/osmo_io_poll.c
index 92f03f8..bf0291e 100644
--- a/src/core/osmo_io_poll.c
+++ b/src/core/osmo_io_poll.c
@@ -128,29 +128,18 @@
struct osmo_fd *ofd = &iofd->u.poll.ofd;
int rc;
- if (IOFD_FLAG_ISSET(iofd, IOFD_FLAG_FD_REGISTERED))
- return 0;
-
osmo_fd_setup(ofd, iofd->fd, 0, &iofd_poll_ofd_cb_dispatch, iofd, 0);
if (IOFD_FLAG_ISSET(iofd, IOFD_FLAG_NOTIFY_CONNECTED))
osmo_fd_write_enable(&iofd->u.poll.ofd);
rc = osmo_fd_register(ofd);
- if (!rc)
- IOFD_FLAG_SET(iofd, IOFD_FLAG_FD_REGISTERED);
-
return rc;
}
static int iofd_poll_unregister(struct osmo_io_fd *iofd)
{
struct osmo_fd *ofd = &iofd->u.poll.ofd;
-
- if (!IOFD_FLAG_ISSET(iofd, IOFD_FLAG_FD_REGISTERED))
- return 0;
osmo_fd_unregister(ofd);
- IOFD_FLAG_UNSET(iofd, IOFD_FLAG_FD_REGISTERED);
-
return 0;
}
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/39071?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Id5e92aa22ce1c5d76028c539784118be227b9d5a
Gerrit-Change-Number: 39071
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Attention is currently required from: fixeria.
pespin has posted comments on this change by fixeria. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/39079?usp=email )
Change subject: s1gw: add constants for PFCP FAR IDs
......................................................................
Patch Set 1: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/39079?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: Ib25e5cc9ca21047f9884e1c13d0861bf4f7251a1
Gerrit-Change-Number: 39079
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-CC: Jenkins Builder
Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Comment-Date: Tue, 10 Dec 2024 11:21:30 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes