pespin has uploaded this change for review. ( 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(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/68/39068/1
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: newchange
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ifac374170736a9fe922362e95059a18c2a3ccaac
Gerrit-Change-Number: 39068
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
pespin has uploaded this change for review. ( 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(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/70/39070/1
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: newchange
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I0150afcc0b83ea8b2d00d108658ed688ce487f7f
Gerrit-Change-Number: 39070
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/39072?usp=email )
Change subject: osmo_io: segmented_read: Avoid triggering read events if user unregisters
......................................................................
osmo_io: segmented_read: Avoid triggering read events if user unregisters
The user code doesn't expect to receive any more read cb events after
unregistering the FD. Avoid keep calling the read cb if several entire
messages were received at once in a single tcp chunk.
Related: SYS#7063
Change-Id: Id2199b9aa805cc7e7793c1a8aecd10b61f2b4c90
---
M src/core/osmo_io.c
1 file changed, 9 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/72/39072/1
diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c
index c61c8e9..d1767d2 100644
--- a/src/core/osmo_io.c
+++ b/src/core/osmo_io.c
@@ -340,8 +340,16 @@
do {
pending = NULL;
res = iofd_handle_segmentation(iofd, msg, &pending);
- if (res != IOFD_SEG_ACT_DEFER || rc < 0)
+ if (res != IOFD_SEG_ACT_DEFER || rc < 0) {
iofd->io_ops.read_cb(iofd, rc, msg);
+ /* The user could unregister/close the iofd during read_cb() above.
+ * Once that's done, it doesn't expect to receive any more events,
+ * so discard it: */
+ if (!IOFD_FLAG_ISSET(iofd, IOFD_FLAG_FD_REGISTERED)) {
+ msgb_free(pending);
+ return;
+ }
+ }
if (res == IOFD_SEG_ACT_HANDLE_MORE)
msg = pending;
} while (res == IOFD_SEG_ACT_HANDLE_MORE);
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/39072?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Id2199b9aa805cc7e7793c1a8aecd10b61f2b4c90
Gerrit-Change-Number: 39072
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
pespin has uploaded this change for review. ( 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(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/71/39071/1
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: newchange
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Id5e92aa22ce1c5d76028c539784118be227b9d5a
Gerrit-Change-Number: 39071
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
pespin has uploaded this change for review. ( 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(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/67/39067/1
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: newchange
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Idd4c4f2da7f15b86ddd4765c60680130af08b22d
Gerrit-Change-Number: 39067
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>