pespin submitted this change.

View Change

Approvals: Jenkins Builder: Verified jolly: Looks good to me, but someone else must approve pespin: Looks good to me, approved laforge: Looks good to me, but someone else must approve fixeria: Looks good to me, but someone else must approve
io_uring: Avoid extra reads if iofd becomes unregistered by user

The user callback (read_cb, segmentation_cb, etc.) may decide to
unregister the iofd instead of closing it. In this scenario, we should
avoid calling the callback further until the iofd is registered again.

Change-Id: I231d5a16768b730f67089090c244bcc10dc69c3a
---
M src/core/osmo_io_uring.c
M tests/osmo_io/osmo_io_test.c
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/core/osmo_io_uring.c b/src/core/osmo_io_uring.c
index 01b8063..e4a87ad 100644
--- a/src/core/osmo_io_uring.c
+++ b/src/core/osmo_io_uring.c
@@ -359,7 +359,7 @@
}

/* Check for every iteration, because iofd might get unregistered/closed during receive function. */
- if (iofd->u.uring.read.enabled && !IOFD_FLAG_ISSET(iofd, IOFD_FLAG_CLOSED))
+ if (IOFD_FLAG_ISSET(iofd, IOFD_FLAG_FD_REGISTERED) && iofd->u.uring.read.enabled)
iofd_handle_recv(iofd, msg, chunk, msghdr);
else
msgb_free(msg);
@@ -372,7 +372,7 @@
msghdr->msg[idx] = NULL;
}

- if (iofd->u.uring.read.enabled && !IOFD_FLAG_ISSET(iofd, IOFD_FLAG_CLOSED))
+ if (IOFD_FLAG_ISSET(iofd, IOFD_FLAG_FD_REGISTERED) && iofd->u.uring.read.enabled)
iofd_uring_submit_recv(iofd, msghdr->action);

iofd_msghdr_free(msghdr);
diff --git a/tests/osmo_io/osmo_io_test.c b/tests/osmo_io/osmo_io_test.c
index 0812ea8..06491a7 100644
--- a/tests/osmo_io/osmo_io_test.c
+++ b/tests/osmo_io/osmo_io_test.c
@@ -280,7 +280,7 @@
} else {
OSMO_ASSERT(rc == 0);
file_eof_read = true;
- osmo_iofd_close(iofd);
+ osmo_iofd_unregister(iofd);
}
talloc_free(msg);
}

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

Gerrit-MessageType: merged
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I231d5a16768b730f67089090c244bcc10dc69c3a
Gerrit-Change-Number: 41300
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: jolly <andreas@eversberg.eu>
Gerrit-Reviewer: laforge <laforge@osmocom.org>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>